commit b03e832c78721f58049b2c37957fce86015a064e Author: Hackpad Date: Fri Aug 14 12:11:45 2015 -0700 Improvements diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8f81f5c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +.gitattributes export-ignore +.gitignore export-ignore +client export-ignore +rhino1_7R1 export-ignore +phantom export-ignore +etherpad/etc/Hackpad-APNS-beta.p12 export-ignore +etherpad/etc/Hackpad-APNS.p12 export-ignore +etherpad/etc/Hackpad-APNS-debug.p12 export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f31df61 --- /dev/null +++ b/.gitignore @@ -0,0 +1,152 @@ +*~ +etherpad/etc/etherpad.local.properties +etherpad/src/etherpad/collab/ace/contentcollector.js +etherpad/src/etherpad/collab/ace/domline.js +etherpad/src/etherpad/collab/ace/easysync1.js +etherpad/src/etherpad/collab/ace/easysync2.js +etherpad/src/etherpad/collab/ace/easysync2_tests.js +etherpad/src/etherpad/collab/ace/linestylefilter.js +etherpad/src/static/js/ace.js +etherpad/src/static/js/colorutils.js +etherpad/src/static/js/cssmanager_client.js +etherpad/src/static/js/domline_client.js +etherpad/src/static/js/easysync2_client.js +etherpad/src/static/js/linestylefilter_client.js +etherpad/*.log +infrastructure/lib/cos.jar +build-arch-stamp +build-indep-stamp +configure-stamp +infrastructure/lib/mysql-connector*.jar +debian/etherpad.debhelper.log +debian/etherpad.*.debhelper +debian/etherpad.substvars +debian/etherpad +debian/files +build-stamp +infrastructure/lib/mysql-*.jar +.tags +.tags_sorted_by_file + +# https://gist.github.com/3786883 +######################### +# .gitignore file for Xcode4 / OS X Source projects +# +# NB: if you are storing "built" products, this WILL NOT WORK, +# and you should use a different .gitignore (or none at all) +# This file is for SOURCE projects, where there are many extra +# files that we want to exclude +# +# For updates, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects +######################### + +##### +# OS X temporary files that should never be committed + +.DS_Store +*.swp +*.lock +profile + + +#### +# Xcode temporary files that should never be committed +# +# NB: NIB/XIB files still exist even on Storyboard projects, so we want this... + +*~.nib + + +#### +# Xcode build files - +# +# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "DerivedData" + +DerivedData/ + +# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "build" + +build/ + + +##### +# Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups) +# +# This is complicated: +# +# SOMETIMES you need to put this file in version control. +# Apple designed it poorly - if you use "custom executables", they are +# saved in this file. +# 99% of projects do NOT use those, so they do NOT want to version control this file. +# ..but if you're in the 1%, comment out the line "*.pbxuser" + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 +# NB: also, whitelist the default ones, some projects need to use these +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + + +#### +# Xcode 4 - semi-personal settings, often included in workspaces +# +# You can safely ignore the xcuserdata files - but do NOT ignore the files next to them +# + +xcuserdata + +#### +# XCode 4 workspaces - more detailed +# +# Workspaces are important! They are a core feature of Xcode - don't exclude them :) +# +# Workspace layout is quite spammy. For reference: +# +# (root)/ +# (project-name).xcodeproj/ +# project.pbxproj +# project.xcworkspace/ +# contents.xcworkspacedata +# xcuserdata/ +# (your name)/xcuserdatad/ +# xcuserdata/ +# (your name)/xcuserdatad/ +# +# +# +# Xcode 4 workspaces - SHARED +# +# This is UNDOCUMENTED (google: "developer.apple.com xcshareddata" - 0 results +# But if you're going to kill personal workspaces, at least keep the shared ones... +# +# +!xcshareddata + +#### +# XCode 4 build-schemes +# +# PRIVATE ones are stored inside xcuserdata +!xcschemes + +#### +# Xcode 4 - Deprecated classes +# +# Allegedly, if you manually "deprecate" your classes, they get moved here. +# +# We're using source-control, so this is a "feature" that we do not want! + +*.moved-aside + + +#### +# UNKNOWN: recommended by others, but I can't discover what these files are +# +# ...none. Everything is now explained. +pad.sublime-project +pad.sublime-workspace +*.xccheckout + diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ce78d8b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "infrastructure/SimpleWebRTC"] + path = infrastructure/SimpleWebRTC + url = git@github.com:HenrikJoreteg/SimpleWebRTC.git diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..20f2fe2 --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,40 @@ +This file has been automatically created using +git log | grep Author: | sort | uniq | sed -e "s+Author: ++g" > CONTRIBUTORS +Manual annotations in braces. Email addresses might or might not be proper email addresses. + +Aaron Iba +Chris Ball +Christian Geier +Colin Zwiebel +Dan Bentley +David Greenspan +Egil Moeller +Elliot Kroo +Elliot Kroo +Elliot Kroo +etherpad +geier +Han Wei +holtzermann17 +Jeff Mitchell +Jeppe Toustrup +Joe Corneli +Joe Corneli +Joseph Corneli +Michael Forrest +Michael Prasuhn +Mikko Rantalainen +Mikyter +penSec.IT UG (haftungsbeschränkt) +Per Andersson +Peter Martischka +Peter Martischka +Peter Martischka +redhog (Egil Möller) +root (John McLear) +root (John McLear) +Sam Freilich +Simon Bohlin +Simon B @piratpartiet +soh335 +TechKid diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/COPYING @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..2316143 --- /dev/null +++ b/INSTALL @@ -0,0 +1,27 @@ +INSTALLATION INSTRUCTIONS + +INSTALLING ON POSIX COMPATIBLE SYSTEMS + +* Install the dependencies: Scala 2.7, Sun Java JDK 7, libmysql-java, mysql + +* Edit the file bin/exports.sh (and optionally + etherpad/bin/etherpad.default) and change the paths to + match your system. + +* Run bin/build.sh + +* Run contrib/scripts/setup-mysql-db.sh + +* Copy etherpad/etc/etherpad.localdev-default.properties to etherpad/etc/etherpad.local.properties +* Edit etherpad/etc/etherpad.local.properties and set + etherpad.superUserEmailAddresses + Example: etherpad.superUserEmailAddresses = name1@example.com,name2@example.com + topdomains + Example: topdomains = yourhostname.com,localhost + +* You can now run etherpad via bin/run.sh + +* If you want emoji support go to https://github.com/github/gemoji/tree/master/images/emoji/unicode + and copy the images into etherpad/src/static/img/emoji/unicode/ + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e6c255f --- /dev/null +++ b/LICENSE @@ -0,0 +1,324 @@ + +Copyright (c) 2015 Dropbox, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software d +istributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied. See the License for the specific language governing permissions and +limitations under the License. + +>>>>>>>>>>>>>> +This software builds on code released by various organizations. Their +copyright and licenses are stated below. The rest is copyright the +Etherpad Foundation contributors, listed in the CONTRIBUTORS file, and +licensed under the Apache License 2.0. + +========================================================================= +Copyright of the original Google code release + +This distribution includes some code written by other organizations. +The rest is Copyright 2007-2009 Google Inc. and licensed under the Apache License 2.0. +========================================================================= + +>>>>>>>>>>>>>> +Apache Commons Lang +Copyright 2001-2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + +========================================================================= +== NOTICE file corresponding to section 4(d) of the Apache License, == +== Version 2.0, in this case for the Apache Derby distribution. == +========================================================================= + +>>>>>>>>>>>>>> +Apache Derby +Copyright 2004-2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + +Portions of Derby were originally developed by +International Business Machines Corporation and are +licensed to the Apache Software Foundation under the +"Software Grant and Corporate Contribution License Agreement", +informally known as the "Derby CLA". +The following copyright notice(s) were affixed to portions of the code +with which this file is now or was at one time distributed +and are placed here unaltered. + +(C) Copyright 1997,2004 International Business Machines Corporation. All rights reserved. + +(C) Copyright IBM Corp. 2003. + +The portion of the functionTests under 'nist' was originally +developed by the National Institute of Standards and Technology (NIST), +an agency of the United States Department of Commerce, and adapted by +International Business Machines Corporation in accordance with the NIST +Software Acknowledgment and Redistribution document at +http://www.itl.nist.gov/div897/ctg/sql_form.htm + +>>>>>>>>>>>>>> +Apache Harmony +Copyright 2006, 2009 The Apache Software Foundation. + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + +Portions of Apache Harmony were originally developed by +Intel Corporation and are licensed to the Apache Software +Foundation under the "Software Grant and Corporate Contribution +License Agreement" and for which the following copyright notices +apply + (C) Copyright 2005 Intel Corporation + (C) Copyright 2005-2006 Intel Corporation + (C) Copyright 2006 Intel Corporation + +>>>>>>>>>>>>>> +============================================================== + Jetty Web Container + Copyright 1995-2006 Mort Bay Consulting Pty Ltd +============================================================== + +The Jetty Web Container is Copyright Mort Bay Consulting Pty Ltd +unless otherwise noted. It is licensed under the apache 2.0 +license. + +The javax.servlet package used by Jetty is copyright +Sun Microsystems, Inc and Apache Software Foundation. It is +distributed under the Common Development and Distribution License. +You can obtain a copy of the license at +https://glassfish.dev.java.net/public/CDDLv1.0.html. + +The UnixCrypt.java code ~Implements the one way cryptography used by +Unix systems for simple password protection. Copyright 1996 Aki Yoshida, +modified April 2001 by Iris Van den Broeke, Daniel Deville. +Permission to use, copy, modify and distribute UnixCrypt +for non-commercial or commercial purposes and without fee is +granted provided that the copyright notice appears in all copies. + +The default JSP implementation is provided by the Glassfish JSP engine +from project Glassfish http://glassfish.dev.java.net. Copyright 2005 +Sun Microsystems, Inc. and portions Copyright Apache Software Foundation. + +Some portions of the code are Copyright: + 2006 Tim Vernum + 1999 Jason Gilbert. + +The jboss integration module contains some LGPL code. + +The win32 Java Service Wrapper (v3.2.3) is Copyright (c) 1999, 2006 +Tanuki Software, Inc. and 2001 Silver Egg Technology. It is +covered by an open license which is viewable at +http://svn.codehaus.org/jetty/jetty/branches/jetty-6.1/extras/win32service/LICENSE.txt + +>>>>>>>>>>>>>> +Apache Sanselan +Copyright 2007-2009 The Apache Software Foundation. + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + +>>>>>>>>>>>>>> +TagSoup +Copyright 2002-2008 by John Cowan + +>>>>>>>>>>>>>> +dnsjava: + +Copyright (c) 1999-2005, Brian Wellington +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 the dnsjava project 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. + +>>>>>>>>>>>>>> +jBCrypt: + +Copyright (c) 2006 Damien Miller + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +>>>>>>>>>>>>>> +Scala: + +Copyright (c) 2002-2009 EPFL, Lausanne, unless otherwise specified. +All rights reserved. + +This software was developed by the Programming Methods Laboratory of the +Swiss Federal Institute of Technology (EPFL), Lausanne, Switzerland. + +Permission to use, copy, modify, and distribute this software in source +or binary form for any purpose with or without fee is hereby granted, +provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. 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. + + 3. Neither the name of the EPFL 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 REGENTS 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 REGENTS 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. + +>>>>>>>>>>>>>> +YUI Compressor: + +Copyright (c) 2009, Yahoo! Inc. +All rights reserved. + +Redistribution and use of this software 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 Yahoo! Inc. nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission of Yahoo! Inc. + +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. + +>>>>>>>>>>>>>> +jQuery +Copyright (c) 2009 John Resig, http://jquery.com/ + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +>>>>>>>>>>>>>> +jQuery Pulse: + +Copyright (c) 2008 James Padolsey - jp(at)qd9(dot)co.uk | http://james.padolsey.com / http://enhance.qd-creative.co.uk + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +>>>>>>>>>>>>>> +SWFObject v1.5 +Copyright (c) 2007 Geoff Stearns + +Licensed under the MIT License + +>>>>>>>>>>>>>> +jQuery Context Menu Plugin: + +Original version copyright 2008 A Beautiful Site, LLC. Modifications by AppJet, Inc. released under the same license. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +>>>>>>>>>>>>>> +c3p0 +Copyright (c) 2006 Machinery for Change, Inc. + +Licensed under the LGPL 2.1 + +>>>>>>>>>>>>>> +JCommon, JFreeChart +Copyright (c) 2007-2009 Object Refinery Limited + +Licensed under the LGPL 2.1 + +>>>>>>>>>>>>>> +Mozilla Rhino + +Licensed under the MPL 1.1, GPL 2.0 or later + + +>>>>>>>>>>>>>> +MySQL Connector + +Licensed uder the GPL 2.0 or later with the FOSS exception + +#### Emoji One Artwork + +* Applies to all PNG and SVG files as well as any adaptations made. +* License: Creative Commons Attribution-ShareAlike 4.0 International +* Human Readable License: http://creativecommons.org/licenses/by-sa/4.0/ +* Complete Legal Terms: http://creativecommons.org/licenses/by-sa/4.0/legalcode + + +#### Emoji One Non-Artwork + +* Applies to the Javascript, JSON, PHP, CSS, HTML files, and everything else not covered under the artwork license above. +* License: MIT +* Complete Legal Terms: http://opensource.org/licenses/MIT + diff --git a/README.md b/README.md new file mode 100644 index 0000000..d88cf20 --- /dev/null +++ b/README.md @@ -0,0 +1,189 @@ +# About Hackpad +Hackpad is a web-based realtime wiki, based on the open source EtherPad collaborative document editor. + + +The etherpad package is distributed under the Apache License, Version 2.0. + +All other packages are redistributed under their original license terms. See below for a license summary of redistributed software. More comprehensive license information can be found in the documentation of each package. + +This document contains licensing information relating to the use of free and open-source software (FOSS) with or within the Hackpad software. The authors, licensors, and distributors of the FOSS disclaim all express or implied conditions, representations, and warranties relating to the FOSS and any liability arising from use and distribution of the FOSS. + +This document identifies the FOSS packages used in the Hackpad software, the FOSS licenses that Dropbox believes govern those FOSS packages. While Dropbox has sought to provide complete and accurate licensing information for each FOSS package, Dropbox does not represent or warrant that the licensing information provided herein is correct or error-free. Recipients of the Hackpad software should investigate the identified FOSS packages to confirm the accuracy of the licensing information provided herein. Recipients are also encouraged to notify Dropbox of any inaccurate information or errors found in these notices. + + +———————————————————————— + + +* Apache License, Version 2.0 * + +solr +http://lucene.apache.org/solr/ + +smack api +http://www.igniterealtime.org/projects/smack/ + +gdata java client +https://code.google.com/p/gdata-java-client/ + +FacebookSDK.framework +https://developers.facebook.com/docs/ios/ + +GoogleToolbox +https://code.google.com/p/google-toolbox-for-mac/ + +OCMock +https://github.com/erikdoe/ocmock/blob/master/Source/License.txt + +* MIT and MIT-Style Licenses * + +bililiteRange.js +https://github.com/dwachss/bililiteRange + +handlebars.js +https://github.com/wycats/handlebars.js/blob/master/LICENSE + +html5shiv +https://code.google.com/p/html5shiv/ + +i18next +http://i18next.com/ + +JQuery +http://jquery.com/ + +JQueryUI +http://jqueryui.com/ + +jquery.ajaxqueue.js +http://www.onemoretake.com/2009/10/11/ajaxqueue-and-jquery-1-3/ + +jquery.autocomplete.js +http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ + +jquery.ba-dotimeout.min.js +http://benalman.com/projects/jquery-dotimeout-plugin/ + +jquery.color.js +https://github.com/jquery/jquery-color + +jquery.contextMenu.js +https://github.com/medialize/jQuery-contextMenu + +jquery.customSelect.js +https://github.com/adamcoulombe/jquery.customSelect + +jquery.embedly.js +https://github.com/embedly/embedly-jquery + +jquery.handsontable.js +http://handsontable.com/ + +jquery.placeholder.js +https://github.com/mathiasbynens/jquery-placeholder + +jquery.sendkeys.js +https://github.com/dwachss/bililiteRange + +jquery.tablesorter.js +http://tablesorter.com/docs/ + +jquery.textcomplete.min.js +https://github.com/yuku-t/jquery-textcomplete/ + +jquery.tinysort.js +http://tinysort.sjeiti.com/ + +jquery.ui.position.js +http://jqueryui.com/ + +jquery.ui.touch-punch.min.js +http://touchpunch.furf.com/ + +jquery.validate.js +http://bassistance.de/jquery-plugins/jquery-plugin-validation/ + +jquery.transition.js +https://github.com/louisremi/jquery.transition.js/ + +less-1.4.1.min.js +http://www.lesscss.org/ + +LESS Hat +http://LESSHat.com/ + +pagedown +https://code.google.com/p/pagedown/source/browse/LICENSE.txt + +require.js +http://github.com/jrburke/requirejs + +selectivizr-min.js +http://selectivizr.com/ + +simplewebrtc.bundle.js +https://github.com/HenrikJoreteg/SimpleWebRTC + +socket.io.js +https://github.com/LearnBoost/socket.io-client + +ACE Syntax Highlighter (tokenizer.js) +http://ace.c9.io/ + +to-markdown +https://github.com/domchristie/to-markdown + +unicode.js +http://xregexp.com + +MBProgressHUD +https://github.com/jdg/MBProgressHUD + +WebViewJavascriptBridge +https://github.com/marcuswestin/WebViewJavascriptBridge/blob/master/LICENSE + +JavaScript Pretty Date +http://ejohn.org/blog/javascript-pretty-date/ + +JSON Framework +https://code.google.com/p/json-framework/ + +Emoji One Non-Artwork +https://github.com/Ranks/emojione + +ZeroClipboard +https://github.com/zeroclipboard/zeroclipboard + +* BSD and BSD-Style Licenses * + +java-apns +https://github.com/notnoop/java-apns + +glue sprite generator +https://github.com/jorgebastida/glue + +NSAttributedString+DDHTML +https://github.com/dbowen/NSAttributedString-DDHTML/ + +RNCachingURLProtocol +https://github.com/rnapier/RNCachingURLProtocol + +Sente Testing Kit +http://www.quantum-step.com/download/sources/mystep/OCUnit/SourceCode/SenTestingKit/OpenSourceLicense.html + +ASIHTTPRequest +http://allseeing-i.com/ASIHTTPRequest/ + +* Other Licenses * + +jquery.autoresize.js +https://github.com/warpech/jQuery.fn.autoResize + +vocaro.com UIImage Resize +https://gist.github.com/benilovj/2009030 + +Emoji One Artwork +https://github.com/Ranks/emojione + + + + diff --git a/bin/build.sh b/bin/build.sh new file mode 100755 index 0000000..d9ca2d3 --- /dev/null +++ b/bin/build.sh @@ -0,0 +1,30 @@ +#! /bin/bash + +################################################################################ +# +# Copyright (c) 2010 penSec.IT UG (haftungsbeschränkt) +# http://www.pensec.it +# mail@pensec.it +# Copyright (c) 2010 Egil Möller +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +################################################################################ + +ETHERPADDIR="$(cd "$(dirname "$0")/.."; pwd)" +source "$ETHERPADDIR/bin/exports.sh" + +# Rebuild jar +( cd "$ETHERPADDIR"/infrastructure; ./bin/makejar.sh; ) +cp "$ETHERPADDIR"/infrastructure/build/appjet.jar $ETHERPADDIR/etherpad/appjet-eth-dev.jar +rm -rf "$ETHERPADDIR"/infrastructure/{appjet,build,buildjs,buildcache} diff --git a/bin/exports.sh b/bin/exports.sh new file mode 100755 index 0000000..dae457a --- /dev/null +++ b/bin/exports.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +################################################################################ +# +# Copyright (c) 2010 penSec.IT UG (haftungsbeschränkt) +# http://www.pensec.it +# mail@pensec.it +# Copyright (c) 2010 Egil Möller +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +################################################################################ + + + + + +##### +# You have to change following lines to your requirements: +# +[ -e "/usr/lib/jvm/java-6-openjdk" ] && export JAVA_HOME="/usr/lib/jvm/java-6-openjdk" +[ -e "/usr/lib/jvm/java-6-sun" ] && export JAVA_HOME="/usr/lib/jvm/java-6-sun" +[ -e "/opt/java/64/jre1.6.0_31" ] && export JAVA_HOME="/opt/java/64/jre1.6.0_31" +export SCALA_HOME="/usr/share/java" +export SCALA_LIBRARY_JAR="$PWD/lib/scala-library.jar" +export MYSQL_CONNECTOR_JAR="$PWD/lib/mysql-connector-java-5.1.34-bin.jar" +[ -e "/usr/lib/jvm/java-6-openjdk" ] && export JAVA_OPTS="-Xbootclasspath/p:../infrastructure/lib/rhino-js-1.7r3.jar:/usr/share/java/scala-library.jar" +export JAVA="/usr/bin/java" +export SCALA="/usr/bin/scala" +export PATH="$JAVA_HOME/bin:$PATH" + +if ! [ -e "$MYSQL_CONNECTOR_JAR" ]; then + echo "MySql Connector jar '$MYSQL_CONNECTOR_JAR' not found - Download it here: http://dev.mysql.com/downloads/connector/j/3.1.html" + exit 1 +fi + +if ! [ -e "$SCALA_LIBRARY_JAR" ]; then + echo "Scala Library cannot be found '$SCALA_LIBRARY_JAR' not found - Download it here: http://www.scala-lang.org/" + exit 1 +fi + +if ! [ -e "$JAVA" ]; then + echo "Java cannot be found '$JAVA' not found - Download it here: http://openjdk.java.net/" + exit 1 +fi + +#if ! [ -e "$SCALA" ]; then +# echo "Java cannot be found '$SCALA' not found - Download it here: http://www.scala-lang.org/" +# exit 1 +#fi + diff --git a/bin/hpush b/bin/hpush new file mode 100755 index 0000000..f992f99 --- /dev/null +++ b/bin/hpush @@ -0,0 +1,77 @@ +#!/bin/bash +REPO_ROOT=$(git rev-parse --show-toplevel) + +# List all the machine if no destination specified +if [ "$#" -eq 0 ]; then + cat $REPO_ROOT/contrib/ssh_config | grep -v "User " | grep -v IdentityFile + echo + echo "$0 destination [branch(default is master)] [-f]" + echo + exit +fi + +# Grep for the host, user and key to use +host=`grep -A 1 ".*Host\\s\+$1$" $REPO_ROOT/contrib/ssh_config | grep HostName | awk '{print $2}'` +identity=`grep -A 4 ".*Host\\s\+$1$" $REPO_ROOT/contrib/ssh_config | grep Identity| awk '{print $2}'` +user=`grep -A 4 ".*Host\\s\+$1$" $REPO_ROOT/contrib/ssh_config | grep User | awk '{print $2}'` +eval identity_absolute=$identity + +# Load the key +ssh-add $identity_absolute > /dev/null 2>&1 + +# Announce what we're doing - give a grace period +echo "Pushing ${2:-master} to $1" +for i in `seq 1 5`; do + printf . + sleep 1 +done + +echo + +# Ensure we're on the branch we say we want pushed +git branch | grep "* ${2:-master}" > /dev/null 2>&1 +if [ $? -ne 0 ]; then + echo + echo "You're asking to push ${2:-master} but you have a different branch checked out!" + echo + exit +fi + +# Ensure we're in sync with origin (hpush destination master -f) to override +if [ "$3" != "-f" ]; then + git push origin ${2:-master} + if [ $? -ne 0 ]; then + echo + echo "Oops. Please push to origin first!" + echo + exit + fi +fi + +# Manually handle pushing to nginx +if [ "$1" == "nginx" ]; then + # backup old config + scp $user@$host:~/pad/contrib/nginx.conf /tmp/nginx.conf.old + + # push new config + echo scp $REPO_ROOT/contrib/nginx.conf $user@$host:/etc/nginx/nginx.conf + scp $REPO_ROOT/contrib/nginx.conf $user@$host:~/pad/contrib/nginx.conf + + # push error pages + hssh nginx mkdir -p /home/ubuntu/pad/etherpad/src/static + scp $REPO_ROOT/etherpad/src/static/502.html $user@$host:~/pad/etherpad/src/static/ + + # confirm the diff + echo "Configuration pushed to nginx. Saved old config to /tmp/nginx.conf.old. Diff is:" + diff /tmp/nginx.conf.old $REPO_ROOT/contrib/nginx.conf + + echo "Don't forget to reload the config (sudo nginx -s reload)" + echo "Also -- make sure the configuration is the same between the Hackpad and Composer repos!" + exit +fi + +# Push +git push ${3} ssh://$user@$host/home/$user/pad ${2:-master} +if [ $? -ne 0 ]; then + exit +fi diff --git a/bin/hssh b/bin/hssh new file mode 100755 index 0000000..ceebff6 --- /dev/null +++ b/bin/hssh @@ -0,0 +1,9 @@ +#!/bin/bash +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +if [ "$#" -le 0 ]; then + cat $DIR/../contrib/ssh_config + exit +fi + +ssh -F $DIR/../contrib/ssh_config $@ diff --git a/bin/run.sh b/bin/run.sh new file mode 100755 index 0000000..255bab9 --- /dev/null +++ b/bin/run.sh @@ -0,0 +1,35 @@ +#! /bin/bash + +################################################################################ +# +# Copyright (c) 2010 penSec.IT UG (haftungsbeschränkt) +# http://www.pensec.it +# mail@pensec.it +# Copyright (c) 2010 Egil Möller +# Copyright (c) 2010 Mikko Rantalainen +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +################################################################################ + +ETHERPADDIR="$(cd "$(dirname "$0")/.."; pwd)" +source "$ETHERPADDIR/bin/exports.sh" +source "$ETHERPADDIR/bin/ooffice.sh" + +PID_FILE="${ETHERPADDIR}/etherpad/data/etherpad.pid" +echo $$ > $PID_FILE + +cd "$ETHERPADDIR/etherpad" + +# the argument here is the maximum amount of RAM to allocate +exec bin/run-local.sh "$@" --etherpad.soffice="$SOFFICE_BIN" 256M diff --git a/bin/stop.sh b/bin/stop.sh new file mode 100755 index 0000000..6e2a2ad --- /dev/null +++ b/bin/stop.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# requires bash 3 + +TEST_STRING=java + +### +# Test if the etherpad instance is alive by checking for +# the process in etherpad/data/etherpad.pid +# +# Use that PID to see if there are any processes running +# and if the command of that process matches $TEST_STRING +# +# If it matches kill the $PID, +# wait and see if the process ended. +# +# Exits 0 on success, 1 on failure + +ETHERPADDIR="$(cd "$(dirname "$0")/.."; pwd)" +PID_FILE="${ETHERPADDIR}/etherpad/data/etherpad.pid" + +PID=`cat ${PID_FILE}` +RUNNING_CMD="ps -o pid,ruser,ucmd --no-headers -p ${PID}" + +function check_if_alive_by_pid { + result=`ps -o pid,ruser,ucmd --no-headers -p ${1}` + if [[ "${result}" =~ "${TEST_STRING}" ]] ; then + return 0 + else + return 1 + fi +} + +i=0 +while [ $i -le 10 ] ; do + check_if_alive_by_pid $PID + if [[ $? -eq 0 ]] ; then + kill -9 $PID + sleep 5 + else + exit 0 + fi + + i=$(( $i + 1 )) +done + +# Should only get here if we've tried restarting the +# Etherpad process 10 times unsuccessfully +exit 1 diff --git a/client/ios/Hackpad/AppleSampleCode/KeychainItemWrapper.h b/client/ios/Hackpad/AppleSampleCode/KeychainItemWrapper.h new file mode 100755 index 0000000..2ec18cb --- /dev/null +++ b/client/ios/Hackpad/AppleSampleCode/KeychainItemWrapper.h @@ -0,0 +1,74 @@ +/* + File: KeychainItemWrapper.h + Abstract: + Objective-C wrapper for accessing a single keychain item. + + Version: 1.2 + + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple + Inc. ("Apple") in consideration of your agreement to the following + terms, and your use, installation, modification or redistribution of + this Apple software constitutes acceptance of these terms. If you do + not agree with these terms, please do not use, install, modify or + redistribute this Apple software. + + In consideration of your agreement to abide by the following terms, and + subject to these terms, Apple grants you a personal, non-exclusive + license, under Apple's copyrights in this original Apple software (the + "Apple Software"), to use, reproduce, modify and redistribute the Apple + Software, with or without modifications, in source and/or binary forms; + provided that if you redistribute the Apple Software in its entirety and + without modifications, you must retain this notice and the following + text and disclaimers in all such redistributions of the Apple Software. + Neither the name, trademarks, service marks or logos of Apple Inc. may + be used to endorse or promote products derived from the Apple Software + without specific prior written permission from Apple. Except as + expressly stated in this notice, no other rights or licenses, express or + implied, are granted by Apple herein, including but not limited to any + patent rights that may be infringed by your derivative works or by other + works in which the Apple Software may be incorporated. + + The Apple Software is provided by Apple on an "AS IS" basis. APPLE + MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION + THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND + OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. + + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, + MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED + AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), + STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + Copyright (C) 2010 Apple Inc. All Rights Reserved. + +*/ + +#import + +/* + The KeychainItemWrapper class is an abstraction layer for the iPhone Keychain communication. It is merely a + simple wrapper to provide a distinct barrier between all the idiosyncracies involved with the Keychain + CF/NS container objects. +*/ +@interface KeychainItemWrapper : NSObject +{ + NSMutableDictionary *keychainItemData; // The actual keychain item data backing store. + NSMutableDictionary *genericPasswordQuery; // A placeholder for the generic keychain item query used to locate the item. +} + +@property (nonatomic, retain) NSMutableDictionary *keychainItemData; +@property (nonatomic, retain) NSMutableDictionary *genericPasswordQuery; + +// Designated initializer. +- (id)initWithIdentifier: (NSString *)identifier accessGroup:(NSString *) accessGroup; +- (void)setObject:(id)inObject forKey:(id)key; +- (id)objectForKey:(id)key; + +// Initializes and resets the default generic keychain item data. +- (void)resetKeychainItem; + +@end \ No newline at end of file diff --git a/client/ios/Hackpad/AppleSampleCode/KeychainItemWrapper.m b/client/ios/Hackpad/AppleSampleCode/KeychainItemWrapper.m new file mode 100755 index 0000000..36ef36a --- /dev/null +++ b/client/ios/Hackpad/AppleSampleCode/KeychainItemWrapper.m @@ -0,0 +1,313 @@ +/* + File: KeychainItemWrapper.m + Abstract: + Objective-C wrapper for accessing a single keychain item. + + Version: 1.2 + + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple + Inc. ("Apple") in consideration of your agreement to the following + terms, and your use, installation, modification or redistribution of + this Apple software constitutes acceptance of these terms. If you do + not agree with these terms, please do not use, install, modify or + redistribute this Apple software. + + In consideration of your agreement to abide by the following terms, and + subject to these terms, Apple grants you a personal, non-exclusive + license, under Apple's copyrights in this original Apple software (the + "Apple Software"), to use, reproduce, modify and redistribute the Apple + Software, with or without modifications, in source and/or binary forms; + provided that if you redistribute the Apple Software in its entirety and + without modifications, you must retain this notice and the following + text and disclaimers in all such redistributions of the Apple Software. + Neither the name, trademarks, service marks or logos of Apple Inc. may + be used to endorse or promote products derived from the Apple Software + without specific prior written permission from Apple. Except as + expressly stated in this notice, no other rights or licenses, express or + implied, are granted by Apple herein, including but not limited to any + patent rights that may be infringed by your derivative works or by other + works in which the Apple Software may be incorporated. + + The Apple Software is provided by Apple on an "AS IS" basis. APPLE + MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION + THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND + OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. + + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, + MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED + AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), + STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + Copyright (C) 2010 Apple Inc. All Rights Reserved. + +*/ + +#import "KeychainItemWrapper.h" +#import + +/* + +These are the default constants and their respective types, +available for the kSecClassGenericPassword Keychain Item class: + +kSecAttrAccessGroup - CFStringRef +kSecAttrCreationDate - CFDateRef +kSecAttrModificationDate - CFDateRef +kSecAttrDescription - CFStringRef +kSecAttrComment - CFStringRef +kSecAttrCreator - CFNumberRef +kSecAttrType - CFNumberRef +kSecAttrLabel - CFStringRef +kSecAttrIsInvisible - CFBooleanRef +kSecAttrIsNegative - CFBooleanRef +kSecAttrAccount - CFStringRef +kSecAttrService - CFStringRef +kSecAttrGeneric - CFDataRef + +See the header file Security/SecItem.h for more details. + +*/ + +@interface KeychainItemWrapper (PrivateMethods) +/* +The decision behind the following two methods (secItemFormatToDictionary and dictionaryToSecItemFormat) was +to encapsulate the transition between what the detail view controller was expecting (NSString *) and what the +Keychain API expects as a validly constructed container class. +*/ +- (NSMutableDictionary *)secItemFormatToDictionary:(NSDictionary *)dictionaryToConvert; +- (NSMutableDictionary *)dictionaryToSecItemFormat:(NSDictionary *)dictionaryToConvert; + +// Updates the item in the keychain, or adds it if it doesn't exist. +- (void)writeToKeychain; + +@end + +@implementation KeychainItemWrapper + +@synthesize keychainItemData, genericPasswordQuery; + +- (id)initWithIdentifier: (NSString *)identifier accessGroup:(NSString *) accessGroup; +{ + if (self = [super init]) + { + // Begin Keychain search setup. The genericPasswordQuery leverages the special user + // defined attribute kSecAttrGeneric to distinguish itself between other generic Keychain + // items which may be included by the same application. + genericPasswordQuery = [[NSMutableDictionary alloc] init]; + + [genericPasswordQuery setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; + [genericPasswordQuery setObject:identifier forKey:(id)kSecAttrGeneric]; + + // The keychain access group attribute determines if this item can be shared + // amongst multiple apps whose code signing entitlements contain the same keychain access group. + if (accessGroup != nil) + { +#if TARGET_IPHONE_SIMULATOR + // Ignore the access group if running on the iPhone simulator. + // + // Apps that are built for the simulator aren't signed, so there's no keychain access group + // for the simulator to check. This means that all apps can see all keychain items when run + // on the simulator. + // + // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the + // simulator will return -25243 (errSecNoAccessForItem). +#else + [genericPasswordQuery setObject:accessGroup forKey:(id)kSecAttrAccessGroup]; +#endif + } + + // Use the proper search constants, return only the attributes of the first match. + [genericPasswordQuery setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit]; + [genericPasswordQuery setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes]; + + NSDictionary *tempQuery = [NSDictionary dictionaryWithDictionary:genericPasswordQuery]; + + NSMutableDictionary *outDictionary = nil; + + if (! SecItemCopyMatching((CFDictionaryRef)tempQuery, (CFTypeRef *)&outDictionary) == noErr) + { + // Stick these default values into keychain item if nothing found. + [self resetKeychainItem]; + + // Add the generic attribute and the keychain access group. + [keychainItemData setObject:identifier forKey:(id)kSecAttrGeneric]; + if (accessGroup != nil) + { +#if TARGET_IPHONE_SIMULATOR + // Ignore the access group if running on the iPhone simulator. + // + // Apps that are built for the simulator aren't signed, so there's no keychain access group + // for the simulator to check. This means that all apps can see all keychain items when run + // on the simulator. + // + // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the + // simulator will return -25243 (errSecNoAccessForItem). +#else + [keychainItemData setObject:accessGroup forKey:(id)kSecAttrAccessGroup]; +#endif + } + } + else + { + // load the saved data from Keychain. + self.keychainItemData = [self secItemFormatToDictionary:outDictionary]; + } + + [outDictionary release]; + } + + return self; +} + +- (void)dealloc +{ + [keychainItemData release]; + [genericPasswordQuery release]; + + [super dealloc]; +} + +- (void)setObject:(id)inObject forKey:(id)key +{ + if (inObject == nil) return; + id currentObject = [keychainItemData objectForKey:key]; + if (![currentObject isEqual:inObject]) + { + [keychainItemData setObject:inObject forKey:key]; + [self writeToKeychain]; + } +} + +- (id)objectForKey:(id)key +{ + return [keychainItemData objectForKey:key]; +} + +- (void)resetKeychainItem +{ + OSStatus junk = noErr; + if (!keychainItemData) + { + keychainItemData = [[NSMutableDictionary alloc] init]; + } + else if (keychainItemData) + { + NSMutableDictionary *tempDictionary = [self dictionaryToSecItemFormat:keychainItemData]; + junk = SecItemDelete((CFDictionaryRef)tempDictionary); + NSAssert( junk == noErr || junk == errSecItemNotFound, @"Problem deleting current dictionary." ); + } + + // Default attributes for keychain item. + [keychainItemData setObject:@"" forKey:(id)kSecAttrAccount]; + [keychainItemData setObject:@"" forKey:(id)kSecAttrLabel]; + [keychainItemData setObject:@"" forKey:(id)kSecAttrDescription]; + + // Default data for keychain item. + [keychainItemData setObject:@"" forKey:(id)kSecValueData]; +} + +- (NSMutableDictionary *)dictionaryToSecItemFormat:(NSDictionary *)dictionaryToConvert +{ + // The assumption is that this method will be called with a properly populated dictionary + // containing all the right key/value pairs for a SecItem. + + // Create a dictionary to return populated with the attributes and data. + NSMutableDictionary *returnDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionaryToConvert]; + + // Add the Generic Password keychain item class attribute. + [returnDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; + + // Convert the NSString to NSData to meet the requirements for the value type kSecValueData. + // This is where to store sensitive data that should be encrypted. + NSString *passwordString = [dictionaryToConvert objectForKey:(id)kSecValueData]; + [returnDictionary setObject:[passwordString dataUsingEncoding:NSUTF8StringEncoding] forKey:(id)kSecValueData]; + + return returnDictionary; +} + +- (NSMutableDictionary *)secItemFormatToDictionary:(NSDictionary *)dictionaryToConvert +{ + // The assumption is that this method will be called with a properly populated dictionary + // containing all the right key/value pairs for the UI element. + + // Create a dictionary to return populated with the attributes and data. + NSMutableDictionary *returnDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionaryToConvert]; + + // Add the proper search key and class attribute. + [returnDictionary setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData]; + [returnDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; + + // Acquire the password data from the attributes. + NSData *passwordData = NULL; + if (SecItemCopyMatching((CFDictionaryRef)returnDictionary, (CFTypeRef *)&passwordData) == noErr) + { + // Remove the search, class, and identifier key/value, we don't need them anymore. + [returnDictionary removeObjectForKey:(id)kSecReturnData]; + + // Add the password to the dictionary, converting from NSData to NSString. + NSString *password = [[[NSString alloc] initWithBytes:[passwordData bytes] length:[passwordData length] + encoding:NSUTF8StringEncoding] autorelease]; + [returnDictionary setObject:password forKey:(id)kSecValueData]; + } + else + { + // Don't do anything if nothing is found. + NSAssert(NO, @"Serious error, no matching item found in the keychain.\n"); + } + + [passwordData release]; + + return returnDictionary; +} + +- (void)writeToKeychain +{ + NSDictionary *attributes = NULL; + NSMutableDictionary *updateItem = NULL; + OSStatus result; + + if (SecItemCopyMatching((CFDictionaryRef)genericPasswordQuery, (CFTypeRef *)&attributes) == noErr) + { + // First we need the attributes from the Keychain. + updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes]; + // Second we need to add the appropriate search key/values. + [updateItem setObject:[genericPasswordQuery objectForKey:(id)kSecClass] forKey:(id)kSecClass]; + + // Lastly, we need to set up the updated attribute list being careful to remove the class. + NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainItemData]; + [tempCheck removeObjectForKey:(id)kSecClass]; + +#if TARGET_IPHONE_SIMULATOR + // Remove the access group if running on the iPhone simulator. + // + // Apps that are built for the simulator aren't signed, so there's no keychain access group + // for the simulator to check. This means that all apps can see all keychain items when run + // on the simulator. + // + // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the + // simulator will return -25243 (errSecNoAccessForItem). + // + // The access group attribute will be included in items returned by SecItemCopyMatching, + // which is why we need to remove it before updating the item. + [tempCheck removeObjectForKey:(id)kSecAttrAccessGroup]; +#endif + + // An implicit assumption is that you can only update a single item at a time. + + result = SecItemUpdate((CFDictionaryRef)updateItem, (CFDictionaryRef)tempCheck); + NSAssert( result == noErr, @"Couldn't update the Keychain Item." ); + } + else + { + // No previous item found; add the new one. + result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL); + NSAssert( result == noErr, @"Couldn't add the Keychain Item." ); + } +} + +@end diff --git a/client/ios/Hackpad/AppleSampleCode/Reachability.h b/client/ios/Hackpad/AppleSampleCode/Reachability.h new file mode 100644 index 0000000..103a544 --- /dev/null +++ b/client/ios/Hackpad/AppleSampleCode/Reachability.h @@ -0,0 +1,104 @@ +/* + File: Reachability.h + Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs. + Version: 3.0 + + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple + Inc. ("Apple") in consideration of your agreement to the following + terms, and your use, installation, modification or redistribution of + this Apple software constitutes acceptance of these terms. If you do + not agree with these terms, please do not use, install, modify or + redistribute this Apple software. + + In consideration of your agreement to abide by the following terms, and + subject to these terms, Apple grants you a personal, non-exclusive + license, under Apple's copyrights in this original Apple software (the + "Apple Software"), to use, reproduce, modify and redistribute the Apple + Software, with or without modifications, in source and/or binary forms; + provided that if you redistribute the Apple Software in its entirety and + without modifications, you must retain this notice and the following + text and disclaimers in all such redistributions of the Apple Software. + Neither the name, trademarks, service marks or logos of Apple Inc. may + be used to endorse or promote products derived from the Apple Software + without specific prior written permission from Apple. Except as + expressly stated in this notice, no other rights or licenses, express or + implied, are granted by Apple herein, including but not limited to any + patent rights that may be infringed by your derivative works or by other + works in which the Apple Software may be incorporated. + + The Apple Software is provided by Apple on an "AS IS" basis. APPLE + MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION + THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND + OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. + + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, + MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED + AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), + STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + Copyright (C) 2013 Apple Inc. All Rights Reserved. + + */ + +#import +#import +#import + + +typedef enum : NSInteger { + NotReachable = 0, + ReachableViaWiFi, + ReachableViaWWAN +} NetworkStatus; + + +extern NSString *kReachabilityChangedNotification; + + +@interface Reachability : NSObject +{ + BOOL localWiFiRef; + SCNetworkReachabilityRef reachabilityRef; +} + +/*! + * Use to check the reachability of a given host name. + */ ++ (instancetype)reachabilityWithHostName:(NSString *)hostName; + +/*! + * Use to check the reachability of a given IP address. + */ ++ (instancetype)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress; + +/*! + * Checks whether the default route is available. Should be used by applications that do not connect to a particular host. + */ ++ (instancetype)reachabilityForInternetConnection; + +/*! + * Checks whether a local WiFi connection is available. + */ ++ (instancetype)reachabilityForLocalWiFi; + +/*! + * Start listening for reachability notifications on the current run loop. + */ +- (BOOL)startNotifier; +- (void)stopNotifier; + +- (NetworkStatus)currentReachabilityStatus; + +/*! + * WWAN may be available, but not active until a connection has been established. WiFi may require a connection for VPN on Demand. + */ +- (BOOL)connectionRequired; + +@end + + diff --git a/client/ios/Hackpad/AppleSampleCode/Reachability.m b/client/ios/Hackpad/AppleSampleCode/Reachability.m new file mode 100644 index 0000000..266a538 --- /dev/null +++ b/client/ios/Hackpad/AppleSampleCode/Reachability.m @@ -0,0 +1,307 @@ +/* + File: Reachability.m + Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs. + Version: 3.0 + + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple + Inc. ("Apple") in consideration of your agreement to the following + terms, and your use, installation, modification or redistribution of + this Apple software constitutes acceptance of these terms. If you do + not agree with these terms, please do not use, install, modify or + redistribute this Apple software. + + In consideration of your agreement to abide by the following terms, and + subject to these terms, Apple grants you a personal, non-exclusive + license, under Apple's copyrights in this original Apple software (the + "Apple Software"), to use, reproduce, modify and redistribute the Apple + Software, with or without modifications, in source and/or binary forms; + provided that if you redistribute the Apple Software in its entirety and + without modifications, you must retain this notice and the following + text and disclaimers in all such redistributions of the Apple Software. + Neither the name, trademarks, service marks or logos of Apple Inc. may + be used to endorse or promote products derived from the Apple Software + without specific prior written permission from Apple. Except as + expressly stated in this notice, no other rights or licenses, express or + implied, are granted by Apple herein, including but not limited to any + patent rights that may be infringed by your derivative works or by other + works in which the Apple Software may be incorporated. + + The Apple Software is provided by Apple on an "AS IS" basis. APPLE + MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION + THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND + OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. + + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, + MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED + AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), + STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + Copyright (C) 2013 Apple Inc. All Rights Reserved. + + */ + +#import +#import +#import +#import + +#import + +#import "Reachability.h" + + +NSString *kReachabilityChangedNotification = @"kNetworkReachabilityChangedNotification"; + + +#pragma mark - Supporting functions + +#define kShouldPrintReachabilityFlags 0 + +static void PrintReachabilityFlags(SCNetworkReachabilityFlags flags, const char* comment) +{ +#if kShouldPrintReachabilityFlags + + NSLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s\n", + (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-', + (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-', + + (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-', + (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-', + (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-', + (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-', + comment + ); +#endif +} + + +static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) +{ +#pragma unused (target, flags) + NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback"); + NSCAssert([(__bridge NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback"); + + Reachability* noteObject = (__bridge Reachability *)info; + // Post a notification to notify the client that the network reachability changed. + [[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject]; +} + + +#pragma mark - Reachability implementation + +@implementation Reachability + ++ (instancetype)reachabilityWithHostName:(NSString *)hostName; +{ + Reachability* returnValue = NULL; + SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]); + if (reachability != NULL) + { + returnValue= [[self alloc] init]; + if (returnValue != NULL) + { + returnValue->reachabilityRef = reachability; + returnValue->localWiFiRef = NO; + } + } + return returnValue; +} + + ++ (instancetype)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress; +{ + SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)hostAddress); + + Reachability* returnValue = NULL; + + if (reachability != NULL) + { + returnValue = [[self alloc] init]; + if (returnValue != NULL) + { + returnValue->reachabilityRef = reachability; + returnValue->localWiFiRef = NO; + } + } + return returnValue; +} + + + ++ (instancetype)reachabilityForInternetConnection; +{ + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + + return [self reachabilityWithAddress:&zeroAddress]; +} + + ++ (instancetype)reachabilityForLocalWiFi; +{ + struct sockaddr_in localWifiAddress; + bzero(&localWifiAddress, sizeof(localWifiAddress)); + localWifiAddress.sin_len = sizeof(localWifiAddress); + localWifiAddress.sin_family = AF_INET; + + // IN_LINKLOCALNETNUM is defined in as 169.254.0.0. + localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); + + Reachability* returnValue = [self reachabilityWithAddress: &localWifiAddress]; + if (returnValue != NULL) + { + returnValue->localWiFiRef = YES; + } + + return returnValue; +} + + +#pragma mark - Start and stop notifier + +- (BOOL)startNotifier +{ + BOOL returnValue = NO; + SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; + + if (SCNetworkReachabilitySetCallback(reachabilityRef, ReachabilityCallback, &context)) + { + if (SCNetworkReachabilityScheduleWithRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) + { + returnValue = YES; + } + } + + return returnValue; +} + + +- (void)stopNotifier +{ + if (reachabilityRef != NULL) + { + SCNetworkReachabilityUnscheduleFromRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + } +} + + +- (void)dealloc +{ + [self stopNotifier]; + if (reachabilityRef != NULL) + { + CFRelease(reachabilityRef); + } +} + + +#pragma mark - Network Flag Handling + +- (NetworkStatus)localWiFiStatusForFlags:(SCNetworkReachabilityFlags)flags +{ + PrintReachabilityFlags(flags, "localWiFiStatusForFlags"); + BOOL returnValue = NotReachable; + + if ((flags & kSCNetworkReachabilityFlagsReachable) && (flags & kSCNetworkReachabilityFlagsIsDirect)) + { + returnValue = ReachableViaWiFi; + } + + return returnValue; +} + + +- (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags +{ + PrintReachabilityFlags(flags, "networkStatusForFlags"); + if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) + { + // The target host is not reachable. + return NotReachable; + } + + BOOL returnValue = NotReachable; + + if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) + { + /* + If the target host is reachable and no connection is required then we'll assume (for now) that you're on Wi-Fi... + */ + returnValue = ReachableViaWiFi; + } + + if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || + (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)) + { + /* + ... and the connection is on-demand (or on-traffic) if the calling application is using the CFSocketStream or higher APIs... + */ + + if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) + { + /* + ... and no [user] intervention is needed... + */ + returnValue = ReachableViaWiFi; + } + } + + if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) + { + /* + ... but WWAN connections are OK if the calling application is using the CFNetwork APIs. + */ + returnValue = ReachableViaWWAN; + } + + return returnValue; +} + + +- (BOOL)connectionRequired +{ + NSAssert(reachabilityRef != NULL, @"connectionRequired called with NULL reachabilityRef"); + SCNetworkReachabilityFlags flags; + + if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) + { + return (flags & kSCNetworkReachabilityFlagsConnectionRequired); + } + + return NO; +} + + +- (NetworkStatus)currentReachabilityStatus +{ + NSAssert(reachabilityRef != NULL, @"currentNetworkStatus called with NULL reachabilityRef"); + NetworkStatus returnValue = NotReachable; + SCNetworkReachabilityFlags flags; + + if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) + { + if (localWiFiRef) + { + returnValue = [self localWiFiStatusForFlags:flags]; + } + else + { + returnValue = [self networkStatusForFlags:flags]; + } + } + + return returnValue; +} + + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/FacebookSDK b/client/ios/Hackpad/FacebookSDK.framework/FacebookSDK new file mode 120000 index 0000000..77d5d31 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/FacebookSDK @@ -0,0 +1 @@ +./Versions/A/FacebookSDK \ No newline at end of file diff --git a/client/ios/Hackpad/FacebookSDK.framework/Headers b/client/ios/Hackpad/FacebookSDK.framework/Headers new file mode 120000 index 0000000..b0cc393 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Headers @@ -0,0 +1 @@ +./Versions/A/Headers \ No newline at end of file diff --git a/client/ios/Hackpad/FacebookSDK.framework/Resources b/client/ios/Hackpad/FacebookSDK.framework/Resources new file mode 120000 index 0000000..3afb717 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Resources @@ -0,0 +1 @@ +./Versions/A/Resources \ No newline at end of file diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAccessTokenData.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAccessTokenData.h new file mode 100644 index 0000000..f28039b --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAccessTokenData.h @@ -0,0 +1,140 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBSession.h" + +/*! + @class FBAccessTokenData + + @abstract Represents an access token used for the Facebook login flow + and includes associated metadata such as expiration date and permissions. + You should use factory methods (createToken...) to construct instances + and should be treated as immutable. + + @discussion For more information, see + https://developers.facebook.com/docs/concepts/login/access-tokens-and-types/. +*/ +@interface FBAccessTokenData : NSObject + +/*! + @method + + @abstract Creates an FBAccessTokenData from an App Link provided by the Facebook application + or nil if the url is not valid. + + @param url The url provided. + @param appID needed in order to verify URL format. + @param urlSchemeSuffix needed in order to verify URL format. + +*/ ++ (FBAccessTokenData *) createTokenFromFacebookURL:(NSURL *)url appID:(NSString *)appID urlSchemeSuffix:(NSString *)urlSchemeSuffix; + +/*! + @method + + @abstract Creates an FBAccessTokenData from a dictionary or returns nil if required data is missing. + @param dictionary the dictionary with FBSessionTokenCachingStrategy keys. + */ ++ (FBAccessTokenData *) createTokenFromDictionary:(NSDictionary *)dictionary; + +/*! + @method + + @abstract Creates an FBAccessTokenData from existing information or returns nil if required data is missing. + + @param accessToken The token string. If nil or empty, this method will return nil. + @param permissions The permissions set. A value of nil indicates basic permissions. + @param expirationDate The expiration date. A value of nil defaults to `[NSDate distantFuture]`. + @param loginType The login source of the token. + @param refreshDate The date that token was last refreshed. A value of nil defaults to `[NSDate date]`. + */ ++ (FBAccessTokenData *) createTokenFromString:(NSString *)accessToken + permissions:(NSArray *)permissions + expirationDate:(NSDate *)expirationDate + loginType:(FBSessionLoginType)loginType + refreshDate:(NSDate *)refreshDate; + +/*! + @method + + @abstract Creates an FBAccessTokenData from existing information or returns nil if required data is missing. + + @param accessToken The token string. If nil or empty, this method will return nil. + @param permissions The permissions set. A value of nil indicates basic permissions. + @param expirationDate The expiration date. A value of nil defaults to `[NSDate distantFuture]`. + @param loginType The login source of the token. + @param refreshDate The date that token was last refreshed. A value of nil defaults to `[NSDate date]`. + @param permissionsRefreshDate The date the permissions were last refreshed. A value of nil defaults to `[NSDate distantPast]`. + */ ++ (FBAccessTokenData *) createTokenFromString:(NSString *)accessToken + permissions:(NSArray *)permissions + expirationDate:(NSDate *)expirationDate + loginType:(FBSessionLoginType)loginType + refreshDate:(NSDate *)refreshDate + permissionsRefreshDate:(NSDate *)permissionsRefreshDate; + +/*! + @method + + @abstract Returns a dictionary representation of this instance. + + @discussion This is provided for backwards compatibility with previous + access token related APIs that used a NSDictionary (see `FBSessionTokenCachingStrategy`). +*/ +- (NSMutableDictionary *) dictionary; + +/*! + @method + + @abstract Returns a Boolean value that indicates whether a given object is an FBAccessTokenData object and exactly equal the receiver. + + @param accessTokenData the data to compare to the receiver. +*/ +- (BOOL) isEqualToAccessTokenData:(FBAccessTokenData *)accessTokenData; + +/*! + @abstract returns the access token NSString. +*/ +@property (readonly, nonatomic, copy) NSString *accessToken; + +/*! + @abstract returns the permissions associated with the access token. +*/ +@property (readonly, nonatomic, copy) NSArray *permissions; + +/*! + @abstract returns the expiration date of the access token. +*/ +@property (readonly, nonatomic, copy) NSDate *expirationDate; + +/*! + @abstract returns the login type associated with the token. +*/ +@property (readonly, nonatomic) FBSessionLoginType loginType; + +/*! + @abstract returns the date the token was last refreshed. +*/ +@property (readonly, nonatomic, copy) NSDate *refreshDate; + +/*! + @abstract returns the date the permissions were last refreshed. +*/ +@property (readonly, nonatomic, copy) NSDate *permissionsRefreshDate; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAppCall.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAppCall.h new file mode 100644 index 0000000..9756925 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAppCall.h @@ -0,0 +1,232 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBAccessTokenData.h" +#import "FBAppLinkData.h" +#import "FBDialogsData.h" +#import "FBSession.h" + +@class FBAppCall; + +/*! + @typedef FBAppCallHandler + + @abstract + A block that is passed to performAppCall to register for a callback with the results + of that AppCall + + @discussion + Pass a block of this type when calling performAppCall. This will be called on the UI + thread, once the AppCall completes. + + @param call The `FBAppCall` that was completed. + + */ +typedef void (^FBAppCallHandler)(FBAppCall *call); + +/*! + @typedef FBAppLinkFallbackHandler + + @abstract + See `+openDeferredAppLink`. + */ +typedef void (^FBAppLinkFallbackHandler)(NSError *error); + +/*! + @class FBAppCall + + @abstract + The FBAppCall object is used to encapsulate state when the app performs an + action that requires switching over to the native Facebook app, or when the app + receives an App Link. + + @discussion + - Each FBAppCall instance will have a unique ID + - This object is passed into an FBAppCallHandler for context + - dialogData will be present if this AppCall is for a Native Dialog + - appLinkData will be present if this AppCall is for an App Link + - accessTokenData will be present if this AppCall contains an access token. + */ +@interface FBAppCall : NSObject + +/*! @abstract The ID of this FBAppCall instance */ +@property (nonatomic, readonly) NSString *ID; + +/*! @abstract Error that occurred in processing this AppCall */ +@property (nonatomic, readonly) NSError *error; + +/*! @abstract Data related to a Dialog AppCall */ +@property (nonatomic, readonly) FBDialogsData *dialogData; + +/*! @abstract Data for native app link */ +@property (nonatomic, readonly) FBAppLinkData *appLinkData; + +/*! @abstract Access Token that was returned in this AppCall */ +@property (nonatomic, readonly) FBAccessTokenData *accessTokenData; + +/*! + @abstract + Returns an FBAppCall instance from a url, if applicable. Otherwise, returns nil. + + @param url The url. + + @return an FBAppCall instance if the url is valid; nil otherwise. + + @discussion This is typically used for App Link URLs. + */ ++ (FBAppCall *) appCallFromURL:(NSURL *)url; + +/*! + @abstract + Compares the receiving FBAppCall to the passed in FBAppCall + + @param appCall the other FBAppCall to compare to. + + @return YES if the AppCalls can be considered to be the same; NO if otherwise. + */ +- (BOOL)isEqualToAppCall:(FBAppCall *)appCall; + +/*! + @abstract + Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method + of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction + with the native Facebook app or as part of SSO authorization flow. + + @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @return YES if the url was intended for the Facebook SDK, NO if not. + */ ++ (BOOL)handleOpenURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication; + +/*! + @abstract + Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method + of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction + with the native Facebook app or as part of SSO authorization flow. + + @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param handler Optional handler that gives the app the opportunity to do some further processing on urls + that the SDK could not completely process. A fallback handler is not a requirement for such a url to be considered + handled. The fallback handler, if specified, is only ever called sychronously, before the method returns. + + @return YES if the url was intended for the Facebook SDK, NO if not. + */ ++ (BOOL)handleOpenURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication + fallbackHandler:(FBAppCallHandler)handler; + +/*! + @abstract + Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method + of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction + with the native Facebook app or as part of SSO authorization flow. + + @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param session If this url is being sent back to this app as part of SSO authorization flow, then pass in the + session that was being opened. A nil value defaults to FBSession.activeSession + + @return YES if the url was intended for the Facebook SDK, NO if not. + */ ++ (BOOL)handleOpenURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication + withSession:(FBSession *)session; + +/*! + @abstract + Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method + of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction + with the native Facebook app or as part of SSO authorization flow. + + @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param session If this url is being sent back to this app as part of SSO authorization flow, then pass in the + session that was being opened. A nil value defaults to FBSession.activeSession + + @param handler Optional handler that gives the app the opportunity to do some further processing on urls + that the SDK could not completely process. A fallback handler is not a requirement for such a url to be considered + handled. The fallback handler, if specified, is only ever called sychronously, before the method returns. + + @return YES if the url was intended for the Facebook SDK, NO if not. + */ ++ (BOOL)handleOpenURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication + withSession:(FBSession *)session + fallbackHandler:(FBAppCallHandler)handler; + +/*! + @abstract + Call this method when the application's applicationDidBecomeActive: is invoked. + This ensures proper state management of any pending FBAppCalls or pending login flow for the + FBSession.activeSession. If any pending FBAppCalls are found, their registered callbacks + will be invoked with appropriate state + */ ++ (void)handleDidBecomeActive; + +/*! + @abstract + Call this method when the application's applicationDidBecomeActive: is invoked. + This ensures proper state management of any pending FBAppCalls or a pending open for the + passed in FBSession. If any pending FBAppCalls are found, their registered callbacks will + be invoked with appropriate state + + @param session Session that is currently being used. Any pending calls to open will be cancelled. + If no session is provided, then the activeSession (if present) is used. + */ ++ (void)handleDidBecomeActiveWithSession:(FBSession *)session; + +/*! + @abstract + Call this method from the main thread to fetch deferred applink data. This may require + a network round trip. If successful, [+UIApplication openURL:] is invoked with the link + data. Otherwise, the fallbackHandler will be dispatched to the main thread. + + @param fallbackHandler the handler to be invoked if applink data could not be opened. + + @discussion the fallbackHandler may contain an NSError instance to capture any errors. In the + common case where there simply was no app link data, the NSError instance will be nil. + + This method should only be called from a location that occurs after any launching URL has + been processed (e.g., you should call this method from your application delegate's applicationDidBecomeActive:) + to avoid duplicate invocations of openURL:. + + If you must call this from the delegate's didFinishLaunchingWithOptions: you should + only do so if the application is not being launched by a URL. For example, + + if (launchOptions[UIApplicationLaunchOptionsURLKey] == nil) { + [FBAppCall openDeferredAppLink:^(NSError *error) { + // .... + } + } +*/ ++ (void)openDeferredAppLink:(FBAppLinkFallbackHandler)fallbackHandler; + +@end + + + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAppEvents.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAppEvents.h new file mode 100644 index 0000000..d9415d2 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAppEvents.h @@ -0,0 +1,451 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBSession.h" + +/*! + + @typedef FBAppEventsFlushBehavior enum + + @abstract + Control when sends log events to the server + + @discussion + + */ +typedef enum { + + /*! Flush automatically: periodically (once a minute or every 100 logged events) and always at app reactivation. */ + FBAppEventsFlushBehaviorAuto, + + /*! Only flush when the `flush` method is called. When an app is moved to background/terminated, the + events are persisted and re-established at activation, but they will only be written with an + explicit call to `flush`. */ + FBAppEventsFlushBehaviorExplicitOnly, + +} FBAppEventsFlushBehavior; + +/* + * Constant used by NSNotificationCenter for results of flushing AppEvents event logs + */ + +/*! NSNotificationCenter name indicating a result of a failed log flush attempt */ +extern NSString *const FBAppEventsLoggingResultNotification; + + +// Predefined event names for logging events common to many apps. Logging occurs through the `logEvent` family of methods on `FBAppEvents`. +// Common event parameters are provided in the `FBAppEventsParameterNames*` constants. + +// General purpose + +/*! Log this event when an app is being activated, typically in the AppDelegate's applicationDidBecomeActive. */ +extern NSString *const FBAppEventNameActivatedApp; + +/*! Log this event when a user has completed registration with the app. */ +extern NSString *const FBAppEventNameCompletedRegistration; + +/*! Log this event when a user has viewed a form of content in the app. */ +extern NSString *const FBAppEventNameViewedContent; + +/*! Log this event when a user has performed a search within the app. */ +extern NSString *const FBAppEventNameSearched; + +/*! Log this event when the user has rated an item in the app. The valueToSum passed to logEvent should be the numeric rating. */ +extern NSString *const FBAppEventNameRated; + +/*! Log this event when the user has completed a tutorial in the app. */ +extern NSString *const FBAppEventNameCompletedTutorial; + +// Ecommerce related + +/*! Log this event when the user has added an item to their cart. The valueToSum passed to logEvent should be the item's price. */ +extern NSString *const FBAppEventNameAddedToCart; + +/*! Log this event when the user has added an item to their wishlist. The valueToSum passed to logEvent should be the item's price. */ +extern NSString *const FBAppEventNameAddedToWishlist; + +/*! Log this event when the user has entered the checkout process. The valueToSum passed to logEvent should be the total price in the cart. */ +extern NSString *const FBAppEventNameInitiatedCheckout; + +/*! Log this event when the user has entered their payment info. */ +extern NSString *const FBAppEventNameAddedPaymentInfo; + +/*! Log this event when the user has completed a purchase. The `[FBAppEvents logPurchase]` method is a shortcut for logging this event. */ +extern NSString *const FBAppEventNamePurchased; + +// Gaming related + +/*! Log this event when the user has achieved a level in the app. */ +extern NSString *const FBAppEventNameAchievedLevel; + +/*! Log this event when the user has unlocked an achievement in the app. */ +extern NSString *const FBAppEventNameUnlockedAchievement; + +/*! Log this event when the user has spent app credits. The valueToSum passed to logEvent should be the number of credits spent. */ +extern NSString *const FBAppEventNameSpentCredits; + + + +// Predefined event name parameters for common additional information to accompany events logged through the `logEvent` family +// of methods on `FBAppEvents`. Common event names are provided in the `FBAppEventName*` constants. + +/*! Parameter key used to specify currency used with logged event. E.g. "USD", "EUR", "GBP". See ISO-4217 for specific values. One reference for these is . */ +extern NSString *const FBAppEventParameterNameCurrency; + +/*! Parameter key used to specify method user has used to register for the app, e.g., "Facebook", "email", "Twitter", etc */ +extern NSString *const FBAppEventParameterNameRegistrationMethod; + +/*! Parameter key used to specify a generic content type/family for the logged event, e.g. "music", "photo", "video". Options to use will vary based upon what the app is all about. */ +extern NSString *const FBAppEventParameterNameContentType; + +/*! Parameter key used to specify an ID for the specific piece of content being logged about. Could be an EAN, article identifier, etc., depending on the nature of the app. */ +extern NSString *const FBAppEventParameterNameContentID; + +/*! Parameter key used to specify the string provided by the user for a search operation. */ +extern NSString *const FBAppEventParameterNameSearchString; + +/*! Parameter key used to specify whether the activity being logged about was successful or not. `FBAppEventParameterValueYes` and `FBAppEventParameterValueNo` are good canonical values to use for this parameter. */ +extern NSString *const FBAppEventParameterNameSuccess; + +/*! Parameter key used to specify the maximum rating available for the `FBAppEventNameRate` event. E.g., "5" or "10". */ +extern NSString *const FBAppEventParameterNameMaxRatingValue; + +/*! Parameter key used to specify whether payment info is available for the `FBAppEventNameInitiatedCheckout` event. `FBAppEventParameterValueYes` and `FBAppEventParameterValueNo` are good canonical values to use for this parameter. */ +extern NSString *const FBAppEventParameterNamePaymentInfoAvailable; + +/*! Parameter key used to specify how many items are being processed for an `FBAppEventNameInitiatedCheckout` or `FBAppEventNamePurchased` event. */ +extern NSString *const FBAppEventParameterNameNumItems; + +/*! Parameter key used to specify the level achieved in a `FBAppEventNameAchieved` event. */ +extern NSString *const FBAppEventParameterNameLevel; + +/*! Parameter key used to specify a description appropriate to the event being logged. E.g., the name of the achievement unlocked in the `FBAppEventNameAchievementUnlocked` event. */ +extern NSString *const FBAppEventParameterNameDescription; + + + +// Predefined values to assign to event parameters that accompany events logged through the `logEvent` family +// of methods on `FBAppEvents`. Common event parameters are provided in the `FBAppEventParameterName*` constants. + +/*! Yes-valued parameter value to be used with parameter keys that need a Yes/No value */ +extern NSString *const FBAppEventParameterValueYes; + +/*! No-valued parameter value to be used with parameter keys that need a Yes/No value */ +extern NSString *const FBAppEventParameterValueNo; + + +/*! + + @class FBAppEvents + + @abstract + Client-side event logging for specialized application analytics available through Facebook App Insights + and for use with Facebook Ads conversion tracking and optimization. + + @discussion + The `FBAppEvents` static class has a few related roles: + + + Logging predefined and application-defined events to Facebook App Insights with a + numeric value to sum across a large number of events, and an optional set of key/value + parameters that define "segments" for this event (e.g., 'purchaserStatus' : 'frequent', or + 'gamerLevel' : 'intermediate') + + + Logging events to later be used for ads optimization around lifetime value. + + + Methods that control the way in which events are flushed out to the Facebook servers. + + Here are some important characteristics of the logging mechanism provided by `FBAppEvents`: + + + Events are not sent immediately when logged. They're cached and flushed out to the Facebook servers + in a number of situations: + - when an event count threshold is passed (currently 100 logged events). + - when a time threshold is passed (currently 60 seconds). + - when an app has gone to background and is then brought back to the foreground. + + + Events will be accumulated when the app is in a disconnected state, and sent when the connection is + restored and one of the above 'flush' conditions are met. + + + The `FBAppEvents` class in thread-safe in that events may be logged from any of the app's threads. + + + The developer can set the `flushBehavior` on `FBAppEvents` to force the flushing of events to only + occur on an explicit call to the `flush` method. + + + The developer can turn on console debug output for event logging and flushing to the server by using + the `FBLoggingBehaviorAppEvents` value in `[FBSettings setLoggingBehavior:]`. + + Some things to note when logging events: + + + There is a limit on the number of unique event names an app can use, on the order of 300. + + There is a limit to the number of unique parameter names in the provided parameters that can + be used per event, on the order of 10. This is not just for an individual call, but for all + invocations for that eventName. + + Event names and parameter names (the keys in the NSDictionary) must be between 2 and 40 characters, and + must consist of alphanumeric characters, _, -, or spaces. + + The length of each parameter value can be no more than on the order of 100 characters. + + */ +@interface FBAppEvents : NSObject + +/* + * Basic event logging + */ + +/*! + + @method + + @abstract + Log an event with just an eventName. + + @param eventName The name of the event to record. Limitations on number of events and name length + are given in the `FBAppEvents` documentation. + + */ ++ (void)logEvent:(NSString *)eventName; + +/*! + + @method + + @abstract + Log an event with an eventName and a numeric value to be aggregated with other events of this name. + + @param eventName The name of the event to record. Limitations on number of events and name length + are given in the `FBAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants. + + @param valueToSum Amount to be aggregated into all events of this eventName, and App Insights will report + the cumulative and average value of this amount. + */ ++ (void)logEvent:(NSString *)eventName + valueToSum:(double)valueToSum; + + +/*! + + @method + + @abstract + Log an event with an eventName and a set of key/value pairs in the parameters dictionary. + Parameter limitations are described above. + + @param eventName The name of the event to record. Limitations on number of events and name construction + are given in the `FBAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants. + + @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must + be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of + parameters and name construction are given in the `FBAppEvents` documentation. Commonly used parameter names + are provided in `FBAppEventParameterName*` constants. + */ ++ (void)logEvent:(NSString *)eventName + parameters:(NSDictionary *)parameters; + +/*! + + @method + + @abstract + Log an event with an eventName, a numeric value to be aggregated with other events of this name, + and a set of key/value pairs in the parameters dictionary. + + @param eventName The name of the event to record. Limitations on number of events and name construction + are given in the `FBAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants. + + @param valueToSum Amount to be aggregated into all events of this eventName, and App Insights will report + the cumulative and average value of this amount. + + @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must + be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of + parameters and name construction are given in the `FBAppEvents` documentation. Commonly used parameter names + are provided in `FBAppEventParameterName*` constants. + + */ ++ (void)logEvent:(NSString *)eventName + valueToSum:(double)valueToSum + parameters:(NSDictionary *)parameters; + + +/*! + + @method + + @abstract + Log an event with an eventName, a numeric value to be aggregated with other events of this name, + and a set of key/value pairs in the parameters dictionary. Providing session lets the developer + target a particular . If nil is provided, then `[FBSession activeSession]` will be used. + + @param eventName The name of the event to record. Limitations on number of events and name construction + are given in the `FBAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants. + + @param valueToSum Amount to be aggregated into all events of this eventName, and App Insights will report + the cumulative and average value of this amount. Note that this is an NSNumber, and a value of `nil` denotes + that this event doesn't have a value associated with it for summation. + + @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must + be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of + parameters and name construction are given in the `FBAppEvents` documentation. Commonly used parameter names + are provided in `FBAppEventParameterName*` constants. + + @param session to direct the event logging to, and thus be logged with whatever user (if any) + is associated with that . + */ ++ (void)logEvent:(NSString *)eventName + valueToSum:(NSNumber *)valueToSum + parameters:(NSDictionary *)parameters + session:(FBSession *)session; + + +/* + * Purchase logging + */ + +/*! + + @method + + @abstract + Log a purchase of the specified amount, in the specified currency. + + @param purchaseAmount Purchase amount to be logged, as expressed in the specified currency. This value + will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). + + @param currency Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for + specific values. One reference for these is . + + @discussion This event immediately triggers a flush of the `FBAppEvents` event queue, unless the `flushBehavior` is set + to `FBAppEventsFlushBehaviorExplicitOnly`. + + */ ++ (void)logPurchase:(double)purchaseAmount + currency:(NSString *)currency; + +/*! + + @method + + @abstract + Log a purchase of the specified amount, in the specified currency, also providing a set of + additional characteristics describing the purchase. + + @param purchaseAmount Purchase amount to be logged, as expressed in the specified currency.This value + will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). + + @param currency Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for + specific values. One reference for these is . + + @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must + be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of + parameters and name construction are given in the `FBAppEvents` documentation. Commonly used parameter names + are provided in `FBAppEventParameterName*` constants. + + @discussion This event immediately triggers a flush of the `FBAppEvents` event queue, unless the `flushBehavior` is set + to `FBAppEventsFlushBehaviorExplicitOnly`. + + */ ++ (void)logPurchase:(double)purchaseAmount + currency:(NSString *)currency + parameters:(NSDictionary *)parameters; + +/*! + + @method + + @abstract + Log a purchase of the specified amount, in the specified currency, also providing a set of + additional characteristics describing the purchase, as well as an to log to. + + @param purchaseAmount Purchase amount to be logged, as expressed in the specified currency.This value + will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). + + @param currency Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for + specific values. One reference for these is . + + @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must + be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of + parameters and name construction are given in the `FBAppEvents` documentation. Commonly used parameter names + are provided in `FBAppEventParameterName*` constants. + + @param session to direct the event logging to, and thus be logged with whatever user (if any) + is associated with that . A value of `nil` will use `[FBSession activeSession]`. + + @discussion This event immediately triggers a flush of the `FBAppEvents` event queue, unless the `flushBehavior` is set + to `FBAppEventsFlushBehaviorExplicitOnly`. + + */ ++ (void)logPurchase:(double)purchaseAmount + currency:(NSString *)currency + parameters:(NSDictionary *)parameters + session:(FBSession *)session; + +/*! + @method + + @abstract This method has been replaced by [FBSettings limitEventAndDataUsage] */ ++ (BOOL)limitEventUsage __attribute__ ((deprecated("use [FBSettings limitEventAndDataUsage] instead"))); + +/*! + @method + + @abstract This method has been replaced by [FBSettings setLimitEventUsage] */ ++ (void)setLimitEventUsage:(BOOL)limitEventUsage __attribute__ ((deprecated("use [FBSettings setLimitEventAndDataUsage] instead"))); + +/*! + + @method + + @abstract + Notifies the events system that the app has launched & logs an activatedApp event. Should typically be placed in the app delegates' `applicationDidBecomeActive:` method. + */ ++ (void)activateApp; + +/* + * Control over event batching/flushing + */ + +/*! + + @method + + @abstract + Get the current event flushing behavior specifying when events are sent back to Facebook servers. + */ ++ (FBAppEventsFlushBehavior)flushBehavior; + +/*! + + @method + + @abstract + Set the current event flushing behavior specifying when events are sent back to Facebook servers. + + @param flushBehavior The desired `FBAppEventsFlushBehavior` to be used. + */ ++ (void)setFlushBehavior:(FBAppEventsFlushBehavior)flushBehavior; + + +/*! + + @method + + @abstract + Explicitly kick off flushing of events to Facebook. This is an asynchronous method, but it does initiate an immediate + kick off. Server failures will be reported through the NotificationCenter with notification ID `FBAppEventsLoggingResultNotification`. + */ ++ (void)flush; + + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAppLinkData.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAppLinkData.h new file mode 100644 index 0000000..dfdcd2e --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBAppLinkData.h @@ -0,0 +1,51 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +/*! + @abstract This class contains information that represents an App Link from Facebook. + */ +@interface FBAppLinkData : NSObject + +/*! @abstract The target */ +@property (readonly) NSURL *targetURL; + +/*! @abstract List of the types of actions for this target */ +@property (readonly) NSArray *actionTypes; + +/*! @abstract List of the ids of the actions for this target */ +@property (readonly) NSArray *actionIDs; + +/*! @abstract Reference breadcrumb provided during creation of story */ +@property (readonly) NSString *ref; + +/*! @abstract User Agent string set by the referer */ +@property (readonly) NSString *userAgent; + +/*! @abstract Referer data is a JSON object set by the referer with referer-specific content */ +@property (readonly) NSDictionary *refererData; + +/*! @abstract Full set of query parameters for this app link */ +@property (readonly) NSDictionary *originalQueryParameters; + +/*! @abstract Original url from which applinkData was extracted */ +@property (readonly) NSURL *originalURL; + +/*! @abstract Addtional arguments supplied with the App Link data. */ +@property (readonly) NSDictionary *arguments; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBCacheDescriptor.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBCacheDescriptor.h new file mode 100644 index 0000000..cf0b34d --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBCacheDescriptor.h @@ -0,0 +1,43 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBSession.h" + +/*! + @class + + @abstract + Base class from which CacheDescriptors derive, provides a method to fetch data for later use + + @discussion + Cache descriptors allow your application to specify the arguments that will be + later used with another object, such as the FBFriendPickerViewController. By using a cache descriptor + instance, an application can choose to fetch data ahead of the point in time where the data is needed. + */ +@interface FBCacheDescriptor : NSObject + +/*! + @method + @abstract + Fetches and caches the data described by the cache descriptor instance, for the given session. + + @param session the to use for fetching data + */ +- (void)prefetchAndCacheForSession:(FBSession*)session; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBConnect.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBConnect.h new file mode 100644 index 0000000..2d688e9 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBConnect.h @@ -0,0 +1,21 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "FBDialog.h" +#include "FBLoginDialog.h" +#include "FBRequest.h" +#include "Facebook.h" diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialog.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialog.h new file mode 100644 index 0000000..8bee943 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialog.h @@ -0,0 +1,165 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +@protocol FBDialogDelegate; +@class FBFrictionlessRequestSettings; + +/** + * Do not use this interface directly, instead, use dialog in Facebook.h + * + * Facebook dialog interface for start the facebook webView UIServer Dialog. + */ + +@interface FBDialog : UIView { + id _delegate; + NSMutableDictionary *_params; + NSString * _serverURL; + NSURL* _loadingURL; + UIWebView* _webView; + UIActivityIndicatorView* _spinner; + UIButton* _closeButton; + UIInterfaceOrientation _orientation; + BOOL _showingKeyboard; + BOOL _isViewInvisible; + FBFrictionlessRequestSettings* _frictionlessSettings; + + // Ensures that UI elements behind the dialog are disabled. + UIView* _modalBackgroundView; +} + +/** + * The delegate. + */ +@property (nonatomic, assign) id delegate; + +/** + * The parameters. + */ +@property (nonatomic, retain) NSMutableDictionary* params; + +- (NSString *) getStringFromUrl: (NSString*) url needle:(NSString *) needle; + +- (id)initWithURL: (NSString *) loadingURL + params: (NSMutableDictionary *) params + isViewInvisible: (BOOL) isViewInvisible + frictionlessSettings: (FBFrictionlessRequestSettings *) frictionlessSettings + delegate: (id ) delegate; + +/** + * Displays the view with an animation. + * + * The view will be added to the top of the current key window. + */ +- (void)show; + +/** + * Displays the first page of the dialog. + * + * Do not ever call this directly. It is intended to be overriden by subclasses. + */ +- (void)load; + +/** + * Displays a URL in the dialog. + */ +- (void)loadURL:(NSString*)url + get:(NSDictionary*)getParams; + +/** + * Hides the view and notifies delegates of success or cancellation. + */ +- (void)dismissWithSuccess:(BOOL)success animated:(BOOL)animated; + +/** + * Hides the view and notifies delegates of an error. + */ +- (void)dismissWithError:(NSError*)error animated:(BOOL)animated; + +/** + * Subclasses may override to perform actions just prior to showing the dialog. + */ +- (void)dialogWillAppear; + +/** + * Subclasses may override to perform actions just after the dialog is hidden. + */ +- (void)dialogWillDisappear; + +/** + * Subclasses should override to process data returned from the server in a 'fbconnect' url. + * + * Implementations must call dismissWithSuccess:YES at some point to hide the dialog. + */ +- (void)dialogDidSucceed:(NSURL *)url; + +/** + * Subclasses should override to process data returned from the server in a 'fbconnect' url. + * + * Implementations must call dismissWithSuccess:YES at some point to hide the dialog. + */ +- (void)dialogDidCancel:(NSURL *)url; +@end + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +/* + *Your application should implement this delegate + */ +@protocol FBDialogDelegate + +@optional + +/** + * Called when the dialog succeeds and is about to be dismissed. + */ +- (void)dialogDidComplete:(FBDialog *)dialog; + +/** + * Called when the dialog succeeds with a returning url. + */ +- (void)dialogCompleteWithUrl:(NSURL *)url; + +/** + * Called when the dialog get canceled by the user. + */ +- (void)dialogDidNotCompleteWithUrl:(NSURL *)url; + +/** + * Called when the dialog is cancelled and is about to be dismissed. + */ +- (void)dialogDidNotComplete:(FBDialog *)dialog; + +/** + * Called when dialog failed to load due to an error. + */ +- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError *)error; + +/** + * Asks if a link touched by a user should be opened in an external browser. + * + * If a user touches a link, the default behavior is to open the link in the Safari browser, + * which will cause your app to quit. You may want to prevent this from happening, open the link + * in your own internal browser, or perhaps warn the user that they are about to leave your app. + * If so, implement this method on your delegate and return NO. If you warn the user, you + * should hold onto the URL and once you have received their acknowledgement open the URL yourself + * using [[UIApplication sharedApplication] openURL:]. + */ +- (BOOL)dialog:(FBDialog*)dialog shouldOpenURLInExternalBrowser:(NSURL *)url; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialogs.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialogs.h new file mode 100644 index 0000000..1d84796 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialogs.h @@ -0,0 +1,492 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +#import "FBAppCall.h" +#import "FBOpenGraphActionShareDialogParams.h" +#import "FBShareDialogParams.h" + +@class FBSession; +@protocol FBOpenGraphAction; + +/*! + @typedef FBNativeDialogResult enum + + @abstract + Passed to a handler to indicate the result of a dialog being displayed to the user. + */ +typedef enum { + /*! Indicates that the dialog action completed successfully. */ + FBOSIntegratedShareDialogResultSucceeded = 0, + /*! Indicates that the dialog action was cancelled (either by the user or the system). */ + FBOSIntegratedShareDialogResultCancelled = 1, + /*! Indicates that the dialog could not be shown (because not on ios6 or ios6 auth was not used). */ + FBOSIntegratedShareDialogResultError = 2 +} FBOSIntegratedShareDialogResult; + +/*! + @typedef + + @abstract Defines a handler that will be called in response to the native share dialog + being displayed. + */ +typedef void (^FBOSIntegratedShareDialogHandler)(FBOSIntegratedShareDialogResult result, NSError *error); + +/*! + @typedef FBDialogAppCallCompletionHandler + + @abstract + A block that when passed to a method in FBDialogs is called back + with the results of the AppCall for that dialog. + + @discussion + This will be called on the UI thread, once the AppCall completes. + + @param call The `FBAppCall` that was completed. + + @param results The results of the AppCall for the dialog. This parameters is present + purely for convenience, and is the exact same value as call.dialogData.results. + + @param error The `NSError` representing any error that occurred. This parameters is + present purely for convenience, and is the exact same value as call.error. + + */ +typedef void (^FBDialogAppCallCompletionHandler)( +FBAppCall *call, +NSDictionary *results, +NSError *error); + +/*! + @class FBDialogs + + @abstract + Provides methods to display native (i.e., non-Web-based) dialogs to the user. + + @discussion + If you are building an app with a urlSchemeSuffix, you should also set the appropriate + plist entry. See `[FBSettings defaultUrlSchemeSuffix]`. + */ +@interface FBDialogs : NSObject + +/*! + @abstract + Presents a dialog that allows the user to share a status update that may include + text, images, or URLs. This dialog is only available on iOS 6.0 and above. The + current active session returned by [FBSession activeSession] will be used to determine + whether the dialog will be displayed. If a session is active, it must be open and the + login method used to authenticate the user must be native iOS 6.0 authentication. + If no session active, then whether the call succeeds or not will depend on + whether Facebook integration has been configured. + + @param viewController The view controller which will present the dialog. + + @param initialText The text which will initially be populated in the dialog. The user + will have the opportunity to edit this text before posting it. May be nil. + + @param image A UIImage that will be attached to the status update. May be nil. + + @param url An NSURL that will be attached to the status update. May be nil. + + @param handler A handler that will be called when the dialog is dismissed, or if an error + occurs. May be nil. + + @return YES if the dialog was presented, NO if not (in the case of a NO result, the handler + will still be called, with an error indicating the reason the dialog was not displayed) + */ ++ (BOOL)presentOSIntegratedShareDialogModallyFrom:(UIViewController*)viewController + initialText:(NSString*)initialText + image:(UIImage*)image + url:(NSURL*)url + handler:(FBOSIntegratedShareDialogHandler)handler; + +/*! + @abstract + Presents a dialog that allows the user to share a status update that may include + text, images, or URLs. This dialog is only available on iOS 6.0 and above. The + current active session returned by [FBSession activeSession] will be used to determine + whether the dialog will be displayed. If a session is active, it must be open and the + login method used to authenticate the user must be native iOS 6.0 authentication. + If no session active, then whether the call succeeds or not will depend on + whether Facebook integration has been configured. + + @param viewController The view controller which will present the dialog. + + @param initialText The text which will initially be populated in the dialog. The user + will have the opportunity to edit this text before posting it. May be nil. + + @param images An array of UIImages that will be attached to the status update. May + be nil. + + @param urls An array of NSURLs that will be attached to the status update. May be nil. + + @param handler A handler that will be called when the dialog is dismissed, or if an error + occurs. May be nil. + + @return YES if the dialog was presented, NO if not (in the case of a NO result, the handler + will still be called, with an error indicating the reason the dialog was not displayed) + */ ++ (BOOL)presentOSIntegratedShareDialogModallyFrom:(UIViewController*)viewController + initialText:(NSString*)initialText + images:(NSArray*)images + urls:(NSArray*)urls + handler:(FBOSIntegratedShareDialogHandler)handler; + +/*! + @abstract + Presents a dialog that allows the user to share a status update that may include + text, images, or URLs. This dialog is only available on iOS 6.0 and above. An + may be specified, or nil may be passed to indicate that the current + active session should be used. If a session is specified (whether explicitly or by + virtue of being the active session), it must be open and the login method used to + authenticate the user must be native iOS 6.0 authentication. If no session is specified + (and there is no active session), then whether the call succeeds or not will depend on + whether Facebook integration has been configured. + + @param viewController The view controller which will present the dialog. + + @param session The to use to determine whether or not the user has been + authenticated with iOS native authentication. If nil, then [FBSession activeSession] + will be checked. See discussion above for the implications of nil or non-nil session. + + @param initialText The text which will initially be populated in the dialog. The user + will have the opportunity to edit this text before posting it. May be nil. + + @param images An array of UIImages that will be attached to the status update. May + be nil. + + @param urls An array of NSURLs that will be attached to the status update. May be nil. + + @param handler A handler that will be called when the dialog is dismissed, or if an error + occurs. May be nil. + + @return YES if the dialog was presented, NO if not (in the case of a NO result, the handler + will still be called, with an error indicating the reason the dialog was not displayed) + */ ++ (BOOL)presentOSIntegratedShareDialogModallyFrom:(UIViewController*)viewController + session:(FBSession*)session + initialText:(NSString*)initialText + images:(NSArray*)images + urls:(NSArray*)urls + handler:(FBOSIntegratedShareDialogHandler)handler; + +/*! + @abstract + Determines whether a call to presentShareDialogModallyFrom: will successfully present + a dialog. This is useful for applications that need to modify the available UI controls + depending on whether the dialog is available on the current platform and for the current + user. + + @param session The to use to determine whether or not the user has been + authenticated with iOS native authentication. If nil, then [FBSession activeSession] + will be checked. See discussion above for the implications of nil or non-nil session. + + @return YES if the dialog would be presented for the session, and NO if not + */ ++ (BOOL)canPresentOSIntegratedShareDialogWithSession:(FBSession*)session; + +/*! + @abstract + Determines whether a call to presentShareDialogWithTarget: will successfully + present a dialog in the Facebook application. This is useful for applications that + need to modify the available UI controls depending on whether the dialog is + available on the current platform. + + @param params The parameters for the FB share dialog. + + @return YES if the dialog would be presented, and NO if not + + @discussion A return value of YES here indicates that the corresponding + presentShareDialogWithParams method will return a non-nil FBAppCall for the same + params. And vice versa. + */ ++ (BOOL)canPresentShareDialogWithParams:(FBShareDialogParams *)params; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to share a status + update that may include text, images, or URLs. No session is required, and the app + does not need to be authorized to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param params The parameters for the FB share dialog. + + @param clientState An NSDictionary that's passed through when the completion handler + is called. This is useful for the app to maintain state about the share request that + was made so as to have appropriate action when the handler is called. May be nil. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithParams:(FBShareDialogParams *)params + clientState:(NSDictionary *)clientState + handler:(FBDialogAppCallCompletionHandler)handler; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to share the + supplied link. No session is required, and the app does not need to be authorized + to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param link The URL link to be attached to the post. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithLink:(NSURL *)link + handler:(FBDialogAppCallCompletionHandler)handler; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to share the + supplied link. No session is required, and the app does not need to be authorized + to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param link The URL link to be attached to the post. + + @param name The name, or title associated with the link. May be nil. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithLink:(NSURL *)link + name:(NSString *)name + handler:(FBDialogAppCallCompletionHandler)handler; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to share the + supplied link. No session is required, and the app does not need to be authorized + to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param link The URL link to be attached to the post. + + @param name The name, or title associated with the link. May be nil. + + @param caption The caption to be used with the link. May be nil. + + @param description The description associated with the link. May be nil. + + @param picture The link to a thumbnail to associate with the link. May be nil. + + @param clientState An NSDictionary that's passed through when the completion handler + is called. This is useful for the app to maintain state about the share request that + was made so as to have appropriate action when the handler is called. May be nil. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithLink:(NSURL *)link + name:(NSString *)name + caption:(NSString *)caption + description:(NSString *)description + picture:(NSURL *)picture + clientState:(NSDictionary *)clientState + handler:(FBDialogAppCallCompletionHandler)handler; + +/*! + @abstract + Determines whether a call to presentShareDialogWithOpenGraphActionParams:clientState:handler: + will successfully present a dialog in the Facebook application. This is useful for applications + that need to modify the available UI controls depending on whether the dialog is + available on the current platform. + + @param params The parameters for the FB share dialog. + + @return YES if the dialog would be presented, and NO if not + + @discussion A return value of YES here indicates that the corresponding + presentShareDialogWithOpenGraphActionParams method will return a non-nil FBAppCall for + the same params. And vice versa. + */ ++ (BOOL)canPresentShareDialogWithOpenGraphActionParams:(FBOpenGraphActionShareDialogParams *)params; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to publish an Open + Graph action. No session is required, and the app does not need to be authorized to call + this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param params The parameters for the Open Graph action dialog. + + @param clientState An NSDictionary that's passed through when the completion handler + is called. This is useful for the app to maintain state about the share request that + was made so as to have appropriate action when the handler is called. May be nil. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithOpenGraphActionParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithOpenGraphActionParams:(FBOpenGraphActionShareDialogParams *)params + clientState:(NSDictionary *)clientState + handler:(FBDialogAppCallCompletionHandler)handler; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to publish the + supplied Open Graph action. No session is required, and the app does not need to be + authorized to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param action The Open Graph action to be published. May not be nil. + + @param actionType the fully-specified Open Graph action type of the action (e.g., + my_app_namespace:my_action). + + @param previewPropertyName the name of the property on the action that represents the + primary Open Graph object associated with the action; this object will be displayed in the + preview portion of the share dialog. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithOpenGraphActionParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithOpenGraphAction:(id)action + actionType:(NSString *)actionType + previewPropertyName:(NSString *)previewPropertyName + handler:(FBDialogAppCallCompletionHandler) handler; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to publish the + supplied Open Graph action. No session is required, and the app does not need to be + authorized to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param action The Open Graph action to be published. May not be nil. + + @param actionType the fully-specified Open Graph action type of the action (e.g., + my_app_namespace:my_action). + + @param previewPropertyName the name of the property on the action that represents the + primary Open Graph object associated with the action; this object will be displayed in the + preview portion of the share dialog. + + @param clientState An NSDictionary that's passed through when the completion handler + is called. This is useful for the app to maintain state about the share request that + was made so as to have appropriate action when the handler is called. May be nil. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithOpenGraphActionParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithOpenGraphAction:(id)action + actionType:(NSString *)actionType + previewPropertyName:(NSString *)previewPropertyName + clientState:(NSDictionary *)clientState + handler:(FBDialogAppCallCompletionHandler) handler; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialogsData.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialogsData.h new file mode 100644 index 0000000..bffbc46 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialogsData.h @@ -0,0 +1,35 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +/*! + @abstract + This class encapsulates state and data related to the presentation and completion + of a dialog. + */ +@interface FBDialogsData : NSObject + +/*! @abstract The method being performed */ +@property (nonatomic, readonly) NSString *method; +/*! @abstract The arguments being passed to the entity that will show the dialog */ +@property (nonatomic, readonly) NSDictionary *arguments; +/*! @abstract Client JSON state that is passed through to the completion handler for context */ +@property (nonatomic, readonly) NSDictionary *clientState; +/*! @abstract Results of this FBAppCall that are only set before calling an FBAppCallHandler */ +@property (nonatomic, readonly) NSDictionary *results; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialogsParams.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialogsParams.h new file mode 100644 index 0000000..9197de5 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBDialogsParams.h @@ -0,0 +1,28 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +/*! + @class FBDialogsParams + + @abstract + This object is used as a base class for parameters passed to native dialogs that + open in the Facebook app. + */ +@interface FBDialogsParams : NSObject + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBError.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBError.h new file mode 100644 index 0000000..70ef2a4 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBError.h @@ -0,0 +1,372 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +/*! + The NSError domain of all errors returned by the Facebook SDK. +*/ +extern NSString *const FacebookSDKDomain; + +/*! + The NSError domain of all errors surfaced by the Facebook SDK that + were returned by the Facebook Application + */ +extern NSString *const FacebookNativeApplicationDomain; + +/*! + The key in the userInfo NSDictionary of NSError where you can find + the inner NSError (if any). +*/ +extern NSString *const FBErrorInnerErrorKey; + +/*! + The key in the userInfo NSDictionary of NSError for the parsed JSON response + from the server. In case of a batch, includes the JSON for a single FBRequest. +*/ +extern NSString *const FBErrorParsedJSONResponseKey; + +/*! + The key in the userInfo NSDictionary of NSError indicating + the HTTP status code of the response (if any). +*/ +extern NSString *const FBErrorHTTPStatusCodeKey; + +/*! + @abstract Error codes returned by the Facebook SDK in NSError. + + @discussion + These are valid only in the scope of FacebookSDKDomain. + */ +typedef enum FBErrorCode { + /*! + Like nil for FBErrorCode values, represents an error code that + has not been initialized yet. + */ + FBErrorInvalid = 0, + + /// The operation failed because it was cancelled. + FBErrorOperationCancelled, + + /// A login attempt failed + FBErrorLoginFailedOrCancelled, + + /// The graph API returned an error for this operation. + FBErrorRequestConnectionApi, + + /*! + The operation failed because the server returned an unexpected + response. You can get this error if you are not using the most + recent SDK, or if you set your application's migration settings + incorrectly for the version of the SDK you are using. + + If this occurs on the current SDK with proper app migration + settings, you may need to try changing to one request per batch. + */ + FBErrorProtocolMismatch, + + /// Non-success HTTP status code was returned from the operation. + FBErrorHTTPError, + + /// An endpoint that returns a binary response was used with FBRequestConnection; + /// endpoints that return image/jpg, etc. should be accessed using NSURLRequest + FBErrorNonTextMimeTypeReturned, + + /// An error occurred while trying to display a native dialog + FBErrorDialog, + + /// An error occurred using the FBAppEvents class + FBErrorAppEvents, + + /// An error occurred related to an iOS API call + FBErrorSystemAPI, + + /// An error occurred while trying to fetch publish install response data + FBErrorPublishInstallResponse, + + /*! + The application had its applicationDidBecomeActive: method called while waiting + on a response from the native Facebook app for a pending FBAppCall. + */ + FBErrorAppActivatedWhilePendingAppCall, + + /*! + The application had its openURL: method called from a source that was not a + Facebook app and with a URL that was intended for the AppBridge + */ + FBErrorUntrustedURL, + + /*! + The URL passed to FBAppCall, was not able to be parsed + */ + FBErrorMalformedURL, + + /*! + The operation failed because the session is currently busy reconnecting. + */ + FBErrorSessionReconnectInProgess, + + /*! + Reserved for future use. + */ + FBErrorOperationDisallowedForRestrictedTreament, +} FBErrorCode; + +/*! + @abstract Error codes returned by the Facebook SDK in NSError. + + @discussion + These are valid only in the scope of FacebookNativeApplicationDomain. + */ +typedef enum FBNativeApplicationErrorCode { + // A general error in processing an FBAppCall, without a known cause. Unhandled exceptions are a good example + FBAppCallErrorUnknown = 1, + + // The FBAppCall cannot be processed for some reason + FBAppCallErrorUnsupported = 2, + + // The FBAppCall is for a method that does not exist (or is turned off) + FBAppCallErrorUnknownMethod = 3, + + // The FBAppCall cannot be processed at the moment, but can be retried at a later time. + FBAppCallErrorServiceBusy = 4, + + // Share was called in the native Facebook app with incomplete or incorrect arguments + FBShareErrorInvalidParam = 100, + + // A server error occurred while calling Share in the native Facebook app. + FBShareErrorServer = 102, + + // An unknown error occurred while calling Share in the native Facebook app. + FBShareErrorUnknown = 103, + + // Disallowed from calling Share in the native Facebook app. + FBShareErrorDenied = 104, + +} FBNativeApplicationErrorCode; + +/*! + @typedef FBErrorCategory enum + + @abstract Indicates the Facebook SDK classification for the error + + @discussion + */ +typedef enum { + /*! Indicates that the error category is invalid and likely represents an error that + is unrelated to Facebook or the Facebook SDK */ + FBErrorCategoryInvalid = 0, + /*! Indicates that the error may be authentication related but the application should retry the operation. + This case may involve user action that must be taken, and so the application should also test + the fberrorShouldNotifyUser property and if YES display fberrorUserMessage to the user before retrying.*/ + FBErrorCategoryRetry = 1, + /*! Indicates that the error is authentication related and the application should reopen the session*/ + FBErrorCategoryAuthenticationReopenSession = 2, + /*! Indicates that the error is permission related */ + FBErrorCategoryPermissions = 3, + /*! Indicates that the error implies that the server had an unexpected failure or may be temporarily down */ + FBErrorCategoryServer = 4, + /*! Indicates that the error results from the server throttling the client */ + FBErrorCategoryThrottling = 5, + /*! Indicates the user cancelled the operation */ + FBErrorCategoryUserCancelled = 6, + /*! Indicates that the error is Facebook-related but is uncategorizable, and likely newer than the + current version of the SDK */ + FBErrorCategoryFacebookOther = -1, + /*! Indicates that the error is an application error resulting in a bad or malformed request to the server. */ + FBErrorCategoryBadRequest = -2, +} FBErrorCategory; + +/*! + The key in the userInfo NSDictionary of NSError where you can find + the inner NSError (if any). + */ +extern NSString *const FBErrorInnerErrorKey; + +/*! + The key in the userInfo NSDictionary of NSError where you can find + the session associated with the error (if any). +*/ +extern NSString *const FBErrorSessionKey; + +/*! + The key in the userInfo NSDictionary of NSError that points to the URL + that caused an error, in its processing by FBAppCall. + */ +extern NSString *const FBErrorUnprocessedURLKey; + +/*! + The key in the userInfo NSDictionary of NSError for unsuccessful + logins (error.code equals FBErrorLoginFailedOrCancelled). If present, + the value will be one of the constants prefixed by FBErrorLoginFailedReason*. +*/ +extern NSString *const FBErrorLoginFailedReason; + +/*! + The key in the userInfo NSDictionary of NSError for unsuccessful + logins (error.code equals FBErrorLoginFailedOrCancelled). If present, + the value indicates an original login error code wrapped by this error. + This is only used in the web dialog login flow. + */ +extern NSString *const FBErrorLoginFailedOriginalErrorCode; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates the user + cancelled a web dialog auth. +*/ +extern NSString *const FBErrorLoginFailedReasonInlineCancelledValue; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates the user + did not cancel a web dialog auth. + */ +extern NSString *const FBErrorLoginFailedReasonInlineNotCancelledValue; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates the user + cancelled a non-iOS 6 SSO (either Safari or Facebook App) login. + */ +extern NSString *const FBErrorLoginFailedReasonUserCancelledValue; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates the user + cancelled an iOS system login. + */ +extern NSString *const FBErrorLoginFailedReasonUserCancelledSystemValue; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates an error + condition. You may inspect the rest of userInfo for other data. + */ +extern NSString *const FBErrorLoginFailedReasonOtherError; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates the app's + slider in iOS 6 (device Settings -> Privacy -> Facebook {app} ) has + been disabled. + */ +extern NSString *const FBErrorLoginFailedReasonSystemDisallowedWithoutErrorValue; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates an error + has occurred when requesting Facebook account acccess in iOS 6 that was + not `FBErrorLoginFailedReasonSystemDisallowedWithoutErrorValue` nor + a user cancellation. + */ +extern NSString *const FBErrorLoginFailedReasonSystemError; +extern NSString *const FBErrorLoginFailedReasonUnitTestResponseUnrecognized; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key when requesting new permissions fails. Indicates + the request for new permissions has failed because the session was closed. + */ +extern NSString *const FBErrorReauthorizeFailedReasonSessionClosed; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key when requesting new permissions fails. Indicates + the request for new permissions has failed because the user cancelled. + */ +extern NSString *const FBErrorReauthorizeFailedReasonUserCancelled; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key when requesting new permissions fails on + iOS 6 with the Facebook account. Indicates the request for new permissions has + failed because the user cancelled. + */ +extern NSString *const FBErrorReauthorizeFailedReasonUserCancelledSystem; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key when requesting new permissions fails. Indicates + the request for new permissions has failed because the request was + for a different user than the original permission set. + */ +extern NSString *const FBErrorReauthorizeFailedReasonWrongUser; + +/*! + The key in the userInfo NSDictionary of NSError for errors + encountered with `FBDialogs` operations. (error.code equals FBErrorDialog). + If present, the value will be one of the constants prefixed by FBErrorDialog*. +*/ +extern NSString *const FBErrorDialogReasonKey; + +/*! + A value that may appear in the NSError userInfo dictionary under the +`FBErrorDialogReasonKey` key. Indicates that a native dialog is not supported + in the current OS. +*/ +extern NSString *const FBErrorDialogNotSupported; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorDialogReasonKey` key. Indicates that a native dialog cannot be + displayed because it is not appropriate for the current session. +*/ +extern NSString *const FBErrorDialogInvalidForSession; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorDialogReasonKey` key. Indicates that a native dialog cannot be + displayed for some other reason. + */ +extern NSString *const FBErrorDialogCantBeDisplayed; + +/*! + A value that may appear in the NSError userInfo ditionary under the + `FBErrorDialogReasonKey` key. Indicates that a native dialog cannot be + displayed because an Open Graph object that was passed was not configured + correctly. The object must either (a) exist by having an 'id' or 'url' value; + or, (b) configured for creation (by setting the 'type' value and + provisionedForPost property) +*/ +extern NSString *const FBErrorDialogInvalidOpenGraphObject; + +/*! + A value that may appear in the NSError userInfo ditionary under the + `FBErrorDialogReasonKey` key. Indicates that a native dialog cannot be + displayed because the parameters for sharing an Open Graph action were + not configured. The parameters must include an 'action', 'actionType', and + 'previewPropertyName'. + */ +extern NSString *const FBErrorDialogInvalidOpenGraphActionParameters; + +/*! + The key in the userInfo NSDictionary of NSError for errors + encountered with `FBAppEvents` operations (error.code equals FBErrorAppEvents). +*/ +extern NSString *const FBErrorAppEventsReasonKey; + +// Exception strings raised by the Facebook SDK + +/*! + This exception is raised by methods in the Facebook SDK to indicate + that an attempted operation is invalid + */ +extern NSString *const FBInvalidOperationException; + +// Facebook SDK also raises exceptions the following common exceptions: +// NSInvalidArgumentException + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBErrorUtility.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBErrorUtility.h new file mode 100644 index 0000000..61ae2ca --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBErrorUtility.h @@ -0,0 +1,66 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/*! + @class FBErrorUtility + + @abstract A utility class with methods to provide more information for Facebook + related errors if you do not want to use the NSError(FBError) category. + + */ +@interface FBErrorUtility : NSObject + +/*! + @abstract + Categorizes the error, if it is Facebook related, to simplify application mitigation behavior + + @discussion + In general, in response to an error connecting to Facebook, an application should, retry the + operation, request permissions, reconnect the application, or prompt the user to take an action. + The error category can be used to understand the class of error received from Facebook. For more infomation on this + see https://developers.facebook.com/docs/reference/api/errors/ + + @param error the error to be categorized. + */ ++(FBErrorCategory) errorCategoryForError:(NSError *)error; + +/*! + @abstract + If YES indicates that a user action is required in order to successfully continue with the facebook operation + + @discussion + In general if this returns NO, then the application has a straightforward mitigation, such as + retry the operation or request permissions from the user, etc. In some cases it is necessary for the user to + take an action before the application continues to attempt a Facebook connection. For more infomation on this + see https://developers.facebook.com/docs/reference/api/errors/ + + @param error the error to inspect. + */ ++(BOOL) shouldNotifyUserForError:(NSError *)error; + +/*! + @abstract + A message suitable for display to the user, describing a user action necessary to enable Facebook functionality. + Not all Facebook errors yield a message suitable for user display; however in all cases where + fberrorShouldNotifyUser is YES, this property returns a localizable message suitable for display. + + @param error the error to inspect. + */ ++(NSString *) userMessageForError:(NSError *)error; + + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBFrictionlessRecipientCache.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBFrictionlessRecipientCache.h new file mode 100644 index 0000000..09f8d9d --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBFrictionlessRecipientCache.h @@ -0,0 +1,87 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#import + +#import "FBCacheDescriptor.h" +#import "FBRequest.h" +#import "FBWebDialogs.h" + +/*! + @class FBFrictionlessRecipientCache + + @abstract + Maintains a cache of friends that can recieve application requests from the user in + using the frictionless feature of the requests web dialog. + + This class follows the `FBCacheDescriptor` pattern used elsewhere in the SDK, and applications may call + one of the prefetchAndCacheForSession methods to fetch a friend list prior to the + point where a dialog is presented. The cache is also updated with each presentation of the request + dialog using the cache instance. + */ +@interface FBFrictionlessRecipientCache : FBCacheDescriptor + +/*! + @abstract + Initializes an empty cache instance + */ +- (id)init; + +/*! @abstract An array containing the list of known FBIDs for recipients enabled for frictionless requests */ +@property (nonatomic, readwrite, copy) NSArray *recipientIDs; + +/*! + @abstract + Checks to see if a given user or FBID for a user is known to be enabled for + frictionless requestests + + @param user An NSString, NSNumber of `FBGraphUser` representing a user to check + */ +- (BOOL)isFrictionlessRecipient:(id)user; + +/*! + @abstract + Checks to see if a collection of users or FBIDs for users are known to be enabled for + frictionless requestests + + @param users An NSArray of NSString, NSNumber of `FBGraphUser` objects + representing users to check + */ +- (BOOL)areFrictionlessRecipients:(NSArray*)users; + +/*! + @abstract + Issues a request and fills the cache with a list of users to use for frictionless requests + + @param session The session to use for the request; nil indicates that the Active Session should + be used + */ +- (void)prefetchAndCacheForSession:(FBSession *)session; + +/*! + @abstract + Issues a request and fills the cache with a list of users to use for frictionless requests + + @param session The session to use for the request; nil indicates that the Active Session should + be used + + @param handler An optional completion handler, called when the request for cached users has + completed. It can be useful to use the handler to enable UI or perform other request-related + operations, after the cache is populated. + */ +- (void)prefetchAndCacheForSession:(FBSession *)session + completionHandler:(FBRequestHandler)handler; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBFrictionlessRequestSettings.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBFrictionlessRequestSettings.h new file mode 100644 index 0000000..7f171d9 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBFrictionlessRequestSettings.h @@ -0,0 +1,85 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@class FBRequest; +@class Facebook; + +/** + * Do not use this interface directly, instead, use methods in Facebook.h + * + * Handles frictionless interaction and recipient-caching by the SDK, + * see https://developers.facebook.com/docs/reference/dialogs/requests/ + */ +@interface FBFrictionlessRequestSettings : NSObject { +@private + NSArray* _allowedRecipients; + FBRequest* _activeRequest; + BOOL _enabled; +} + +/** + * BOOL indicating whether frictionless request sending has been enabled + */ +@property (nonatomic, readonly) BOOL enabled; + +/** + * NSArray of recipients + */ +@property (nonatomic, readonly) NSArray *recipientIDs; + +/** + * Enable frictionless request sending by the sdk; this means: + * 1. query and cache the current set of frictionless recipients + * 2. flag other facets of the sdk to behave in a frictionless way + */ +- (void)enableWithFacebook:(Facebook*)facebook; + +/** + * Reload recipient cache; called by the sdk to keep the cache fresh; + * method makes graph request: me/apprequestformerrecipients + */ +- (void)reloadRecipientCacheWithFacebook:(Facebook*)facebook; + +/** + * Update the recipient cache; called by the sdk to keep the cache fresh; + */ +- (void)updateRecipientCacheWithRecipients:(NSArray*)ids; + +/** + * Update the recipient cache, using a request result + */ +- (void)updateRecipientCacheWithRequestResult:(id)result; + +/** + * Given an fbID for a user, indicates whether user is enabled for + * frictionless calls + */ +- (BOOL)isFrictionlessEnabledForRecipient:(id)fbid; + +/** + * Given an array of user fbIDs, indicates whether they are enabled for + * frictionless calls + */ +- (BOOL)isFrictionlessEnabledForRecipients:(NSArray*)fbids; + +/** + * init the frictionless cache object + */ +- (id)init; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBFriendPickerViewController.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBFriendPickerViewController.h new file mode 100644 index 0000000..6c8af5b --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBFriendPickerViewController.h @@ -0,0 +1,296 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBCacheDescriptor.h" +#import "FBGraphUser.h" +#import "FBSession.h" +#import "FBViewController.h" + +@protocol FBFriendPickerDelegate; +@class FBFriendPickerCacheDescriptor; + +/*! + @typedef FBFriendSortOrdering enum + + @abstract Indicates the order in which friends should be listed in the friend picker. + + @discussion + */ +typedef enum { + /*! Sort friends by first, middle, last names. */ + FBFriendSortByFirstName, + /*! Sort friends by last, first, middle names. */ + FBFriendSortByLastName +} FBFriendSortOrdering; + +/*! + @typedef FBFriendDisplayOrdering enum + + @abstract Indicates whether friends should be displayed first-name-first or last-name-first. + + @discussion + */ +typedef enum { + /*! Display friends as First Middle Last. */ + FBFriendDisplayByFirstName, + /*! Display friends as Last First Middle. */ + FBFriendDisplayByLastName, +} FBFriendDisplayOrdering; + + +/*! + @class + + @abstract + The `FBFriendPickerViewController` class creates a controller object that manages + the user interface for displaying and selecting Facebook friends. + + @discussion + When the `FBFriendPickerViewController` view loads it creates a `UITableView` object + where the friends will be displayed. You can access this view through the `tableView` + property. The friend display can be sorted by first name or last name. Friends' + names can be displayed with the first name first or the last name first. + + The friend data can be pre-fetched and cached prior to using the view controller. The + cache is setup using an object that can trigger the + data fetch. Any friend data requests will first check the cache and use that data. + If the friend picker is being displayed cached data will initially be shown before + a fresh copy is retrieved. + + The `delegate` property may be set to an object that conforms to the + protocol. The `delegate` object will receive updates related to friend selection and + data changes. The delegate can also be used to filter the friends to display in the + picker. + */ +@interface FBFriendPickerViewController : FBViewController + +/*! + @abstract + Returns an outlet for the spinner used in the view controller. + */ +@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *spinner; + +/*! + @abstract + Returns an outlet for the table view managed by the view controller. + */ +@property (nonatomic, retain) IBOutlet UITableView *tableView; + +/*! + @abstract + A Boolean value that specifies whether multi-select is enabled. + */ +@property (nonatomic) BOOL allowsMultipleSelection; + +/*! + @abstract + A Boolean value that indicates whether friend profile pictures are displayed. + */ +@property (nonatomic) BOOL itemPicturesEnabled; + +/*! + @abstract + Addtional fields to fetch when making the Graph API call to get friend data. + */ +@property (nonatomic, copy) NSSet *fieldsForRequest; + +/*! + @abstract + The session that is used in the request for friend data. + */ +@property (nonatomic, retain) FBSession *session; + +/*! + @abstract + The profile ID of the user whose friends are being viewed. + */ +@property (nonatomic, copy) NSString *userID; + +/*! + @abstract + The list of friends that are currently selected in the veiw. + The items in the array are objects. + + @discussion + You can set this this array to pre-select items in the picker. The objects in the array + must be complete id objects (i.e., fetched from a Graph query or from a + previous picker's selection, with id and appropriate name fields). + */ +@property (nonatomic, copy) NSArray *selection; + +/*! + @abstract + The order in which friends are sorted in the display. + */ +@property (nonatomic) FBFriendSortOrdering sortOrdering; + +/*! + @abstract + The order in which friends' names are displayed. + */ +@property (nonatomic) FBFriendDisplayOrdering displayOrdering; + +/*! + @abstract + Initializes a friend picker view controller. + */ +- (id)init; + +/*! + @abstract + Initializes a friend picker view controller. + + @param aDecoder An unarchiver object. + */ +- (id)initWithCoder:(NSCoder *)aDecoder; + +/*! + @abstract + Used to initialize the object + + @param nibNameOrNil The name of the nib file to associate with the view controller. The nib file name should not contain any leading path information. If you specify nil, the nibName property is set to nil. + @param nibBundleOrNil The bundle in which to search for the nib file. This method looks for the nib file in the bundle's language-specific project directories first, followed by the Resources directory. If nil, this method looks for the nib file in the main bundle. + */ +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil; + +/*! + @abstract + Configures the properties used in the caching data queries. + + @discussion + Cache descriptors are used to fetch and cache the data used by the view controller. + If the view controller finds a cached copy of the data, it will + first display the cached content then fetch a fresh copy from the server. + + @param cacheDescriptor The containing the cache query properties. + */ +- (void)configureUsingCachedDescriptor:(FBCacheDescriptor*)cacheDescriptor; + +/*! + @abstract + Initiates a query to get friend data. + + @discussion + A cached copy will be returned if available. The cached view is temporary until a fresh copy is + retrieved from the server. It is legal to call this more than once. + */ +- (void)loadData; + +/*! + @abstract + Updates the view locally without fetching data from the server or from cache. + + @discussion + Use this if the filter or sort properties change. This may affect the order or + display of friend information but should not need require new data. + */ +- (void)updateView; + +/*! + @abstract + Clears the current selection, so the picker is ready for a fresh use. + */ +- (void)clearSelection; + +/*! + @method + + @abstract + Creates a cache descriptor based on default settings of the `FBFriendPickerViewController` object. + + @discussion + An `FBCacheDescriptor` object may be used to pre-fetch data before it is used by + the view controller. It may also be used to configure the `FBFriendPickerViewController` + object. + */ ++ (FBCacheDescriptor*)cacheDescriptor; + +/*! + @method + + @abstract + Creates a cache descriptor with additional fields and a profile ID for use with the `FBFriendPickerViewController` object. + + @discussion + An `FBCacheDescriptor` object may be used to pre-fetch data before it is used by + the view controller. It may also be used to configure the `FBFriendPickerViewController` + object. + + @param userID The profile ID of the user whose friends will be displayed. A nil value implies a "me" alias. + @param fieldsForRequest The set of additional fields to include in the request for friend data. + */ ++ (FBCacheDescriptor*)cacheDescriptorWithUserID:(NSString*)userID fieldsForRequest:(NSSet*)fieldsForRequest; + +@end + +/*! + @protocol + + @abstract + The `FBFriendPickerDelegate` protocol defines the methods used to receive event + notifications and allow for deeper control of the + view. + */ +@protocol FBFriendPickerDelegate +@optional + +/*! + @abstract + Tells the delegate that data has been loaded. + + @discussion + The object's `tableView` property is automatically + reloaded when this happens. However, if another table view, for example the + `UISearchBar` is showing data, then it may also need to be reloaded. + + @param friendPicker The friend picker view controller whose data changed. + */ +- (void)friendPickerViewControllerDataDidChange:(FBFriendPickerViewController *)friendPicker; + +/*! + @abstract + Tells the delegate that the selection has changed. + + @param friendPicker The friend picker view controller whose selection changed. + */ +- (void)friendPickerViewControllerSelectionDidChange:(FBFriendPickerViewController *)friendPicker; + +/*! + @abstract + Asks the delegate whether to include a friend in the list. + + @discussion + This can be used to implement a search bar that filters the friend list. + + @param friendPicker The friend picker view controller that is requesting this information. + @param user An object representing the friend. + */ +- (BOOL)friendPickerViewController:(FBFriendPickerViewController *)friendPicker + shouldIncludeUser:(id )user; + +/*! + @abstract + Tells the delegate that there is a communication error. + + @param friendPicker The friend picker view controller that encountered the error. + @param error An error object containing details of the error. + */ +- (void)friendPickerViewController:(FBFriendPickerViewController *)friendPicker + handleError:(NSError *)error; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphLocation.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphLocation.h new file mode 100644 index 0000000..7f71ce6 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphLocation.h @@ -0,0 +1,78 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphObject.h" + +/*! + @protocol + + @abstract + The `FBGraphLocation` protocol enables typed access to the `location` property + of a Facebook place object. + + + @discussion + The `FBGraphLocation` protocol represents the most commonly used properties of a + location object. It may be used to access an `NSDictionary` object that has + been wrapped with an facade. + */ +@protocol FBGraphLocation + +/*! + @property + @abstract Typed access to a location's street. + */ +@property (retain, nonatomic) NSString *street; + +/*! + @property + @abstract Typed access to a location's city. + */ +@property (retain, nonatomic) NSString *city; + +/*! + @property + @abstract Typed access to a location's state. + */ +@property (retain, nonatomic) NSString *state; + +/*! + @property + @abstract Typed access to a location's country. + */ +@property (retain, nonatomic) NSString *country; + +/*! + @property + @abstract Typed access to a location's zip code. + */ +@property (retain, nonatomic) NSString *zip; + +/*! + @property + @abstract Typed access to a location's latitude. + */ +@property (retain, nonatomic) NSNumber *latitude; + +/*! + @property + @abstract Typed access to a location's longitude. + */ +@property (retain, nonatomic) NSNumber *longitude; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphObject.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphObject.h new file mode 100644 index 0000000..74460f6 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphObject.h @@ -0,0 +1,269 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@protocol FBOpenGraphObject; +@protocol FBOpenGraphAction; + +/*! + @protocol + + @abstract + The `FBGraphObject` protocol is the base protocol which enables typed access to graph objects and + open graph objects. Inherit from this protocol or a sub-protocol in order to introduce custom types + for typed access to Facebook objects. + + @discussion + The `FBGraphObject` protocol is the core type used by the Facebook SDK for iOS to + represent objects in the Facebook Social Graph and the Facebook Open Graph (OG). + The `FBGraphObject` class implements useful default functionality, but is rarely + used directly by applications. The `FBGraphObject` protocol, in contrast is the + base protocol for all graph object access via the SDK. + + Goals of the FBGraphObject types: +
    +
  • Lightweight/maintainable/robust
  • +
  • Extensible and resilient to change, both by Facebook and third party (OG)
  • +
  • Simple and natural extension to Objective-C
  • +
+ + The FBGraphObject at its core is a duck typed (if it walks/swims/quacks... + its a duck) model which supports an optional static facade. Duck-typing achieves + the flexibility necessary for Social Graph and OG uses, and the static facade + increases discoverability, maintainability, robustness and simplicity. + The following excerpt from the PlacePickerSample shows a simple use of the + a facade protocol `FBGraphPlace` by an application: + +
+ ‐ (void)placePickerViewControllerSelectionDidChange:(FBPlacePickerViewController *)placePicker
+ {
+   id<FBGraphPlace> place = placePicker.selection;
+
+   // we'll use logging to show the simple typed property access to place and location info
+   NSLog(@"place=%@, city=%@, state=%@, lat long=%@ %@",
+     place.name,
+     place.location.city,
+     place.location.state,
+     place.location.latitude,
+     place.location.longitude);
+ }
+ 
+ + Note that in this example, access to common place information is available through typed property + syntax. But if at some point places in the Social Graph supported additional fields "foo" and "bar", not + reflected in the `FBGraphPlace` protocol, the application could still access the values like so: + +
+ NSString *foo = [place objectForKey:@"foo"]; // perhaps located at the ... in the preceding example
+ NSNumber *bar = [place objectForKey:@"bar"]; // extensibility applies to Social and Open graph uses
+ 
+ + In addition to untyped access, applications and future revisions of the SDK may add facade protocols by + declaring a protocol inheriting the `FBGraphObject` protocol, like so: + +
+ @protocol MyGraphThing<FBGraphObject>
+ @property (copy, nonatomic) NSString *id;
+ @property (copy, nonatomic) NSString *name;
+ @end
+ 
+ + Important: facade implementations are inferred by graph objects returned by the methods of the SDK. This + means that no explicit implementation is required by application or SDK code. Any `FBGraphObject` instance + may be cast to any `FBGraphObject` facade protocol, and accessed via properties. If a field is not present + for a given facade property, the property will return nil. + + The following layer diagram depicts some of the concepts discussed thus far: + +
+                       *-------------* *------------* *-------------**--------------------------*
+            Facade --> | FBGraphUser | |FBGraphPlace| | MyGraphThing|| MyGraphPersonExtentension| ...
+                       *-------------* *------------* *-------------**--------------------------*
+                       *------------------------------------* *--------------------------------------*
+  Transparent impl --> |     FBGraphObject (instances)      | |      CustomClass<FBGraphObject>      |
+                       *------------------------------------* *--------------------------------------*
+                       *-------------------**------------------------* *-----------------------------*
+     Apparent impl --> |NSMutableDictionary||FBGraphObject (protocol)| |FBGraphObject (class methods)|
+                       *-------------------**------------------------* *-----------------------------*
+ 
+ + The *Facade* layer is meant for typed access to graph objects. The *Transparent impl* layer (more + specifically, the instance capabilities of `FBGraphObject`) are used by the SDK and app logic + internally, but are not part of the public interface between application and SDK. The *Apparent impl* + layer represents the lower-level "duck-typed" use of graph objects. + + Implementation note: the SDK returns `NSMutableDictionary` derived instances with types declared like + one of the following: + +
+ NSMutableDictionary<FBGraphObject> *obj;     // no facade specified (still castable by app)
+ NSMutableDictionary<FBGraphPlace> *person;   // facade specified when possible
+ 
+ + However, when passing a graph object to the SDK, `NSMutableDictionary` is not assumed; only the + FBGraphObject protocol is assumed, like so: + +
+ id<FBGraphObject> anyGraphObj;
+ 
+ + As such, the methods declared on the `FBGraphObject` protocol represent the methods used by the SDK to + consume graph objects. While the `FBGraphObject` class implements the full `NSMutableDictionary` and KVC + interfaces, these are not consumed directly by the SDK, and are optional for custom implementations. + */ +@protocol FBGraphObject + +/*! + @method + @abstract + Returns the number of properties on this `FBGraphObject`. + */ +- (NSUInteger)count; +/*! + @method + @abstract + Returns a property on this `FBGraphObject`. + + @param aKey name of the property to return + */ +- (id)objectForKey:(id)aKey; +/*! + @method + @abstract + Returns an enumerator of the property naems on this `FBGraphObject`. + */ +- (NSEnumerator *)keyEnumerator; +/*! + @method + @abstract + Removes a property on this `FBGraphObject`. + + @param aKey name of the property to remove + */ +- (void)removeObjectForKey:(id)aKey; +/*! + @method + @abstract + Sets the value of a property on this `FBGraphObject`. + + @param anObject the new value of the property + @param aKey name of the property to set + */ +- (void)setObject:(id)anObject forKey:(id)aKey; + +@optional + +/*! + @abstract + This property signifies that the current graph object is provisioned for POST (as a definition + for a new or updated graph object), and should be posted AS-IS in its JSON encoded form, whereas + some graph objects (usually those embedded in other graph objects as references to existing objects) + may only have their "id" or "url" posted. + */ +@property (nonatomic, assign) BOOL provisionedForPost; + +@end + +/*! + @class + + @abstract + Static class with helpers for use with graph objects + + @discussion + The public interface of this class is useful for creating objects that have the same graph characteristics + of those returned by methods of the SDK. This class also represents the internal implementation of the + `FBGraphObject` protocol, used by the Facebook SDK. Application code should not use the `FBGraphObject` class to + access instances and instance members, favoring the protocol. + */ +@interface FBGraphObject : NSMutableDictionary + +/*! + @method + @abstract + Used to create a graph object, usually for use in posting a new graph object or action. + */ ++ (NSMutableDictionary*)graphObject; + +/*! + @method + @abstract + Used to wrap an existing dictionary with a `FBGraphObject` facade + + @discussion + Normally you will not need to call this method, as the Facebook SDK already "FBGraphObject-ifys" json objects + fetch via `FBRequest` and `FBRequestConnection`. However, you may have other reasons to create json objects in your + application, which you would like to treat as a graph object. The pattern for doing this is that you pass the root + node of the json to this method, to retrieve a wrapper. From this point, if you traverse the graph, any other objects + deeper in the hierarchy will be wrapped as `FBGraphObject`'s in a lazy fashion. + + This method is designed to avoid unnecessary memory allocations, and object copying. Due to this, the method does + not copy the source object if it can be avoided, but rather wraps and uses it as is. The returned object derives + callers shoudl use the returned object after calls to this method, rather than continue to call methods on the original + object. + + @param jsonDictionary the dictionary representing the underlying object to wrap + */ ++ (NSMutableDictionary*)graphObjectWrappingDictionary:(NSDictionary*)jsonDictionary; + +/*! + @method + @abstract + Used to create a graph object that's provisioned for POST, usually for use in posting a new Open Graph Action. + */ ++ (NSMutableDictionary*)openGraphActionForPost; + +/*! + @method + @abstract + Used to create a graph object that's provisioned for POST, usually for use in posting a new Open Graph object. + */ ++ (NSMutableDictionary*)openGraphObjectForPost; + +/*! + @method + @abstract + Used to create a graph object that's provisioned for POST, usually for use in posting a new Open Graph object. + + @param type the object type name, in the form namespace:typename + @param title a title for the object + @param image the image property for the object + @param url the url property for the object + @param description the description for the object + */ ++ (NSMutableDictionary*)openGraphObjectForPostWithType:(NSString *)type + title:(NSString *)title + image:(id)image + url:(id)url + description:(NSString *)description; + +/*! + @method + @abstract + Used to compare two `FBGraphObject`s to determine if represent the same object. We do not overload + the concept of equality as there are various types of equality that may be important for an `FBGraphObject` + (for instance, two different `FBGraphObject`s could represent the same object, but contain different + subsets of fields). + + @param anObject an `FBGraphObject` to test + + @param anotherObject the `FBGraphObject` to compare it against + */ ++ (BOOL)isGraphObjectID:(id)anObject sameAs:(id)anotherObject; + + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphPlace.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphPlace.h new file mode 100644 index 0000000..40e144f --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphPlace.h @@ -0,0 +1,61 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphLocation.h" +#import "FBGraphObject.h" + +/*! + @protocol + + @abstract + The `FBGraphPlace` protocol enables typed access to a place object + as represented in the Graph API. + + + @discussion + The `FBGraphPlace` protocol represents the most commonly used properties of a + Facebook place object. It may be used to access an `NSDictionary` object that has + been wrapped with an facade. + */ +@protocol FBGraphPlace + +/*! + @property + @abstract Typed access to the place ID. + */ +@property (retain, nonatomic) NSString *id; + +/*! + @property + @abstract Typed access to the place name. + */ +@property (retain, nonatomic) NSString *name; + +/*! + @property + @abstract Typed access to the place category. + */ +@property (retain, nonatomic) NSString *category; + +/*! + @property + @abstract Typed access to the place location. + */ +@property (retain, nonatomic) id location; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphUser.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphUser.h new file mode 100644 index 0000000..645ea1d --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBGraphUser.h @@ -0,0 +1,91 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphObject.h" +#import "FBGraphPlace.h" + +/*! + @protocol + + @abstract + The `FBGraphUser` protocol enables typed access to a user object + as represented in the Graph API. + + + @discussion + The `FBGraphUser` protocol represents the most commonly used properties of a + Facebook user object. It may be used to access an `NSDictionary` object that has + been wrapped with an facade. + */ +@protocol FBGraphUser + +/*! + @property + @abstract Typed access to the user's ID. + */ +@property (retain, nonatomic) NSString *id; + +/*! + @property + @abstract Typed access to the user's name. + */ +@property (retain, nonatomic) NSString *name; + +/*! + @property + @abstract Typed access to the user's first name. + */ +@property (retain, nonatomic) NSString *first_name; + +/*! + @property + @abstract Typed access to the user's middle name. + */ +@property (retain, nonatomic) NSString *middle_name; + +/*! + @property + @abstract Typed access to the user's last name. + */ +@property (retain, nonatomic) NSString *last_name; + +/*! + @property + @abstract Typed access to the user's profile URL. + */ +@property (retain, nonatomic) NSString *link; + +/*! + @property + @abstract Typed access to the user's username. + */ +@property (retain, nonatomic) NSString *username; + +/*! + @property + @abstract Typed access to the user's birthday. + */ +@property (retain, nonatomic) NSString *birthday; + +/*! + @property + @abstract Typed access to the user's current city. + */ +@property (retain, nonatomic) id location; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBInsights.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBInsights.h new file mode 100644 index 0000000..d1a35de --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBInsights.h @@ -0,0 +1,57 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBSession.h" + +/*! + @typedef FBInsightsFlushBehavior enum + + @abstract This enum has been deprecated in favor of FBAppEventsFlushBehavior. + */ +__attribute__ ((deprecated("use FBAppEventsFlushBehavior instead"))) +typedef enum { + FBInsightsFlushBehaviorAuto __attribute__ ((deprecated("use FBAppEventsFlushBehaviorAuto instead"))), + FBInsightsFlushBehaviorExplicitOnly __attribute__ ((deprecated("use FBAppEventsFlushBehaviorExplicitOnly instead"))), +} FBInsightsFlushBehavior; + +extern NSString *const FBInsightsLoggingResultNotification __attribute__((deprecated)); + +/*! + @class FBInsights + + @abstract This class has been deprecated in favor of FBAppEvents. + */ +__attribute__ ((deprecated("Use the FBAppEvents class instead"))) +@interface FBInsights : NSObject + ++ (NSString *)appVersion __attribute__((deprecated)); ++ (void)setAppVersion:(NSString *)appVersion __attribute__((deprecated("use [FBSettings setAppVersion] instead"))); + ++ (void)logPurchase:(double)purchaseAmount currency:(NSString *)currency __attribute__((deprecated("use [FBAppEvents logPurchase] instead"))); ++ (void)logPurchase:(double)purchaseAmount currency:(NSString *)currency parameters:(NSDictionary *)parameters __attribute__((deprecated("use [FBAppEvents logPurchase] instead"))); ++ (void)logPurchase:(double)purchaseAmount currency:(NSString *)currency parameters:(NSDictionary *)parameters session:(FBSession *)session __attribute__((deprecated("use [FBAppEvents logPurchase] instead"))); + ++ (void)logConversionPixel:(NSString *)pixelID valueOfPixel:(double)value __attribute__((deprecated)); ++ (void)logConversionPixel:(NSString *)pixelID valueOfPixel:(double)value session:(FBSession *)session __attribute__((deprecated)); + ++ (FBInsightsFlushBehavior)flushBehavior __attribute__((deprecated("use [FBAppEvents flushBehavior] instead"))); ++ (void)setFlushBehavior:(FBInsightsFlushBehavior)flushBehavior __attribute__((deprecated("use [FBAppEvents setFlushBehavior] instead"))); + ++ (void)flush __attribute__((deprecated("use [FBAppEvents flush] instead"))); + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBLoginDialog.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBLoginDialog.h new file mode 100644 index 0000000..5f8f5b5 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBLoginDialog.h @@ -0,0 +1,48 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#import "FBDialog.h" + +@protocol FBLoginDialogDelegate; + +/** + * Do not use this interface directly, instead, use authorize in Facebook.h + * + * Facebook Login Dialog interface for start the facebook webView login dialog. + * It start pop-ups prompting for credentials and permissions. + */ + +@interface FBLoginDialog : FBDialog { + id _loginDelegate; +} + +-(id) initWithURL:(NSString *) loginURL + loginParams:(NSMutableDictionary *) params + delegate:(id ) delegate; +@end + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +@protocol FBLoginDialogDelegate + +- (void)fbDialogLogin:(NSString*)token expirationDate:(NSDate*)expirationDate params:(NSDictionary *)params; + +- (void)fbDialogNotLogin:(BOOL)cancelled; + +@end + + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBLoginView.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBLoginView.h new file mode 100644 index 0000000..4f75e3a --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBLoginView.h @@ -0,0 +1,189 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphUser.h" +#import "FBSession.h" + +@protocol FBLoginViewDelegate; + +/*! + @class FBLoginView + @abstract FBLoginView is a custom UIView that renders a button to login or logout based on the + state of `FBSession.activeSession` + + @discussion This view is closely associated with `FBSession.activeSession`. Upon initialization, + it will attempt to open an active session without UI if the current active session is not open. + + The FBLoginView instance also monitors for changes to the active session. + */ +@interface FBLoginView : UIView + +/*! + @abstract + The permissions to login with. Defaults to nil, meaning basic permissions. + + @discussion Methods and properties that specify permissions without a read or publish + qualification are deprecated; use of a read-qualified or publish-qualified alternative is preferred. + */ +@property (readwrite, copy) NSArray *permissions __attribute__((deprecated)); + +/*! + @abstract + The read permissions to request if the user logs in via this view. The basic_info permission must be explicitly requested at + first login, and is no longer inferred, (subject to an active migration.) + + @discussion + Note, that if read permissions are specified, then publish permissions should not be specified. + */ +@property (nonatomic, copy) NSArray *readPermissions; + +/*! + @abstract + The publish permissions to request if the user logs in via this view. + + @discussion + Note, that a defaultAudience value of FBSessionDefaultAudienceOnlyMe, FBSessionDefaultAudienceEveryone, or + FBSessionDefaultAudienceFriends should be set if publish permissions are specified. Additionally, when publish + permissions are specified, then read should not be specified. + */ +@property (nonatomic, copy) NSArray *publishPermissions; + +/*! + @abstract + The default audience to use, if publish permissions are requested at login time. + */ +@property (nonatomic, assign) FBSessionDefaultAudience defaultAudience; + +/*! + @abstract + The login behavior for the active session if the user logs in via this view + + @discussion + The default value is FBSessionLoginBehaviorUseSystemAccountIfPresent. + */ +@property (nonatomic) FBSessionLoginBehavior loginBehavior; + + +/*! + @abstract + Initializes and returns an `FBLoginView` object. The underlying session has basic permissions granted to it. + */ +- (id)init; + +/*! + @method + + @abstract + Initializes and returns an `FBLoginView` object constructed with the specified permissions. + + @param permissions An array of strings representing the permissions to request during the + authentication flow. A value of nil will indicates basic permissions. + + @discussion Methods and properties that specify permissions without a read or publish + qualification are deprecated; use of a read-qualified or publish-qualified alternative is preferred. + */ +- (id)initWithPermissions:(NSArray *)permissions __attribute__((deprecated)); + +/*! + @method + + @abstract + Initializes and returns an `FBLoginView` object constructed with the specified permissions. + + @param readPermissions An array of strings representing the read permissions to request during the + authentication flow. A value of nil will indicates basic permissions. + + */ +- (id)initWithReadPermissions:(NSArray *)readPermissions; + +/*! + @method + + @abstract + Initializes and returns an `FBLoginView` object constructed with the specified permissions. + + @param publishPermissions An array of strings representing the publish permissions to request during the + authentication flow. + + @param defaultAudience An audience for published posts; note that FBSessionDefaultAudienceNone is not valid + for permission requests that include publish or manage permissions. + + */ +- (id)initWithPublishPermissions:(NSArray *)publishPermissions + defaultAudience:(FBSessionDefaultAudience)defaultAudience; + +/*! + @abstract + The delegate object that receives updates for selection and display control. + */ +@property (nonatomic, assign) IBOutlet id delegate; + +@end + +/*! + @protocol + + @abstract + The `FBLoginViewDelegate` protocol defines the methods used to receive event + notifications from `FBLoginView` objects. + */ +@protocol FBLoginViewDelegate + +@optional + +/*! + @abstract + Tells the delegate that the view is now in logged in mode + + @param loginView The login view that transitioned its view mode + */ +- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView; + +/*! + @abstract + Tells the delegate that the view is has now fetched user info + + @param loginView The login view that transitioned its view mode + + @param user The user info object describing the logged in user + */ +- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView + user:(id)user; + +/*! + @abstract + Tells the delegate that the view is now in logged out mode + + @param loginView The login view that transitioned its view mode + */ +- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView; + +/*! + @abstract + Tells the delegate that there is a communication or authorization error. + + @param loginView The login view that transitioned its view mode + @param error An error object containing details of the error. + @discussion See https://developers.facebook.com/docs/technical-guides/iossdk/errors/ + for error handling best practices. + */ +- (void)loginView:(FBLoginView *)loginView + handleError:(NSError *)error; + +@end + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBNativeDialogs.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBNativeDialogs.h new file mode 100644 index 0000000..f8723fc --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBNativeDialogs.h @@ -0,0 +1,109 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +#import "FBAppCall.h" +#import "FBOpenGraphActionShareDialogParams.h" +#import "FBShareDialogParams.h" + +@class FBSession; +@protocol FBOpenGraphAction; + +// note that the following class and types are deprecated in favor of FBDialogs and its methods + +/*! + @typedef FBNativeDialogResult enum + + @abstract + Please note that this enum and its related methods have been deprecated, please migrate your + code to use `FBOSIntegratedShareDialogResult` and its related methods. + */ +typedef enum { + /*! Indicates that the dialog action completed successfully. */ + FBNativeDialogResultSucceeded, + /*! Indicates that the dialog action was cancelled (either by the user or the system). */ + FBNativeDialogResultCancelled, + /*! Indicates that the dialog could not be shown (because not on ios6 or ios6 auth was not used). */ + FBNativeDialogResultError +} FBNativeDialogResult +__attribute__((deprecated)); + +/*! + @typedef + + @abstract + Please note that `FBShareDialogHandler` and its related methods have been deprecated, please migrate your + code to use `FBOSIntegratedShareDialogHandler` and its related methods. + */ +typedef void (^FBShareDialogHandler)(FBNativeDialogResult result, NSError *error) +__attribute__((deprecated)); + +/*! + @class FBNativeDialogs + + @abstract + Please note that `FBNativeDialogs` has been deprecated, please migrate your + code to use `FBDialogs`. + */ +@interface FBNativeDialogs : NSObject + +/*! + @abstract + Please note that this method has been deprecated, please migrate your + code to use `FBDialogs` and the related method `presentOSIntegratedShareDialogModallyFrom`. + */ ++ (BOOL)presentShareDialogModallyFrom:(UIViewController*)viewController + initialText:(NSString*)initialText + image:(UIImage*)image + url:(NSURL*)url + handler:(FBShareDialogHandler)handler +__attribute__((deprecated)); + +/*! + @abstract + Please note that this method has been deprecated, please migrate your + code to use `FBDialogs` and the related method `presentOSIntegratedShareDialogModallyFrom`. + */ ++ (BOOL)presentShareDialogModallyFrom:(UIViewController*)viewController + initialText:(NSString*)initialText + images:(NSArray*)images + urls:(NSArray*)urls + handler:(FBShareDialogHandler)handler +__attribute__((deprecated)); + +/*! + @abstract + Please note that this method has been deprecated, please migrate your + code to use `FBDialogs` and the related method `presentOSIntegratedShareDialogModallyFrom`. + */ ++ (BOOL)presentShareDialogModallyFrom:(UIViewController*)viewController + session:(FBSession*)session + initialText:(NSString*)initialText + images:(NSArray*)images + urls:(NSArray*)urls + handler:(FBShareDialogHandler)handler +__attribute__((deprecated)); + +/*! + @abstract + Please note that this method has been deprecated, please migrate your + code to use `FBDialogs` and the related method `canPresentOSIntegratedShareDialogWithSession`. + */ ++ (BOOL)canPresentShareDialogWithSession:(FBSession*)session __attribute__((deprecated)); + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBOpenGraphAction.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBOpenGraphAction.h new file mode 100644 index 0000000..adc5ef4 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBOpenGraphAction.h @@ -0,0 +1,128 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphObject.h" + +@protocol FBGraphPlace; +@protocol FBGraphUser; + +/*! + @protocol + + @abstract + The `FBOpenGraphAction` protocol is the base protocol for use in posting and retrieving Open Graph actions. + It inherits from the `FBGraphObject` protocol; you may derive custome protocols from `FBOpenGraphAction` in order + implement typed access to your application's custom actions. + + @discussion + Represents an Open Graph custom action, to be used directly, or from which to + derive custom action protocols with custom properties. + */ +@protocol FBOpenGraphAction + +/*! + @property + @abstract Typed access to action's id + */ +@property (retain, nonatomic) NSString *id; + +/*! + @property + @abstract Typed access to action's start time + */ +@property (retain, nonatomic) NSString *start_time; + +/*! + @property + @abstract Typed access to action's end time + */ +@property (retain, nonatomic) NSString *end_time; + +/*! + @property + @abstract Typed access to action's publication time + */ +@property (retain, nonatomic) NSString *publish_time; + +/*! + @property + @abstract Typed access to action's creation time + */ +@property (retain, nonatomic) NSString *created_time; + +/*! + @property + @abstract Typed access to action's expiration time + */ +@property (retain, nonatomic) NSString *expires_time; + +/*! + @property + @abstract Typed access to action's ref + */ +@property (retain, nonatomic) NSString *ref; + +/*! + @property + @abstract Typed access to action's user message + */ +@property (retain, nonatomic) NSString *message; + +/*! + @property + @abstract Typed access to action's place + */ +@property (retain, nonatomic) id place; + +/*! + @property + @abstract Typed access to action's tags + */ +@property (retain, nonatomic) NSArray *tags; + +/*! + @property + @abstract Typed access to action's image(s) + */ +@property (retain, nonatomic) id image; + +/*! + @property + @abstract Typed access to action's from-user + */ +@property (retain, nonatomic) id from; + +/*! + @property + @abstract Typed access to action's likes + */ +@property (retain, nonatomic) NSArray *likes; + +/*! + @property + @abstract Typed access to action's application + */ +@property (retain, nonatomic) id application; + +/*! + @property + @abstract Typed access to action's comments + */ +@property (retain, nonatomic) NSArray *comments; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBOpenGraphActionShareDialogParams.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBOpenGraphActionShareDialogParams.h new file mode 100644 index 0000000..89f49d7 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBOpenGraphActionShareDialogParams.h @@ -0,0 +1,43 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBDialogsParams.h" +#import "FBOpenGraphAction.h" + +extern NSString *const FBPostObject; + +/*! + @class FBOpenGraphActionShareDialogParams + + @abstract + This object is used to encapsulate state for parameters to an Open Graph share + dialog that opens in the Facebook app. + */ +@interface FBOpenGraphActionShareDialogParams : FBDialogsParams + +/*! @abstract The Open Graph action to be published. */ +@property (nonatomic, retain) id action; + +/*! @abstract The name of the property representing the primary target of the Open + Graph action, which will be displayed as a preview in the dialog. */ +@property (nonatomic, copy) NSString *previewPropertyName; + +/*! @abstract The fully qualified type of the Open Graph action. */ +@property (nonatomic, copy) NSString *actionType; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBOpenGraphObject.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBOpenGraphObject.h new file mode 100644 index 0000000..be73a3b --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBOpenGraphObject.h @@ -0,0 +1,77 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphObject.h" + +/*! + @protocol + + @abstract + The `FBOpenGraphObject` protocol is the base protocol for use in posting and retrieving Open Graph objects. + It inherits from the `FBGraphObject` protocol; you may derive custome protocols from `FBOpenGraphObject` in order + implement typed access to your application's custom objects. + + @discussion + Represents an Open Graph custom object, to be used directly, or from which to + derive custom action protocols with custom properties. + */ +@protocol FBOpenGraphObject + +/*! + @property + @abstract Typed access to the object's id + */ +@property (retain, nonatomic) NSString *id; + +/*! + @property + @abstract Typed access to the object's type, which is a string in the form mynamespace:mytype + */ +@property (retain, nonatomic) NSString *type; + +/*! + @property + @abstract Typed access to object's title + */ +@property (retain, nonatomic) NSString *title; + +/*! + @property + @abstract Typed access to the object's image property + */ +@property (retain, nonatomic) id image; + +/*! + @property + @abstract Typed access to the object's url property + */ +@property (retain, nonatomic) id url; + +/*! + @property + @abstract Typed access to the object's description property + */ +@property (retain, nonatomic) id description; + +/*! + @property + @abstract Typed access to action's data, which is a dictionary of custom properties + */ +@property (retain, nonatomic) id data; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBPlacePickerViewController.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBPlacePickerViewController.h new file mode 100644 index 0000000..735cf92 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBPlacePickerViewController.h @@ -0,0 +1,258 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +#import "FBCacheDescriptor.h" +#import "FBGraphPlace.h" +#import "FBSession.h" +#import "FBViewController.h" + +@protocol FBPlacePickerDelegate; + +/*! + @class FBPlacePickerViewController + + @abstract + The `FBPlacePickerViewController` class creates a controller object that manages + the user interface for displaying and selecting nearby places. + + @discussion + When the `FBPlacePickerViewController` view loads it creates a `UITableView` object + where the places near a given location will be displayed. You can access this view + through the `tableView` property. + + The place data can be pre-fetched and cached prior to using the view controller. The + cache is setup using an object that can trigger the + data fetch. Any place data requests will first check the cache and use that data. + If the place picker is being displayed cached data will initially be shown before + a fresh copy is retrieved. + + The `delegate` property may be set to an object that conforms to the + protocol. The `delegate` object will receive updates related to place selection and + data changes. The delegate can also be used to filter the places to display in the + picker. + */ +@interface FBPlacePickerViewController : FBViewController + +/*! + @abstract + Returns an outlet for the spinner used in the view controller. + */ +@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *spinner; + +/*! + @abstract + Returns an outlet for the table view managed by the view controller. + */ +@property (nonatomic, retain) IBOutlet UITableView *tableView; + +/*! + @abstract + Addtional fields to fetch when making the Graph API call to get place data. + */ +@property (nonatomic, copy) NSSet *fieldsForRequest; + +/*! + @abstract + A Boolean value that indicates whether place profile pictures are displayed. + */ +@property (nonatomic) BOOL itemPicturesEnabled; + +/*! + @abstract + The coordinates to use for place discovery. + */ +@property (nonatomic) CLLocationCoordinate2D locationCoordinate; + +/*! + @abstract + The radius to use for place discovery. + */ +@property (nonatomic) NSInteger radiusInMeters; + +/*! + @abstract + The maximum number of places to fetch. + */ +@property (nonatomic) NSInteger resultsLimit; + +/*! + @abstract + The search words used to narrow down the results returned. + */ +@property (nonatomic, copy) NSString *searchText; + +/*! + @abstract + The session that is used in the request for place data. + */ +@property (nonatomic, retain) FBSession *session; + +/*! + @abstract + The place that is currently selected in the view. This is nil + if nothing is selected. + */ +@property (nonatomic, retain, readonly) id selection; + +/*! + @abstract + Clears the current selection, so the picker is ready for a fresh use. + */ +- (void)clearSelection; + +/*! + @abstract + Initializes a place picker view controller. + */ +- (id)init; + +/*! + @abstract + Initializes a place picker view controller. + + @param aDecoder An unarchiver object. + */ +- (id)initWithCoder:(NSCoder *)aDecoder; + +/*! + @abstract + Initializes a place picker view controller. + + @param nibNameOrNil The name of the nib file to associate with the view controller. The nib file name should not contain any leading path information. If you specify nil, the nibName property is set to nil. + @param nibBundleOrNil The bundle in which to search for the nib file. This method looks for the nib file in the bundle's language-specific project directories first, followed by the Resources directory. If nil, this method looks for the nib file in the main bundle. + */ +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil; + +/*! + @abstract + Configures the properties used in the caching data queries. + + @discussion + Cache descriptors are used to fetch and cache the data used by the view controller. + If the view controller finds a cached copy of the data, it will + first display the cached content then fetch a fresh copy from the server. + + @param cacheDescriptor The containing the cache query properties. + */ +- (void)configureUsingCachedDescriptor:(FBCacheDescriptor*)cacheDescriptor; + +/*! + @abstract + Initiates a query to get place data the first time or in response to changes in + the search criteria, filter, or location information. + + + @discussion + A cached copy will be returned if available. The cached view is temporary until a fresh copy is + retrieved from the server. It is legal to call this more than once. + */ +- (void)loadData; + +/*! + @abstract + Updates the view locally without fetching data from the server or from cache. + + @discussion + Use this if the filter properties change. This may affect the order or + display of information. + */ +- (void)updateView; + +/*! + @method + + @abstract + Creates a cache descriptor with additional fields and a profile ID for use with the + `FBPlacePickerViewController` object. + + @discussion + An `FBCacheDescriptor` object may be used to pre-fetch data before it is used by + the view controller. It may also be used to configure the `FBPlacePickerViewController` + object. + + @param locationCoordinate The coordinates to use for place discovery. + @param radiusInMeters The radius to use for place discovery. + @param searchText The search words used to narrow down the results returned. + @param resultsLimit The maximum number of places to fetch. + @param fieldsForRequest Addtional fields to fetch when making the Graph API call to get place data. + */ ++ (FBCacheDescriptor*)cacheDescriptorWithLocationCoordinate:(CLLocationCoordinate2D)locationCoordinate + radiusInMeters:(NSInteger)radiusInMeters + searchText:(NSString*)searchText + resultsLimit:(NSInteger)resultsLimit + fieldsForRequest:(NSSet*)fieldsForRequest; + +@end + +/*! + @protocol + + @abstract + The `FBPlacePickerDelegate` protocol defines the methods used to receive event + notifications and allow for deeper control of the + view. + */ +@protocol FBPlacePickerDelegate +@optional + +/*! + @abstract + Tells the delegate that data has been loaded. + + @discussion + The object's `tableView` property is automatically + reloaded when this happens. However, if another table view, for example the + `UISearchBar` is showing data, then it may also need to be reloaded. + + @param placePicker The place picker view controller whose data changed. + */ +- (void)placePickerViewControllerDataDidChange:(FBPlacePickerViewController *)placePicker; + +/*! + @abstract + Tells the delegate that the selection has changed. + + @param placePicker The place picker view controller whose selection changed. + */ +- (void)placePickerViewControllerSelectionDidChange:(FBPlacePickerViewController *)placePicker; + +/*! + @abstract + Asks the delegate whether to include a place in the list. + + @discussion + This can be used to implement a search bar that filters the places list. + + @param placePicker The place picker view controller that is requesting this information. + @param place An object representing the place. + */ +- (BOOL)placePickerViewController:(FBPlacePickerViewController *)placePicker + shouldIncludePlace:(id )place; + +/*! + @abstract + Called if there is a communication error. + + @param placePicker The place picker view controller that encountered the error. + @param error An error object containing details of the error. + */ +- (void)placePickerViewController:(FBPlacePickerViewController *)placePicker + handleError:(NSError *)error; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBProfilePictureView.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBProfilePictureView.h new file mode 100644 index 0000000..c1f31c6 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBProfilePictureView.h @@ -0,0 +1,80 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +/*! + @typedef FBProfilePictureCropping enum + + @abstract + Type used to specify the cropping treatment of the profile picture. + + @discussion + */ +typedef enum { + + /*! Square (default) - the square version that the Facebook user defined. */ + FBProfilePictureCroppingSquare = 0, + + /*! Original - the original profile picture, as uploaded. */ + FBProfilePictureCroppingOriginal = 1 + +} FBProfilePictureCropping; + +/*! + @class + @abstract + An instance of `FBProfilePictureView` is used to display a profile picture. + + The default behavior of this control is to center the profile picture + in the view and shrinks it, if necessary, to the view's bounds, preserving the aspect ratio. The smallest + possible image is downloaded to ensure that scaling up never happens. Resizing the view may result in + a different size of the image being loaded. Canonical image sizes are documented in the "Pictures" section + of https://developers.facebook.com/docs/reference/api. + */ +@interface FBProfilePictureView : UIView + +/*! + @abstract + The Facebook ID of the user, place or object for which a picture should be fetched and displayed. + */ +@property (copy, nonatomic) NSString* profileID; + +/*! + @abstract + The cropping to use for the profile picture. + */ +@property (nonatomic) FBProfilePictureCropping pictureCropping; + +/*! + @abstract + Initializes and returns a profile view object. + */ +- (id)init; + + +/*! + @abstract + Initializes and returns a profile view object for the given Facebook ID and cropping. + + @param profileID The Facebook ID of the user, place or object for which a picture should be fetched and displayed. + @param pictureCropping The cropping to use for the profile picture. + */ +- (id)initWithProfileID:(NSString*)profileID + pictureCropping:(FBProfilePictureCropping)pictureCropping; + + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBRequest.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBRequest.h new file mode 100644 index 0000000..187bd7a --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBRequest.h @@ -0,0 +1,672 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +#import "FBGraphObject.h" +#import "FBOpenGraphAction.h" +#import "FBOpenGraphObject.h" +#import "FBRequestConnection.h" + +/*! The base URL used for graph requests */ +extern NSString* const FBGraphBasePath __attribute__((deprecated)); + +// up-front decl's +@protocol FBRequestDelegate; +@class FBSession; +@class UIImage; + +/*! + @typedef FBRequestState + + @abstract + Deprecated - do not use in new code. + + @discussion + FBRequestState is retained from earlier versions of the SDK to give existing + apps time to remove dependency on this. + + @deprecated +*/ +typedef NSUInteger FBRequestState __attribute__((deprecated)); + +/*! + @class FBRequest + + @abstract + The `FBRequest` object is used to setup and manage requests to Facebook Graph + and REST APIs. This class provides helper methods that simplify the connection + and response handling. + + @discussion + An object is required for all authenticated uses of `FBRequest`. + Requests that do not require an unauthenticated user are also supported and + do not require an object to be passed in. + + An instance of `FBRequest` represents the arguments and setup for a connection + to Facebook. After creating an `FBRequest` object it can be used to setup a + connection to Facebook through the object. The + object is created to manage a single connection. To + cancel a connection use the instance method in the class. + + An `FBRequest` object may be reused to issue multiple connections to Facebook. + However each instance will manage one connection. + + Class and instance methods prefixed with **start* ** can be used to perform the + request setup and initiate the connection in a single call. + +*/ +@interface FBRequest : NSObject { +@private + id _delegate; + NSString* _url; + NSURLConnection* _connection; + NSMutableData* _responseText; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + FBRequestState _state; +#pragma GCC diagnostic pop + NSError* _error; + BOOL _sessionDidExpire; + id _graphObject; +} + +/*! + @methodgroup Creating a request + + @method + Calls with the default parameters. +*/ +- (id)init; + +/*! + @method + Calls with default parameters + except for the ones provided to this method. + + @param session The session object representing the identity of the Facebook user making + the request. A nil value indicates a request that requires no token; to + use the active session pass `[FBSession activeSession]`. + + @param graphPath The Graph API endpoint to use for the request, for example "me". +*/ +- (id)initWithSession:(FBSession*)session + graphPath:(NSString *)graphPath; + +/*! + @method + + @abstract + Initializes an `FBRequest` object for a Graph API request call. + + @discussion + Note that this only sets properties on the `FBRequest` object. + + To send the request, initialize an object, add this request, + and send <[FBRequestConnection start]>. See other methods on this + class for shortcuts to simplify this process. + + @param session The session object representing the identity of the Facebook user making + the request. A nil value indicates a request that requires no token; to + use the active session pass `[FBSession activeSession]`. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param parameters The parameters for the request. A value of nil sends only the automatically handled + parameters, for example, the access token. The default is nil. + + @param HTTPMethod The HTTP method to use for the request. The default is value of nil implies a GET. +*/ +- (id)initWithSession:(FBSession*)session + graphPath:(NSString *)graphPath + parameters:(NSDictionary *)parameters + HTTPMethod:(NSString *)HTTPMethod; + +/*! + @method + @abstract + Initialize a `FBRequest` object that will do a graph request. + + @discussion + Note that this only sets properties on the `FBRequest`. + + To send the request, initialize a , add this request, + and send <[FBRequestConnection start]>. See other methods on this + class for shortcuts to simplify this process. + + @param session The session object representing the identity of the Facebook user making + the request. A nil value indicates a request that requires no token; to + use the active session pass `[FBSession activeSession]`. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param graphObject An object or open graph action to post. +*/ +- (id)initForPostWithSession:(FBSession*)session + graphPath:(NSString *)graphPath + graphObject:(id)graphObject; + +/*! + @method + @abstract + Initialize a `FBRequest` object that will do a rest API request. + + @discussion + Prefer to use graph requests instead of this where possible. + + Note that this only sets properties on the `FBRequest`. + + To send the request, initialize a , add this request, + and send <[FBRequestConnection start]>. See other methods on this + class for shortcuts to simplify this process. + + @param session The session object representing the identity of the Facebook user making + the request. A nil value indicates a request that requires no token; to + use the active session pass `[FBSession activeSession]`. + + @param restMethod A valid REST API method. + + @param parameters The parameters for the request. A value of nil sends only the automatically handled + parameters, for example, the access token. The default is nil. + + @param HTTPMethod The HTTP method to use for the request. The default is value of nil implies a GET. + +*/ +- (id)initWithSession:(FBSession*)session + restMethod:(NSString *)restMethod + parameters:(NSDictionary *)parameters + HTTPMethod:(NSString *)HTTPMethod; + +/*! + @abstract + The parameters for the request. + + @discussion + May be used to read the parameters that were automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. + + `NSString` parameters are used to generate URL parameter values or JSON + parameters. `NSData` and `UIImage` parameters are added as attachments + to the HTTP body and referenced by name in the URL and/or JSON. +*/ +@property (nonatomic, retain, readonly) NSMutableDictionary *parameters; + +/*! + @abstract + The session object to use for the request. + + @discussion + May be used to read the session that was automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. +*/ +@property (nonatomic, retain) FBSession *session; + +/*! + @abstract + The Graph API endpoint to use for the request, for example "me". + + @discussion + May be used to read the Graph API endpoint that was automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. +*/ +@property (nonatomic, copy) NSString *graphPath; + +/*! + @abstract + A valid REST API method. + + @discussion + May be used to read the REST method that was automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. + + Use the Graph API equivalent of the API if it exists as the REST API + method is deprecated if there is a Graph API equivalent. +*/ +@property (nonatomic, copy) NSString *restMethod; + +/*! + @abstract + The HTTPMethod to use for the request, for example "GET" or "POST". + + @discussion + May be used to read the HTTP method that was automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. +*/ +@property (nonatomic, copy) NSString *HTTPMethod; + +/*! + @abstract + The graph object to post with the request. + + @discussion + May be used to read the graph object that was automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. +*/ +@property (nonatomic, retain) id graphObject; + +/*! + @methodgroup Instance methods +*/ + +/*! + @method + + @abstract + Starts a connection to the Facebook API. + + @discussion + This is used to start an API call to Facebook and call the block when the + request completes with a success, error, or cancel. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + The handler will be invoked on the main thread. +*/ +- (FBRequestConnection*)startWithCompletionHandler:(FBRequestHandler)handler; + +/*! + @methodgroup FBRequestConnection start methods + + @abstract + These methods start an . + + @discussion + These methods simplify the process of preparing a request and starting + the connection. The methods handle initializing an `FBRequest` object, + initializing a object, adding the `FBRequest` + object to the to the , and finally starting the + connection. +*/ + +/*! + @methodgroup FBRequest factory methods + + @abstract + These methods initialize a `FBRequest` for common scenarios. + + @discussion + These simplify the process of preparing a request to send. These + initialize a `FBRequest` based on strongly typed parameters that are + specific to the scenario. + + These method do not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. +*/ + +// request* +// +// Summary: +// Helper methods used to create common request objects which can be used to create single or batch connections +// +// session: - the session object representing the identity of the +// Facebook user making the request; nil implies an +// unauthenticated request; default=nil + +/*! + @method + + @abstract + Creates a request representing a Graph API call to the "me" endpoint, using the active session. + + @discussion + Simplifies preparing a request to retrieve the user's identity. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + A successful Graph API call will return an object representing the + user's identity. + + Note you may change the session property after construction if a session other than + the active session is preferred. +*/ ++ (FBRequest *)requestForMe; + +/*! + @method + + @abstract + Creates a request representing a Graph API call to the "me/friends" endpoint using the active session. + + @discussion + Simplifies preparing a request to retrieve the user's friends. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + A successful Graph API call will return an array of objects representing the + user's friends. +*/ ++ (FBRequest *)requestForMyFriends; + +/*! + @method + + @abstract + Creates a request representing a Graph API call to upload a photo to the app's album using the active session. + + @discussion + Simplifies preparing a request to post a photo. + + To post a photo to a specific album, get the `FBRequest` returned from this method + call, then modify the request parameters by adding the album ID to an "album" key. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param photo A `UIImage` for the photo to upload. + */ ++ (FBRequest *)requestForUploadPhoto:(UIImage *)photo; + +/*! + @method + + @abstract + Creates a request representing a status update. + + @discussion + Simplifies preparing a request to post a status update. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param message The message to post. + */ ++ (FBRequest *)requestForPostStatusUpdate:(NSString *)message; + +/*! + @method + + @abstract + Creates a request representing a status update. + + @discussion + Simplifies preparing a request to post a status update. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param message The message to post. + @param place The place to checkin with, or nil. Place may be an fbid or a + graph object representing a place. + @param tags Array of friends to tag in the status update, each element + may be an fbid or a graph object representing a user. + */ ++ (FBRequest *)requestForPostStatusUpdate:(NSString *)message + place:(id)place + tags:(id)tags; + +/*! + @method + + @abstract + Creates a request representing a Graph API call to the "search" endpoint + for a given location using the active session. + + @discussion + Simplifies preparing a request to search for places near a coordinate. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + A successful Graph API call will return an array of objects representing + the nearby locations. + + @param coordinate The search coordinates. + + @param radius The search radius in meters. + + @param limit The maxiumum number of results to return. It is + possible to receive fewer than this because of the radius and because of server limits. + + @param searchText The text to use in the query to narrow the set of places + returned. +*/ ++ (FBRequest *)requestForPlacesSearchAtCoordinate:(CLLocationCoordinate2D)coordinate + radiusInMeters:(NSInteger)radius + resultsLimit:(NSInteger)limit + searchText:(NSString*)searchText; + +/*! + @method + + @abstract + Creates a request representing the Graph API call to retrieve a Custom Audience "thirdy party ID" for the app's Facebook user. + Callers will send this ID back to their own servers, collect up a set to create a Facebook Custom Audience with, + and then use the resultant Custom Audience to target ads. + + @param session The FBSession to use to establish the user's identity for users logged into Facebook through this app. + If `nil`, then the activeSession is used. + + @discussion + This method will throw an exception if <[FBSettings defaultAppID]> is `nil`. The appID won't be nil when the pList + includes the appID, or if it's explicitly set. + + The JSON in the request's response will include an "custom_audience_third_party_id" key/value pair, with the value being the ID retrieved. + This ID is an encrypted encoding of the Facebook user's ID and the invoking Facebook app ID. + Multiple calls with the same user will return different IDs, thus these IDs cannot be used to correlate behavior + across devices or applications, and are only meaningful when sent back to Facebook for creating Custom Audiences. + + The ID retrieved represents the Facebook user identified in the following way: if the specified session (or activeSession if the specified + session is `nil`) is open, the ID will represent the user associated with the activeSession; otherwise the ID will represent the user logged into the + native Facebook app on the device. If there is no native Facebook app, no one is logged into it, or the user has opted out + at the iOS level from ad tracking, then a `nil` ID will be returned. + + This method returns `nil` if either the user has opted-out (via iOS) from Ad Tracking, the app itself has limited event usage + via the `[FBAppEvents setLimitEventUsage]` flag, or a specific Facebook user cannot be identified. + */ ++ (FBRequest *)requestForCustomAudienceThirdPartyID:(FBSession *)session; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to make a Graph API call for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + */ ++ (FBRequest *)requestForGraphPath:(NSString*)graphPath; + +/*! + @method + + @abstract + Creates request representing a DELETE to a object. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param object This can be an NSString, NSNumber or NSDictionary representing an object to delete + */ ++ (FBRequest *)requestForDeleteObject:(id)object; + +/*! + @method + + @abstract + Creates a request representing a POST for a graph object. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param graphObject An object or open graph action to post. + + @discussion This method is typically used for posting an open graph action. If you are only + posting an open graph object (without an action), consider using `requestForPostOpenGraphObject:` + */ ++ (FBRequest *)requestForPostWithGraphPath:(NSString*)graphPath + graphObject:(id)graphObject; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to make a Graph API call for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param parameters The parameters for the request. A value of nil sends only the automatically handled parameters, for example, the access token. The default is nil. + + @param HTTPMethod The HTTP method to use for the request. A nil value implies a GET. + */ ++ (FBRequest *)requestWithGraphPath:(NSString*)graphPath + parameters:(NSDictionary*)parameters + HTTPMethod:(NSString*)HTTPMethod; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to create a user owned + Open Graph object for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param object The Open Graph object to create. Some common expected fields include "title", "image", "url", etc. + */ ++ (FBRequest *)requestForPostOpenGraphObject:(id)object; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to create a user owned + Open Graph object for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param type The fully-specified Open Graph object type (e.g., my_app_namespace:my_object_name) + @param title The title of the Open Graph object. + @param image The link to an image to be associated with the Open Graph object. + @param url The url to be associated with the Open Graph object. + @param description The description to be associated with the object. + @param objectProperties Any additional properties for the Open Graph object. + */ ++ (FBRequest *)requestForPostOpenGraphObjectWithType:(NSString *)type + title:(NSString *)title + image:(id)image + url:(id)url + description:(NSString *)description + objectProperties:(NSDictionary *)objectProperties; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to update a user owned + Open Graph object for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param object The Open Graph object to update the existing object with. + */ ++ (FBRequest *)requestForUpdateOpenGraphObject:(id)object; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to update a user owned + Open Graph object for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param objectId The id of the Open Graph object to update. + @param title The updated title of the Open Graph object. + @param image The updated link to an image to be associated with the Open Graph object. + @param url The updated url to be associated with the Open Graph object. + @param description The updated description of the Open Graph object. + @param objectProperties Any additional properties to update for the Open Graph object. + */ ++ (FBRequest *)requestForUpdateOpenGraphObjectWithId:(id)objectId + title:(NSString *)title + image:(id)image + url:(id)url + description:(NSString *)description + objectProperties:(NSDictionary *)objectProperties; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to upload an image + to create a staging resource. Staging resources allow you to post binary data + such as images, in preparation for a post of an open graph object or action + which references the image. The URI returned when uploading a staging resource + may be passed as the image property for an open graph object or action. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param image A `UIImage` for the image to upload. + */ ++ (FBRequest *)requestForUploadStagingResourceWithImage:(UIImage *)image; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBRequestConnection.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBRequestConnection.h new file mode 100644 index 0000000..140267f --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBRequestConnection.h @@ -0,0 +1,626 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +#import "FBGraphObject.h" + +// up-front decl's +@class FBRequest; +@class FBRequestConnection; +@class FBSession; +@class UIImage; + + +/*! + @attribute beta true + + @typedef FBRequestConnectionErrorBehavior enum + + @abstract Describes what automatic error handling behaviors to provide (if any). + + @discussion This is a bitflag enum that can be composed of different values. + + See FBError.h and FBErrorUtility.h for error category and user message details. + */ +typedef enum { + /*! The default behavior of none */ + FBRequestConnectionErrorBehaviorNone = 0, + + /*! This will retry any requests whose error category is classified as `FBErrorCategoryRetry`. + If the retry fails, the normal handler is invoked. */ + FBRequestConnectionErrorBehaviorRetry = 1, + + /*! This will automatically surface any SDK provided userMessage (at most one), after + retry attempts, but before any reconnects are tried. The alert will have one button + whose text can be localized with the key "FBE:AlertMessageButton". + + You should not display your own alert views in your request handler when specifying this + behavior. + */ + FBRequestConnectionErrorBehaviorAlertUser = 2, + + /*! This will automatically reconnect a session if the request failed due to an invalid token + that would otherwise close the session (such as an expired token or password change). Note + this will NOT reconnect a session if the user had uninstalled the app, or if the user had + disabled the app's slider in their privacy settings (in cases of iOS 6 system auth). + If the session is reconnected, this will transition the session state to FBSessionStateTokenExtended + which will invoke any state change handlers. Otherwise, the session is closed as normal. + + This behavior should not be used if the FBRequestConnection contains multiple + session instances. Further, when this behavior is used, you must not request new permissions + for the session until the connection is completed. + + Lastly, you should avoid using additional FBRequestConnections with the same session because + that will be subject to race conditions. + */ + FBRequestConnectionErrorBehaviorReconnectSession = 4, +} FBRequestConnectionErrorBehavior; + +/*! + Normally requests return JSON data that is parsed into a set of `NSDictionary` + and `NSArray` objects. + + When a request returns a non-JSON response, that response is packaged in + a `NSDictionary` using FBNonJSONResponseProperty as the key and the literal + response as the value. +*/ +extern NSString *const FBNonJSONResponseProperty; + +/*! + @typedef FBRequestHandler + + @abstract + A block that is passed to addRequest to register for a callback with the results of that + request once the connection completes. + + @discussion + Pass a block of this type when calling addRequest. This will be called once + the request completes. The call occurs on the UI thread. + + @param connection The `FBRequestConnection` that sent the request. + + @param result The result of the request. This is a translation of + JSON data to `NSDictionary` and `NSArray` objects. This + is nil if there was an error. + + @param error The `NSError` representing any error that occurred. + +*/ +typedef void (^FBRequestHandler)(FBRequestConnection *connection, + id result, + NSError *error); + +/*! + @class FBRequestConnection + + @abstract + The `FBRequestConnection` represents a single connection to Facebook to service a request. + + @discussion + The request settings are encapsulated in a reusable object. The + `FBRequestConnection` object encapsulates the concerns of a single communication + e.g. starting a connection, canceling a connection, or batching requests. + +*/ +@interface FBRequestConnection : NSObject + +/*! + @methodgroup Creating a request +*/ + +/*! + @method + + Calls with a default timeout of 180 seconds. +*/ +- (id)init; + +/*! + @method + + @abstract + `FBRequestConnection` objects are used to issue one or more requests as a single + request/response connection with Facebook. + + @discussion + For a single request, the usual method for creating an `FBRequestConnection` + object is to call one of the **start* ** methods on . However, it is + allowable to init an `FBRequestConnection` object directly, and call + to add one or more request objects to the + connection, before calling start. + + Note that if requests are part of a batch, they must have an open + FBSession that has an access token associated with it. Alternatively a default App ID + must be set either in the plist or through an explicit call to <[FBSession defaultAppID]>. + + @param timeout The `NSTimeInterval` (seconds) to wait for a response before giving up. +*/ + +- (id)initWithTimeout:(NSTimeInterval)timeout; + +// properties + +/*! + @abstract + The request that will be sent to the server. + + @discussion + This property can be used to create a `NSURLRequest` without using + `FBRequestConnection` to send that request. It is legal to set this property + in which case the provided `NSMutableURLRequest` will be used instead. However, + the `NSMutableURLRequest` must result in an appropriate response. Furthermore, once + this property has been set, no more objects can be added to this + `FBRequestConnection`. +*/ +@property (nonatomic, retain, readwrite) NSMutableURLRequest *urlRequest; + +/*! + @abstract + The raw response that was returned from the server. (readonly) + + @discussion + This property can be used to inspect HTTP headers that were returned from + the server. + + The property is nil until the request completes. If there was a response + then this property will be non-nil during the FBRequestHandler callback. +*/ +@property (nonatomic, retain, readonly) NSHTTPURLResponse *urlResponse; + +/*! + @attribute beta true + + @abstract Set the automatic error handling behaviors. + @discussion + + This must be set before any requests are added. + + When using retry behaviors, note the FBRequestConnection instance + passed to the FBRequestHandler may be a different instance that the + one the requests were originally started on. +*/ +@property (nonatomic, assign) FBRequestConnectionErrorBehavior errorBehavior; + +/*! + @methodgroup Adding requests +*/ + +/*! + @method + + @abstract + This method adds an object to this connection. + + @discussion + The completion handler is retained until the block is called upon the + completion or cancellation of the connection. + + @param request A request to be included in the round-trip when start is called. + @param handler A handler to call back when the round-trip completes or times out. + The handler will be invoked on the main thread. +*/ +- (void)addRequest:(FBRequest*)request + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + This method adds an object to this connection. + + @discussion + The completion handler is retained until the block is called upon the + completion or cancellation of the connection. This request can be named + to allow for using the request's response in a subsequent request. + + @param request A request to be included in the round-trip when start is called. + + @param handler A handler to call back when the round-trip completes or times out. + The handler will be invoked on the main thread. + + @param name An optional name for this request. This can be used to feed + the results of one request to the input of another in the same + `FBRequestConnection` as described in + [Graph API Batch Requests]( https://developers.facebook.com/docs/reference/api/batch/ ). +*/ +- (void)addRequest:(FBRequest*)request + completionHandler:(FBRequestHandler)handler + batchEntryName:(NSString*)name; + +/*! + @method + + @abstract + This method adds an object to this connection. + + @discussion + The completion handler is retained until the block is called upon the + completion or cancellation of the connection. This request can be named + to allow for using the request's response in a subsequent request. + + @param request A request to be included in the round-trip when start is called. + + @param handler A handler to call back when the round-trip completes or times out. + + @param batchParameters The optional dictionary of parameters to include for this request + as described in [Graph API Batch Requests]( https://developers.facebook.com/docs/reference/api/batch/ ). + Examples include "depends_on", "name", or "omit_response_on_success". + */ +- (void)addRequest:(FBRequest*)request + completionHandler:(FBRequestHandler)handler + batchParameters:(NSDictionary*)batchParameters; + +/*! + @methodgroup Instance methods +*/ + +/*! + @method + + @abstract + This method starts a connection with the server and is capable of handling all of the + requests that were added to the connection. + + @discussion + Errors are reported via the handler callback, even in cases where no + communication is attempted by the implementation of `FBRequestConnection`. In + such cases multiple error conditions may apply, and if so the following + priority (highest to lowest) is used: + + - `FBRequestConnectionInvalidRequestKey` -- this error is reported when an + cannot be encoded for transmission. + + - `FBRequestConnectionInvalidBatchKey` -- this error is reported when any + request in the connection cannot be encoded for transmission with the batch. + In this scenario all requests fail. + + This method cannot be called twice for an `FBRequestConnection` instance. +*/ +- (void)start; + +/*! + @method + + @abstract + Signals that a connection should be logically terminated as the + application is no longer interested in a response. + + @discussion + Synchronously calls any handlers indicating the request was cancelled. Cancel + does not guarantee that the request-related processing will cease. It + does promise that all handlers will complete before the cancel returns. A call to + cancel prior to a start implies a cancellation of all requests associated + with the connection. +*/ +- (void)cancel; + +/*! + @method + + @abstract + Simple method to make a graph API request for user info (/me), creates an + then uses an object to start the connection with Facebook. The + request uses the active session represented by `[FBSession activeSession]`. + + See + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForMeWithCompletionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to make a graph API request for user friends (/me/friends), creates an + then uses an object to start the connection with Facebook. The + request uses the active session represented by `[FBSession activeSession]`. + + See + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForMyFriendsWithCompletionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to make a graph API post of a photo. The request + uses the active session represented by `[FBSession activeSession]`. + + @param photo A `UIImage` for the photo to upload. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForUploadPhoto:(UIImage *)photo + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to make a graph API post of a status update. The request + uses the active session represented by `[FBSession activeSession]`. + + @param message The message to post. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection *)startForPostStatusUpdate:(NSString *)message + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to make a graph API post of a status update. The request + uses the active session represented by `[FBSession activeSession]`. + + @param message The message to post. + @param place The place to checkin with, or nil. Place may be an fbid or a + graph object representing a place. + @param tags Array of friends to tag in the status update, each element + may be an fbid or a graph object representing a user. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection *)startForPostStatusUpdate:(NSString *)message + place:(id)place + tags:(id)tags + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Starts a request representing a Graph API call to the "search" endpoint + for a given location using the active session. + + @discussion + Simplifies starting a request to search for places near a coordinate. + + This method creates the necessary object and initializes and + starts an object. A successful Graph API call will + return an array of objects representing the nearby locations. + + @param coordinate The search coordinates. + + @param radius The search radius in meters. + + @param limit The maxiumum number of results to return. It is + possible to receive fewer than this because of the + radius and because of server limits. + + @param searchText The text to use in the query to narrow the set of places + returned. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForPlacesSearchAtCoordinate:(CLLocationCoordinate2D)coordinate + radiusInMeters:(NSInteger)radius + resultsLimit:(NSInteger)limit + searchText:(NSString*)searchText + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Starts a request representing the Graph API call to retrieve a Custom Audience "third party ID" for the app's Facebook user. + Callers will send this ID back to their own servers, collect up a set to create a Facebook Custom Audience with, + and then use the resultant Custom Audience to target ads. + + @param session The FBSession to use to establish the user's identity for users logged into Facebook through this app. + If `nil`, then the activeSession is used. + + @discussion + This method will throw an exception if <[FBSettings defaultAppID]> is `nil`. The appID won't be nil when the pList + includes the appID, or if it's explicitly set. + + The JSON in the request's response will include an "custom_audience_third_party_id" key/value pair, with the value being the ID retrieved. + This ID is an encrypted encoding of the Facebook user's ID and the invoking Facebook app ID. + Multiple calls with the same user will return different IDs, thus these IDs cannot be used to correlate behavior + across devices or applications, and are only meaningful when sent back to Facebook for creating Custom Audiences. + + The ID retrieved represents the Facebook user identified in the following way: if the specified session (or activeSession if the specified + session is `nil`) is open, the ID will represent the user associated with the activeSession; otherwise the ID will represent the user logged into the + native Facebook app on the device. If there is no native Facebook app, no one is logged into it, or the user has opted out + at the iOS level from ad tracking, then a `nil` ID will be returned. + + This method returns `nil` if either the user has opted-out (via iOS) from Ad Tracking, the app itself has limited event usage + via the `[FBAppEvents setLimitEventUsage]` flag, or a specific Facebook user cannot be identified. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForCustomAudienceThirdPartyID:(FBSession *)session + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to make a graph API request, creates an object for HTTP GET, + then uses an object to start the connection with Facebook. The + request uses the active session represented by `[FBSession activeSession]`. + + See + + @param graphPath The Graph API endpoint to use for the request, for example "me". + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startWithGraphPath:(NSString*)graphPath + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to delete an object using the graph API, creates an object for + HTTP DELETE, then uses an object to start the connection with Facebook. + The request uses the active session represented by `[FBSession activeSession]`. + + @param object The object to delete, may be an NSString or NSNumber representing an fbid or an NSDictionary with an id property + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForDeleteObject:(id)object + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to post an object using the graph API, creates an object for + HTTP POST, then uses to start a connection with Facebook. The request uses + the active session represented by `[FBSession activeSession]`. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param graphObject An object or open graph action to post. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + + @discussion This method is typically used for posting an open graph action. If you are only + posting an open graph object (without an action), consider using `startForPostOpenGraphObject:completionHandler:` +*/ ++ (FBRequestConnection*)startForPostWithGraphPath:(NSString*)graphPath + graphObject:(id)graphObject + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Creates an `FBRequest` object for a Graph API call, instantiate an + object, add the request to the newly created + connection and finally start the connection. Use this method for + specifying the request parameters and HTTP Method. The request uses + the active session represented by `[FBSession activeSession]`. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param parameters The parameters for the request. A value of nil sends only the automatically handled parameters, for example, the access token. The default is nil. + + @param HTTPMethod The HTTP method to use for the request. A nil value implies a GET. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startWithGraphPath:(NSString*)graphPath + parameters:(NSDictionary*)parameters + HTTPMethod:(NSString*)HTTPMethod + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Creates an `FBRequest` for creating a user owned Open Graph object, instantiate a + object, add the request to the newly created + connection and finally start the connection. The request uses + the active session represented by `[FBSession activeSession]`. + + @param object The Open Graph object to create. Some common expected fields include "title", "image", "url", etc. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForPostOpenGraphObject:(id)object + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Creates an `FBRequest` for creating a user owned Open Graph object, instantiate a + object, add the request to the newly created + connection and finally start the connection. The request uses + the active session represented by `[FBSession activeSession]`. + + @param type The fully-specified Open Graph object type (e.g., my_app_namespace:my_object_name) + @param title The title of the Open Graph object. + @param image The link to an image to be associated with the Open Graph object. + @param url The url to be associated with the Open Graph object. + @param description The description for the object. + @param objectProperties Any additional properties for the Open Graph object. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForPostOpenGraphObjectWithType:(NSString *)type + title:(NSString *)title + image:(id)image + url:(id)url + description:(NSString *)description + objectProperties:(NSDictionary *)objectProperties + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Creates an `FBRequest` for updating a user owned Open Graph object, instantiate a + object, add the request to the newly created + connection and finally start the connection. The request uses + the active session represented by `[FBSession activeSession]`. + + @param object The Open Graph object to update the existing object with. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForUpdateOpenGraphObject:(id)object + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Creates an `FBRequest` for updating a user owned Open Graph object, instantiate a + object, add the request to the newly created + connection and finally start the connection. The request uses + the active session represented by `[FBSession activeSession]`. + + @param objectId The id of the Open Graph object to update. + @param title The updated title of the Open Graph object. + @param image The updated link to an image to be associated with the Open Graph object. + @param url The updated url to be associated with the Open Graph object. + @param description The object's description. + @param objectProperties Any additional properties to update for the Open Graph object. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection *)startForUpdateOpenGraphObjectWithId:(id)objectId + title:(NSString *)title + image:(id)image + url:(id)url + description:(NSString *)description + objectProperties:(NSDictionary *)objectProperties + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Starts a request connection to upload an image + to create a staging resource. Staging resources allow you to post binary data + such as images, in preparation for a post of an open graph object or action + which references the image. The URI returned when uploading a staging resource + may be passed as the value for the image property of an open graph object or action. + + @discussion + This method simplifies the preparation of a Graph API call be creating the FBRequest + object and starting the request connection with a single method + + @param image A `UIImage` for the image to upload. + @param handler The handler block to call when the request completes. + */ ++ (FBRequestConnection *)startForUploadStagingResourceWithImage:(UIImage *)image + completionHandler:(FBRequestHandler)handler; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSession.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSession.h new file mode 100644 index 0000000..63b0187 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSession.h @@ -0,0 +1,785 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +// up-front decl's +@class FBAccessTokenData; +@class FBSession; +@class FBSessionTokenCachingStrategy; + +#define FB_SESSIONSTATETERMINALBIT (1 << 8) + +#define FB_SESSIONSTATEOPENBIT (1 << 9) + +/* + * Constants used by NSNotificationCenter for active session notification + */ + +/*! NSNotificationCenter name indicating that a new active session was set */ +extern NSString *const FBSessionDidSetActiveSessionNotification; + +/*! NSNotificationCenter name indicating that an active session was unset */ +extern NSString *const FBSessionDidUnsetActiveSessionNotification; + +/*! NSNotificationCenter name indicating that the active session is open */ +extern NSString *const FBSessionDidBecomeOpenActiveSessionNotification; + +/*! NSNotificationCenter name indicating that there is no longer an open active session */ +extern NSString *const FBSessionDidBecomeClosedActiveSessionNotification; + +/*! + @typedef FBSessionState enum + + @abstract Passed to handler block each time a session state changes + + @discussion + */ +typedef enum { + /*! One of two initial states indicating that no valid cached token was found */ + FBSessionStateCreated = 0, + /*! One of two initial session states indicating that a cached token was loaded; + when a session is in this state, a call to open* will result in an open session, + without UX or app-switching*/ + FBSessionStateCreatedTokenLoaded = 1, + /*! One of three pre-open session states indicating that an attempt to open the session + is underway*/ + FBSessionStateCreatedOpening = 2, + + /*! Open session state indicating user has logged in or a cached token is available */ + FBSessionStateOpen = 1 | FB_SESSIONSTATEOPENBIT, + /*! Open session state indicating token has been extended */ + FBSessionStateOpenTokenExtended = 2 | FB_SESSIONSTATEOPENBIT, + + /*! Closed session state indicating that a login attempt failed */ + FBSessionStateClosedLoginFailed = 1 | FB_SESSIONSTATETERMINALBIT, // NSError obj w/more info + /*! Closed session state indicating that the session was closed, but the users token + remains cached on the device for later use */ + FBSessionStateClosed = 2 | FB_SESSIONSTATETERMINALBIT, // " +} FBSessionState; + +/*! helper macro to test for states that imply an open session */ +#define FB_ISSESSIONOPENWITHSTATE(state) (0 != (state & FB_SESSIONSTATEOPENBIT)) + +/*! helper macro to test for states that are terminal */ +#define FB_ISSESSIONSTATETERMINAL(state) (0 != (state & FB_SESSIONSTATETERMINALBIT)) + +/*! + @typedef FBSessionLoginBehavior enum + + @abstract + Passed to open to indicate whether Facebook Login should allow for fallback to be attempted. + + @discussion + Facebook Login authorizes the application to act on behalf of the user, using the user's + Facebook account. Usually a Facebook Login will rely on an account maintained outside of + the application, by the native Facebook application, the browser, or perhaps the device + itself. This avoids the need for a user to enter their username and password directly, and + provides the most secure and lowest friction way for a user to authorize the application to + interact with Facebook. If a Facebook Login is not possible, a fallback Facebook Login may be + attempted, where the user is prompted to enter their credentials in a web-view hosted directly + by the application. + + The `FBSessionLoginBehavior` enum specifies whether to allow fallback, disallow fallback, or + force fallback login behavior. Most applications will use the default, which attempts a normal + Facebook Login, and only falls back if needed. In rare cases, it may be preferable to disallow + fallback Facebook Login completely, or to force a fallback login. + */ +typedef enum { + /*! Attempt Facebook Login, ask user for credentials if necessary */ + FBSessionLoginBehaviorWithFallbackToWebView = 0, + /*! Attempt Facebook Login, no direct request for credentials will be made */ + FBSessionLoginBehaviorWithNoFallbackToWebView = 1, + /*! Only attempt WebView Login; ask user for credentials */ + FBSessionLoginBehaviorForcingWebView = 2, + /*! Attempt Facebook Login, prefering system account and falling back to fast app switch if necessary */ + FBSessionLoginBehaviorUseSystemAccountIfPresent = 3, +} FBSessionLoginBehavior; + +/*! + @typedef FBSessionDefaultAudience enum + + @abstract + Passed to open to indicate which default audience to use for sessions that post data to Facebook. + + @discussion + Certain operations such as publishing a status or publishing a photo require an audience. When the user + grants an application permission to perform a publish operation, a default audience is selected as the + publication ceiling for the application. This enumerated value allows the application to select which + audience to ask the user to grant publish permission for. + */ +typedef enum { + /*! No audience needed; this value is useful for cases where data will only be read from Facebook */ + FBSessionDefaultAudienceNone = 0, + /*! Indicates that only the user is able to see posts made by the application */ + FBSessionDefaultAudienceOnlyMe = 10, + /*! Indicates that the user's friends are able to see posts made by the application */ + FBSessionDefaultAudienceFriends = 20, + /*! Indicates that all Facebook users are able to see posts made by the application */ + FBSessionDefaultAudienceEveryone = 30, +} FBSessionDefaultAudience; + +/*! + @typedef FBSessionLoginType enum + + @abstract + Used as the type of the loginType property in order to specify what underlying technology was used to + login the user. + + @discussion + The FBSession object is an abstraction over five distinct mechanisms. This enum allows an application + to test for the mechanism used by a particular instance of FBSession. Usually the mechanism used for a + given login does not matter, however for certain capabilities, the type of login can impact the behavior + of other Facebook functionality. + */ +typedef enum { + /*! A login type has not yet been established */ + FBSessionLoginTypeNone = 0, + /*! A system integrated account was used to log the user into the application */ + FBSessionLoginTypeSystemAccount = 1, + /*! The Facebook native application was used to log the user into the application */ + FBSessionLoginTypeFacebookApplication = 2, + /*! Safari was used to log the user into the application */ + FBSessionLoginTypeFacebookViaSafari = 3, + /*! A web view was used to log the user into the application */ + FBSessionLoginTypeWebView = 4, + /*! A test user was used to create an open session */ + FBSessionLoginTypeTestUser = 5, +} FBSessionLoginType; + +/*! + @typedef + + @abstract Block type used to define blocks called by for state updates + @discussion See https://developers.facebook.com/docs/technical-guides/iossdk/errors/ + for error handling best practices. + + Requesting additional permissions inside this handler (such as by calling + `requestNewPublishPermissions`) should be avoided because it is a poor user + experience and its behavior may vary depending on the login type. You should + request the permissions closer to the operation that requires it (e.g., when + the user performs some action). + */ +typedef void (^FBSessionStateHandler)(FBSession *session, + FBSessionState status, + NSError *error); + +/*! + @typedef + + @abstract Block type used to define blocks called by <[FBSession requestNewReadPermissions:completionHandler:]> + and <[FBSession requestNewPublishPermissions:defaultAudience:completionHandler:]>. + + @discussion See https://developers.facebook.com/docs/technical-guides/iossdk/errors/ + for error handling best practices. + + Requesting additional permissions inside this handler (such as by calling + `requestNewPublishPermissions`) should be avoided because it is a poor user + experience and its behavior may vary depending on the login type. You should + request the permissions closer to the operation that requires it (e.g., when + the user performs some action). + */ +typedef void (^FBSessionRequestPermissionResultHandler)(FBSession *session, + NSError *error); + +/*! + @typedef + + @abstract Block type used to define blocks called by <[FBSession reauthorizeWithPermissions]>. + + @discussion You should use the preferred FBSessionRequestPermissionHandler typedef rather than + this synonym, which has been deprecated. + */ +typedef FBSessionRequestPermissionResultHandler FBSessionReauthorizeResultHandler __attribute__((deprecated)); + +/*! + @typedef + + @abstract Block type used to define blocks called for system credential renewals. + @discussion + */ +typedef void (^FBSessionRenewSystemCredentialsHandler)(ACAccountCredentialRenewResult result, NSError *error) ; + +/*! + @class FBSession + + @abstract + The `FBSession` object is used to authenticate a user and manage the user's session. After + initializing a `FBSession` object the Facebook App ID and desired permissions are stored. + Opening the session will initiate the authentication flow after which a valid user session + should be available and subsequently cached. Closing the session can optionally clear the + cache. + + If an request requires user authorization then an `FBSession` object should be used. + + + @discussion + Instances of the `FBSession` class provide notification of state changes in the following ways: + + 1. Callers of certain `FBSession` methods may provide a block that will be called + back in the course of state transitions for the session (e.g. login or session closed). + + 2. The object supports Key-Value Observing (KVO) for property changes. + */ +@interface FBSession : NSObject + +/*! + @methodgroup Creating a session + */ + +/*! + @method + + @abstract + Returns a newly initialized Facebook session with default values for the parameters + to . + */ +- (id)init; + +/*! + @method + + @abstract + Returns a newly initialized Facebook session with the specified permissions and other + default values for parameters to . + + @param permissions An array of strings representing the permissions to request during the + authentication flow. The basic_info permission must be explicitly requested at first login, and is no + longer inferred, (subject to an active migration.) The default is nil. + + @discussion + It is required that any single permission request request (including initial log in) represent read-only permissions + or publish permissions only; not both. The permissions passed here should reflect this requirement. + + */ +- (id)initWithPermissions:(NSArray*)permissions; + +/*! + @method + + @abstract + Following are the descriptions of the arguments along with their + defaults when ommitted. + + @param permissions An array of strings representing the permissions to request during the + authentication flow. The basic_info permission must be explicitly requested at first login, and is no longer inferred, (subject to an active migration.) The default is nil. + @param appID The Facebook App ID for the session. If nil is passed in the default App ID will be obtained from a call to <[FBSession defaultAppID]>. The default is nil. + @param urlSchemeSuffix The URL Scheme Suffix to be used in scenarious where multiple iOS apps use one Facebook App ID. A value of nil indicates that this information should be pulled from [FBSettings defaultUrlSchemeSuffix]. The default is nil. + @param tokenCachingStrategy Specifies a key name to use for cached token information in NSUserDefaults, nil + indicates a default value of @"FBAccessTokenInformationKey". + + @discussion + It is required that any single permission request request (including initial log in) represent read-only permissions + or publish permissions only; not both. The permissions passed here should reflect this requirement. + */ +- (id)initWithAppID:(NSString*)appID + permissions:(NSArray*)permissions + urlSchemeSuffix:(NSString*)urlSchemeSuffix + tokenCacheStrategy:(FBSessionTokenCachingStrategy*)tokenCachingStrategy; + +/*! + @method + + @abstract + Following are the descriptions of the arguments along with their + defaults when ommitted. + + @param permissions An array of strings representing the permissions to request during the + authentication flow. The basic_info permission must be explicitly requested at first login, and is no longer inferred, (subject to an active migration.) The default is nil. + @param defaultAudience Most applications use FBSessionDefaultAudienceNone here, only specifying an audience when using reauthorize to request publish permissions. + @param appID The Facebook App ID for the session. If nil is passed in the default App ID will be obtained from a call to <[FBSession defaultAppID]>. The default is nil. + @param urlSchemeSuffix The URL Scheme Suffix to be used in scenarious where multiple iOS apps use one Facebook App ID. A value of nil indicates that this information should be pulled from [FBSettings defaultUrlSchemeSuffix]. The default is nil. + @param tokenCachingStrategy Specifies a key name to use for cached token information in NSUserDefaults, nil + indicates a default value of @"FBAccessTokenInformationKey". + + @discussion + It is required that any single permission request request (including initial log in) represent read-only permissions + or publish permissions only; not both. The permissions passed here should reflect this requirement. If publish permissions + are used, then the audience must also be specified. + */ +- (id)initWithAppID:(NSString*)appID + permissions:(NSArray*)permissions + defaultAudience:(FBSessionDefaultAudience)defaultAudience + urlSchemeSuffix:(NSString*)urlSchemeSuffix + tokenCacheStrategy:(FBSessionTokenCachingStrategy*)tokenCachingStrategy; + +// instance readonly properties + +/*! @abstract Indicates whether the session is open and ready for use. */ +@property (readonly) BOOL isOpen; + +/*! @abstract Detailed session state */ +@property (readonly) FBSessionState state; + +/*! @abstract Identifies the Facebook app which the session object represents. */ +@property (readonly, copy) NSString *appID; + +/*! @abstract Identifies the URL Scheme Suffix used by the session. This is used when multiple iOS apps share a single Facebook app ID. */ +@property (readonly, copy) NSString *urlSchemeSuffix; + +/*! @abstract The access token for the session object. + @discussion Deprecated. Use the `accessTokenData` property. */ +@property(readonly, copy) NSString *accessToken +__attribute__((deprecated)); + +/*! @abstract The expiration date of the access token for the session object. + @discussion Deprecated. Use the `accessTokenData` property. */ +@property(readonly, copy) NSDate *expirationDate +__attribute__((deprecated)); + +/*! @abstract The permissions granted to the access token during the authentication flow. */ +@property (readonly, copy) NSArray *permissions; + +/*! @abstract Specifies the login type used to authenticate the user. + @discussion Deprecated. Use the `accessTokenData` property. */ +@property(readonly) FBSessionLoginType loginType +__attribute__((deprecated)); + +/*! @abstract Gets the FBAccessTokenData for the session */ +@property (readonly, copy) FBAccessTokenData *accessTokenData; + +/*! + @methodgroup Instance methods + */ + +/*! + @method + + @abstract Opens a session for the Facebook. + + @discussion + A session may not be used with and other classes in the SDK until it is open. If, prior + to calling open, the session is in the state, then no UX occurs, and + the session becomes available for use. If the session is in the state, prior + to calling open, then a call to open causes login UX to occur, either via the Facebook application + or via mobile Safari. + + Open may be called at most once and must be called after the `FBSession` is initialized. Open must + be called before the session is closed. Calling an open method at an invalid time will result in + an exception. The open session methods may be passed a block that will be called back when the session + state changes. The block will be released when the session is closed. + + @param handler A block to call with the state changes. The default is nil. +*/ +- (void)openWithCompletionHandler:(FBSessionStateHandler)handler; + +/*! + @method + + @abstract Logs a user on to Facebook. + + @discussion + A session may not be used with and other classes in the SDK until it is open. If, prior + to calling open, the session is in the state, then no UX occurs, and + the session becomes available for use. If the session is in the state, prior + to calling open, then a call to open causes login UX to occur, either via the Facebook application + or via mobile Safari. + + The method may be called at most once and must be called after the `FBSession` is initialized. It must + be called before the session is closed. Calling the method at an invalid time will result in + an exception. The open session methods may be passed a block that will be called back when the session + state changes. The block will be released when the session is closed. + + @param behavior Controls whether to allow, force, or prohibit Facebook Login or Inline Facebook Login. The default + is to allow Facebook Login, with fallback to Inline Facebook Login. + @param handler A block to call with session state changes. The default is nil. + */ +- (void)openWithBehavior:(FBSessionLoginBehavior)behavior + completionHandler:(FBSessionStateHandler)handler; + +/*! + @method + + @abstract Imports an existing access token and opens the session with it. + + @discussion + The method attempts to open the session using an existing access token. No UX will occur. If + successful, the session with be in an Open state and the method will return YES; otherwise, NO. + + The method may be called at most once and must be called after the `FBSession` is initialized (see below). + It must be called before the session is closed. Calling the method at an invalid time will result in + an exception. The open session methods may be passed a block that will be called back when the session + state changes. The block will be released when the session is closed. + + The initialized session must not have already been initialized from a cache (for example, you could use + the `[FBSessionTokenCachingStrategy nullCacheInstance]` instance). + + @param accessTokenData The token data. See `FBAccessTokenData` for construction methods. + @param handler A block to call with session state changes. The default is nil. + */ +- (BOOL)openFromAccessTokenData:(FBAccessTokenData *)accessTokenData completionHandler:(FBSessionStateHandler) handler; + +/*! + @abstract + Closes the local in-memory session object, but does not clear the persisted token cache. + */ +- (void)close; + +/*! + @abstract + Closes the in-memory session, and clears any persisted cache related to the session. +*/ +- (void)closeAndClearTokenInformation; + +/*! + @abstract + Reauthorizes the session, with additional permissions. + + @param permissions An array of strings representing the permissions to request during the + authentication flow. A value of nil indicates basic permissions. The default is nil. + @param behavior Controls whether to allow, force, or prohibit Facebook Login. The default + is to allow Facebook Login and fall back to Inline Facebook Login if needed. + @param handler A block to call with session state changes. The default is nil. + + @discussion Methods and properties that specify permissions without a read or publish + qualification are deprecated; use of a read-qualified or publish-qualified alternative is preferred + (e.g. reauthorizeWithReadPermissions or reauthorizeWithPublishPermissions) + */ +- (void)reauthorizeWithPermissions:(NSArray*)permissions + behavior:(FBSessionLoginBehavior)behavior + completionHandler:(FBSessionReauthorizeResultHandler)handler + __attribute__((deprecated)); + +/*! + @abstract + Reauthorizes the session, with additional permissions. + + @param readPermissions An array of strings representing the permissions to request during the + authentication flow. A value of nil indicates basic permissions. + + @param handler A block to call with session state changes. The default is nil. + + @discussion This method is a deprecated alias of <[FBSession requestNewReadPermissions:completionHandler:]>. Consider + using <[FBSession requestNewReadPermissions:completionHandler:]>, which is preferred for readability. + */ +- (void)reauthorizeWithReadPermissions:(NSArray*)readPermissions + completionHandler:(FBSessionReauthorizeResultHandler)handler +__attribute__((deprecated)); + +/*! + @abstract + Reauthorizes the session, with additional permissions. + + @param writePermissions An array of strings representing the permissions to request during the + authentication flow. + + @param defaultAudience Specifies the audience for posts. + + @param handler A block to call with session state changes. The default is nil. + + @discussion This method is a deprecated alias of <[FBSession requestNewPublishPermissions:defaultAudience:completionHandler:]>. + Consider using <[FBSession requestNewPublishPermissions:defaultAudience:completionHandler:]>, which is preferred for readability. + */ +- (void)reauthorizeWithPublishPermissions:(NSArray*)writePermissions + defaultAudience:(FBSessionDefaultAudience)defaultAudience + completionHandler:(FBSessionReauthorizeResultHandler)handler +__attribute__((deprecated)); + +/*! + @abstract + Requests new or additional read permissions for the session. + + @param readPermissions An array of strings representing the permissions to request during the + authentication flow. A value of nil indicates basic permissions. + + @param handler A block to call with session state changes. The default is nil. + + @discussion The handler, if non-nil, is called once the operation has completed or failed. This is in contrast to the + state completion handler used in <[FBSession openWithCompletionHandler:]> (and other `open*` methods) which is called + for each state-change for the session. + */ +- (void)requestNewReadPermissions:(NSArray*)readPermissions + completionHandler:(FBSessionRequestPermissionResultHandler)handler; + +/*! + @abstract + Requests new or additional write permissions for the session. + + @param writePermissions An array of strings representing the permissions to request during the + authentication flow. + + @param defaultAudience Specifies the audience for posts. + + @param handler A block to call with session state changes. The default is nil. + + @discussion The handler, if non-nil, is called once the operation has completed or failed. This is in contrast to the + state completion handler used in <[FBSession openWithCompletionHandler:]> (and other `open*` methods) which is called + for each state-change for the session. + */ +- (void)requestNewPublishPermissions:(NSArray*)writePermissions + defaultAudience:(FBSessionDefaultAudience)defaultAudience + completionHandler:(FBSessionRequestPermissionResultHandler)handler; + +/*! + @abstract + A helper method that is used to provide an implementation for + [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. It should be invoked during + the Facebook Login flow and will update the session information based on the incoming URL. + + @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. +*/ +- (BOOL)handleOpenURL:(NSURL*)url; + +/*! + @abstract + A helper method that is used to provide an implementation for + [UIApplicationDelegate applicationDidBecomeActive:] to properly resolve session state for + the Facebook Login flow, specifically to support app-switch login. +*/ +- (void)handleDidBecomeActive; + +/*! + @abstract + Assign the block to be invoked for session state changes. + + @discussion + This will overwrite any state change handler that was already assigned. Typically, + you should only use this setter if you were unable to assign a state change handler explicitly. + One example of this is if you are not opening the session (e.g., using the `open*`) + but still want to assign a `FBSessionStateHandler` block. This can happen when the SDK + opens a session from an app link. +*/ +- (void)setStateChangeHandler:(FBSessionStateHandler)stateChangeHandler; + +/*! + @methodgroup Class methods + */ + +/*! + @abstract + This is the simplest method for opening a session with Facebook. Using sessionOpen logs on a user, + and sets the static activeSession which becomes the default session object for any Facebook UI widgets + used by the application. This session becomes the active session, whether open succeeds or fails. + + Note, if there is not a cached token available, this method will present UI to the user in order to + open the session via explicit login by the user. + + @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if + no login UI will be required to accomplish the operation. For example, at application startup it may not + be disirable to transition to login UI for the user, and yet an open session is desired so long as a cached + token can be used to open the session. Passing NO to this argument, assures the method will not present UI + to the user in order to open the session. + + @discussion + Returns YES if the session was opened synchronously without presenting UI to the user. This occurs + when there is a cached token available from a previous run of the application. If NO is returned, this indicates + that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is + possible that the user will login, and the session will become open asynchronously. The primary use for + this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session + is opened via cache. + */ ++ (BOOL)openActiveSessionWithAllowLoginUI:(BOOL)allowLoginUI; + +/*! + @abstract + This is a simple method for opening a session with Facebook. Using sessionOpen logs on a user, + and sets the static activeSession which becomes the default session object for any Facebook UI widgets + used by the application. This session becomes the active session, whether open succeeds or fails. + + @param permissions An array of strings representing the permissions to request during the + authentication flow. A value of nil indicates basic permissions. A nil value specifies + default permissions. + + @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if + no login UI will be required to accomplish the operation. For example, at application startup it may not + be desirable to transition to login UI for the user, and yet an open session is desired so long as a cached + token can be used to open the session. Passing NO to this argument, assures the method will not present UI + to the user in order to open the session. + + @param handler Many applications will benefit from notification when a session becomes invalid + or undergoes other state transitions. If a block is provided, the FBSession + object will call the block each time the session changes state. + + @discussion + Returns true if the session was opened synchronously without presenting UI to the user. This occurs + when there is a cached token available from a previous run of the application. If NO is returned, this indicates + that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is + possible that the user will login, and the session will become open asynchronously. The primary use for + this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session + is opened via cache. + + It is required that initial permissions requests represent read-only permissions only. If publish + permissions are needed, you may use reauthorizeWithPermissions to specify additional permissions as + well as an audience. Use of this method will result in a legacy fast-app-switch Facebook Login due to + the requirement to separate read and publish permissions for newer applications. Methods and properties + that specify permissions without a read or publish qualification are deprecated; use of a read-qualified + or publish-qualified alternative is preferred. + */ ++ (BOOL)openActiveSessionWithPermissions:(NSArray*)permissions + allowLoginUI:(BOOL)allowLoginUI + completionHandler:(FBSessionStateHandler)handler + __attribute__((deprecated)); + +/*! + @abstract + This is a simple method for opening a session with Facebook. Using sessionOpen logs on a user, + and sets the static activeSession which becomes the default session object for any Facebook UI widgets + used by the application. This session becomes the active session, whether open succeeds or fails. + + @param readPermissions An array of strings representing the read permissions to request during the + authentication flow. The basic_info permission must be explicitly requested at first login, and is no longer + inferred, (subject to an active migration.) It is not allowed to pass publish permissions to this method. + + @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if + no login UI will be required to accomplish the operation. For example, at application startup it may not + be desirable to transition to login UI for the user, and yet an open session is desired so long as a cached + token can be used to open the session. Passing NO to this argument, assures the method will not present UI + to the user in order to open the session. + + @param handler Many applications will benefit from notification when a session becomes invalid + or undergoes other state transitions. If a block is provided, the FBSession + object will call the block each time the session changes state. + + @discussion + Returns true if the session was opened synchronously without presenting UI to the user. This occurs + when there is a cached token available from a previous run of the application. If NO is returned, this indicates + that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is + possible that the user will login, and the session will become open asynchronously. The primary use for + this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session + is opened via cache. + + */ ++ (BOOL)openActiveSessionWithReadPermissions:(NSArray*)readPermissions + allowLoginUI:(BOOL)allowLoginUI + completionHandler:(FBSessionStateHandler)handler; + +/*! + @abstract + This is a simple method for opening a session with Facebook. Using sessionOpen logs on a user, + and sets the static activeSession which becomes the default session object for any Facebook UI widgets + used by the application. This session becomes the active session, whether open succeeds or fails. + + @param publishPermissions An array of strings representing the publish permissions to request during the + authentication flow. + + @param defaultAudience Anytime an app publishes on behalf of a user, the post must have an audience (e.g. me, my friends, etc.) + The default audience is used to notify the user of the cieling that the user agrees to grant to the app for the provided permissions. + + @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if + no login UI will be required to accomplish the operation. For example, at application startup it may not + be desirable to transition to login UI for the user, and yet an open session is desired so long as a cached + token can be used to open the session. Passing NO to this argument, assures the method will not present UI + to the user in order to open the session. + + @param handler Many applications will benefit from notification when a session becomes invalid + or undergoes other state transitions. If a block is provided, the FBSession + object will call the block each time the session changes state. + + @discussion + Returns true if the session was opened synchronously without presenting UI to the user. This occurs + when there is a cached token available from a previous run of the application. If NO is returned, this indicates + that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is + possible that the user will login, and the session will become open asynchronously. The primary use for + this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session + is opened via cache. + + */ ++ (BOOL)openActiveSessionWithPublishPermissions:(NSArray*)publishPermissions + defaultAudience:(FBSessionDefaultAudience)defaultAudience + allowLoginUI:(BOOL)allowLoginUI + completionHandler:(FBSessionStateHandler)handler; + +/*! + @abstract + An application may get or set the current active session. Certain high-level components in the SDK + will use the activeSession to set default session (e.g. `FBLoginView`, `FBFriendPickerViewController`) + + @discussion + If sessionOpen* is called, the resulting `FBSession` object also becomes the activeSession. If another + session was active at the time, it is closed automatically. If activeSession is called when no session + is active, a session object is instatiated and returned; in this case open must be called on the session + in order for it to be useable for communication with Facebook. + */ ++ (FBSession*)activeSession; + +/*! + @abstract + An application may get or set the current active session. Certain high-level components in the SDK + will use the activeSession to set default session (e.g. `FBLoginView`, `FBFriendPickerViewController`) + + @param session The FBSession object to become the active session + + @discussion + If an application prefers the flexibilility of directly instantiating a session object, an active + session can be set directly. + */ ++ (FBSession*)setActiveSession:(FBSession*)session; + +/*! + @method + + @abstract Set the default Facebook App ID to use for sessions. The app ID may be + overridden on a per session basis. + + @discussion This method has been deprecated in favor of [FBSettings setDefaultAppID]. + + @param appID The default Facebook App ID to use for methods. + */ ++ (void)setDefaultAppID:(NSString*)appID __attribute__((deprecated)); + +/*! + @method + + @abstract Get the default Facebook App ID to use for sessions. If not explicitly + set, the default will be read from the application's plist. The app ID may be + overridden on a per session basis. + + @discussion This method has been deprecated in favor of [FBSettings defaultAppID]. +*/ ++ (NSString*)defaultAppID __attribute__((deprecated)); + +/*! + @method + + @abstract Set the default url scheme suffix to use for sessions. The url + scheme suffix may be overridden on a per session basis. + + @discussion This method has been deprecated in favor of [FBSettings setDefaultUrlSchemeSuffix]. + + @param urlSchemeSuffix The default url scheme suffix to use for methods. + */ ++ (void)setDefaultUrlSchemeSuffix:(NSString*)urlSchemeSuffix __attribute__((deprecated)); + +/*! + @method + + @abstract Get the default url scheme suffix used for sessions. If not + explicitly set, the default will be read from the application's plist. The + url scheme suffix may be overridden on a per session basis. + + @discussion This method has been deprecated in favor of [FBSettings defaultUrlSchemeSuffix]. + */ ++ (NSString*)defaultUrlSchemeSuffix __attribute__((deprecated)); + +/*! + @method + + @abstract Issues an asychronous renewCredentialsForAccount call to the device Facebook account store. + + @param handler The completion handler to call when the renewal is completed. The handler will be + invoked on the main thread. + + @discussion This can be used to explicitly renew account credentials on iOS 6 devices and is provided + as a convenience wrapper around `[ACAccountStore renewCredentialsForAccount:completion]`. Note the + method will not issue the renewal call if the the Facebook account has not been set on the device, or + if access had not been granted to the account (though the handler wil receive an error). + + This is safe to call (and will surface an error to the handler) on versions of iOS before 6 or if the user + logged in via Safari or Facebook SSO. +*/ ++ (void)renewSystemCredentials:(FBSessionRenewSystemCredentialsHandler)handler; +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSessionManualTokenCachingStrategy.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSessionManualTokenCachingStrategy.h new file mode 100644 index 0000000..f3789d9 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSessionManualTokenCachingStrategy.h @@ -0,0 +1,32 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "FBSessionTokenCachingStrategy.h" + +// FBSessionManualTokenCachingStrategy +// +// Summary: +// Internal use only, this class enables migration logic for the Facebook class, by providing +// a means to directly provide the access token to a FBSession object +// +@interface FBSessionManualTokenCachingStrategy : FBSessionTokenCachingStrategy + +// set the properties before instantiating the FBSession object in order to seed a token +@property (readwrite, copy) NSString* accessToken; +@property (readwrite, copy) NSDate* expirationDate; + +@end + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSessionTokenCachingStrategy.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSessionTokenCachingStrategy.h new file mode 100644 index 0000000..6190e53 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSessionTokenCachingStrategy.h @@ -0,0 +1,160 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBAccessTokenData.h" + +/*! + @class + + @abstract + The `FBSessionTokenCachingStrategy` class is responsible for persisting and retrieving cached data related to + an object, including the user's Facebook access token. + + @discussion + `FBSessionTokenCachingStrategy` is designed to be instantiated directly or used as a base class. Usually default + token caching behavior is sufficient, and you do not need to interface directly with `FBSessionTokenCachingStrategy` objects. + However, if you need to control where or how `FBSession` information is cached, then you may take one of two approaches. + + The first and simplest approach is to instantiate an instance of `FBSessionTokenCachingStrategy`, and then pass + the instance to `FBSession` class' `init` method. This enables your application to control the key name used in + `NSUserDefaults` to store session information. You may consider this approach if you plan to cache session information + for multiple users. + + The second and more advanced approached is to derive a custom class from `FBSessionTokenCachingStrategy`, which will + be responsible for caching behavior of your application. This approach is useful if you need to change where the + information is cached, for example if you prefer to use the filesystem or make a network connection to fetch and + persist cached tokens. Inheritors should override the cacheTokenInformation, fetchTokenInformation, and clearToken methods. + Doing this enables your application to implement any token caching scheme, including no caching at all (see + `[FBSessionTokenCachingStrategy* nullCacheInstance ]`. + + Direct use of `FBSessionTokenCachingStrategy`is an advanced technique. Most applications use objects without + passing an `FBSessionTokenCachingStrategy`, which yields default caching to `NSUserDefaults`. + */ +@interface FBSessionTokenCachingStrategy : NSObject + +/*! + @abstract Initializes and returns an instance + */ +- (id)init; + +/*! + @abstract + Initializes and returns an instance + + @param tokenInformationKeyName Specifies a key name to use for cached token information in NSUserDefaults, nil + indicates a default value of @"FBAccessTokenInformationKey" + */ +- (id)initWithUserDefaultTokenInformationKeyName:(NSString*)tokenInformationKeyName; + +/*! + @abstract + Called by (and overridden by inheritors), in order to cache token information. + + @param tokenInformation Dictionary containing token information to be cached by the method + @discussion You should favor overriding this instead of `cacheFBAccessTokenData` only if you intend + to cache additional data not captured by the FBAccessTokenData type. + */ +- (void)cacheTokenInformation:(NSDictionary*)tokenInformation; + +/*! + @abstract Cache the supplied token. + @param accessToken The token instance. + @discussion This essentially wraps a call to `cacheTokenInformation` so you should + override this when providing a custom token caching strategy. +*/ +- (void)cacheFBAccessTokenData:(FBAccessTokenData *)accessToken; + +/*! + @abstract + Called by (and overridden by inheritors), in order to fetch cached token information + + @discussion + An overriding implementation should only return a token if it + can also return an expiration date, otherwise return nil. + You should favor overriding this instead of `fetchFBAccessTokenData` only if you intend + to cache additional data not captured by the FBAccessTokenData type. + + */ +- (NSDictionary*)fetchTokenInformation; + +/*! + @abstract + Fetches the cached token instance. + + @discussion + This essentially wraps a call to `fetchTokenInformation` so you should + override this when providing a custom token caching strategy. + + In order for an `FBSession` instance to be able to use a cached token, + the token must be not be expired (see `+isValidTokenInformation:`) and + must also contain all permissions in the initialized session instance. + */ +- (FBAccessTokenData *)fetchFBAccessTokenData; + +/*! + @abstract + Called by (and overridden by inheritors), in order delete any cached information for the current token + */ +- (void)clearToken; + +/*! + @abstract + Helper function called by the SDK as well as apps, in order to fetch the default strategy instance. + */ ++ (FBSessionTokenCachingStrategy*)defaultInstance; + +/*! + @abstract + Helper function to return a FBSessionTokenCachingStrategy instance that does not perform any caching. + */ ++ (FBSessionTokenCachingStrategy*)nullCacheInstance; + +/*! + @abstract + Helper function called by the SDK as well as application code, used to determine whether a given dictionary + contains the minimum token information usable by the . + + @param tokenInformation Dictionary containing token information to be validated + */ ++ (BOOL)isValidTokenInformation:(NSDictionary*)tokenInformation; + +@end + +// The key to use with token information dictionaries to get and set the token value +extern NSString *const FBTokenInformationTokenKey; + +// The to use with token information dictionaries to get and set the expiration date +extern NSString *const FBTokenInformationExpirationDateKey; + +// The to use with token information dictionaries to get and set the refresh date +extern NSString *const FBTokenInformationRefreshDateKey; + +// The key to use with token information dictionaries to get the related user's fbid +extern NSString *const FBTokenInformationUserFBIDKey; + +// The key to use with token information dictionaries to determine whether the token was fetched via Facebook Login +extern NSString *const FBTokenInformationIsFacebookLoginKey; + +// The key to use with token information dictionaries to determine whether the token was fetched via the OS +extern NSString *const FBTokenInformationLoginTypeLoginKey; + +// The key to use with token information dictionaries to get the latest known permissions +extern NSString *const FBTokenInformationPermissionsKey; + +// The key to use with token information dictionaries to get the date the permissions were last refreshed. +extern NSString *const FBTokenInformationPermissionsRefreshDateKey; diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSettings.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSettings.h new file mode 100644 index 0000000..a9fc57b --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBSettings.h @@ -0,0 +1,327 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +/* + * Constants defining logging behavior. Use with <[FBSettings setLoggingBehavior]>. + */ + +/*! Log requests from FBRequest* classes */ +extern NSString *const FBLoggingBehaviorFBRequests; + +/*! Log requests from FBURLConnection* classes */ +extern NSString *const FBLoggingBehaviorFBURLConnections; + +/*! Include access token in logging. */ +extern NSString *const FBLoggingBehaviorAccessTokens; + +/*! Log session state transitions. */ +extern NSString *const FBLoggingBehaviorSessionStateTransitions; + +/*! Log performance characteristics */ +extern NSString *const FBLoggingBehaviorPerformanceCharacteristics; + +/*! Log FBAppEvents interactions */ +extern NSString *const FBLoggingBehaviorAppEvents; + +/*! Log Informational occurrences */ +extern NSString *const FBLoggingBehaviorInformational; + +/*! Log errors likely to be preventable by the developer. This is in the default set of enabled logging behaviors. */ +extern NSString *const FBLoggingBehaviorDeveloperErrors; + +@class FBGraphObject; + +/*! + @typedef + + @abstract Block type used to get install data that is returned by server when publishInstall is called + @discussion + */ +typedef void (^FBInstallResponseDataHandler)(FBGraphObject *response, NSError *error); + +/*! + @typedef + + @abstract A list of beta features that can be enabled for the SDK. Beta features are for evaluation only, + and are therefore only enabled for DEBUG builds. Beta features should not be enabled + in release builds. + */ +typedef enum : NSUInteger { + FBBetaFeaturesNone = 0, +#if defined(DEBUG) || defined(FB_BUILD_ONLY) + FBBetaFeaturesShareDialog = 1 << 0, + FBBetaFeaturesOpenGraphShareDialog = 1 << 1, +#endif +} FBBetaFeatures; + +/*! + @typedef + @abstract Indicates if this app should be restricted + */ +typedef NS_ENUM(NSUInteger, FBRestrictedTreatment) { + /*! The default treatment indicating the app is not restricted. */ + FBRestrictedTreatmentNO = 0, + + /*! Indicates the app is restricted. */ + FBRestrictedTreatmentYES = 1 +}; + +@interface FBSettings : NSObject + +/*! + @method + + @abstract Retrieve the current iOS SDK version. + + */ ++ (NSString *)sdkVersion; + +/*! + @method + + @abstract Retrieve the current Facebook SDK logging behavior. + + */ ++ (NSSet *)loggingBehavior; + +/*! + @method + + @abstract Set the current Facebook SDK logging behavior. This should consist of strings defined as + constants with FBLogBehavior*, and can be constructed with, e.g., [NSSet initWithObjects:]. + + @param loggingBehavior A set of strings indicating what information should be logged. If nil is provided, the logging + behavior is reset to the default set of enabled behaviors. Set in an empty set in order to disable all logging. + */ ++ (void)setLoggingBehavior:(NSSet *)loggingBehavior; + +/*! @abstract deprecated method */ ++ (BOOL)shouldAutoPublishInstall __attribute__ ((deprecated)); + +/*! @abstract deprecated method */ ++ (void)setShouldAutoPublishInstall:(BOOL)autoPublishInstall __attribute__ ((deprecated)); + +/*! + @method + + @abstract This method has been replaced by [FBAppEvents activateApp] */ ++ (void)publishInstall:(NSString *)appID __attribute__ ((deprecated("use [FBAppEvents activateApp] instead"))); + +/*! + @method + + @abstract Manually publish an attributed install to the Facebook graph, and return the server response back in + the supplied handler. Calling this method will implicitly turn off auto-publish. This method acquires the + current attribution id from the facebook application, queries the graph API to determine if the application + has install attribution enabled, publishes the id, and records success to avoid reporting more than once. + + @param appID A specific appID to publish an install for. If nil, uses [FBSession defaultAppID]. + @param handler A block to call with the server's response. + */ ++ (void)publishInstall:(NSString *)appID + withHandler:(FBInstallResponseDataHandler)handler __attribute__ ((deprecated)); + + +/*! + @method + + @abstract + Gets the application version to the provided string. `FBAppEvents`, for instance, attaches the app version to + events that it logs, which are then available in App Insights. + */ ++ (NSString *)appVersion; + +/*! + @method + + @abstract + Sets the application version to the provided string. `FBAppEvents`, for instance, attaches the app version to + events that it logs, which are then available in App Insights. + + @param appVersion The version identifier of the iOS app. + */ ++ (void)setAppVersion:(NSString *)appVersion; + +/*! + @method + + @abstract Retrieve the Client Token that has been set via [FBSettings setClientToken] + */ ++ (NSString *)clientToken; + +/*! + @method + + @abstract Sets the Client Token for the Facebook App. This is needed for certain API calls when made anonymously, + without a user-based Session. + + @param clientToken The Facebook App's "client token", which, for a given appid can be found in the Security + section of the Advanced tab of the Facebook App settings found at + + */ ++ (void)setClientToken:(NSString *)clientToken; + +/*! + @method + + @abstract Set the default Facebook Display Name to be used by the SDK. This should match + the Display Name that has been set for the app with the corresponding Facebook App ID, in + the Facebook App Dashboard + + @param displayName The default Facebook Display Name to be used by the SDK. + */ ++ (void)setDefaultDisplayName:(NSString *)displayName; + +/*! + @method + + @abstract Get the default Facebook Display Name used by the SDK. If not explicitly + set, the default will be read from the application's plist. + */ ++ (NSString *)defaultDisplayName; + +/*! + @method + + @abstract Set the default Facebook App ID to use for sessions. The SDK allows the appID + to be overridden per instance in certain cases (e.g. per instance of FBSession) + + @param appID The default Facebook App ID to be used by the SDK. + */ ++ (void)setDefaultAppID:(NSString*)appID; + +/*! + @method + + @abstract Get the default Facebook App ID used by the SDK. If not explicitly + set, the default will be read from the application's plist. The SDK allows the appID + to be overridden per instance in certain cases (e.g. per instance of FBSession) + */ ++ (NSString*)defaultAppID; + +/*! + @method + + @abstract Set the default url scheme suffix used by the SDK. + + @param urlSchemeSuffix The default url scheme suffix to be used by the SDK. + */ ++ (void)setDefaultUrlSchemeSuffix:(NSString*)urlSchemeSuffix; + +/*! + @method + + @abstract Get the default url scheme suffix used for sessions. If not + explicitly set, the default will be read from the application's plist value for 'FacebookUrlSchemeSuffix'. + */ ++ (NSString*)defaultUrlSchemeSuffix; + +/*! + @method + + @abstract Set the bundle name from the SDK will try and load overrides of images and text + + @param bundleName The name of the bundle (MyFBBundle). + */ ++ (void)setResourceBundleName:(NSString*)bundleName; + +/*! + @method + + @abstract Get the name of the bundle to override the SDK images and text + */ ++ (NSString*)resourceBundleName; + +/*! + @method + + @abstract Set the subpart of the facebook domain (e.g. @"beta") so that requests will be sent to graph.beta.facebook.com + + @param facebookDomainPart The domain part to be inserted into facebook.com + */ ++ (void)setFacebookDomainPart:(NSString*)facebookDomainPart; + +/*! + @method + + @abstract Get the Facebook domain part + */ ++ (NSString*)facebookDomainPart; + +/*! + @method + + @abstract Enables the specified beta features. Beta features are for evaluation only, + and are therefore only enabled for debug builds. Beta features should not be enabled + in release builds. + + @param betaFeatures The beta features to enable (expects a bitwise OR of FBBetaFeatures) + */ ++ (void)enableBetaFeatures:(NSUInteger)betaFeatures; + +/*! + @method + + @abstract Enables a beta feature. Beta features are for evaluation only, + and are therefore only enabled for debug builds. Beta features should not be enabled + in release builds. + + @param betaFeature The beta feature to enable. + */ ++ (void)enableBetaFeature:(FBBetaFeatures)betaFeature; + +/*! + @method + + @abstract Disables a beta feature. + + @param betaFeature The beta feature to disable. + */ ++ (void)disableBetaFeature:(FBBetaFeatures)betaFeature; + +/*! + @method + + @abstract Determines whether a beta feature is enabled or not. + + @param betaFeature The beta feature to check. + + @return YES if the beta feature is enabled, NO if not. + */ ++ (BOOL)isBetaFeatureEnabled:(FBBetaFeatures)betaFeature; + +/*! + @method + + @abstract + Gets whether data such as that generated through FBAppEvents and sent to Facebook should be restricted from being used for other than analytics and conversions. Defaults to NO. This value is stored on the device and persists across app launches. + */ ++ (BOOL)limitEventAndDataUsage; + +/*! + @method + + @abstract + Sets whether data such as that generated through FBAppEvents and sent to Facebook should be restricted from being used for other than analytics and conversions. Defaults to NO. This value is stored on the device and persists across app launches. + + @param limitEventAndDataUsage The desired value. + */ ++ (void)setLimitEventAndDataUsage:(BOOL)limitEventAndDataUsage; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBShareDialogParams.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBShareDialogParams.h new file mode 100644 index 0000000..fc2832c --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBShareDialogParams.h @@ -0,0 +1,67 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBDialogsParams.h" + +/*! + @class FBShareDialogParams + + @abstract + This object is used to encapsulate state for parameters to a share dialog that + opens in the Facebook app. + */ +@interface FBShareDialogParams : FBDialogsParams + +/*! @abstract The URL link to be attached to the post. Only "http" or "https" + schemes are supported. */ +@property (nonatomic, copy) NSURL *link; + +/*! @abstract The name, or title associated with the link. Is only used if the + link is non-nil. */ +@property (nonatomic, copy) NSString *name; + +/*! @abstract The caption to be used with the link. Is only used if the link is + non-nil. */ +@property (nonatomic, copy) NSString *caption; + +/*! @abstract The description associated with the link. Is only used if the + link is non-nil. */ +@property (nonatomic, copy) NSString *description; + +/*! @abstract The link to a thumbnail to associate with the post. Is only used + if the link is non-nil. Only "http" or "https" schemes are supported.*/ +@property (nonatomic, copy) NSURL *picture; + +/*! @abstract An array of NSStrings or FBGraphUsers to tag in the post. + If using NSStrings, the values must represent the IDs of the users to tag. */ +@property (nonatomic, copy) NSArray *friends; + +/*! @abstract An NSString or FBGraphPlace to tag in the status update. If + NSString, the value must be the ID of the place to tag. */ +@property (nonatomic, copy) id place; + +/*! @abstract A text reference for the category of the post, used on Facebook + Insights. */ +@property (nonatomic, copy) NSString *ref; + +/*! @abstract If YES, treats any data failures (e.g. failures when getting + data for IDs passed through "friends" or "place") as a fatal error, and will not + continue with the status update. */ +@property (nonatomic, assign) BOOL dataFailuresFatal; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBTestSession.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBTestSession.h new file mode 100644 index 0000000..707dad5 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBTestSession.h @@ -0,0 +1,138 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "FBSession.h" + +#if defined (DEBUG) + #define SAFE_TO_USE_FBTESTSESSION +#endif + +#if !defined(SAFE_TO_USE_FBTESTSESSION) + #pragma message ("warning: using FBTestSession, which is designed for unit-testing uses only, in non-DEBUG code -- ensure this is what you really want") +#endif + +/*! + Consider using this tag to pass to sessionWithSharedUserWithPermissions:uniqueUserTag: when + you need a second unique test user in a test case. Using the same tag each time reduces + the proliferation of test users. + */ +extern NSString *kSecondTestUserTag; +/*! + Consider using this tag to pass to sessionWithSharedUserWithPermissions:uniqueUserTag: when + you need a third unique test user in a test case. Using the same tag each time reduces + the proliferation of test users. + */ +extern NSString *kThirdTestUserTag; + +/*! + @class FBTestSession + + @abstract + Implements an FBSession subclass that knows about test users for a particular + application. This should never be used from a real application, but may be useful + for writing unit tests, etc. + + @discussion + Facebook allows developers to create test accounts for testing their applications' + Facebook integration (see https://developers.facebook.com/docs/test_users/). This class + simplifies use of these accounts for writing unit tests. It is not designed for use in + production application code. + + The main use case for this class is using sessionForUnitTestingWithPermissions:mode: + to create a session for a test user. Two modes are supported. In "shared" mode, an attempt + is made to find an existing test user that has the required permissions and, if it is not + currently in use by another FBTestSession, just use that user. If no such user is available, + a new one is created with the required permissions. In "private" mode, designed for + scenarios which require a new user in a known clean state, a new test user will always be + created, and it will be automatically deleted when the FBTestSession is closed. + + Note that the shared test user functionality depends on a naming convention for the test users. + It is important that any testing of functionality which will mutate the permissions for a + test user NOT use a shared test user, or this scheme will break down. If a shared test user + seems to be in an invalid state, it can be deleted manually via the Web interface at + https://developers.facebook.com/apps/APP_ID/permissions?role=test+users. + */ +@interface FBTestSession : FBSession + +/// The app access token (composed of app ID and secret) to use for accessing test users. +@property (readonly, copy) NSString *appAccessToken; +/// The ID of the test user associated with this session. +@property (readonly, copy) NSString *testUserID; +/// The App ID of the test app as configured in the plist. +@property (readonly, copy) NSString *testAppID; +/// The App Secret of the test app as configured in the plist. +@property (readonly, copy) NSString *testAppSecret; +// Defaults to NO. If set to YES, reauthorize calls will fail with a nil token +// as if the user had cancelled it reauthorize. +@property (assign) BOOL disableReauthorize; + +/*! + @abstract + Constructor helper to create a session for use in unit tests + + @discussion + This method creates a session object which uses a shared test user with the right permissions, + creating one if necessary on open (but not deleting it on close, so it can be re-used in later + tests). Calling this method multiple times may return sessions with the same user. If this is not + desired, use the variant sessionWithSharedUserWithPermissions:uniqueUserTag:. + + This method should not be used in application code -- but is useful for creating unit tests + that use the Facebook SDK. + + @param permissions array of strings naming permissions to authorize; nil indicates + a common default set of permissions should be used for unit testing + */ ++ (id)sessionWithSharedUserWithPermissions:(NSArray*)permissions; + +/*! + @abstract + Constructor helper to create a session for use in unit tests + + @discussion + This method creates a session object which uses a shared test user with the right permissions, + creating one if necessary on open (but not deleting it on close, so it can be re-used in later + tests). + + This method should not be used in application code -- but is useful for creating unit tests + that use the Facebook SDK. + + @param permissions array of strings naming permissions to authorize; nil indicates + a common default set of permissions should be used for unit testing + + @param uniqueUserTag a string which will be used to make this user unique among other + users with the same permissions. Useful for tests which require two or more users to interact + with each other, and which therefore must have sessions associated with different users. For + this case, consider using kSecondTestUserTag and kThirdTestUserTag so these users can be shared + with other, similar, tests. + */ ++ (id)sessionWithSharedUserWithPermissions:(NSArray*)permissions + uniqueUserTag:(NSString*)uniqueUserTag; + +/*! + @abstract + Constructor helper to create a session for use in unit tests + + @discussion + This method creates a session object which creates a test user on open, and destroys the user on + close; This method should not be used in application code -- but is useful for creating unit tests + that use the Facebook SDK. + + @param permissions array of strings naming permissions to authorize; nil indicates + a common default set of permissions should be used for unit testing + */ ++ (id)sessionWithPrivateUserWithPermissions:(NSArray*)permissions; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBUserSettingsViewController.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBUserSettingsViewController.h new file mode 100644 index 0000000..5df08e7 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBUserSettingsViewController.h @@ -0,0 +1,128 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBSession.h" +#import "FBViewController.h" + +/*! + @protocol + + @abstract + The `FBUserSettingsDelegate` protocol defines the methods called by a . + */ +@protocol FBUserSettingsDelegate + +@optional + +/*! + @abstract + Called when the view controller will log the user out in response to a button press. + + @param sender The view controller sending the message. + */ +- (void)loginViewControllerWillLogUserOut:(id)sender; + +/*! + @abstract + Called after the view controller logged the user out in response to a button press. + + @param sender The view controller sending the message. + */ +- (void)loginViewControllerDidLogUserOut:(id)sender; + +/*! + @abstract + Called when the view controller will log the user in in response to a button press. + Note that logging in can fail for a number of reasons, so there is no guarantee that this + will be followed by a call to loginViewControllerDidLogUserIn:. Callers wanting more granular + notification of the session state changes can use KVO or the NSNotificationCenter to observe them. + + @param sender The view controller sending the message. + */ +- (void)loginViewControllerWillAttemptToLogUserIn:(id)sender; + +/*! + @abstract + Called after the view controller successfully logged the user in in response to a button press. + + @param sender The view controller sending the message. + */ +- (void)loginViewControllerDidLogUserIn:(id)sender; + +/*! + @abstract + Called if the view controller encounters an error while trying to log a user in. + + @param sender The view controller sending the message. + @param error The error encountered. + @discussion See https://developers.facebook.com/docs/technical-guides/iossdk/errors/ + for error handling best practices. + */ +- (void)loginViewController:(id)sender receivedError:(NSError *)error; + +@end + + +/*! + @class FBUserSettingsViewController + + @abstract + The `FBUserSettingsViewController` class provides a user interface exposing a user's + Facebook-related settings. Currently, this is limited to whether they are logged in or out + of Facebook. + + Because of the size of some graphics used in this view, its resources are packaged as a separate + bundle. In order to use `FBUserSettingsViewController`, drag the `FBUserSettingsViewResources.bundle` + from the SDK directory into your Xcode project. + */ +@interface FBUserSettingsViewController : FBViewController + +/*! + @abstract + The permissions to request if the user logs in via this view. + */ +@property (nonatomic, copy) NSArray *permissions __attribute__((deprecated)); + +/*! + @abstract + The read permissions to request if the user logs in via this view. + + @discussion + Note, that if read permissions are specified, then publish permissions should not be specified. + */ +@property (nonatomic, copy) NSArray *readPermissions; + +/*! + @abstract + The publish permissions to request if the user logs in via this view. + + @discussion + Note, that a defaultAudience value of FBSessionDefaultAudienceOnlyMe, FBSessionDefaultAudienceEveryone, or + FBSessionDefaultAudienceFriends should be set if publish permissions are specified. Additionally, when publish + permissions are specified, then read should not be specified. + */ +@property (nonatomic, copy) NSArray *publishPermissions; + +/*! + @abstract + The default audience to use, if publish permissions are requested at login time. + */ +@property (nonatomic, assign) FBSessionDefaultAudience defaultAudience; + +@end + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBViewController.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBViewController.h new file mode 100644 index 0000000..3025fd8 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBViewController.h @@ -0,0 +1,118 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@class FBViewController; + +/*! + @typedef FBModalCompletionHandler + + @abstract + A block that is passed to [FBViewController presentModallyInViewController:animated:handler:] + and called when the view controller is dismissed via either Done or Cancel. + + @param sender The that is being dismissed. + + @param donePressed If YES, Done was pressed. If NO, Cancel was pressed. + */ +typedef void (^FBModalCompletionHandler)(FBViewController *sender, BOOL donePressed); + +/*! + @protocol + + @abstract + The `FBViewControllerDelegate` protocol defines the methods called when the Cancel or Done + buttons are pressed in a . + */ +@protocol FBViewControllerDelegate + +@optional + +/*! + @abstract + Called when the Cancel button is pressed on a modally-presented . + + @param sender The view controller sending the message. + */ +- (void)facebookViewControllerCancelWasPressed:(id)sender; + +/*! + @abstract + Called when the Done button is pressed on a modally-presented . + + @param sender The view controller sending the message. + */ +- (void)facebookViewControllerDoneWasPressed:(id)sender; + +@end + + +/*! + @class FBViewController + + @abstract + The `FBViewController` class is a base class encapsulating functionality common to several + other view controller classes. Specifically, it provides UI when a view controller is presented + modally, in the form of optional Cancel and Done buttons. + */ +@interface FBViewController : UIViewController + +/*! + @abstract + The Cancel button to display when presented modally. If nil, no Cancel button is displayed. + If this button is provided, its target and action will be redirected to internal handlers, replacing + any previous target that may have been set. + */ +@property (nonatomic, retain) IBOutlet UIBarButtonItem *cancelButton; + +/*! + @abstract + The Done button to display when presented modally. If nil, no Done button is displayed. + If this button is provided, its target and action will be redirected to internal handlers, replacing + any previous target that may have been set. + */ +@property (nonatomic, retain) IBOutlet UIBarButtonItem *doneButton; + +/*! + @abstract + The delegate that will be called when Cancel or Done is pressed. Derived classes may specify + derived types for their delegates that provide additional functionality. + */ +@property (nonatomic, assign) IBOutlet id delegate; + +/*! + @abstract + The view into which derived classes should put their subviews. This view will be resized correctly + depending on whether or not a toolbar is displayed. + */ +@property (nonatomic, readonly, retain) UIView *canvasView; + +/*! + @abstract + Provides a wrapper that presents the view controller modally and automatically dismisses it + when either the Done or Cancel button is pressed. + + @param viewController The view controller that is presenting this view controller. + @param animated If YES, presenting and dismissing the view controller is animated. + @param handler The block called when the Done or Cancel button is pressed. + */ +- (void)presentModallyFromViewController:(UIViewController*)viewController + animated:(BOOL)animated + handler:(FBModalCompletionHandler)handler; + +@end + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBWebDialogs.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBWebDialogs.h new file mode 100644 index 0000000..8b0429e --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FBWebDialogs.h @@ -0,0 +1,234 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@class FBFrictionlessRecipientCache; +@class FBSession; +@protocol FBWebDialogsDelegate; + +/*! + @typedef FBWebDialogResult enum + + @abstract + Passed to a handler to indicate the result of a dialog being displayed to the user. +*/ +typedef enum { + /*! Indicates that the dialog action completed successfully. Note, that cancel operations represent completed dialog operations. + The url argument may be used to distinguish between success and user-cancelled cases */ + FBWebDialogResultDialogCompleted, + /*! Indicates that the dialog operation was not completed. This occurs in cases such as the closure of the web-view using the X in the upper left corner. */ + FBWebDialogResultDialogNotCompleted +} FBWebDialogResult; + +/*! + @typedef + + @abstract Defines a handler that will be called in response to the web dialog + being dismissed + */ +typedef void (^FBWebDialogHandler)( + FBWebDialogResult result, + NSURL *resultURL, + NSError *error); + +/*! + @class FBWebDialogs + + @abstract + Provides methods to display web based dialogs to the user. +*/ +@interface FBWebDialogs : NSObject + +/*! + @abstract + Presents a Facebook web dialog (https://developers.facebook.com/docs/reference/dialogs/ ) + such as feed or apprequest. + + @param session Represents the session to use for the dialog. May be nil, which uses + the active session if present, or returns NO, if not. + + @param dialog Represents the dialog or method name, such as @"feed" + + @param parameters A dictionary of parameters to be passed to the dialog + + @param handler An optional handler that will be called when the dialog is dismissed. Note, + that if the method returns NO, the handler is not called. May be nil. + */ ++ (void)presentDialogModallyWithSession:(FBSession *)session + dialog:(NSString *)dialog + parameters:(NSDictionary *)parameters + handler:(FBWebDialogHandler)handler; + +/*! + @abstract + Presents a Facebook web dialog (https://developers.facebook.com/docs/reference/dialogs/ ) + such as feed or apprequest. + + @param session Represents the session to use for the dialog. May be nil, which uses + the active session if present, or returns NO, if not. + + @param dialog Represents the dialog or method name, such as @"feed" + + @param parameters A dictionary of parameters to be passed to the dialog + + @param handler An optional handler that will be called when the dialog is dismissed. Note, + that if the method returns NO, the handler is not called. May be nil. + + @param delegate An optional delegate to allow for advanced processing of web based + dialogs. See 'FBWebDialogsDelegate' for more details. + */ ++ (void)presentDialogModallyWithSession:(FBSession *)session + dialog:(NSString *)dialog + parameters:(NSDictionary *)parameters + handler:(FBWebDialogHandler)handler + delegate:(id)delegate; + +/*! + @abstract + Presents a Facebook apprequest dialog. + + @param session Represents the session to use for the dialog. May be nil, which uses + the active session if present. + + @param message The required message for the dialog. + + @param title An optional title for the dialog. + + @param parameters A dictionary of additional parameters to be passed to the dialog. May be nil + + @param handler An optional handler that will be called when the dialog is dismissed. May be nil. + */ ++ (void)presentRequestsDialogModallyWithSession:(FBSession *)session + message:(NSString *)message + title:(NSString *)title + parameters:(NSDictionary *)parameters + handler:(FBWebDialogHandler)handler; + +/*! + @abstract + Presents a Facebook apprequest dialog. + + @param session Represents the session to use for the dialog. May be nil, which uses + the active session if present. + + @param message The required message for the dialog. + + @param title An optional title for the dialog. + + @param parameters A dictionary of additional parameters to be passed to the dialog. May be nil + + @param handler An optional handler that will be called when the dialog is dismissed. May be nil. + + @param friendCache An optional cache object used to enable frictionless sharing for a known set of friends. The + cache instance should be preserved for the life of the session and reused for multiple calls to the present method. + As the users set of friends enabled for frictionless sharing changes, this method auto-updates the cache. + */ ++ (void)presentRequestsDialogModallyWithSession:(FBSession *)session + message:(NSString *)message + title:(NSString *)title + parameters:(NSDictionary *)parameters + handler:(FBWebDialogHandler)handler + friendCache:(FBFrictionlessRecipientCache *)friendCache; + +/*! + @abstract + Presents a Facebook feed dialog. + + @param session Represents the session to use for the dialog. May be nil, which uses + the active session if present. + + @param parameters A dictionary of additional parameters to be passed to the dialog. May be nil + + @param handler An optional handler that will be called when the dialog is dismissed. May be nil. + */ ++ (void)presentFeedDialogModallyWithSession:(FBSession *)session + parameters:(NSDictionary *)parameters + handler:(FBWebDialogHandler)handler; + +@end + +/*! + @protocol + + @abstract + The `FBWebDialogsDelegate` protocol enables the plugging of advanced behaviors into + the presentation flow of a Facebook web dialog. Advanced uses include modification + of parameters and application-level handling of links on the dialog. The + `FBFrictionlessRequestFriendCache` class implements this protocol to add frictionless + behaviors to a presentation of the request dialog. + */ +@protocol FBWebDialogsDelegate + +@optional + +/*! + @abstract + Called prior to the presentation of a web dialog + + @param dialog A string representing the method or dialog name of the dialog being presented. + + @param parameters A mutable dictionary of parameters which will be sent to the dialog. + + @param session The session object to use with the dialog. + */ +- (void)webDialogsWillPresentDialog:(NSString *)dialog + parameters:(NSMutableDictionary *)parameters + session:(FBSession *)session; + +/*! + @abstract + Called when the user of a dialog clicks a link that would cause a transition away from the application. + Your application may handle this method, and return NO if the URL handling will be performed by the application. + + @param dialog A string representing the method or dialog name of the dialog being presented. + + @param parameters A dictionary of parameters which were sent to the dialog. + + @param session The session object to use with the dialog. + + @param url The url in question, which will not be handled by the SDK if this method NO + */ +- (BOOL)webDialogsDialog:(NSString *)dialog + parameters:(NSDictionary *)parameters + session:(FBSession *)session + shouldAutoHandleURL:(NSURL *)url; + +/*! + @abstract + Called when the dialog is about to be dismissed + + @param dialog A string representing the method or dialog name of the dialog being presented. + + @param parameters A dictionary of parameters which were sent to the dialog. + + @param session The session object to use with the dialog. + + @param result A pointer to a result, which may be read or changed by the handling method as needed + + @param url A pointer to a pointer to a URL representing the URL returned by the dialog, which may be read or changed by this mehthod + + @param error A pointer to a pointer to an error object which may be read or changed by this method as needed + */ +- (void)webDialogsWillDismissDialog:(NSString *)dialog + parameters:(NSDictionary *)parameters + session:(FBSession *)session + result:(FBWebDialogResult *)result + url:(NSURL **)url + error:(NSError **)error; + +@end + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/Facebook.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/Facebook.h new file mode 100644 index 0000000..c1b2387 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/Facebook.h @@ -0,0 +1,281 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "FBFrictionlessRequestSettings.h" +#import "FBLoginDialog.h" +#import "FBRequest.h" +#import "FBSessionManualTokenCachingStrategy.h" +#import "FacebookSDK.h" + +//////////////////////////////////////////////////////////////////////////////// +// deprecated API +// +// Summary +// The classes, protocols, etc. in this header are provided for backward +// compatibility and migration; for new code, use FacebookSDK.h, and/or the +// public headers that it imports; for existing code under active development, +// Facebook.h imports FacebookSDK.h, and updates should favor the new interfaces +// whenever possible + +// up-front decl's +@class FBFrictionlessRequestSettings; +@protocol FBRequestDelegate; +@protocol FBSessionDelegate; + +/** + * Main Facebook interface for interacting with the Facebook developer API. + * Provides methods to log in and log out a user, make requests using the REST + * and Graph APIs, and start user interface interactions (such as + * pop-ups promoting for credentials, permissions, stream posts, etc.) + */ +@interface Facebook : NSObject{ + id _sessionDelegate; + NSMutableSet* _requests; + FBSession* _session; + FBSessionManualTokenCachingStrategy *_tokenCaching; + FBDialog* _fbDialog; + NSString* _appId; + NSString* _urlSchemeSuffix; + BOOL _isExtendingAccessToken; + FBRequest *_requestExtendingAccessToken; + NSDate* _lastAccessTokenUpdate; + FBFrictionlessRequestSettings* _frictionlessRequestSettings; +} + +@property (nonatomic, copy) NSString* accessToken; +@property (nonatomic, copy) NSDate* expirationDate; +@property (nonatomic, assign) id sessionDelegate; +@property (nonatomic, copy) NSString* urlSchemeSuffix; +@property (nonatomic, readonly) BOOL isFrictionlessRequestsEnabled; +@property (nonatomic, readonly, retain) FBSession *session; + +- (id)initWithAppId:(NSString *)appId + andDelegate:(id)delegate; + +- (id)initWithAppId:(NSString *)appId + urlSchemeSuffix:(NSString *)urlSchemeSuffix + andDelegate:(id)delegate; + +- (void)authorize:(NSArray *)permissions; + +- (void)extendAccessToken; + +- (void)extendAccessTokenIfNeeded; + +- (BOOL)shouldExtendAccessToken; + +- (BOOL)handleOpenURL:(NSURL *)url; + +- (void)logout; + +- (void)logout:(id)delegate; + +- (FBRequest*)requestWithParams:(NSMutableDictionary *)params + andDelegate:(id )delegate; + +- (FBRequest*)requestWithMethodName:(NSString *)methodName + andParams:(NSMutableDictionary *)params + andHttpMethod:(NSString *)httpMethod + andDelegate:(id )delegate; + +- (FBRequest*)requestWithGraphPath:(NSString *)graphPath + andDelegate:(id )delegate; + +- (FBRequest*)requestWithGraphPath:(NSString *)graphPath + andParams:(NSMutableDictionary *)params + andDelegate:(id )delegate; + +- (FBRequest*)requestWithGraphPath:(NSString *)graphPath + andParams:(NSMutableDictionary *)params + andHttpMethod:(NSString *)httpMethod + andDelegate:(id )delegate; + +- (void)dialog:(NSString *)action + andDelegate:(id)delegate; + +- (void)dialog:(NSString *)action + andParams:(NSMutableDictionary *)params + andDelegate:(id )delegate; + +- (BOOL)isSessionValid; + +- (void)enableFrictionlessRequests; + +- (void)reloadFrictionlessRecipientCache; + +- (BOOL)isFrictionlessEnabledForRecipient:(id)fbid; + +- (BOOL)isFrictionlessEnabledForRecipients:(NSArray*)fbids; + +@end + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Your application should implement this delegate to receive session callbacks. + */ +@protocol FBSessionDelegate + +/** + * Called when the user successfully logged in. + */ +- (void)fbDidLogin; + +/** + * Called when the user dismissed the dialog without logging in. + */ +- (void)fbDidNotLogin:(BOOL)cancelled; + +/** + * Called after the access token was extended. If your application has any + * references to the previous access token (for example, if your application + * stores the previous access token in persistent storage), your application + * should overwrite the old access token with the new one in this method. + * See extendAccessToken for more details. + */ +- (void)fbDidExtendToken:(NSString*)accessToken + expiresAt:(NSDate*)expiresAt; + +/** + * Called when the user logged out. + */ +- (void)fbDidLogout; + +/** + * Called when the current session has expired. This might happen when: + * - the access token expired + * - the app has been disabled + * - the user revoked the app's permissions + * - the user changed his or her password + */ +- (void)fbSessionInvalidated; + +@end + +@protocol FBRequestDelegate; + +enum { + kFBRequestStateReady, + kFBRequestStateLoading, + kFBRequestStateComplete, + kFBRequestStateError +}; + +// FBRequest(Deprecated) +// +// Summary +// The deprecated category is used to maintain back compat and ease migration +// to the revised SDK for iOS + +/** + * Do not use this interface directly, instead, use method in Facebook.h + */ +@interface FBRequest(Deprecated) + +@property (nonatomic, assign) id delegate; + +/** + * The URL which will be contacted to execute the request. + */ +@property (nonatomic, copy) NSString* url; + +/** + * The API method which will be called. + */ +@property (nonatomic, copy) NSString* httpMethod; + +/** + * The dictionary of parameters to pass to the method. + * + * These values in the dictionary will be converted to strings using the + * standard Objective-C object-to-string conversion facilities. + */ +@property (nonatomic, retain) NSMutableDictionary* params; +@property (nonatomic, retain) NSURLConnection* connection; +@property (nonatomic, retain) NSMutableData* responseText; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +@property (nonatomic) FBRequestState state; +#pragma GCC diagnostic pop +@property (nonatomic) BOOL sessionDidExpire; + +/** + * Error returned by the server in case of request's failure (or nil otherwise). + */ +@property (nonatomic, retain) NSError* error; + +- (BOOL) loading; + ++ (NSString *)serializeURL:(NSString *)baseUrl + params:(NSDictionary *)params; + ++ (NSString*)serializeURL:(NSString *)baseUrl + params:(NSDictionary *)params + httpMethod:(NSString *)httpMethod; + +@end + +//////////////////////////////////////////////////////////////////////////////// + +/* + *Your application should implement this delegate + */ +@protocol FBRequestDelegate + +@optional + +/** + * Called just before the request is sent to the server. + */ +- (void)requestLoading:(FBRequest *)request; + +/** + * Called when the Facebook API request has returned a response. + * + * This callback gives you access to the raw response. It's called before + * (void)request:(FBRequest *)request didLoad:(id)result, + * which is passed the parsed response object. + */ +- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response; + +/** + * Called when an error prevents the request from completing successfully. + */ +- (void)request:(FBRequest *)request didFailWithError:(NSError *)error; + +/** + * Called when a request returns and its response has been parsed into + * an object. + * + * The resulting object may be a dictionary, an array or a string, depending + * on the format of the API response. If you need access to the raw response, + * use: + * + * (void)request:(FBRequest *)request + * didReceiveResponse:(NSURLResponse *)response + */ +- (void)request:(FBRequest *)request didLoad:(id)result; + +/** + * Called when a request returns a response. + * + * The result object is the raw response from the server of type NSData + */ +- (void)request:(FBRequest *)request didLoadRawResponse:(NSData *)data; + +@end + + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FacebookSDK.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FacebookSDK.h new file mode 100644 index 0000000..40147ef --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/FacebookSDK.h @@ -0,0 +1,139 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// core +#import "FBAccessTokenData.h" +#import "FBAppCall.h" +#import "FBAppEvents.h" +#import "FBCacheDescriptor.h" +#import "FBDialogs.h" +#import "FBError.h" +#import "FBErrorUtility.h" +#import "FBFrictionlessRecipientCache.h" +#import "FBFriendPickerViewController.h" +#import "FBGraphLocation.h" +#import "FBGraphObject.h" // + design summary for graph component-group +#import "FBGraphPlace.h" +#import "FBGraphUser.h" +#import "FBInsights.h" +#import "FBLoginView.h" +#import "FBNativeDialogs.h" // deprecated, use FBDialogs.h +#import "FBOpenGraphAction.h" +#import "FBOpenGraphActionShareDialogParams.h" +#import "FBOpenGraphObject.h" +#import "FBPlacePickerViewController.h" +#import "FBProfilePictureView.h" +#import "FBRequest.h" +#import "FBSession.h" +#import "FBSessionTokenCachingStrategy.h" +#import "FBSettings.h" +#import "FBShareDialogParams.h" +#import "FBUserSettingsViewController.h" +#import "FBWebDialogs.h" +#import "NSError+FBError.h" + +/*! + @header + + @abstract Library header, import this to import all of the public types + in the Facebook SDK + + @discussion + +//////////////////////////////////////////////////////////////////////////////// + + + Summary: this header summarizes the structure and goals of the Facebook SDK for iOS. + Goals: + * Leverage and work well with modern features of iOS (e.g. blocks, ARC, etc.) + * Patterned after best of breed iOS frameworks (e.g. naming, pattern-use, etc.) + * Common integration experience is simple & easy to describe + * Factored to enable a growing list of scenarios over time + + Notes on approaches: + 1. We use a key scenario to drive prioritization of work for a given update + 2. We are building-atop and refactoring, rather than replacing, existing iOS SDK releases + 3. We use take an incremental approach where we can choose to maintain as little or as much compatibility with the existing SDK needed + a) and so we will be developing to this approach + b) and then at push-time for a release we will decide when/what to break + on a feature by feature basis + 4. Some light but critical infrastructure is needed to support both the goals + and the execution of this change (e.g. a build/package/deploy process) + + Design points: + We will move to a more object-oriented approach, in order to facilitate the + addition of a different class of objects, such as controls and visual helpers + (e.g. FBLikeView, FBPersonView), as well as sub-frameworks to enable scenarios + such (e.g. FBOpenGraphEntity, FBLocalEntityCache, etc.) + + As we add features, it will no longer be appropriate to host all functionality + in the Facebook class, though it will be maintained for some time for migration + purposes. Instead functionality lives in related collections of classes. + +
+ @textblock
+
+               *------------* *----------*  *----------------* *---*
+  Scenario --> |FBPersonView| |FBLikeView|  | FBPlacePicker  | | F |
+               *------------* *----------*  *----------------* | a |
+               *-------------------*  *----------*  *--------* | c |
+ Component --> |   FBGraphObject   |  | FBDialog |  | FBView | | e |
+               *-------------------*  *----------*  *--------* | b |
+               *---------* *---------* *---------------------* | o |
+      Core --> |FBSession| |FBRequest| |Utilities (e.g. JSON)| | o |
+               *---------* *---------* *---------------------* * k *
+
+ @/textblock
+ 
+ + The figure above describes three layers of functionality, with the existing + Facebook on the side as a helper proxy to a subset of the overall SDK. The + layers loosely organize the SDK into *Core Objects* necessary to interface + with Facebook, higher-level *Framework Components* that feel like natural + extensions to existing frameworks such as UIKit and Foundation, but which + surface behavior broadly applicable to Facebook, and finally the + *Scenario Objects*, which provide deeper turn-key capibilities for useful + mobile scenarios. + + Use example (low barrier use case): + +
+ @textblock
+
+// log on to Facebook
+[FBSession sessionOpenWithPermissions:nil
+                    completionHandler:^(FBSession *session,
+                                        FBSessionState status,
+                                        NSError *error) {
+                        if (session.isOpen) {
+                            // request basic information for the user
+                            [FBRequestConnection startWithGraphPath:@"me"
+                                                  completionHandler:^void(FBRequestConnection *request,
+                                                                          id result,
+                                                                          NSError *error) {
+                                                      if (!error) {
+                                                          // get json from result
+                                                      }
+                                                  }];
+                        }
+                    }];
+ @/textblock
+ 
+ + */ + +#define FB_IOS_SDK_VERSION_STRING @"3.11.1" + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/NSError+FBError.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/NSError+FBError.h new file mode 100644 index 0000000..61659a5 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/DeprecatedHeaders/NSError+FBError.h @@ -0,0 +1,59 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "FBError.h" + +/*! + @category NSError(FBError) + + @abstract + Adds additional properties to NSError to provide more information for Facebook related errors. + */ +@interface NSError (FBError) + +/*! + @abstract + Categorizes the error, if it is Facebook related, to simplify application mitigation behavior + + @discussion + In general, in response to an error connecting to Facebook, an application should, retry the + operation, request permissions, reconnect the application, or prompt the user to take an action. + The error category can be used to understand the class of error received from Facebook. For more infomation on this + see https://developers.facebook.com/docs/reference/api/errors/ + */ +@property (readonly) FBErrorCategory fberrorCategory; + +/*! + @abstract + If YES indicates that a user action is required in order to successfully continue with the facebook operation + + @discussion + In general if fberrorShouldNotifyUser is NO, then the application has a straightforward mitigation, such as + retry the operation or request permissions from the user, etc. In some cases it is necessary for the user to + take an action before the application continues to attempt a Facebook connection. For more infomation on this + see https://developers.facebook.com/docs/reference/api/errors/ + */ +@property (readonly) BOOL fberrorShouldNotifyUser; + +/*! + @abstract + A message suitable for display to the user, describing a user action necessary to enable Facebook functionality. + Not all Facebook errors yield a message suitable for user display; however in all cases where + fberrorShouldNotifyUser is YES, this property returns a localizable message suitable for display. + */ +@property (readonly, copy) NSString *fberrorUserMessage; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/FacebookSDK b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/FacebookSDK new file mode 100644 index 0000000..a0a22e3 Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/FacebookSDK differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAccessTokenData.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAccessTokenData.h new file mode 100644 index 0000000..f28039b --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAccessTokenData.h @@ -0,0 +1,140 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBSession.h" + +/*! + @class FBAccessTokenData + + @abstract Represents an access token used for the Facebook login flow + and includes associated metadata such as expiration date and permissions. + You should use factory methods (createToken...) to construct instances + and should be treated as immutable. + + @discussion For more information, see + https://developers.facebook.com/docs/concepts/login/access-tokens-and-types/. +*/ +@interface FBAccessTokenData : NSObject + +/*! + @method + + @abstract Creates an FBAccessTokenData from an App Link provided by the Facebook application + or nil if the url is not valid. + + @param url The url provided. + @param appID needed in order to verify URL format. + @param urlSchemeSuffix needed in order to verify URL format. + +*/ ++ (FBAccessTokenData *) createTokenFromFacebookURL:(NSURL *)url appID:(NSString *)appID urlSchemeSuffix:(NSString *)urlSchemeSuffix; + +/*! + @method + + @abstract Creates an FBAccessTokenData from a dictionary or returns nil if required data is missing. + @param dictionary the dictionary with FBSessionTokenCachingStrategy keys. + */ ++ (FBAccessTokenData *) createTokenFromDictionary:(NSDictionary *)dictionary; + +/*! + @method + + @abstract Creates an FBAccessTokenData from existing information or returns nil if required data is missing. + + @param accessToken The token string. If nil or empty, this method will return nil. + @param permissions The permissions set. A value of nil indicates basic permissions. + @param expirationDate The expiration date. A value of nil defaults to `[NSDate distantFuture]`. + @param loginType The login source of the token. + @param refreshDate The date that token was last refreshed. A value of nil defaults to `[NSDate date]`. + */ ++ (FBAccessTokenData *) createTokenFromString:(NSString *)accessToken + permissions:(NSArray *)permissions + expirationDate:(NSDate *)expirationDate + loginType:(FBSessionLoginType)loginType + refreshDate:(NSDate *)refreshDate; + +/*! + @method + + @abstract Creates an FBAccessTokenData from existing information or returns nil if required data is missing. + + @param accessToken The token string. If nil or empty, this method will return nil. + @param permissions The permissions set. A value of nil indicates basic permissions. + @param expirationDate The expiration date. A value of nil defaults to `[NSDate distantFuture]`. + @param loginType The login source of the token. + @param refreshDate The date that token was last refreshed. A value of nil defaults to `[NSDate date]`. + @param permissionsRefreshDate The date the permissions were last refreshed. A value of nil defaults to `[NSDate distantPast]`. + */ ++ (FBAccessTokenData *) createTokenFromString:(NSString *)accessToken + permissions:(NSArray *)permissions + expirationDate:(NSDate *)expirationDate + loginType:(FBSessionLoginType)loginType + refreshDate:(NSDate *)refreshDate + permissionsRefreshDate:(NSDate *)permissionsRefreshDate; + +/*! + @method + + @abstract Returns a dictionary representation of this instance. + + @discussion This is provided for backwards compatibility with previous + access token related APIs that used a NSDictionary (see `FBSessionTokenCachingStrategy`). +*/ +- (NSMutableDictionary *) dictionary; + +/*! + @method + + @abstract Returns a Boolean value that indicates whether a given object is an FBAccessTokenData object and exactly equal the receiver. + + @param accessTokenData the data to compare to the receiver. +*/ +- (BOOL) isEqualToAccessTokenData:(FBAccessTokenData *)accessTokenData; + +/*! + @abstract returns the access token NSString. +*/ +@property (readonly, nonatomic, copy) NSString *accessToken; + +/*! + @abstract returns the permissions associated with the access token. +*/ +@property (readonly, nonatomic, copy) NSArray *permissions; + +/*! + @abstract returns the expiration date of the access token. +*/ +@property (readonly, nonatomic, copy) NSDate *expirationDate; + +/*! + @abstract returns the login type associated with the token. +*/ +@property (readonly, nonatomic) FBSessionLoginType loginType; + +/*! + @abstract returns the date the token was last refreshed. +*/ +@property (readonly, nonatomic, copy) NSDate *refreshDate; + +/*! + @abstract returns the date the permissions were last refreshed. +*/ +@property (readonly, nonatomic, copy) NSDate *permissionsRefreshDate; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAppCall.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAppCall.h new file mode 100644 index 0000000..9756925 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAppCall.h @@ -0,0 +1,232 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBAccessTokenData.h" +#import "FBAppLinkData.h" +#import "FBDialogsData.h" +#import "FBSession.h" + +@class FBAppCall; + +/*! + @typedef FBAppCallHandler + + @abstract + A block that is passed to performAppCall to register for a callback with the results + of that AppCall + + @discussion + Pass a block of this type when calling performAppCall. This will be called on the UI + thread, once the AppCall completes. + + @param call The `FBAppCall` that was completed. + + */ +typedef void (^FBAppCallHandler)(FBAppCall *call); + +/*! + @typedef FBAppLinkFallbackHandler + + @abstract + See `+openDeferredAppLink`. + */ +typedef void (^FBAppLinkFallbackHandler)(NSError *error); + +/*! + @class FBAppCall + + @abstract + The FBAppCall object is used to encapsulate state when the app performs an + action that requires switching over to the native Facebook app, or when the app + receives an App Link. + + @discussion + - Each FBAppCall instance will have a unique ID + - This object is passed into an FBAppCallHandler for context + - dialogData will be present if this AppCall is for a Native Dialog + - appLinkData will be present if this AppCall is for an App Link + - accessTokenData will be present if this AppCall contains an access token. + */ +@interface FBAppCall : NSObject + +/*! @abstract The ID of this FBAppCall instance */ +@property (nonatomic, readonly) NSString *ID; + +/*! @abstract Error that occurred in processing this AppCall */ +@property (nonatomic, readonly) NSError *error; + +/*! @abstract Data related to a Dialog AppCall */ +@property (nonatomic, readonly) FBDialogsData *dialogData; + +/*! @abstract Data for native app link */ +@property (nonatomic, readonly) FBAppLinkData *appLinkData; + +/*! @abstract Access Token that was returned in this AppCall */ +@property (nonatomic, readonly) FBAccessTokenData *accessTokenData; + +/*! + @abstract + Returns an FBAppCall instance from a url, if applicable. Otherwise, returns nil. + + @param url The url. + + @return an FBAppCall instance if the url is valid; nil otherwise. + + @discussion This is typically used for App Link URLs. + */ ++ (FBAppCall *) appCallFromURL:(NSURL *)url; + +/*! + @abstract + Compares the receiving FBAppCall to the passed in FBAppCall + + @param appCall the other FBAppCall to compare to. + + @return YES if the AppCalls can be considered to be the same; NO if otherwise. + */ +- (BOOL)isEqualToAppCall:(FBAppCall *)appCall; + +/*! + @abstract + Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method + of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction + with the native Facebook app or as part of SSO authorization flow. + + @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @return YES if the url was intended for the Facebook SDK, NO if not. + */ ++ (BOOL)handleOpenURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication; + +/*! + @abstract + Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method + of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction + with the native Facebook app or as part of SSO authorization flow. + + @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param handler Optional handler that gives the app the opportunity to do some further processing on urls + that the SDK could not completely process. A fallback handler is not a requirement for such a url to be considered + handled. The fallback handler, if specified, is only ever called sychronously, before the method returns. + + @return YES if the url was intended for the Facebook SDK, NO if not. + */ ++ (BOOL)handleOpenURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication + fallbackHandler:(FBAppCallHandler)handler; + +/*! + @abstract + Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method + of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction + with the native Facebook app or as part of SSO authorization flow. + + @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param session If this url is being sent back to this app as part of SSO authorization flow, then pass in the + session that was being opened. A nil value defaults to FBSession.activeSession + + @return YES if the url was intended for the Facebook SDK, NO if not. + */ ++ (BOOL)handleOpenURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication + withSession:(FBSession *)session; + +/*! + @abstract + Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method + of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction + with the native Facebook app or as part of SSO authorization flow. + + @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + + @param session If this url is being sent back to this app as part of SSO authorization flow, then pass in the + session that was being opened. A nil value defaults to FBSession.activeSession + + @param handler Optional handler that gives the app the opportunity to do some further processing on urls + that the SDK could not completely process. A fallback handler is not a requirement for such a url to be considered + handled. The fallback handler, if specified, is only ever called sychronously, before the method returns. + + @return YES if the url was intended for the Facebook SDK, NO if not. + */ ++ (BOOL)handleOpenURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication + withSession:(FBSession *)session + fallbackHandler:(FBAppCallHandler)handler; + +/*! + @abstract + Call this method when the application's applicationDidBecomeActive: is invoked. + This ensures proper state management of any pending FBAppCalls or pending login flow for the + FBSession.activeSession. If any pending FBAppCalls are found, their registered callbacks + will be invoked with appropriate state + */ ++ (void)handleDidBecomeActive; + +/*! + @abstract + Call this method when the application's applicationDidBecomeActive: is invoked. + This ensures proper state management of any pending FBAppCalls or a pending open for the + passed in FBSession. If any pending FBAppCalls are found, their registered callbacks will + be invoked with appropriate state + + @param session Session that is currently being used. Any pending calls to open will be cancelled. + If no session is provided, then the activeSession (if present) is used. + */ ++ (void)handleDidBecomeActiveWithSession:(FBSession *)session; + +/*! + @abstract + Call this method from the main thread to fetch deferred applink data. This may require + a network round trip. If successful, [+UIApplication openURL:] is invoked with the link + data. Otherwise, the fallbackHandler will be dispatched to the main thread. + + @param fallbackHandler the handler to be invoked if applink data could not be opened. + + @discussion the fallbackHandler may contain an NSError instance to capture any errors. In the + common case where there simply was no app link data, the NSError instance will be nil. + + This method should only be called from a location that occurs after any launching URL has + been processed (e.g., you should call this method from your application delegate's applicationDidBecomeActive:) + to avoid duplicate invocations of openURL:. + + If you must call this from the delegate's didFinishLaunchingWithOptions: you should + only do so if the application is not being launched by a URL. For example, + + if (launchOptions[UIApplicationLaunchOptionsURLKey] == nil) { + [FBAppCall openDeferredAppLink:^(NSError *error) { + // .... + } + } +*/ ++ (void)openDeferredAppLink:(FBAppLinkFallbackHandler)fallbackHandler; + +@end + + + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAppEvents.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAppEvents.h new file mode 100644 index 0000000..d9415d2 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAppEvents.h @@ -0,0 +1,451 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBSession.h" + +/*! + + @typedef FBAppEventsFlushBehavior enum + + @abstract + Control when sends log events to the server + + @discussion + + */ +typedef enum { + + /*! Flush automatically: periodically (once a minute or every 100 logged events) and always at app reactivation. */ + FBAppEventsFlushBehaviorAuto, + + /*! Only flush when the `flush` method is called. When an app is moved to background/terminated, the + events are persisted and re-established at activation, but they will only be written with an + explicit call to `flush`. */ + FBAppEventsFlushBehaviorExplicitOnly, + +} FBAppEventsFlushBehavior; + +/* + * Constant used by NSNotificationCenter for results of flushing AppEvents event logs + */ + +/*! NSNotificationCenter name indicating a result of a failed log flush attempt */ +extern NSString *const FBAppEventsLoggingResultNotification; + + +// Predefined event names for logging events common to many apps. Logging occurs through the `logEvent` family of methods on `FBAppEvents`. +// Common event parameters are provided in the `FBAppEventsParameterNames*` constants. + +// General purpose + +/*! Log this event when an app is being activated, typically in the AppDelegate's applicationDidBecomeActive. */ +extern NSString *const FBAppEventNameActivatedApp; + +/*! Log this event when a user has completed registration with the app. */ +extern NSString *const FBAppEventNameCompletedRegistration; + +/*! Log this event when a user has viewed a form of content in the app. */ +extern NSString *const FBAppEventNameViewedContent; + +/*! Log this event when a user has performed a search within the app. */ +extern NSString *const FBAppEventNameSearched; + +/*! Log this event when the user has rated an item in the app. The valueToSum passed to logEvent should be the numeric rating. */ +extern NSString *const FBAppEventNameRated; + +/*! Log this event when the user has completed a tutorial in the app. */ +extern NSString *const FBAppEventNameCompletedTutorial; + +// Ecommerce related + +/*! Log this event when the user has added an item to their cart. The valueToSum passed to logEvent should be the item's price. */ +extern NSString *const FBAppEventNameAddedToCart; + +/*! Log this event when the user has added an item to their wishlist. The valueToSum passed to logEvent should be the item's price. */ +extern NSString *const FBAppEventNameAddedToWishlist; + +/*! Log this event when the user has entered the checkout process. The valueToSum passed to logEvent should be the total price in the cart. */ +extern NSString *const FBAppEventNameInitiatedCheckout; + +/*! Log this event when the user has entered their payment info. */ +extern NSString *const FBAppEventNameAddedPaymentInfo; + +/*! Log this event when the user has completed a purchase. The `[FBAppEvents logPurchase]` method is a shortcut for logging this event. */ +extern NSString *const FBAppEventNamePurchased; + +// Gaming related + +/*! Log this event when the user has achieved a level in the app. */ +extern NSString *const FBAppEventNameAchievedLevel; + +/*! Log this event when the user has unlocked an achievement in the app. */ +extern NSString *const FBAppEventNameUnlockedAchievement; + +/*! Log this event when the user has spent app credits. The valueToSum passed to logEvent should be the number of credits spent. */ +extern NSString *const FBAppEventNameSpentCredits; + + + +// Predefined event name parameters for common additional information to accompany events logged through the `logEvent` family +// of methods on `FBAppEvents`. Common event names are provided in the `FBAppEventName*` constants. + +/*! Parameter key used to specify currency used with logged event. E.g. "USD", "EUR", "GBP". See ISO-4217 for specific values. One reference for these is . */ +extern NSString *const FBAppEventParameterNameCurrency; + +/*! Parameter key used to specify method user has used to register for the app, e.g., "Facebook", "email", "Twitter", etc */ +extern NSString *const FBAppEventParameterNameRegistrationMethod; + +/*! Parameter key used to specify a generic content type/family for the logged event, e.g. "music", "photo", "video". Options to use will vary based upon what the app is all about. */ +extern NSString *const FBAppEventParameterNameContentType; + +/*! Parameter key used to specify an ID for the specific piece of content being logged about. Could be an EAN, article identifier, etc., depending on the nature of the app. */ +extern NSString *const FBAppEventParameterNameContentID; + +/*! Parameter key used to specify the string provided by the user for a search operation. */ +extern NSString *const FBAppEventParameterNameSearchString; + +/*! Parameter key used to specify whether the activity being logged about was successful or not. `FBAppEventParameterValueYes` and `FBAppEventParameterValueNo` are good canonical values to use for this parameter. */ +extern NSString *const FBAppEventParameterNameSuccess; + +/*! Parameter key used to specify the maximum rating available for the `FBAppEventNameRate` event. E.g., "5" or "10". */ +extern NSString *const FBAppEventParameterNameMaxRatingValue; + +/*! Parameter key used to specify whether payment info is available for the `FBAppEventNameInitiatedCheckout` event. `FBAppEventParameterValueYes` and `FBAppEventParameterValueNo` are good canonical values to use for this parameter. */ +extern NSString *const FBAppEventParameterNamePaymentInfoAvailable; + +/*! Parameter key used to specify how many items are being processed for an `FBAppEventNameInitiatedCheckout` or `FBAppEventNamePurchased` event. */ +extern NSString *const FBAppEventParameterNameNumItems; + +/*! Parameter key used to specify the level achieved in a `FBAppEventNameAchieved` event. */ +extern NSString *const FBAppEventParameterNameLevel; + +/*! Parameter key used to specify a description appropriate to the event being logged. E.g., the name of the achievement unlocked in the `FBAppEventNameAchievementUnlocked` event. */ +extern NSString *const FBAppEventParameterNameDescription; + + + +// Predefined values to assign to event parameters that accompany events logged through the `logEvent` family +// of methods on `FBAppEvents`. Common event parameters are provided in the `FBAppEventParameterName*` constants. + +/*! Yes-valued parameter value to be used with parameter keys that need a Yes/No value */ +extern NSString *const FBAppEventParameterValueYes; + +/*! No-valued parameter value to be used with parameter keys that need a Yes/No value */ +extern NSString *const FBAppEventParameterValueNo; + + +/*! + + @class FBAppEvents + + @abstract + Client-side event logging for specialized application analytics available through Facebook App Insights + and for use with Facebook Ads conversion tracking and optimization. + + @discussion + The `FBAppEvents` static class has a few related roles: + + + Logging predefined and application-defined events to Facebook App Insights with a + numeric value to sum across a large number of events, and an optional set of key/value + parameters that define "segments" for this event (e.g., 'purchaserStatus' : 'frequent', or + 'gamerLevel' : 'intermediate') + + + Logging events to later be used for ads optimization around lifetime value. + + + Methods that control the way in which events are flushed out to the Facebook servers. + + Here are some important characteristics of the logging mechanism provided by `FBAppEvents`: + + + Events are not sent immediately when logged. They're cached and flushed out to the Facebook servers + in a number of situations: + - when an event count threshold is passed (currently 100 logged events). + - when a time threshold is passed (currently 60 seconds). + - when an app has gone to background and is then brought back to the foreground. + + + Events will be accumulated when the app is in a disconnected state, and sent when the connection is + restored and one of the above 'flush' conditions are met. + + + The `FBAppEvents` class in thread-safe in that events may be logged from any of the app's threads. + + + The developer can set the `flushBehavior` on `FBAppEvents` to force the flushing of events to only + occur on an explicit call to the `flush` method. + + + The developer can turn on console debug output for event logging and flushing to the server by using + the `FBLoggingBehaviorAppEvents` value in `[FBSettings setLoggingBehavior:]`. + + Some things to note when logging events: + + + There is a limit on the number of unique event names an app can use, on the order of 300. + + There is a limit to the number of unique parameter names in the provided parameters that can + be used per event, on the order of 10. This is not just for an individual call, but for all + invocations for that eventName. + + Event names and parameter names (the keys in the NSDictionary) must be between 2 and 40 characters, and + must consist of alphanumeric characters, _, -, or spaces. + + The length of each parameter value can be no more than on the order of 100 characters. + + */ +@interface FBAppEvents : NSObject + +/* + * Basic event logging + */ + +/*! + + @method + + @abstract + Log an event with just an eventName. + + @param eventName The name of the event to record. Limitations on number of events and name length + are given in the `FBAppEvents` documentation. + + */ ++ (void)logEvent:(NSString *)eventName; + +/*! + + @method + + @abstract + Log an event with an eventName and a numeric value to be aggregated with other events of this name. + + @param eventName The name of the event to record. Limitations on number of events and name length + are given in the `FBAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants. + + @param valueToSum Amount to be aggregated into all events of this eventName, and App Insights will report + the cumulative and average value of this amount. + */ ++ (void)logEvent:(NSString *)eventName + valueToSum:(double)valueToSum; + + +/*! + + @method + + @abstract + Log an event with an eventName and a set of key/value pairs in the parameters dictionary. + Parameter limitations are described above. + + @param eventName The name of the event to record. Limitations on number of events and name construction + are given in the `FBAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants. + + @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must + be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of + parameters and name construction are given in the `FBAppEvents` documentation. Commonly used parameter names + are provided in `FBAppEventParameterName*` constants. + */ ++ (void)logEvent:(NSString *)eventName + parameters:(NSDictionary *)parameters; + +/*! + + @method + + @abstract + Log an event with an eventName, a numeric value to be aggregated with other events of this name, + and a set of key/value pairs in the parameters dictionary. + + @param eventName The name of the event to record. Limitations on number of events and name construction + are given in the `FBAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants. + + @param valueToSum Amount to be aggregated into all events of this eventName, and App Insights will report + the cumulative and average value of this amount. + + @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must + be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of + parameters and name construction are given in the `FBAppEvents` documentation. Commonly used parameter names + are provided in `FBAppEventParameterName*` constants. + + */ ++ (void)logEvent:(NSString *)eventName + valueToSum:(double)valueToSum + parameters:(NSDictionary *)parameters; + + +/*! + + @method + + @abstract + Log an event with an eventName, a numeric value to be aggregated with other events of this name, + and a set of key/value pairs in the parameters dictionary. Providing session lets the developer + target a particular . If nil is provided, then `[FBSession activeSession]` will be used. + + @param eventName The name of the event to record. Limitations on number of events and name construction + are given in the `FBAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants. + + @param valueToSum Amount to be aggregated into all events of this eventName, and App Insights will report + the cumulative and average value of this amount. Note that this is an NSNumber, and a value of `nil` denotes + that this event doesn't have a value associated with it for summation. + + @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must + be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of + parameters and name construction are given in the `FBAppEvents` documentation. Commonly used parameter names + are provided in `FBAppEventParameterName*` constants. + + @param session to direct the event logging to, and thus be logged with whatever user (if any) + is associated with that . + */ ++ (void)logEvent:(NSString *)eventName + valueToSum:(NSNumber *)valueToSum + parameters:(NSDictionary *)parameters + session:(FBSession *)session; + + +/* + * Purchase logging + */ + +/*! + + @method + + @abstract + Log a purchase of the specified amount, in the specified currency. + + @param purchaseAmount Purchase amount to be logged, as expressed in the specified currency. This value + will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). + + @param currency Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for + specific values. One reference for these is . + + @discussion This event immediately triggers a flush of the `FBAppEvents` event queue, unless the `flushBehavior` is set + to `FBAppEventsFlushBehaviorExplicitOnly`. + + */ ++ (void)logPurchase:(double)purchaseAmount + currency:(NSString *)currency; + +/*! + + @method + + @abstract + Log a purchase of the specified amount, in the specified currency, also providing a set of + additional characteristics describing the purchase. + + @param purchaseAmount Purchase amount to be logged, as expressed in the specified currency.This value + will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). + + @param currency Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for + specific values. One reference for these is . + + @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must + be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of + parameters and name construction are given in the `FBAppEvents` documentation. Commonly used parameter names + are provided in `FBAppEventParameterName*` constants. + + @discussion This event immediately triggers a flush of the `FBAppEvents` event queue, unless the `flushBehavior` is set + to `FBAppEventsFlushBehaviorExplicitOnly`. + + */ ++ (void)logPurchase:(double)purchaseAmount + currency:(NSString *)currency + parameters:(NSDictionary *)parameters; + +/*! + + @method + + @abstract + Log a purchase of the specified amount, in the specified currency, also providing a set of + additional characteristics describing the purchase, as well as an to log to. + + @param purchaseAmount Purchase amount to be logged, as expressed in the specified currency.This value + will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). + + @param currency Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for + specific values. One reference for these is . + + @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must + be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of + parameters and name construction are given in the `FBAppEvents` documentation. Commonly used parameter names + are provided in `FBAppEventParameterName*` constants. + + @param session to direct the event logging to, and thus be logged with whatever user (if any) + is associated with that . A value of `nil` will use `[FBSession activeSession]`. + + @discussion This event immediately triggers a flush of the `FBAppEvents` event queue, unless the `flushBehavior` is set + to `FBAppEventsFlushBehaviorExplicitOnly`. + + */ ++ (void)logPurchase:(double)purchaseAmount + currency:(NSString *)currency + parameters:(NSDictionary *)parameters + session:(FBSession *)session; + +/*! + @method + + @abstract This method has been replaced by [FBSettings limitEventAndDataUsage] */ ++ (BOOL)limitEventUsage __attribute__ ((deprecated("use [FBSettings limitEventAndDataUsage] instead"))); + +/*! + @method + + @abstract This method has been replaced by [FBSettings setLimitEventUsage] */ ++ (void)setLimitEventUsage:(BOOL)limitEventUsage __attribute__ ((deprecated("use [FBSettings setLimitEventAndDataUsage] instead"))); + +/*! + + @method + + @abstract + Notifies the events system that the app has launched & logs an activatedApp event. Should typically be placed in the app delegates' `applicationDidBecomeActive:` method. + */ ++ (void)activateApp; + +/* + * Control over event batching/flushing + */ + +/*! + + @method + + @abstract + Get the current event flushing behavior specifying when events are sent back to Facebook servers. + */ ++ (FBAppEventsFlushBehavior)flushBehavior; + +/*! + + @method + + @abstract + Set the current event flushing behavior specifying when events are sent back to Facebook servers. + + @param flushBehavior The desired `FBAppEventsFlushBehavior` to be used. + */ ++ (void)setFlushBehavior:(FBAppEventsFlushBehavior)flushBehavior; + + +/*! + + @method + + @abstract + Explicitly kick off flushing of events to Facebook. This is an asynchronous method, but it does initiate an immediate + kick off. Server failures will be reported through the NotificationCenter with notification ID `FBAppEventsLoggingResultNotification`. + */ ++ (void)flush; + + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAppLinkData.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAppLinkData.h new file mode 100644 index 0000000..dfdcd2e --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBAppLinkData.h @@ -0,0 +1,51 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +/*! + @abstract This class contains information that represents an App Link from Facebook. + */ +@interface FBAppLinkData : NSObject + +/*! @abstract The target */ +@property (readonly) NSURL *targetURL; + +/*! @abstract List of the types of actions for this target */ +@property (readonly) NSArray *actionTypes; + +/*! @abstract List of the ids of the actions for this target */ +@property (readonly) NSArray *actionIDs; + +/*! @abstract Reference breadcrumb provided during creation of story */ +@property (readonly) NSString *ref; + +/*! @abstract User Agent string set by the referer */ +@property (readonly) NSString *userAgent; + +/*! @abstract Referer data is a JSON object set by the referer with referer-specific content */ +@property (readonly) NSDictionary *refererData; + +/*! @abstract Full set of query parameters for this app link */ +@property (readonly) NSDictionary *originalQueryParameters; + +/*! @abstract Original url from which applinkData was extracted */ +@property (readonly) NSURL *originalURL; + +/*! @abstract Addtional arguments supplied with the App Link data. */ +@property (readonly) NSDictionary *arguments; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBCacheDescriptor.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBCacheDescriptor.h new file mode 100644 index 0000000..cf0b34d --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBCacheDescriptor.h @@ -0,0 +1,43 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBSession.h" + +/*! + @class + + @abstract + Base class from which CacheDescriptors derive, provides a method to fetch data for later use + + @discussion + Cache descriptors allow your application to specify the arguments that will be + later used with another object, such as the FBFriendPickerViewController. By using a cache descriptor + instance, an application can choose to fetch data ahead of the point in time where the data is needed. + */ +@interface FBCacheDescriptor : NSObject + +/*! + @method + @abstract + Fetches and caches the data described by the cache descriptor instance, for the given session. + + @param session the to use for fetching data + */ +- (void)prefetchAndCacheForSession:(FBSession*)session; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBDialogs.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBDialogs.h new file mode 100644 index 0000000..1d84796 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBDialogs.h @@ -0,0 +1,492 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +#import "FBAppCall.h" +#import "FBOpenGraphActionShareDialogParams.h" +#import "FBShareDialogParams.h" + +@class FBSession; +@protocol FBOpenGraphAction; + +/*! + @typedef FBNativeDialogResult enum + + @abstract + Passed to a handler to indicate the result of a dialog being displayed to the user. + */ +typedef enum { + /*! Indicates that the dialog action completed successfully. */ + FBOSIntegratedShareDialogResultSucceeded = 0, + /*! Indicates that the dialog action was cancelled (either by the user or the system). */ + FBOSIntegratedShareDialogResultCancelled = 1, + /*! Indicates that the dialog could not be shown (because not on ios6 or ios6 auth was not used). */ + FBOSIntegratedShareDialogResultError = 2 +} FBOSIntegratedShareDialogResult; + +/*! + @typedef + + @abstract Defines a handler that will be called in response to the native share dialog + being displayed. + */ +typedef void (^FBOSIntegratedShareDialogHandler)(FBOSIntegratedShareDialogResult result, NSError *error); + +/*! + @typedef FBDialogAppCallCompletionHandler + + @abstract + A block that when passed to a method in FBDialogs is called back + with the results of the AppCall for that dialog. + + @discussion + This will be called on the UI thread, once the AppCall completes. + + @param call The `FBAppCall` that was completed. + + @param results The results of the AppCall for the dialog. This parameters is present + purely for convenience, and is the exact same value as call.dialogData.results. + + @param error The `NSError` representing any error that occurred. This parameters is + present purely for convenience, and is the exact same value as call.error. + + */ +typedef void (^FBDialogAppCallCompletionHandler)( +FBAppCall *call, +NSDictionary *results, +NSError *error); + +/*! + @class FBDialogs + + @abstract + Provides methods to display native (i.e., non-Web-based) dialogs to the user. + + @discussion + If you are building an app with a urlSchemeSuffix, you should also set the appropriate + plist entry. See `[FBSettings defaultUrlSchemeSuffix]`. + */ +@interface FBDialogs : NSObject + +/*! + @abstract + Presents a dialog that allows the user to share a status update that may include + text, images, or URLs. This dialog is only available on iOS 6.0 and above. The + current active session returned by [FBSession activeSession] will be used to determine + whether the dialog will be displayed. If a session is active, it must be open and the + login method used to authenticate the user must be native iOS 6.0 authentication. + If no session active, then whether the call succeeds or not will depend on + whether Facebook integration has been configured. + + @param viewController The view controller which will present the dialog. + + @param initialText The text which will initially be populated in the dialog. The user + will have the opportunity to edit this text before posting it. May be nil. + + @param image A UIImage that will be attached to the status update. May be nil. + + @param url An NSURL that will be attached to the status update. May be nil. + + @param handler A handler that will be called when the dialog is dismissed, or if an error + occurs. May be nil. + + @return YES if the dialog was presented, NO if not (in the case of a NO result, the handler + will still be called, with an error indicating the reason the dialog was not displayed) + */ ++ (BOOL)presentOSIntegratedShareDialogModallyFrom:(UIViewController*)viewController + initialText:(NSString*)initialText + image:(UIImage*)image + url:(NSURL*)url + handler:(FBOSIntegratedShareDialogHandler)handler; + +/*! + @abstract + Presents a dialog that allows the user to share a status update that may include + text, images, or URLs. This dialog is only available on iOS 6.0 and above. The + current active session returned by [FBSession activeSession] will be used to determine + whether the dialog will be displayed. If a session is active, it must be open and the + login method used to authenticate the user must be native iOS 6.0 authentication. + If no session active, then whether the call succeeds or not will depend on + whether Facebook integration has been configured. + + @param viewController The view controller which will present the dialog. + + @param initialText The text which will initially be populated in the dialog. The user + will have the opportunity to edit this text before posting it. May be nil. + + @param images An array of UIImages that will be attached to the status update. May + be nil. + + @param urls An array of NSURLs that will be attached to the status update. May be nil. + + @param handler A handler that will be called when the dialog is dismissed, or if an error + occurs. May be nil. + + @return YES if the dialog was presented, NO if not (in the case of a NO result, the handler + will still be called, with an error indicating the reason the dialog was not displayed) + */ ++ (BOOL)presentOSIntegratedShareDialogModallyFrom:(UIViewController*)viewController + initialText:(NSString*)initialText + images:(NSArray*)images + urls:(NSArray*)urls + handler:(FBOSIntegratedShareDialogHandler)handler; + +/*! + @abstract + Presents a dialog that allows the user to share a status update that may include + text, images, or URLs. This dialog is only available on iOS 6.0 and above. An + may be specified, or nil may be passed to indicate that the current + active session should be used. If a session is specified (whether explicitly or by + virtue of being the active session), it must be open and the login method used to + authenticate the user must be native iOS 6.0 authentication. If no session is specified + (and there is no active session), then whether the call succeeds or not will depend on + whether Facebook integration has been configured. + + @param viewController The view controller which will present the dialog. + + @param session The to use to determine whether or not the user has been + authenticated with iOS native authentication. If nil, then [FBSession activeSession] + will be checked. See discussion above for the implications of nil or non-nil session. + + @param initialText The text which will initially be populated in the dialog. The user + will have the opportunity to edit this text before posting it. May be nil. + + @param images An array of UIImages that will be attached to the status update. May + be nil. + + @param urls An array of NSURLs that will be attached to the status update. May be nil. + + @param handler A handler that will be called when the dialog is dismissed, or if an error + occurs. May be nil. + + @return YES if the dialog was presented, NO if not (in the case of a NO result, the handler + will still be called, with an error indicating the reason the dialog was not displayed) + */ ++ (BOOL)presentOSIntegratedShareDialogModallyFrom:(UIViewController*)viewController + session:(FBSession*)session + initialText:(NSString*)initialText + images:(NSArray*)images + urls:(NSArray*)urls + handler:(FBOSIntegratedShareDialogHandler)handler; + +/*! + @abstract + Determines whether a call to presentShareDialogModallyFrom: will successfully present + a dialog. This is useful for applications that need to modify the available UI controls + depending on whether the dialog is available on the current platform and for the current + user. + + @param session The to use to determine whether or not the user has been + authenticated with iOS native authentication. If nil, then [FBSession activeSession] + will be checked. See discussion above for the implications of nil or non-nil session. + + @return YES if the dialog would be presented for the session, and NO if not + */ ++ (BOOL)canPresentOSIntegratedShareDialogWithSession:(FBSession*)session; + +/*! + @abstract + Determines whether a call to presentShareDialogWithTarget: will successfully + present a dialog in the Facebook application. This is useful for applications that + need to modify the available UI controls depending on whether the dialog is + available on the current platform. + + @param params The parameters for the FB share dialog. + + @return YES if the dialog would be presented, and NO if not + + @discussion A return value of YES here indicates that the corresponding + presentShareDialogWithParams method will return a non-nil FBAppCall for the same + params. And vice versa. + */ ++ (BOOL)canPresentShareDialogWithParams:(FBShareDialogParams *)params; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to share a status + update that may include text, images, or URLs. No session is required, and the app + does not need to be authorized to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param params The parameters for the FB share dialog. + + @param clientState An NSDictionary that's passed through when the completion handler + is called. This is useful for the app to maintain state about the share request that + was made so as to have appropriate action when the handler is called. May be nil. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithParams:(FBShareDialogParams *)params + clientState:(NSDictionary *)clientState + handler:(FBDialogAppCallCompletionHandler)handler; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to share the + supplied link. No session is required, and the app does not need to be authorized + to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param link The URL link to be attached to the post. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithLink:(NSURL *)link + handler:(FBDialogAppCallCompletionHandler)handler; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to share the + supplied link. No session is required, and the app does not need to be authorized + to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param link The URL link to be attached to the post. + + @param name The name, or title associated with the link. May be nil. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithLink:(NSURL *)link + name:(NSString *)name + handler:(FBDialogAppCallCompletionHandler)handler; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to share the + supplied link. No session is required, and the app does not need to be authorized + to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param link The URL link to be attached to the post. + + @param name The name, or title associated with the link. May be nil. + + @param caption The caption to be used with the link. May be nil. + + @param description The description associated with the link. May be nil. + + @param picture The link to a thumbnail to associate with the link. May be nil. + + @param clientState An NSDictionary that's passed through when the completion handler + is called. This is useful for the app to maintain state about the share request that + was made so as to have appropriate action when the handler is called. May be nil. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithLink:(NSURL *)link + name:(NSString *)name + caption:(NSString *)caption + description:(NSString *)description + picture:(NSURL *)picture + clientState:(NSDictionary *)clientState + handler:(FBDialogAppCallCompletionHandler)handler; + +/*! + @abstract + Determines whether a call to presentShareDialogWithOpenGraphActionParams:clientState:handler: + will successfully present a dialog in the Facebook application. This is useful for applications + that need to modify the available UI controls depending on whether the dialog is + available on the current platform. + + @param params The parameters for the FB share dialog. + + @return YES if the dialog would be presented, and NO if not + + @discussion A return value of YES here indicates that the corresponding + presentShareDialogWithOpenGraphActionParams method will return a non-nil FBAppCall for + the same params. And vice versa. + */ ++ (BOOL)canPresentShareDialogWithOpenGraphActionParams:(FBOpenGraphActionShareDialogParams *)params; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to publish an Open + Graph action. No session is required, and the app does not need to be authorized to call + this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param params The parameters for the Open Graph action dialog. + + @param clientState An NSDictionary that's passed through when the completion handler + is called. This is useful for the app to maintain state about the share request that + was made so as to have appropriate action when the handler is called. May be nil. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithOpenGraphActionParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithOpenGraphActionParams:(FBOpenGraphActionShareDialogParams *)params + clientState:(NSDictionary *)clientState + handler:(FBDialogAppCallCompletionHandler)handler; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to publish the + supplied Open Graph action. No session is required, and the app does not need to be + authorized to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param action The Open Graph action to be published. May not be nil. + + @param actionType the fully-specified Open Graph action type of the action (e.g., + my_app_namespace:my_action). + + @param previewPropertyName the name of the property on the action that represents the + primary Open Graph object associated with the action; this object will be displayed in the + preview portion of the share dialog. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithOpenGraphActionParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithOpenGraphAction:(id)action + actionType:(NSString *)actionType + previewPropertyName:(NSString *)previewPropertyName + handler:(FBDialogAppCallCompletionHandler) handler; + +/*! + @abstract + Presents a dialog in the Facebook application that allows the user to publish the + supplied Open Graph action. No session is required, and the app does not need to be + authorized to call this. + + Note that this will perform an app switch to the Facebook app, and will cause the + current app to be suspended. When the share is complete, the Facebook app will redirect + to a url of the form "fb{APP_ID}://" that the application must handle. The app should + then call [FBAppCall handleOpenURL:sourceApplication:fallbackHandler:] to trigger + the appropriate handling. Note that FBAppCall will first try to call the completion + handler associated with this method, but since during an app switch, the calling app + may be suspended or killed, the app must also give a fallbackHandler to the + handleOpenURL: method in FBAppCall. + + @param action The Open Graph action to be published. May not be nil. + + @param actionType the fully-specified Open Graph action type of the action (e.g., + my_app_namespace:my_action). + + @param previewPropertyName the name of the property on the action that represents the + primary Open Graph object associated with the action; this object will be displayed in the + preview portion of the share dialog. + + @param clientState An NSDictionary that's passed through when the completion handler + is called. This is useful for the app to maintain state about the share request that + was made so as to have appropriate action when the handler is called. May be nil. + + @param handler A completion handler that may be called when the status update is + complete. May be nil. If non-nil, the handler will always be called asynchronously. + + @return An FBAppCall object that will also be passed into the provided + FBAppCallCompletionHandler. + + @discussion A non-nil FBAppCall object is only returned if the corresponding + canPresentShareDialogWithOpenGraphActionParams method is also returning YES for the same params. + */ ++ (FBAppCall *)presentShareDialogWithOpenGraphAction:(id)action + actionType:(NSString *)actionType + previewPropertyName:(NSString *)previewPropertyName + clientState:(NSDictionary *)clientState + handler:(FBDialogAppCallCompletionHandler) handler; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBDialogsData.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBDialogsData.h new file mode 100644 index 0000000..bffbc46 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBDialogsData.h @@ -0,0 +1,35 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +/*! + @abstract + This class encapsulates state and data related to the presentation and completion + of a dialog. + */ +@interface FBDialogsData : NSObject + +/*! @abstract The method being performed */ +@property (nonatomic, readonly) NSString *method; +/*! @abstract The arguments being passed to the entity that will show the dialog */ +@property (nonatomic, readonly) NSDictionary *arguments; +/*! @abstract Client JSON state that is passed through to the completion handler for context */ +@property (nonatomic, readonly) NSDictionary *clientState; +/*! @abstract Results of this FBAppCall that are only set before calling an FBAppCallHandler */ +@property (nonatomic, readonly) NSDictionary *results; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBDialogsParams.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBDialogsParams.h new file mode 100644 index 0000000..9197de5 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBDialogsParams.h @@ -0,0 +1,28 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +/*! + @class FBDialogsParams + + @abstract + This object is used as a base class for parameters passed to native dialogs that + open in the Facebook app. + */ +@interface FBDialogsParams : NSObject + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBError.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBError.h new file mode 100644 index 0000000..70ef2a4 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBError.h @@ -0,0 +1,372 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +/*! + The NSError domain of all errors returned by the Facebook SDK. +*/ +extern NSString *const FacebookSDKDomain; + +/*! + The NSError domain of all errors surfaced by the Facebook SDK that + were returned by the Facebook Application + */ +extern NSString *const FacebookNativeApplicationDomain; + +/*! + The key in the userInfo NSDictionary of NSError where you can find + the inner NSError (if any). +*/ +extern NSString *const FBErrorInnerErrorKey; + +/*! + The key in the userInfo NSDictionary of NSError for the parsed JSON response + from the server. In case of a batch, includes the JSON for a single FBRequest. +*/ +extern NSString *const FBErrorParsedJSONResponseKey; + +/*! + The key in the userInfo NSDictionary of NSError indicating + the HTTP status code of the response (if any). +*/ +extern NSString *const FBErrorHTTPStatusCodeKey; + +/*! + @abstract Error codes returned by the Facebook SDK in NSError. + + @discussion + These are valid only in the scope of FacebookSDKDomain. + */ +typedef enum FBErrorCode { + /*! + Like nil for FBErrorCode values, represents an error code that + has not been initialized yet. + */ + FBErrorInvalid = 0, + + /// The operation failed because it was cancelled. + FBErrorOperationCancelled, + + /// A login attempt failed + FBErrorLoginFailedOrCancelled, + + /// The graph API returned an error for this operation. + FBErrorRequestConnectionApi, + + /*! + The operation failed because the server returned an unexpected + response. You can get this error if you are not using the most + recent SDK, or if you set your application's migration settings + incorrectly for the version of the SDK you are using. + + If this occurs on the current SDK with proper app migration + settings, you may need to try changing to one request per batch. + */ + FBErrorProtocolMismatch, + + /// Non-success HTTP status code was returned from the operation. + FBErrorHTTPError, + + /// An endpoint that returns a binary response was used with FBRequestConnection; + /// endpoints that return image/jpg, etc. should be accessed using NSURLRequest + FBErrorNonTextMimeTypeReturned, + + /// An error occurred while trying to display a native dialog + FBErrorDialog, + + /// An error occurred using the FBAppEvents class + FBErrorAppEvents, + + /// An error occurred related to an iOS API call + FBErrorSystemAPI, + + /// An error occurred while trying to fetch publish install response data + FBErrorPublishInstallResponse, + + /*! + The application had its applicationDidBecomeActive: method called while waiting + on a response from the native Facebook app for a pending FBAppCall. + */ + FBErrorAppActivatedWhilePendingAppCall, + + /*! + The application had its openURL: method called from a source that was not a + Facebook app and with a URL that was intended for the AppBridge + */ + FBErrorUntrustedURL, + + /*! + The URL passed to FBAppCall, was not able to be parsed + */ + FBErrorMalformedURL, + + /*! + The operation failed because the session is currently busy reconnecting. + */ + FBErrorSessionReconnectInProgess, + + /*! + Reserved for future use. + */ + FBErrorOperationDisallowedForRestrictedTreament, +} FBErrorCode; + +/*! + @abstract Error codes returned by the Facebook SDK in NSError. + + @discussion + These are valid only in the scope of FacebookNativeApplicationDomain. + */ +typedef enum FBNativeApplicationErrorCode { + // A general error in processing an FBAppCall, without a known cause. Unhandled exceptions are a good example + FBAppCallErrorUnknown = 1, + + // The FBAppCall cannot be processed for some reason + FBAppCallErrorUnsupported = 2, + + // The FBAppCall is for a method that does not exist (or is turned off) + FBAppCallErrorUnknownMethod = 3, + + // The FBAppCall cannot be processed at the moment, but can be retried at a later time. + FBAppCallErrorServiceBusy = 4, + + // Share was called in the native Facebook app with incomplete or incorrect arguments + FBShareErrorInvalidParam = 100, + + // A server error occurred while calling Share in the native Facebook app. + FBShareErrorServer = 102, + + // An unknown error occurred while calling Share in the native Facebook app. + FBShareErrorUnknown = 103, + + // Disallowed from calling Share in the native Facebook app. + FBShareErrorDenied = 104, + +} FBNativeApplicationErrorCode; + +/*! + @typedef FBErrorCategory enum + + @abstract Indicates the Facebook SDK classification for the error + + @discussion + */ +typedef enum { + /*! Indicates that the error category is invalid and likely represents an error that + is unrelated to Facebook or the Facebook SDK */ + FBErrorCategoryInvalid = 0, + /*! Indicates that the error may be authentication related but the application should retry the operation. + This case may involve user action that must be taken, and so the application should also test + the fberrorShouldNotifyUser property and if YES display fberrorUserMessage to the user before retrying.*/ + FBErrorCategoryRetry = 1, + /*! Indicates that the error is authentication related and the application should reopen the session*/ + FBErrorCategoryAuthenticationReopenSession = 2, + /*! Indicates that the error is permission related */ + FBErrorCategoryPermissions = 3, + /*! Indicates that the error implies that the server had an unexpected failure or may be temporarily down */ + FBErrorCategoryServer = 4, + /*! Indicates that the error results from the server throttling the client */ + FBErrorCategoryThrottling = 5, + /*! Indicates the user cancelled the operation */ + FBErrorCategoryUserCancelled = 6, + /*! Indicates that the error is Facebook-related but is uncategorizable, and likely newer than the + current version of the SDK */ + FBErrorCategoryFacebookOther = -1, + /*! Indicates that the error is an application error resulting in a bad or malformed request to the server. */ + FBErrorCategoryBadRequest = -2, +} FBErrorCategory; + +/*! + The key in the userInfo NSDictionary of NSError where you can find + the inner NSError (if any). + */ +extern NSString *const FBErrorInnerErrorKey; + +/*! + The key in the userInfo NSDictionary of NSError where you can find + the session associated with the error (if any). +*/ +extern NSString *const FBErrorSessionKey; + +/*! + The key in the userInfo NSDictionary of NSError that points to the URL + that caused an error, in its processing by FBAppCall. + */ +extern NSString *const FBErrorUnprocessedURLKey; + +/*! + The key in the userInfo NSDictionary of NSError for unsuccessful + logins (error.code equals FBErrorLoginFailedOrCancelled). If present, + the value will be one of the constants prefixed by FBErrorLoginFailedReason*. +*/ +extern NSString *const FBErrorLoginFailedReason; + +/*! + The key in the userInfo NSDictionary of NSError for unsuccessful + logins (error.code equals FBErrorLoginFailedOrCancelled). If present, + the value indicates an original login error code wrapped by this error. + This is only used in the web dialog login flow. + */ +extern NSString *const FBErrorLoginFailedOriginalErrorCode; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates the user + cancelled a web dialog auth. +*/ +extern NSString *const FBErrorLoginFailedReasonInlineCancelledValue; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates the user + did not cancel a web dialog auth. + */ +extern NSString *const FBErrorLoginFailedReasonInlineNotCancelledValue; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates the user + cancelled a non-iOS 6 SSO (either Safari or Facebook App) login. + */ +extern NSString *const FBErrorLoginFailedReasonUserCancelledValue; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates the user + cancelled an iOS system login. + */ +extern NSString *const FBErrorLoginFailedReasonUserCancelledSystemValue; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates an error + condition. You may inspect the rest of userInfo for other data. + */ +extern NSString *const FBErrorLoginFailedReasonOtherError; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates the app's + slider in iOS 6 (device Settings -> Privacy -> Facebook {app} ) has + been disabled. + */ +extern NSString *const FBErrorLoginFailedReasonSystemDisallowedWithoutErrorValue; + +/*! + A value that may appear in an NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key for login failures. Indicates an error + has occurred when requesting Facebook account acccess in iOS 6 that was + not `FBErrorLoginFailedReasonSystemDisallowedWithoutErrorValue` nor + a user cancellation. + */ +extern NSString *const FBErrorLoginFailedReasonSystemError; +extern NSString *const FBErrorLoginFailedReasonUnitTestResponseUnrecognized; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key when requesting new permissions fails. Indicates + the request for new permissions has failed because the session was closed. + */ +extern NSString *const FBErrorReauthorizeFailedReasonSessionClosed; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key when requesting new permissions fails. Indicates + the request for new permissions has failed because the user cancelled. + */ +extern NSString *const FBErrorReauthorizeFailedReasonUserCancelled; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key when requesting new permissions fails on + iOS 6 with the Facebook account. Indicates the request for new permissions has + failed because the user cancelled. + */ +extern NSString *const FBErrorReauthorizeFailedReasonUserCancelledSystem; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorLoginFailedReason` key when requesting new permissions fails. Indicates + the request for new permissions has failed because the request was + for a different user than the original permission set. + */ +extern NSString *const FBErrorReauthorizeFailedReasonWrongUser; + +/*! + The key in the userInfo NSDictionary of NSError for errors + encountered with `FBDialogs` operations. (error.code equals FBErrorDialog). + If present, the value will be one of the constants prefixed by FBErrorDialog*. +*/ +extern NSString *const FBErrorDialogReasonKey; + +/*! + A value that may appear in the NSError userInfo dictionary under the +`FBErrorDialogReasonKey` key. Indicates that a native dialog is not supported + in the current OS. +*/ +extern NSString *const FBErrorDialogNotSupported; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorDialogReasonKey` key. Indicates that a native dialog cannot be + displayed because it is not appropriate for the current session. +*/ +extern NSString *const FBErrorDialogInvalidForSession; + +/*! + A value that may appear in the NSError userInfo dictionary under the + `FBErrorDialogReasonKey` key. Indicates that a native dialog cannot be + displayed for some other reason. + */ +extern NSString *const FBErrorDialogCantBeDisplayed; + +/*! + A value that may appear in the NSError userInfo ditionary under the + `FBErrorDialogReasonKey` key. Indicates that a native dialog cannot be + displayed because an Open Graph object that was passed was not configured + correctly. The object must either (a) exist by having an 'id' or 'url' value; + or, (b) configured for creation (by setting the 'type' value and + provisionedForPost property) +*/ +extern NSString *const FBErrorDialogInvalidOpenGraphObject; + +/*! + A value that may appear in the NSError userInfo ditionary under the + `FBErrorDialogReasonKey` key. Indicates that a native dialog cannot be + displayed because the parameters for sharing an Open Graph action were + not configured. The parameters must include an 'action', 'actionType', and + 'previewPropertyName'. + */ +extern NSString *const FBErrorDialogInvalidOpenGraphActionParameters; + +/*! + The key in the userInfo NSDictionary of NSError for errors + encountered with `FBAppEvents` operations (error.code equals FBErrorAppEvents). +*/ +extern NSString *const FBErrorAppEventsReasonKey; + +// Exception strings raised by the Facebook SDK + +/*! + This exception is raised by methods in the Facebook SDK to indicate + that an attempted operation is invalid + */ +extern NSString *const FBInvalidOperationException; + +// Facebook SDK also raises exceptions the following common exceptions: +// NSInvalidArgumentException + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBErrorUtility.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBErrorUtility.h new file mode 100644 index 0000000..61ae2ca --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBErrorUtility.h @@ -0,0 +1,66 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/*! + @class FBErrorUtility + + @abstract A utility class with methods to provide more information for Facebook + related errors if you do not want to use the NSError(FBError) category. + + */ +@interface FBErrorUtility : NSObject + +/*! + @abstract + Categorizes the error, if it is Facebook related, to simplify application mitigation behavior + + @discussion + In general, in response to an error connecting to Facebook, an application should, retry the + operation, request permissions, reconnect the application, or prompt the user to take an action. + The error category can be used to understand the class of error received from Facebook. For more infomation on this + see https://developers.facebook.com/docs/reference/api/errors/ + + @param error the error to be categorized. + */ ++(FBErrorCategory) errorCategoryForError:(NSError *)error; + +/*! + @abstract + If YES indicates that a user action is required in order to successfully continue with the facebook operation + + @discussion + In general if this returns NO, then the application has a straightforward mitigation, such as + retry the operation or request permissions from the user, etc. In some cases it is necessary for the user to + take an action before the application continues to attempt a Facebook connection. For more infomation on this + see https://developers.facebook.com/docs/reference/api/errors/ + + @param error the error to inspect. + */ ++(BOOL) shouldNotifyUserForError:(NSError *)error; + +/*! + @abstract + A message suitable for display to the user, describing a user action necessary to enable Facebook functionality. + Not all Facebook errors yield a message suitable for user display; however in all cases where + fberrorShouldNotifyUser is YES, this property returns a localizable message suitable for display. + + @param error the error to inspect. + */ ++(NSString *) userMessageForError:(NSError *)error; + + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBFrictionlessRecipientCache.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBFrictionlessRecipientCache.h new file mode 100644 index 0000000..09f8d9d --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBFrictionlessRecipientCache.h @@ -0,0 +1,87 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#import + +#import "FBCacheDescriptor.h" +#import "FBRequest.h" +#import "FBWebDialogs.h" + +/*! + @class FBFrictionlessRecipientCache + + @abstract + Maintains a cache of friends that can recieve application requests from the user in + using the frictionless feature of the requests web dialog. + + This class follows the `FBCacheDescriptor` pattern used elsewhere in the SDK, and applications may call + one of the prefetchAndCacheForSession methods to fetch a friend list prior to the + point where a dialog is presented. The cache is also updated with each presentation of the request + dialog using the cache instance. + */ +@interface FBFrictionlessRecipientCache : FBCacheDescriptor + +/*! + @abstract + Initializes an empty cache instance + */ +- (id)init; + +/*! @abstract An array containing the list of known FBIDs for recipients enabled for frictionless requests */ +@property (nonatomic, readwrite, copy) NSArray *recipientIDs; + +/*! + @abstract + Checks to see if a given user or FBID for a user is known to be enabled for + frictionless requestests + + @param user An NSString, NSNumber of `FBGraphUser` representing a user to check + */ +- (BOOL)isFrictionlessRecipient:(id)user; + +/*! + @abstract + Checks to see if a collection of users or FBIDs for users are known to be enabled for + frictionless requestests + + @param users An NSArray of NSString, NSNumber of `FBGraphUser` objects + representing users to check + */ +- (BOOL)areFrictionlessRecipients:(NSArray*)users; + +/*! + @abstract + Issues a request and fills the cache with a list of users to use for frictionless requests + + @param session The session to use for the request; nil indicates that the Active Session should + be used + */ +- (void)prefetchAndCacheForSession:(FBSession *)session; + +/*! + @abstract + Issues a request and fills the cache with a list of users to use for frictionless requests + + @param session The session to use for the request; nil indicates that the Active Session should + be used + + @param handler An optional completion handler, called when the request for cached users has + completed. It can be useful to use the handler to enable UI or perform other request-related + operations, after the cache is populated. + */ +- (void)prefetchAndCacheForSession:(FBSession *)session + completionHandler:(FBRequestHandler)handler; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBFriendPickerViewController.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBFriendPickerViewController.h new file mode 100644 index 0000000..6c8af5b --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBFriendPickerViewController.h @@ -0,0 +1,296 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBCacheDescriptor.h" +#import "FBGraphUser.h" +#import "FBSession.h" +#import "FBViewController.h" + +@protocol FBFriendPickerDelegate; +@class FBFriendPickerCacheDescriptor; + +/*! + @typedef FBFriendSortOrdering enum + + @abstract Indicates the order in which friends should be listed in the friend picker. + + @discussion + */ +typedef enum { + /*! Sort friends by first, middle, last names. */ + FBFriendSortByFirstName, + /*! Sort friends by last, first, middle names. */ + FBFriendSortByLastName +} FBFriendSortOrdering; + +/*! + @typedef FBFriendDisplayOrdering enum + + @abstract Indicates whether friends should be displayed first-name-first or last-name-first. + + @discussion + */ +typedef enum { + /*! Display friends as First Middle Last. */ + FBFriendDisplayByFirstName, + /*! Display friends as Last First Middle. */ + FBFriendDisplayByLastName, +} FBFriendDisplayOrdering; + + +/*! + @class + + @abstract + The `FBFriendPickerViewController` class creates a controller object that manages + the user interface for displaying and selecting Facebook friends. + + @discussion + When the `FBFriendPickerViewController` view loads it creates a `UITableView` object + where the friends will be displayed. You can access this view through the `tableView` + property. The friend display can be sorted by first name or last name. Friends' + names can be displayed with the first name first or the last name first. + + The friend data can be pre-fetched and cached prior to using the view controller. The + cache is setup using an object that can trigger the + data fetch. Any friend data requests will first check the cache and use that data. + If the friend picker is being displayed cached data will initially be shown before + a fresh copy is retrieved. + + The `delegate` property may be set to an object that conforms to the + protocol. The `delegate` object will receive updates related to friend selection and + data changes. The delegate can also be used to filter the friends to display in the + picker. + */ +@interface FBFriendPickerViewController : FBViewController + +/*! + @abstract + Returns an outlet for the spinner used in the view controller. + */ +@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *spinner; + +/*! + @abstract + Returns an outlet for the table view managed by the view controller. + */ +@property (nonatomic, retain) IBOutlet UITableView *tableView; + +/*! + @abstract + A Boolean value that specifies whether multi-select is enabled. + */ +@property (nonatomic) BOOL allowsMultipleSelection; + +/*! + @abstract + A Boolean value that indicates whether friend profile pictures are displayed. + */ +@property (nonatomic) BOOL itemPicturesEnabled; + +/*! + @abstract + Addtional fields to fetch when making the Graph API call to get friend data. + */ +@property (nonatomic, copy) NSSet *fieldsForRequest; + +/*! + @abstract + The session that is used in the request for friend data. + */ +@property (nonatomic, retain) FBSession *session; + +/*! + @abstract + The profile ID of the user whose friends are being viewed. + */ +@property (nonatomic, copy) NSString *userID; + +/*! + @abstract + The list of friends that are currently selected in the veiw. + The items in the array are objects. + + @discussion + You can set this this array to pre-select items in the picker. The objects in the array + must be complete id objects (i.e., fetched from a Graph query or from a + previous picker's selection, with id and appropriate name fields). + */ +@property (nonatomic, copy) NSArray *selection; + +/*! + @abstract + The order in which friends are sorted in the display. + */ +@property (nonatomic) FBFriendSortOrdering sortOrdering; + +/*! + @abstract + The order in which friends' names are displayed. + */ +@property (nonatomic) FBFriendDisplayOrdering displayOrdering; + +/*! + @abstract + Initializes a friend picker view controller. + */ +- (id)init; + +/*! + @abstract + Initializes a friend picker view controller. + + @param aDecoder An unarchiver object. + */ +- (id)initWithCoder:(NSCoder *)aDecoder; + +/*! + @abstract + Used to initialize the object + + @param nibNameOrNil The name of the nib file to associate with the view controller. The nib file name should not contain any leading path information. If you specify nil, the nibName property is set to nil. + @param nibBundleOrNil The bundle in which to search for the nib file. This method looks for the nib file in the bundle's language-specific project directories first, followed by the Resources directory. If nil, this method looks for the nib file in the main bundle. + */ +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil; + +/*! + @abstract + Configures the properties used in the caching data queries. + + @discussion + Cache descriptors are used to fetch and cache the data used by the view controller. + If the view controller finds a cached copy of the data, it will + first display the cached content then fetch a fresh copy from the server. + + @param cacheDescriptor The containing the cache query properties. + */ +- (void)configureUsingCachedDescriptor:(FBCacheDescriptor*)cacheDescriptor; + +/*! + @abstract + Initiates a query to get friend data. + + @discussion + A cached copy will be returned if available. The cached view is temporary until a fresh copy is + retrieved from the server. It is legal to call this more than once. + */ +- (void)loadData; + +/*! + @abstract + Updates the view locally without fetching data from the server or from cache. + + @discussion + Use this if the filter or sort properties change. This may affect the order or + display of friend information but should not need require new data. + */ +- (void)updateView; + +/*! + @abstract + Clears the current selection, so the picker is ready for a fresh use. + */ +- (void)clearSelection; + +/*! + @method + + @abstract + Creates a cache descriptor based on default settings of the `FBFriendPickerViewController` object. + + @discussion + An `FBCacheDescriptor` object may be used to pre-fetch data before it is used by + the view controller. It may also be used to configure the `FBFriendPickerViewController` + object. + */ ++ (FBCacheDescriptor*)cacheDescriptor; + +/*! + @method + + @abstract + Creates a cache descriptor with additional fields and a profile ID for use with the `FBFriendPickerViewController` object. + + @discussion + An `FBCacheDescriptor` object may be used to pre-fetch data before it is used by + the view controller. It may also be used to configure the `FBFriendPickerViewController` + object. + + @param userID The profile ID of the user whose friends will be displayed. A nil value implies a "me" alias. + @param fieldsForRequest The set of additional fields to include in the request for friend data. + */ ++ (FBCacheDescriptor*)cacheDescriptorWithUserID:(NSString*)userID fieldsForRequest:(NSSet*)fieldsForRequest; + +@end + +/*! + @protocol + + @abstract + The `FBFriendPickerDelegate` protocol defines the methods used to receive event + notifications and allow for deeper control of the + view. + */ +@protocol FBFriendPickerDelegate +@optional + +/*! + @abstract + Tells the delegate that data has been loaded. + + @discussion + The object's `tableView` property is automatically + reloaded when this happens. However, if another table view, for example the + `UISearchBar` is showing data, then it may also need to be reloaded. + + @param friendPicker The friend picker view controller whose data changed. + */ +- (void)friendPickerViewControllerDataDidChange:(FBFriendPickerViewController *)friendPicker; + +/*! + @abstract + Tells the delegate that the selection has changed. + + @param friendPicker The friend picker view controller whose selection changed. + */ +- (void)friendPickerViewControllerSelectionDidChange:(FBFriendPickerViewController *)friendPicker; + +/*! + @abstract + Asks the delegate whether to include a friend in the list. + + @discussion + This can be used to implement a search bar that filters the friend list. + + @param friendPicker The friend picker view controller that is requesting this information. + @param user An object representing the friend. + */ +- (BOOL)friendPickerViewController:(FBFriendPickerViewController *)friendPicker + shouldIncludeUser:(id )user; + +/*! + @abstract + Tells the delegate that there is a communication error. + + @param friendPicker The friend picker view controller that encountered the error. + @param error An error object containing details of the error. + */ +- (void)friendPickerViewController:(FBFriendPickerViewController *)friendPicker + handleError:(NSError *)error; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphLocation.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphLocation.h new file mode 100644 index 0000000..7f71ce6 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphLocation.h @@ -0,0 +1,78 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphObject.h" + +/*! + @protocol + + @abstract + The `FBGraphLocation` protocol enables typed access to the `location` property + of a Facebook place object. + + + @discussion + The `FBGraphLocation` protocol represents the most commonly used properties of a + location object. It may be used to access an `NSDictionary` object that has + been wrapped with an facade. + */ +@protocol FBGraphLocation + +/*! + @property + @abstract Typed access to a location's street. + */ +@property (retain, nonatomic) NSString *street; + +/*! + @property + @abstract Typed access to a location's city. + */ +@property (retain, nonatomic) NSString *city; + +/*! + @property + @abstract Typed access to a location's state. + */ +@property (retain, nonatomic) NSString *state; + +/*! + @property + @abstract Typed access to a location's country. + */ +@property (retain, nonatomic) NSString *country; + +/*! + @property + @abstract Typed access to a location's zip code. + */ +@property (retain, nonatomic) NSString *zip; + +/*! + @property + @abstract Typed access to a location's latitude. + */ +@property (retain, nonatomic) NSNumber *latitude; + +/*! + @property + @abstract Typed access to a location's longitude. + */ +@property (retain, nonatomic) NSNumber *longitude; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphObject.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphObject.h new file mode 100644 index 0000000..74460f6 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphObject.h @@ -0,0 +1,269 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@protocol FBOpenGraphObject; +@protocol FBOpenGraphAction; + +/*! + @protocol + + @abstract + The `FBGraphObject` protocol is the base protocol which enables typed access to graph objects and + open graph objects. Inherit from this protocol or a sub-protocol in order to introduce custom types + for typed access to Facebook objects. + + @discussion + The `FBGraphObject` protocol is the core type used by the Facebook SDK for iOS to + represent objects in the Facebook Social Graph and the Facebook Open Graph (OG). + The `FBGraphObject` class implements useful default functionality, but is rarely + used directly by applications. The `FBGraphObject` protocol, in contrast is the + base protocol for all graph object access via the SDK. + + Goals of the FBGraphObject types: +
    +
  • Lightweight/maintainable/robust
  • +
  • Extensible and resilient to change, both by Facebook and third party (OG)
  • +
  • Simple and natural extension to Objective-C
  • +
+ + The FBGraphObject at its core is a duck typed (if it walks/swims/quacks... + its a duck) model which supports an optional static facade. Duck-typing achieves + the flexibility necessary for Social Graph and OG uses, and the static facade + increases discoverability, maintainability, robustness and simplicity. + The following excerpt from the PlacePickerSample shows a simple use of the + a facade protocol `FBGraphPlace` by an application: + +
+ ‐ (void)placePickerViewControllerSelectionDidChange:(FBPlacePickerViewController *)placePicker
+ {
+   id<FBGraphPlace> place = placePicker.selection;
+
+   // we'll use logging to show the simple typed property access to place and location info
+   NSLog(@"place=%@, city=%@, state=%@, lat long=%@ %@",
+     place.name,
+     place.location.city,
+     place.location.state,
+     place.location.latitude,
+     place.location.longitude);
+ }
+ 
+ + Note that in this example, access to common place information is available through typed property + syntax. But if at some point places in the Social Graph supported additional fields "foo" and "bar", not + reflected in the `FBGraphPlace` protocol, the application could still access the values like so: + +
+ NSString *foo = [place objectForKey:@"foo"]; // perhaps located at the ... in the preceding example
+ NSNumber *bar = [place objectForKey:@"bar"]; // extensibility applies to Social and Open graph uses
+ 
+ + In addition to untyped access, applications and future revisions of the SDK may add facade protocols by + declaring a protocol inheriting the `FBGraphObject` protocol, like so: + +
+ @protocol MyGraphThing<FBGraphObject>
+ @property (copy, nonatomic) NSString *id;
+ @property (copy, nonatomic) NSString *name;
+ @end
+ 
+ + Important: facade implementations are inferred by graph objects returned by the methods of the SDK. This + means that no explicit implementation is required by application or SDK code. Any `FBGraphObject` instance + may be cast to any `FBGraphObject` facade protocol, and accessed via properties. If a field is not present + for a given facade property, the property will return nil. + + The following layer diagram depicts some of the concepts discussed thus far: + +
+                       *-------------* *------------* *-------------**--------------------------*
+            Facade --> | FBGraphUser | |FBGraphPlace| | MyGraphThing|| MyGraphPersonExtentension| ...
+                       *-------------* *------------* *-------------**--------------------------*
+                       *------------------------------------* *--------------------------------------*
+  Transparent impl --> |     FBGraphObject (instances)      | |      CustomClass<FBGraphObject>      |
+                       *------------------------------------* *--------------------------------------*
+                       *-------------------**------------------------* *-----------------------------*
+     Apparent impl --> |NSMutableDictionary||FBGraphObject (protocol)| |FBGraphObject (class methods)|
+                       *-------------------**------------------------* *-----------------------------*
+ 
+ + The *Facade* layer is meant for typed access to graph objects. The *Transparent impl* layer (more + specifically, the instance capabilities of `FBGraphObject`) are used by the SDK and app logic + internally, but are not part of the public interface between application and SDK. The *Apparent impl* + layer represents the lower-level "duck-typed" use of graph objects. + + Implementation note: the SDK returns `NSMutableDictionary` derived instances with types declared like + one of the following: + +
+ NSMutableDictionary<FBGraphObject> *obj;     // no facade specified (still castable by app)
+ NSMutableDictionary<FBGraphPlace> *person;   // facade specified when possible
+ 
+ + However, when passing a graph object to the SDK, `NSMutableDictionary` is not assumed; only the + FBGraphObject protocol is assumed, like so: + +
+ id<FBGraphObject> anyGraphObj;
+ 
+ + As such, the methods declared on the `FBGraphObject` protocol represent the methods used by the SDK to + consume graph objects. While the `FBGraphObject` class implements the full `NSMutableDictionary` and KVC + interfaces, these are not consumed directly by the SDK, and are optional for custom implementations. + */ +@protocol FBGraphObject + +/*! + @method + @abstract + Returns the number of properties on this `FBGraphObject`. + */ +- (NSUInteger)count; +/*! + @method + @abstract + Returns a property on this `FBGraphObject`. + + @param aKey name of the property to return + */ +- (id)objectForKey:(id)aKey; +/*! + @method + @abstract + Returns an enumerator of the property naems on this `FBGraphObject`. + */ +- (NSEnumerator *)keyEnumerator; +/*! + @method + @abstract + Removes a property on this `FBGraphObject`. + + @param aKey name of the property to remove + */ +- (void)removeObjectForKey:(id)aKey; +/*! + @method + @abstract + Sets the value of a property on this `FBGraphObject`. + + @param anObject the new value of the property + @param aKey name of the property to set + */ +- (void)setObject:(id)anObject forKey:(id)aKey; + +@optional + +/*! + @abstract + This property signifies that the current graph object is provisioned for POST (as a definition + for a new or updated graph object), and should be posted AS-IS in its JSON encoded form, whereas + some graph objects (usually those embedded in other graph objects as references to existing objects) + may only have their "id" or "url" posted. + */ +@property (nonatomic, assign) BOOL provisionedForPost; + +@end + +/*! + @class + + @abstract + Static class with helpers for use with graph objects + + @discussion + The public interface of this class is useful for creating objects that have the same graph characteristics + of those returned by methods of the SDK. This class also represents the internal implementation of the + `FBGraphObject` protocol, used by the Facebook SDK. Application code should not use the `FBGraphObject` class to + access instances and instance members, favoring the protocol. + */ +@interface FBGraphObject : NSMutableDictionary + +/*! + @method + @abstract + Used to create a graph object, usually for use in posting a new graph object or action. + */ ++ (NSMutableDictionary*)graphObject; + +/*! + @method + @abstract + Used to wrap an existing dictionary with a `FBGraphObject` facade + + @discussion + Normally you will not need to call this method, as the Facebook SDK already "FBGraphObject-ifys" json objects + fetch via `FBRequest` and `FBRequestConnection`. However, you may have other reasons to create json objects in your + application, which you would like to treat as a graph object. The pattern for doing this is that you pass the root + node of the json to this method, to retrieve a wrapper. From this point, if you traverse the graph, any other objects + deeper in the hierarchy will be wrapped as `FBGraphObject`'s in a lazy fashion. + + This method is designed to avoid unnecessary memory allocations, and object copying. Due to this, the method does + not copy the source object if it can be avoided, but rather wraps and uses it as is. The returned object derives + callers shoudl use the returned object after calls to this method, rather than continue to call methods on the original + object. + + @param jsonDictionary the dictionary representing the underlying object to wrap + */ ++ (NSMutableDictionary*)graphObjectWrappingDictionary:(NSDictionary*)jsonDictionary; + +/*! + @method + @abstract + Used to create a graph object that's provisioned for POST, usually for use in posting a new Open Graph Action. + */ ++ (NSMutableDictionary*)openGraphActionForPost; + +/*! + @method + @abstract + Used to create a graph object that's provisioned for POST, usually for use in posting a new Open Graph object. + */ ++ (NSMutableDictionary*)openGraphObjectForPost; + +/*! + @method + @abstract + Used to create a graph object that's provisioned for POST, usually for use in posting a new Open Graph object. + + @param type the object type name, in the form namespace:typename + @param title a title for the object + @param image the image property for the object + @param url the url property for the object + @param description the description for the object + */ ++ (NSMutableDictionary*)openGraphObjectForPostWithType:(NSString *)type + title:(NSString *)title + image:(id)image + url:(id)url + description:(NSString *)description; + +/*! + @method + @abstract + Used to compare two `FBGraphObject`s to determine if represent the same object. We do not overload + the concept of equality as there are various types of equality that may be important for an `FBGraphObject` + (for instance, two different `FBGraphObject`s could represent the same object, but contain different + subsets of fields). + + @param anObject an `FBGraphObject` to test + + @param anotherObject the `FBGraphObject` to compare it against + */ ++ (BOOL)isGraphObjectID:(id)anObject sameAs:(id)anotherObject; + + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphPlace.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphPlace.h new file mode 100644 index 0000000..40e144f --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphPlace.h @@ -0,0 +1,61 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphLocation.h" +#import "FBGraphObject.h" + +/*! + @protocol + + @abstract + The `FBGraphPlace` protocol enables typed access to a place object + as represented in the Graph API. + + + @discussion + The `FBGraphPlace` protocol represents the most commonly used properties of a + Facebook place object. It may be used to access an `NSDictionary` object that has + been wrapped with an facade. + */ +@protocol FBGraphPlace + +/*! + @property + @abstract Typed access to the place ID. + */ +@property (retain, nonatomic) NSString *id; + +/*! + @property + @abstract Typed access to the place name. + */ +@property (retain, nonatomic) NSString *name; + +/*! + @property + @abstract Typed access to the place category. + */ +@property (retain, nonatomic) NSString *category; + +/*! + @property + @abstract Typed access to the place location. + */ +@property (retain, nonatomic) id location; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphUser.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphUser.h new file mode 100644 index 0000000..645ea1d --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBGraphUser.h @@ -0,0 +1,91 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphObject.h" +#import "FBGraphPlace.h" + +/*! + @protocol + + @abstract + The `FBGraphUser` protocol enables typed access to a user object + as represented in the Graph API. + + + @discussion + The `FBGraphUser` protocol represents the most commonly used properties of a + Facebook user object. It may be used to access an `NSDictionary` object that has + been wrapped with an facade. + */ +@protocol FBGraphUser + +/*! + @property + @abstract Typed access to the user's ID. + */ +@property (retain, nonatomic) NSString *id; + +/*! + @property + @abstract Typed access to the user's name. + */ +@property (retain, nonatomic) NSString *name; + +/*! + @property + @abstract Typed access to the user's first name. + */ +@property (retain, nonatomic) NSString *first_name; + +/*! + @property + @abstract Typed access to the user's middle name. + */ +@property (retain, nonatomic) NSString *middle_name; + +/*! + @property + @abstract Typed access to the user's last name. + */ +@property (retain, nonatomic) NSString *last_name; + +/*! + @property + @abstract Typed access to the user's profile URL. + */ +@property (retain, nonatomic) NSString *link; + +/*! + @property + @abstract Typed access to the user's username. + */ +@property (retain, nonatomic) NSString *username; + +/*! + @property + @abstract Typed access to the user's birthday. + */ +@property (retain, nonatomic) NSString *birthday; + +/*! + @property + @abstract Typed access to the user's current city. + */ +@property (retain, nonatomic) id location; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBInsights.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBInsights.h new file mode 100644 index 0000000..d1a35de --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBInsights.h @@ -0,0 +1,57 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBSession.h" + +/*! + @typedef FBInsightsFlushBehavior enum + + @abstract This enum has been deprecated in favor of FBAppEventsFlushBehavior. + */ +__attribute__ ((deprecated("use FBAppEventsFlushBehavior instead"))) +typedef enum { + FBInsightsFlushBehaviorAuto __attribute__ ((deprecated("use FBAppEventsFlushBehaviorAuto instead"))), + FBInsightsFlushBehaviorExplicitOnly __attribute__ ((deprecated("use FBAppEventsFlushBehaviorExplicitOnly instead"))), +} FBInsightsFlushBehavior; + +extern NSString *const FBInsightsLoggingResultNotification __attribute__((deprecated)); + +/*! + @class FBInsights + + @abstract This class has been deprecated in favor of FBAppEvents. + */ +__attribute__ ((deprecated("Use the FBAppEvents class instead"))) +@interface FBInsights : NSObject + ++ (NSString *)appVersion __attribute__((deprecated)); ++ (void)setAppVersion:(NSString *)appVersion __attribute__((deprecated("use [FBSettings setAppVersion] instead"))); + ++ (void)logPurchase:(double)purchaseAmount currency:(NSString *)currency __attribute__((deprecated("use [FBAppEvents logPurchase] instead"))); ++ (void)logPurchase:(double)purchaseAmount currency:(NSString *)currency parameters:(NSDictionary *)parameters __attribute__((deprecated("use [FBAppEvents logPurchase] instead"))); ++ (void)logPurchase:(double)purchaseAmount currency:(NSString *)currency parameters:(NSDictionary *)parameters session:(FBSession *)session __attribute__((deprecated("use [FBAppEvents logPurchase] instead"))); + ++ (void)logConversionPixel:(NSString *)pixelID valueOfPixel:(double)value __attribute__((deprecated)); ++ (void)logConversionPixel:(NSString *)pixelID valueOfPixel:(double)value session:(FBSession *)session __attribute__((deprecated)); + ++ (FBInsightsFlushBehavior)flushBehavior __attribute__((deprecated("use [FBAppEvents flushBehavior] instead"))); ++ (void)setFlushBehavior:(FBInsightsFlushBehavior)flushBehavior __attribute__((deprecated("use [FBAppEvents setFlushBehavior] instead"))); + ++ (void)flush __attribute__((deprecated("use [FBAppEvents flush] instead"))); + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBLoginView.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBLoginView.h new file mode 100644 index 0000000..4f75e3a --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBLoginView.h @@ -0,0 +1,189 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphUser.h" +#import "FBSession.h" + +@protocol FBLoginViewDelegate; + +/*! + @class FBLoginView + @abstract FBLoginView is a custom UIView that renders a button to login or logout based on the + state of `FBSession.activeSession` + + @discussion This view is closely associated with `FBSession.activeSession`. Upon initialization, + it will attempt to open an active session without UI if the current active session is not open. + + The FBLoginView instance also monitors for changes to the active session. + */ +@interface FBLoginView : UIView + +/*! + @abstract + The permissions to login with. Defaults to nil, meaning basic permissions. + + @discussion Methods and properties that specify permissions without a read or publish + qualification are deprecated; use of a read-qualified or publish-qualified alternative is preferred. + */ +@property (readwrite, copy) NSArray *permissions __attribute__((deprecated)); + +/*! + @abstract + The read permissions to request if the user logs in via this view. The basic_info permission must be explicitly requested at + first login, and is no longer inferred, (subject to an active migration.) + + @discussion + Note, that if read permissions are specified, then publish permissions should not be specified. + */ +@property (nonatomic, copy) NSArray *readPermissions; + +/*! + @abstract + The publish permissions to request if the user logs in via this view. + + @discussion + Note, that a defaultAudience value of FBSessionDefaultAudienceOnlyMe, FBSessionDefaultAudienceEveryone, or + FBSessionDefaultAudienceFriends should be set if publish permissions are specified. Additionally, when publish + permissions are specified, then read should not be specified. + */ +@property (nonatomic, copy) NSArray *publishPermissions; + +/*! + @abstract + The default audience to use, if publish permissions are requested at login time. + */ +@property (nonatomic, assign) FBSessionDefaultAudience defaultAudience; + +/*! + @abstract + The login behavior for the active session if the user logs in via this view + + @discussion + The default value is FBSessionLoginBehaviorUseSystemAccountIfPresent. + */ +@property (nonatomic) FBSessionLoginBehavior loginBehavior; + + +/*! + @abstract + Initializes and returns an `FBLoginView` object. The underlying session has basic permissions granted to it. + */ +- (id)init; + +/*! + @method + + @abstract + Initializes and returns an `FBLoginView` object constructed with the specified permissions. + + @param permissions An array of strings representing the permissions to request during the + authentication flow. A value of nil will indicates basic permissions. + + @discussion Methods and properties that specify permissions without a read or publish + qualification are deprecated; use of a read-qualified or publish-qualified alternative is preferred. + */ +- (id)initWithPermissions:(NSArray *)permissions __attribute__((deprecated)); + +/*! + @method + + @abstract + Initializes and returns an `FBLoginView` object constructed with the specified permissions. + + @param readPermissions An array of strings representing the read permissions to request during the + authentication flow. A value of nil will indicates basic permissions. + + */ +- (id)initWithReadPermissions:(NSArray *)readPermissions; + +/*! + @method + + @abstract + Initializes and returns an `FBLoginView` object constructed with the specified permissions. + + @param publishPermissions An array of strings representing the publish permissions to request during the + authentication flow. + + @param defaultAudience An audience for published posts; note that FBSessionDefaultAudienceNone is not valid + for permission requests that include publish or manage permissions. + + */ +- (id)initWithPublishPermissions:(NSArray *)publishPermissions + defaultAudience:(FBSessionDefaultAudience)defaultAudience; + +/*! + @abstract + The delegate object that receives updates for selection and display control. + */ +@property (nonatomic, assign) IBOutlet id delegate; + +@end + +/*! + @protocol + + @abstract + The `FBLoginViewDelegate` protocol defines the methods used to receive event + notifications from `FBLoginView` objects. + */ +@protocol FBLoginViewDelegate + +@optional + +/*! + @abstract + Tells the delegate that the view is now in logged in mode + + @param loginView The login view that transitioned its view mode + */ +- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView; + +/*! + @abstract + Tells the delegate that the view is has now fetched user info + + @param loginView The login view that transitioned its view mode + + @param user The user info object describing the logged in user + */ +- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView + user:(id)user; + +/*! + @abstract + Tells the delegate that the view is now in logged out mode + + @param loginView The login view that transitioned its view mode + */ +- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView; + +/*! + @abstract + Tells the delegate that there is a communication or authorization error. + + @param loginView The login view that transitioned its view mode + @param error An error object containing details of the error. + @discussion See https://developers.facebook.com/docs/technical-guides/iossdk/errors/ + for error handling best practices. + */ +- (void)loginView:(FBLoginView *)loginView + handleError:(NSError *)error; + +@end + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBNativeDialogs.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBNativeDialogs.h new file mode 100644 index 0000000..f8723fc --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBNativeDialogs.h @@ -0,0 +1,109 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +#import "FBAppCall.h" +#import "FBOpenGraphActionShareDialogParams.h" +#import "FBShareDialogParams.h" + +@class FBSession; +@protocol FBOpenGraphAction; + +// note that the following class and types are deprecated in favor of FBDialogs and its methods + +/*! + @typedef FBNativeDialogResult enum + + @abstract + Please note that this enum and its related methods have been deprecated, please migrate your + code to use `FBOSIntegratedShareDialogResult` and its related methods. + */ +typedef enum { + /*! Indicates that the dialog action completed successfully. */ + FBNativeDialogResultSucceeded, + /*! Indicates that the dialog action was cancelled (either by the user or the system). */ + FBNativeDialogResultCancelled, + /*! Indicates that the dialog could not be shown (because not on ios6 or ios6 auth was not used). */ + FBNativeDialogResultError +} FBNativeDialogResult +__attribute__((deprecated)); + +/*! + @typedef + + @abstract + Please note that `FBShareDialogHandler` and its related methods have been deprecated, please migrate your + code to use `FBOSIntegratedShareDialogHandler` and its related methods. + */ +typedef void (^FBShareDialogHandler)(FBNativeDialogResult result, NSError *error) +__attribute__((deprecated)); + +/*! + @class FBNativeDialogs + + @abstract + Please note that `FBNativeDialogs` has been deprecated, please migrate your + code to use `FBDialogs`. + */ +@interface FBNativeDialogs : NSObject + +/*! + @abstract + Please note that this method has been deprecated, please migrate your + code to use `FBDialogs` and the related method `presentOSIntegratedShareDialogModallyFrom`. + */ ++ (BOOL)presentShareDialogModallyFrom:(UIViewController*)viewController + initialText:(NSString*)initialText + image:(UIImage*)image + url:(NSURL*)url + handler:(FBShareDialogHandler)handler +__attribute__((deprecated)); + +/*! + @abstract + Please note that this method has been deprecated, please migrate your + code to use `FBDialogs` and the related method `presentOSIntegratedShareDialogModallyFrom`. + */ ++ (BOOL)presentShareDialogModallyFrom:(UIViewController*)viewController + initialText:(NSString*)initialText + images:(NSArray*)images + urls:(NSArray*)urls + handler:(FBShareDialogHandler)handler +__attribute__((deprecated)); + +/*! + @abstract + Please note that this method has been deprecated, please migrate your + code to use `FBDialogs` and the related method `presentOSIntegratedShareDialogModallyFrom`. + */ ++ (BOOL)presentShareDialogModallyFrom:(UIViewController*)viewController + session:(FBSession*)session + initialText:(NSString*)initialText + images:(NSArray*)images + urls:(NSArray*)urls + handler:(FBShareDialogHandler)handler +__attribute__((deprecated)); + +/*! + @abstract + Please note that this method has been deprecated, please migrate your + code to use `FBDialogs` and the related method `canPresentOSIntegratedShareDialogWithSession`. + */ ++ (BOOL)canPresentShareDialogWithSession:(FBSession*)session __attribute__((deprecated)); + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBOpenGraphAction.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBOpenGraphAction.h new file mode 100644 index 0000000..adc5ef4 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBOpenGraphAction.h @@ -0,0 +1,128 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphObject.h" + +@protocol FBGraphPlace; +@protocol FBGraphUser; + +/*! + @protocol + + @abstract + The `FBOpenGraphAction` protocol is the base protocol for use in posting and retrieving Open Graph actions. + It inherits from the `FBGraphObject` protocol; you may derive custome protocols from `FBOpenGraphAction` in order + implement typed access to your application's custom actions. + + @discussion + Represents an Open Graph custom action, to be used directly, or from which to + derive custom action protocols with custom properties. + */ +@protocol FBOpenGraphAction + +/*! + @property + @abstract Typed access to action's id + */ +@property (retain, nonatomic) NSString *id; + +/*! + @property + @abstract Typed access to action's start time + */ +@property (retain, nonatomic) NSString *start_time; + +/*! + @property + @abstract Typed access to action's end time + */ +@property (retain, nonatomic) NSString *end_time; + +/*! + @property + @abstract Typed access to action's publication time + */ +@property (retain, nonatomic) NSString *publish_time; + +/*! + @property + @abstract Typed access to action's creation time + */ +@property (retain, nonatomic) NSString *created_time; + +/*! + @property + @abstract Typed access to action's expiration time + */ +@property (retain, nonatomic) NSString *expires_time; + +/*! + @property + @abstract Typed access to action's ref + */ +@property (retain, nonatomic) NSString *ref; + +/*! + @property + @abstract Typed access to action's user message + */ +@property (retain, nonatomic) NSString *message; + +/*! + @property + @abstract Typed access to action's place + */ +@property (retain, nonatomic) id place; + +/*! + @property + @abstract Typed access to action's tags + */ +@property (retain, nonatomic) NSArray *tags; + +/*! + @property + @abstract Typed access to action's image(s) + */ +@property (retain, nonatomic) id image; + +/*! + @property + @abstract Typed access to action's from-user + */ +@property (retain, nonatomic) id from; + +/*! + @property + @abstract Typed access to action's likes + */ +@property (retain, nonatomic) NSArray *likes; + +/*! + @property + @abstract Typed access to action's application + */ +@property (retain, nonatomic) id application; + +/*! + @property + @abstract Typed access to action's comments + */ +@property (retain, nonatomic) NSArray *comments; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBOpenGraphActionShareDialogParams.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBOpenGraphActionShareDialogParams.h new file mode 100644 index 0000000..89f49d7 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBOpenGraphActionShareDialogParams.h @@ -0,0 +1,43 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBDialogsParams.h" +#import "FBOpenGraphAction.h" + +extern NSString *const FBPostObject; + +/*! + @class FBOpenGraphActionShareDialogParams + + @abstract + This object is used to encapsulate state for parameters to an Open Graph share + dialog that opens in the Facebook app. + */ +@interface FBOpenGraphActionShareDialogParams : FBDialogsParams + +/*! @abstract The Open Graph action to be published. */ +@property (nonatomic, retain) id action; + +/*! @abstract The name of the property representing the primary target of the Open + Graph action, which will be displayed as a preview in the dialog. */ +@property (nonatomic, copy) NSString *previewPropertyName; + +/*! @abstract The fully qualified type of the Open Graph action. */ +@property (nonatomic, copy) NSString *actionType; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBOpenGraphObject.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBOpenGraphObject.h new file mode 100644 index 0000000..be73a3b --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBOpenGraphObject.h @@ -0,0 +1,77 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBGraphObject.h" + +/*! + @protocol + + @abstract + The `FBOpenGraphObject` protocol is the base protocol for use in posting and retrieving Open Graph objects. + It inherits from the `FBGraphObject` protocol; you may derive custome protocols from `FBOpenGraphObject` in order + implement typed access to your application's custom objects. + + @discussion + Represents an Open Graph custom object, to be used directly, or from which to + derive custom action protocols with custom properties. + */ +@protocol FBOpenGraphObject + +/*! + @property + @abstract Typed access to the object's id + */ +@property (retain, nonatomic) NSString *id; + +/*! + @property + @abstract Typed access to the object's type, which is a string in the form mynamespace:mytype + */ +@property (retain, nonatomic) NSString *type; + +/*! + @property + @abstract Typed access to object's title + */ +@property (retain, nonatomic) NSString *title; + +/*! + @property + @abstract Typed access to the object's image property + */ +@property (retain, nonatomic) id image; + +/*! + @property + @abstract Typed access to the object's url property + */ +@property (retain, nonatomic) id url; + +/*! + @property + @abstract Typed access to the object's description property + */ +@property (retain, nonatomic) id description; + +/*! + @property + @abstract Typed access to action's data, which is a dictionary of custom properties + */ +@property (retain, nonatomic) id data; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBPlacePickerViewController.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBPlacePickerViewController.h new file mode 100644 index 0000000..735cf92 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBPlacePickerViewController.h @@ -0,0 +1,258 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +#import "FBCacheDescriptor.h" +#import "FBGraphPlace.h" +#import "FBSession.h" +#import "FBViewController.h" + +@protocol FBPlacePickerDelegate; + +/*! + @class FBPlacePickerViewController + + @abstract + The `FBPlacePickerViewController` class creates a controller object that manages + the user interface for displaying and selecting nearby places. + + @discussion + When the `FBPlacePickerViewController` view loads it creates a `UITableView` object + where the places near a given location will be displayed. You can access this view + through the `tableView` property. + + The place data can be pre-fetched and cached prior to using the view controller. The + cache is setup using an object that can trigger the + data fetch. Any place data requests will first check the cache and use that data. + If the place picker is being displayed cached data will initially be shown before + a fresh copy is retrieved. + + The `delegate` property may be set to an object that conforms to the + protocol. The `delegate` object will receive updates related to place selection and + data changes. The delegate can also be used to filter the places to display in the + picker. + */ +@interface FBPlacePickerViewController : FBViewController + +/*! + @abstract + Returns an outlet for the spinner used in the view controller. + */ +@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *spinner; + +/*! + @abstract + Returns an outlet for the table view managed by the view controller. + */ +@property (nonatomic, retain) IBOutlet UITableView *tableView; + +/*! + @abstract + Addtional fields to fetch when making the Graph API call to get place data. + */ +@property (nonatomic, copy) NSSet *fieldsForRequest; + +/*! + @abstract + A Boolean value that indicates whether place profile pictures are displayed. + */ +@property (nonatomic) BOOL itemPicturesEnabled; + +/*! + @abstract + The coordinates to use for place discovery. + */ +@property (nonatomic) CLLocationCoordinate2D locationCoordinate; + +/*! + @abstract + The radius to use for place discovery. + */ +@property (nonatomic) NSInteger radiusInMeters; + +/*! + @abstract + The maximum number of places to fetch. + */ +@property (nonatomic) NSInteger resultsLimit; + +/*! + @abstract + The search words used to narrow down the results returned. + */ +@property (nonatomic, copy) NSString *searchText; + +/*! + @abstract + The session that is used in the request for place data. + */ +@property (nonatomic, retain) FBSession *session; + +/*! + @abstract + The place that is currently selected in the view. This is nil + if nothing is selected. + */ +@property (nonatomic, retain, readonly) id selection; + +/*! + @abstract + Clears the current selection, so the picker is ready for a fresh use. + */ +- (void)clearSelection; + +/*! + @abstract + Initializes a place picker view controller. + */ +- (id)init; + +/*! + @abstract + Initializes a place picker view controller. + + @param aDecoder An unarchiver object. + */ +- (id)initWithCoder:(NSCoder *)aDecoder; + +/*! + @abstract + Initializes a place picker view controller. + + @param nibNameOrNil The name of the nib file to associate with the view controller. The nib file name should not contain any leading path information. If you specify nil, the nibName property is set to nil. + @param nibBundleOrNil The bundle in which to search for the nib file. This method looks for the nib file in the bundle's language-specific project directories first, followed by the Resources directory. If nil, this method looks for the nib file in the main bundle. + */ +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil; + +/*! + @abstract + Configures the properties used in the caching data queries. + + @discussion + Cache descriptors are used to fetch and cache the data used by the view controller. + If the view controller finds a cached copy of the data, it will + first display the cached content then fetch a fresh copy from the server. + + @param cacheDescriptor The containing the cache query properties. + */ +- (void)configureUsingCachedDescriptor:(FBCacheDescriptor*)cacheDescriptor; + +/*! + @abstract + Initiates a query to get place data the first time or in response to changes in + the search criteria, filter, or location information. + + + @discussion + A cached copy will be returned if available. The cached view is temporary until a fresh copy is + retrieved from the server. It is legal to call this more than once. + */ +- (void)loadData; + +/*! + @abstract + Updates the view locally without fetching data from the server or from cache. + + @discussion + Use this if the filter properties change. This may affect the order or + display of information. + */ +- (void)updateView; + +/*! + @method + + @abstract + Creates a cache descriptor with additional fields and a profile ID for use with the + `FBPlacePickerViewController` object. + + @discussion + An `FBCacheDescriptor` object may be used to pre-fetch data before it is used by + the view controller. It may also be used to configure the `FBPlacePickerViewController` + object. + + @param locationCoordinate The coordinates to use for place discovery. + @param radiusInMeters The radius to use for place discovery. + @param searchText The search words used to narrow down the results returned. + @param resultsLimit The maximum number of places to fetch. + @param fieldsForRequest Addtional fields to fetch when making the Graph API call to get place data. + */ ++ (FBCacheDescriptor*)cacheDescriptorWithLocationCoordinate:(CLLocationCoordinate2D)locationCoordinate + radiusInMeters:(NSInteger)radiusInMeters + searchText:(NSString*)searchText + resultsLimit:(NSInteger)resultsLimit + fieldsForRequest:(NSSet*)fieldsForRequest; + +@end + +/*! + @protocol + + @abstract + The `FBPlacePickerDelegate` protocol defines the methods used to receive event + notifications and allow for deeper control of the + view. + */ +@protocol FBPlacePickerDelegate +@optional + +/*! + @abstract + Tells the delegate that data has been loaded. + + @discussion + The object's `tableView` property is automatically + reloaded when this happens. However, if another table view, for example the + `UISearchBar` is showing data, then it may also need to be reloaded. + + @param placePicker The place picker view controller whose data changed. + */ +- (void)placePickerViewControllerDataDidChange:(FBPlacePickerViewController *)placePicker; + +/*! + @abstract + Tells the delegate that the selection has changed. + + @param placePicker The place picker view controller whose selection changed. + */ +- (void)placePickerViewControllerSelectionDidChange:(FBPlacePickerViewController *)placePicker; + +/*! + @abstract + Asks the delegate whether to include a place in the list. + + @discussion + This can be used to implement a search bar that filters the places list. + + @param placePicker The place picker view controller that is requesting this information. + @param place An object representing the place. + */ +- (BOOL)placePickerViewController:(FBPlacePickerViewController *)placePicker + shouldIncludePlace:(id )place; + +/*! + @abstract + Called if there is a communication error. + + @param placePicker The place picker view controller that encountered the error. + @param error An error object containing details of the error. + */ +- (void)placePickerViewController:(FBPlacePickerViewController *)placePicker + handleError:(NSError *)error; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBProfilePictureView.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBProfilePictureView.h new file mode 100644 index 0000000..c1f31c6 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBProfilePictureView.h @@ -0,0 +1,80 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +/*! + @typedef FBProfilePictureCropping enum + + @abstract + Type used to specify the cropping treatment of the profile picture. + + @discussion + */ +typedef enum { + + /*! Square (default) - the square version that the Facebook user defined. */ + FBProfilePictureCroppingSquare = 0, + + /*! Original - the original profile picture, as uploaded. */ + FBProfilePictureCroppingOriginal = 1 + +} FBProfilePictureCropping; + +/*! + @class + @abstract + An instance of `FBProfilePictureView` is used to display a profile picture. + + The default behavior of this control is to center the profile picture + in the view and shrinks it, if necessary, to the view's bounds, preserving the aspect ratio. The smallest + possible image is downloaded to ensure that scaling up never happens. Resizing the view may result in + a different size of the image being loaded. Canonical image sizes are documented in the "Pictures" section + of https://developers.facebook.com/docs/reference/api. + */ +@interface FBProfilePictureView : UIView + +/*! + @abstract + The Facebook ID of the user, place or object for which a picture should be fetched and displayed. + */ +@property (copy, nonatomic) NSString* profileID; + +/*! + @abstract + The cropping to use for the profile picture. + */ +@property (nonatomic) FBProfilePictureCropping pictureCropping; + +/*! + @abstract + Initializes and returns a profile view object. + */ +- (id)init; + + +/*! + @abstract + Initializes and returns a profile view object for the given Facebook ID and cropping. + + @param profileID The Facebook ID of the user, place or object for which a picture should be fetched and displayed. + @param pictureCropping The cropping to use for the profile picture. + */ +- (id)initWithProfileID:(NSString*)profileID + pictureCropping:(FBProfilePictureCropping)pictureCropping; + + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBRequest.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBRequest.h new file mode 100644 index 0000000..187bd7a --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBRequest.h @@ -0,0 +1,672 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +#import "FBGraphObject.h" +#import "FBOpenGraphAction.h" +#import "FBOpenGraphObject.h" +#import "FBRequestConnection.h" + +/*! The base URL used for graph requests */ +extern NSString* const FBGraphBasePath __attribute__((deprecated)); + +// up-front decl's +@protocol FBRequestDelegate; +@class FBSession; +@class UIImage; + +/*! + @typedef FBRequestState + + @abstract + Deprecated - do not use in new code. + + @discussion + FBRequestState is retained from earlier versions of the SDK to give existing + apps time to remove dependency on this. + + @deprecated +*/ +typedef NSUInteger FBRequestState __attribute__((deprecated)); + +/*! + @class FBRequest + + @abstract + The `FBRequest` object is used to setup and manage requests to Facebook Graph + and REST APIs. This class provides helper methods that simplify the connection + and response handling. + + @discussion + An object is required for all authenticated uses of `FBRequest`. + Requests that do not require an unauthenticated user are also supported and + do not require an object to be passed in. + + An instance of `FBRequest` represents the arguments and setup for a connection + to Facebook. After creating an `FBRequest` object it can be used to setup a + connection to Facebook through the object. The + object is created to manage a single connection. To + cancel a connection use the instance method in the class. + + An `FBRequest` object may be reused to issue multiple connections to Facebook. + However each instance will manage one connection. + + Class and instance methods prefixed with **start* ** can be used to perform the + request setup and initiate the connection in a single call. + +*/ +@interface FBRequest : NSObject { +@private + id _delegate; + NSString* _url; + NSURLConnection* _connection; + NSMutableData* _responseText; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + FBRequestState _state; +#pragma GCC diagnostic pop + NSError* _error; + BOOL _sessionDidExpire; + id _graphObject; +} + +/*! + @methodgroup Creating a request + + @method + Calls with the default parameters. +*/ +- (id)init; + +/*! + @method + Calls with default parameters + except for the ones provided to this method. + + @param session The session object representing the identity of the Facebook user making + the request. A nil value indicates a request that requires no token; to + use the active session pass `[FBSession activeSession]`. + + @param graphPath The Graph API endpoint to use for the request, for example "me". +*/ +- (id)initWithSession:(FBSession*)session + graphPath:(NSString *)graphPath; + +/*! + @method + + @abstract + Initializes an `FBRequest` object for a Graph API request call. + + @discussion + Note that this only sets properties on the `FBRequest` object. + + To send the request, initialize an object, add this request, + and send <[FBRequestConnection start]>. See other methods on this + class for shortcuts to simplify this process. + + @param session The session object representing the identity of the Facebook user making + the request. A nil value indicates a request that requires no token; to + use the active session pass `[FBSession activeSession]`. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param parameters The parameters for the request. A value of nil sends only the automatically handled + parameters, for example, the access token. The default is nil. + + @param HTTPMethod The HTTP method to use for the request. The default is value of nil implies a GET. +*/ +- (id)initWithSession:(FBSession*)session + graphPath:(NSString *)graphPath + parameters:(NSDictionary *)parameters + HTTPMethod:(NSString *)HTTPMethod; + +/*! + @method + @abstract + Initialize a `FBRequest` object that will do a graph request. + + @discussion + Note that this only sets properties on the `FBRequest`. + + To send the request, initialize a , add this request, + and send <[FBRequestConnection start]>. See other methods on this + class for shortcuts to simplify this process. + + @param session The session object representing the identity of the Facebook user making + the request. A nil value indicates a request that requires no token; to + use the active session pass `[FBSession activeSession]`. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param graphObject An object or open graph action to post. +*/ +- (id)initForPostWithSession:(FBSession*)session + graphPath:(NSString *)graphPath + graphObject:(id)graphObject; + +/*! + @method + @abstract + Initialize a `FBRequest` object that will do a rest API request. + + @discussion + Prefer to use graph requests instead of this where possible. + + Note that this only sets properties on the `FBRequest`. + + To send the request, initialize a , add this request, + and send <[FBRequestConnection start]>. See other methods on this + class for shortcuts to simplify this process. + + @param session The session object representing the identity of the Facebook user making + the request. A nil value indicates a request that requires no token; to + use the active session pass `[FBSession activeSession]`. + + @param restMethod A valid REST API method. + + @param parameters The parameters for the request. A value of nil sends only the automatically handled + parameters, for example, the access token. The default is nil. + + @param HTTPMethod The HTTP method to use for the request. The default is value of nil implies a GET. + +*/ +- (id)initWithSession:(FBSession*)session + restMethod:(NSString *)restMethod + parameters:(NSDictionary *)parameters + HTTPMethod:(NSString *)HTTPMethod; + +/*! + @abstract + The parameters for the request. + + @discussion + May be used to read the parameters that were automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. + + `NSString` parameters are used to generate URL parameter values or JSON + parameters. `NSData` and `UIImage` parameters are added as attachments + to the HTTP body and referenced by name in the URL and/or JSON. +*/ +@property (nonatomic, retain, readonly) NSMutableDictionary *parameters; + +/*! + @abstract + The session object to use for the request. + + @discussion + May be used to read the session that was automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. +*/ +@property (nonatomic, retain) FBSession *session; + +/*! + @abstract + The Graph API endpoint to use for the request, for example "me". + + @discussion + May be used to read the Graph API endpoint that was automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. +*/ +@property (nonatomic, copy) NSString *graphPath; + +/*! + @abstract + A valid REST API method. + + @discussion + May be used to read the REST method that was automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. + + Use the Graph API equivalent of the API if it exists as the REST API + method is deprecated if there is a Graph API equivalent. +*/ +@property (nonatomic, copy) NSString *restMethod; + +/*! + @abstract + The HTTPMethod to use for the request, for example "GET" or "POST". + + @discussion + May be used to read the HTTP method that was automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. +*/ +@property (nonatomic, copy) NSString *HTTPMethod; + +/*! + @abstract + The graph object to post with the request. + + @discussion + May be used to read the graph object that was automatically set during + the object initiliazation. Make any required modifications prior to + sending the request. +*/ +@property (nonatomic, retain) id graphObject; + +/*! + @methodgroup Instance methods +*/ + +/*! + @method + + @abstract + Starts a connection to the Facebook API. + + @discussion + This is used to start an API call to Facebook and call the block when the + request completes with a success, error, or cancel. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + The handler will be invoked on the main thread. +*/ +- (FBRequestConnection*)startWithCompletionHandler:(FBRequestHandler)handler; + +/*! + @methodgroup FBRequestConnection start methods + + @abstract + These methods start an . + + @discussion + These methods simplify the process of preparing a request and starting + the connection. The methods handle initializing an `FBRequest` object, + initializing a object, adding the `FBRequest` + object to the to the , and finally starting the + connection. +*/ + +/*! + @methodgroup FBRequest factory methods + + @abstract + These methods initialize a `FBRequest` for common scenarios. + + @discussion + These simplify the process of preparing a request to send. These + initialize a `FBRequest` based on strongly typed parameters that are + specific to the scenario. + + These method do not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. +*/ + +// request* +// +// Summary: +// Helper methods used to create common request objects which can be used to create single or batch connections +// +// session: - the session object representing the identity of the +// Facebook user making the request; nil implies an +// unauthenticated request; default=nil + +/*! + @method + + @abstract + Creates a request representing a Graph API call to the "me" endpoint, using the active session. + + @discussion + Simplifies preparing a request to retrieve the user's identity. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + A successful Graph API call will return an object representing the + user's identity. + + Note you may change the session property after construction if a session other than + the active session is preferred. +*/ ++ (FBRequest *)requestForMe; + +/*! + @method + + @abstract + Creates a request representing a Graph API call to the "me/friends" endpoint using the active session. + + @discussion + Simplifies preparing a request to retrieve the user's friends. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + A successful Graph API call will return an array of objects representing the + user's friends. +*/ ++ (FBRequest *)requestForMyFriends; + +/*! + @method + + @abstract + Creates a request representing a Graph API call to upload a photo to the app's album using the active session. + + @discussion + Simplifies preparing a request to post a photo. + + To post a photo to a specific album, get the `FBRequest` returned from this method + call, then modify the request parameters by adding the album ID to an "album" key. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param photo A `UIImage` for the photo to upload. + */ ++ (FBRequest *)requestForUploadPhoto:(UIImage *)photo; + +/*! + @method + + @abstract + Creates a request representing a status update. + + @discussion + Simplifies preparing a request to post a status update. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param message The message to post. + */ ++ (FBRequest *)requestForPostStatusUpdate:(NSString *)message; + +/*! + @method + + @abstract + Creates a request representing a status update. + + @discussion + Simplifies preparing a request to post a status update. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param message The message to post. + @param place The place to checkin with, or nil. Place may be an fbid or a + graph object representing a place. + @param tags Array of friends to tag in the status update, each element + may be an fbid or a graph object representing a user. + */ ++ (FBRequest *)requestForPostStatusUpdate:(NSString *)message + place:(id)place + tags:(id)tags; + +/*! + @method + + @abstract + Creates a request representing a Graph API call to the "search" endpoint + for a given location using the active session. + + @discussion + Simplifies preparing a request to search for places near a coordinate. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + A successful Graph API call will return an array of objects representing + the nearby locations. + + @param coordinate The search coordinates. + + @param radius The search radius in meters. + + @param limit The maxiumum number of results to return. It is + possible to receive fewer than this because of the radius and because of server limits. + + @param searchText The text to use in the query to narrow the set of places + returned. +*/ ++ (FBRequest *)requestForPlacesSearchAtCoordinate:(CLLocationCoordinate2D)coordinate + radiusInMeters:(NSInteger)radius + resultsLimit:(NSInteger)limit + searchText:(NSString*)searchText; + +/*! + @method + + @abstract + Creates a request representing the Graph API call to retrieve a Custom Audience "thirdy party ID" for the app's Facebook user. + Callers will send this ID back to their own servers, collect up a set to create a Facebook Custom Audience with, + and then use the resultant Custom Audience to target ads. + + @param session The FBSession to use to establish the user's identity for users logged into Facebook through this app. + If `nil`, then the activeSession is used. + + @discussion + This method will throw an exception if <[FBSettings defaultAppID]> is `nil`. The appID won't be nil when the pList + includes the appID, or if it's explicitly set. + + The JSON in the request's response will include an "custom_audience_third_party_id" key/value pair, with the value being the ID retrieved. + This ID is an encrypted encoding of the Facebook user's ID and the invoking Facebook app ID. + Multiple calls with the same user will return different IDs, thus these IDs cannot be used to correlate behavior + across devices or applications, and are only meaningful when sent back to Facebook for creating Custom Audiences. + + The ID retrieved represents the Facebook user identified in the following way: if the specified session (or activeSession if the specified + session is `nil`) is open, the ID will represent the user associated with the activeSession; otherwise the ID will represent the user logged into the + native Facebook app on the device. If there is no native Facebook app, no one is logged into it, or the user has opted out + at the iOS level from ad tracking, then a `nil` ID will be returned. + + This method returns `nil` if either the user has opted-out (via iOS) from Ad Tracking, the app itself has limited event usage + via the `[FBAppEvents setLimitEventUsage]` flag, or a specific Facebook user cannot be identified. + */ ++ (FBRequest *)requestForCustomAudienceThirdPartyID:(FBSession *)session; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to make a Graph API call for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + */ ++ (FBRequest *)requestForGraphPath:(NSString*)graphPath; + +/*! + @method + + @abstract + Creates request representing a DELETE to a object. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param object This can be an NSString, NSNumber or NSDictionary representing an object to delete + */ ++ (FBRequest *)requestForDeleteObject:(id)object; + +/*! + @method + + @abstract + Creates a request representing a POST for a graph object. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param graphObject An object or open graph action to post. + + @discussion This method is typically used for posting an open graph action. If you are only + posting an open graph object (without an action), consider using `requestForPostOpenGraphObject:` + */ ++ (FBRequest *)requestForPostWithGraphPath:(NSString*)graphPath + graphObject:(id)graphObject; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to make a Graph API call for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param parameters The parameters for the request. A value of nil sends only the automatically handled parameters, for example, the access token. The default is nil. + + @param HTTPMethod The HTTP method to use for the request. A nil value implies a GET. + */ ++ (FBRequest *)requestWithGraphPath:(NSString*)graphPath + parameters:(NSDictionary*)parameters + HTTPMethod:(NSString*)HTTPMethod; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to create a user owned + Open Graph object for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param object The Open Graph object to create. Some common expected fields include "title", "image", "url", etc. + */ ++ (FBRequest *)requestForPostOpenGraphObject:(id)object; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to create a user owned + Open Graph object for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param type The fully-specified Open Graph object type (e.g., my_app_namespace:my_object_name) + @param title The title of the Open Graph object. + @param image The link to an image to be associated with the Open Graph object. + @param url The url to be associated with the Open Graph object. + @param description The description to be associated with the object. + @param objectProperties Any additional properties for the Open Graph object. + */ ++ (FBRequest *)requestForPostOpenGraphObjectWithType:(NSString *)type + title:(NSString *)title + image:(id)image + url:(id)url + description:(NSString *)description + objectProperties:(NSDictionary *)objectProperties; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to update a user owned + Open Graph object for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param object The Open Graph object to update the existing object with. + */ ++ (FBRequest *)requestForUpdateOpenGraphObject:(id)object; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to update a user owned + Open Graph object for the active session. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param objectId The id of the Open Graph object to update. + @param title The updated title of the Open Graph object. + @param image The updated link to an image to be associated with the Open Graph object. + @param url The updated url to be associated with the Open Graph object. + @param description The updated description of the Open Graph object. + @param objectProperties Any additional properties to update for the Open Graph object. + */ ++ (FBRequest *)requestForUpdateOpenGraphObjectWithId:(id)objectId + title:(NSString *)title + image:(id)image + url:(id)url + description:(NSString *)description + objectProperties:(NSDictionary *)objectProperties; + +/*! + @method + + @abstract + Returns a newly initialized request object that can be used to upload an image + to create a staging resource. Staging resources allow you to post binary data + such as images, in preparation for a post of an open graph object or action + which references the image. The URI returned when uploading a staging resource + may be passed as the image property for an open graph object or action. + + @discussion + This method simplifies the preparation of a Graph API call. + + This method does not initialize an object. To initiate the API + call first instantiate an object, add the request to this object, + then call the `start` method on the connection instance. + + @param image A `UIImage` for the image to upload. + */ ++ (FBRequest *)requestForUploadStagingResourceWithImage:(UIImage *)image; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBRequestConnection.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBRequestConnection.h new file mode 100644 index 0000000..140267f --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBRequestConnection.h @@ -0,0 +1,626 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +#import "FBGraphObject.h" + +// up-front decl's +@class FBRequest; +@class FBRequestConnection; +@class FBSession; +@class UIImage; + + +/*! + @attribute beta true + + @typedef FBRequestConnectionErrorBehavior enum + + @abstract Describes what automatic error handling behaviors to provide (if any). + + @discussion This is a bitflag enum that can be composed of different values. + + See FBError.h and FBErrorUtility.h for error category and user message details. + */ +typedef enum { + /*! The default behavior of none */ + FBRequestConnectionErrorBehaviorNone = 0, + + /*! This will retry any requests whose error category is classified as `FBErrorCategoryRetry`. + If the retry fails, the normal handler is invoked. */ + FBRequestConnectionErrorBehaviorRetry = 1, + + /*! This will automatically surface any SDK provided userMessage (at most one), after + retry attempts, but before any reconnects are tried. The alert will have one button + whose text can be localized with the key "FBE:AlertMessageButton". + + You should not display your own alert views in your request handler when specifying this + behavior. + */ + FBRequestConnectionErrorBehaviorAlertUser = 2, + + /*! This will automatically reconnect a session if the request failed due to an invalid token + that would otherwise close the session (such as an expired token or password change). Note + this will NOT reconnect a session if the user had uninstalled the app, or if the user had + disabled the app's slider in their privacy settings (in cases of iOS 6 system auth). + If the session is reconnected, this will transition the session state to FBSessionStateTokenExtended + which will invoke any state change handlers. Otherwise, the session is closed as normal. + + This behavior should not be used if the FBRequestConnection contains multiple + session instances. Further, when this behavior is used, you must not request new permissions + for the session until the connection is completed. + + Lastly, you should avoid using additional FBRequestConnections with the same session because + that will be subject to race conditions. + */ + FBRequestConnectionErrorBehaviorReconnectSession = 4, +} FBRequestConnectionErrorBehavior; + +/*! + Normally requests return JSON data that is parsed into a set of `NSDictionary` + and `NSArray` objects. + + When a request returns a non-JSON response, that response is packaged in + a `NSDictionary` using FBNonJSONResponseProperty as the key and the literal + response as the value. +*/ +extern NSString *const FBNonJSONResponseProperty; + +/*! + @typedef FBRequestHandler + + @abstract + A block that is passed to addRequest to register for a callback with the results of that + request once the connection completes. + + @discussion + Pass a block of this type when calling addRequest. This will be called once + the request completes. The call occurs on the UI thread. + + @param connection The `FBRequestConnection` that sent the request. + + @param result The result of the request. This is a translation of + JSON data to `NSDictionary` and `NSArray` objects. This + is nil if there was an error. + + @param error The `NSError` representing any error that occurred. + +*/ +typedef void (^FBRequestHandler)(FBRequestConnection *connection, + id result, + NSError *error); + +/*! + @class FBRequestConnection + + @abstract + The `FBRequestConnection` represents a single connection to Facebook to service a request. + + @discussion + The request settings are encapsulated in a reusable object. The + `FBRequestConnection` object encapsulates the concerns of a single communication + e.g. starting a connection, canceling a connection, or batching requests. + +*/ +@interface FBRequestConnection : NSObject + +/*! + @methodgroup Creating a request +*/ + +/*! + @method + + Calls with a default timeout of 180 seconds. +*/ +- (id)init; + +/*! + @method + + @abstract + `FBRequestConnection` objects are used to issue one or more requests as a single + request/response connection with Facebook. + + @discussion + For a single request, the usual method for creating an `FBRequestConnection` + object is to call one of the **start* ** methods on . However, it is + allowable to init an `FBRequestConnection` object directly, and call + to add one or more request objects to the + connection, before calling start. + + Note that if requests are part of a batch, they must have an open + FBSession that has an access token associated with it. Alternatively a default App ID + must be set either in the plist or through an explicit call to <[FBSession defaultAppID]>. + + @param timeout The `NSTimeInterval` (seconds) to wait for a response before giving up. +*/ + +- (id)initWithTimeout:(NSTimeInterval)timeout; + +// properties + +/*! + @abstract + The request that will be sent to the server. + + @discussion + This property can be used to create a `NSURLRequest` without using + `FBRequestConnection` to send that request. It is legal to set this property + in which case the provided `NSMutableURLRequest` will be used instead. However, + the `NSMutableURLRequest` must result in an appropriate response. Furthermore, once + this property has been set, no more objects can be added to this + `FBRequestConnection`. +*/ +@property (nonatomic, retain, readwrite) NSMutableURLRequest *urlRequest; + +/*! + @abstract + The raw response that was returned from the server. (readonly) + + @discussion + This property can be used to inspect HTTP headers that were returned from + the server. + + The property is nil until the request completes. If there was a response + then this property will be non-nil during the FBRequestHandler callback. +*/ +@property (nonatomic, retain, readonly) NSHTTPURLResponse *urlResponse; + +/*! + @attribute beta true + + @abstract Set the automatic error handling behaviors. + @discussion + + This must be set before any requests are added. + + When using retry behaviors, note the FBRequestConnection instance + passed to the FBRequestHandler may be a different instance that the + one the requests were originally started on. +*/ +@property (nonatomic, assign) FBRequestConnectionErrorBehavior errorBehavior; + +/*! + @methodgroup Adding requests +*/ + +/*! + @method + + @abstract + This method adds an object to this connection. + + @discussion + The completion handler is retained until the block is called upon the + completion or cancellation of the connection. + + @param request A request to be included in the round-trip when start is called. + @param handler A handler to call back when the round-trip completes or times out. + The handler will be invoked on the main thread. +*/ +- (void)addRequest:(FBRequest*)request + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + This method adds an object to this connection. + + @discussion + The completion handler is retained until the block is called upon the + completion or cancellation of the connection. This request can be named + to allow for using the request's response in a subsequent request. + + @param request A request to be included in the round-trip when start is called. + + @param handler A handler to call back when the round-trip completes or times out. + The handler will be invoked on the main thread. + + @param name An optional name for this request. This can be used to feed + the results of one request to the input of another in the same + `FBRequestConnection` as described in + [Graph API Batch Requests]( https://developers.facebook.com/docs/reference/api/batch/ ). +*/ +- (void)addRequest:(FBRequest*)request + completionHandler:(FBRequestHandler)handler + batchEntryName:(NSString*)name; + +/*! + @method + + @abstract + This method adds an object to this connection. + + @discussion + The completion handler is retained until the block is called upon the + completion or cancellation of the connection. This request can be named + to allow for using the request's response in a subsequent request. + + @param request A request to be included in the round-trip when start is called. + + @param handler A handler to call back when the round-trip completes or times out. + + @param batchParameters The optional dictionary of parameters to include for this request + as described in [Graph API Batch Requests]( https://developers.facebook.com/docs/reference/api/batch/ ). + Examples include "depends_on", "name", or "omit_response_on_success". + */ +- (void)addRequest:(FBRequest*)request + completionHandler:(FBRequestHandler)handler + batchParameters:(NSDictionary*)batchParameters; + +/*! + @methodgroup Instance methods +*/ + +/*! + @method + + @abstract + This method starts a connection with the server and is capable of handling all of the + requests that were added to the connection. + + @discussion + Errors are reported via the handler callback, even in cases where no + communication is attempted by the implementation of `FBRequestConnection`. In + such cases multiple error conditions may apply, and if so the following + priority (highest to lowest) is used: + + - `FBRequestConnectionInvalidRequestKey` -- this error is reported when an + cannot be encoded for transmission. + + - `FBRequestConnectionInvalidBatchKey` -- this error is reported when any + request in the connection cannot be encoded for transmission with the batch. + In this scenario all requests fail. + + This method cannot be called twice for an `FBRequestConnection` instance. +*/ +- (void)start; + +/*! + @method + + @abstract + Signals that a connection should be logically terminated as the + application is no longer interested in a response. + + @discussion + Synchronously calls any handlers indicating the request was cancelled. Cancel + does not guarantee that the request-related processing will cease. It + does promise that all handlers will complete before the cancel returns. A call to + cancel prior to a start implies a cancellation of all requests associated + with the connection. +*/ +- (void)cancel; + +/*! + @method + + @abstract + Simple method to make a graph API request for user info (/me), creates an + then uses an object to start the connection with Facebook. The + request uses the active session represented by `[FBSession activeSession]`. + + See + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForMeWithCompletionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to make a graph API request for user friends (/me/friends), creates an + then uses an object to start the connection with Facebook. The + request uses the active session represented by `[FBSession activeSession]`. + + See + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForMyFriendsWithCompletionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to make a graph API post of a photo. The request + uses the active session represented by `[FBSession activeSession]`. + + @param photo A `UIImage` for the photo to upload. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForUploadPhoto:(UIImage *)photo + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to make a graph API post of a status update. The request + uses the active session represented by `[FBSession activeSession]`. + + @param message The message to post. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection *)startForPostStatusUpdate:(NSString *)message + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to make a graph API post of a status update. The request + uses the active session represented by `[FBSession activeSession]`. + + @param message The message to post. + @param place The place to checkin with, or nil. Place may be an fbid or a + graph object representing a place. + @param tags Array of friends to tag in the status update, each element + may be an fbid or a graph object representing a user. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection *)startForPostStatusUpdate:(NSString *)message + place:(id)place + tags:(id)tags + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Starts a request representing a Graph API call to the "search" endpoint + for a given location using the active session. + + @discussion + Simplifies starting a request to search for places near a coordinate. + + This method creates the necessary object and initializes and + starts an object. A successful Graph API call will + return an array of objects representing the nearby locations. + + @param coordinate The search coordinates. + + @param radius The search radius in meters. + + @param limit The maxiumum number of results to return. It is + possible to receive fewer than this because of the + radius and because of server limits. + + @param searchText The text to use in the query to narrow the set of places + returned. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForPlacesSearchAtCoordinate:(CLLocationCoordinate2D)coordinate + radiusInMeters:(NSInteger)radius + resultsLimit:(NSInteger)limit + searchText:(NSString*)searchText + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Starts a request representing the Graph API call to retrieve a Custom Audience "third party ID" for the app's Facebook user. + Callers will send this ID back to their own servers, collect up a set to create a Facebook Custom Audience with, + and then use the resultant Custom Audience to target ads. + + @param session The FBSession to use to establish the user's identity for users logged into Facebook through this app. + If `nil`, then the activeSession is used. + + @discussion + This method will throw an exception if <[FBSettings defaultAppID]> is `nil`. The appID won't be nil when the pList + includes the appID, or if it's explicitly set. + + The JSON in the request's response will include an "custom_audience_third_party_id" key/value pair, with the value being the ID retrieved. + This ID is an encrypted encoding of the Facebook user's ID and the invoking Facebook app ID. + Multiple calls with the same user will return different IDs, thus these IDs cannot be used to correlate behavior + across devices or applications, and are only meaningful when sent back to Facebook for creating Custom Audiences. + + The ID retrieved represents the Facebook user identified in the following way: if the specified session (or activeSession if the specified + session is `nil`) is open, the ID will represent the user associated with the activeSession; otherwise the ID will represent the user logged into the + native Facebook app on the device. If there is no native Facebook app, no one is logged into it, or the user has opted out + at the iOS level from ad tracking, then a `nil` ID will be returned. + + This method returns `nil` if either the user has opted-out (via iOS) from Ad Tracking, the app itself has limited event usage + via the `[FBAppEvents setLimitEventUsage]` flag, or a specific Facebook user cannot be identified. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForCustomAudienceThirdPartyID:(FBSession *)session + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to make a graph API request, creates an object for HTTP GET, + then uses an object to start the connection with Facebook. The + request uses the active session represented by `[FBSession activeSession]`. + + See + + @param graphPath The Graph API endpoint to use for the request, for example "me". + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startWithGraphPath:(NSString*)graphPath + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to delete an object using the graph API, creates an object for + HTTP DELETE, then uses an object to start the connection with Facebook. + The request uses the active session represented by `[FBSession activeSession]`. + + @param object The object to delete, may be an NSString or NSNumber representing an fbid or an NSDictionary with an id property + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForDeleteObject:(id)object + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Simple method to post an object using the graph API, creates an object for + HTTP POST, then uses to start a connection with Facebook. The request uses + the active session represented by `[FBSession activeSession]`. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param graphObject An object or open graph action to post. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + + @discussion This method is typically used for posting an open graph action. If you are only + posting an open graph object (without an action), consider using `startForPostOpenGraphObject:completionHandler:` +*/ ++ (FBRequestConnection*)startForPostWithGraphPath:(NSString*)graphPath + graphObject:(id)graphObject + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Creates an `FBRequest` object for a Graph API call, instantiate an + object, add the request to the newly created + connection and finally start the connection. Use this method for + specifying the request parameters and HTTP Method. The request uses + the active session represented by `[FBSession activeSession]`. + + @param graphPath The Graph API endpoint to use for the request, for example "me". + + @param parameters The parameters for the request. A value of nil sends only the automatically handled parameters, for example, the access token. The default is nil. + + @param HTTPMethod The HTTP method to use for the request. A nil value implies a GET. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startWithGraphPath:(NSString*)graphPath + parameters:(NSDictionary*)parameters + HTTPMethod:(NSString*)HTTPMethod + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Creates an `FBRequest` for creating a user owned Open Graph object, instantiate a + object, add the request to the newly created + connection and finally start the connection. The request uses + the active session represented by `[FBSession activeSession]`. + + @param object The Open Graph object to create. Some common expected fields include "title", "image", "url", etc. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForPostOpenGraphObject:(id)object + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Creates an `FBRequest` for creating a user owned Open Graph object, instantiate a + object, add the request to the newly created + connection and finally start the connection. The request uses + the active session represented by `[FBSession activeSession]`. + + @param type The fully-specified Open Graph object type (e.g., my_app_namespace:my_object_name) + @param title The title of the Open Graph object. + @param image The link to an image to be associated with the Open Graph object. + @param url The url to be associated with the Open Graph object. + @param description The description for the object. + @param objectProperties Any additional properties for the Open Graph object. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForPostOpenGraphObjectWithType:(NSString *)type + title:(NSString *)title + image:(id)image + url:(id)url + description:(NSString *)description + objectProperties:(NSDictionary *)objectProperties + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Creates an `FBRequest` for updating a user owned Open Graph object, instantiate a + object, add the request to the newly created + connection and finally start the connection. The request uses + the active session represented by `[FBSession activeSession]`. + + @param object The Open Graph object to update the existing object with. + + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection*)startForUpdateOpenGraphObject:(id)object + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Creates an `FBRequest` for updating a user owned Open Graph object, instantiate a + object, add the request to the newly created + connection and finally start the connection. The request uses + the active session represented by `[FBSession activeSession]`. + + @param objectId The id of the Open Graph object to update. + @param title The updated title of the Open Graph object. + @param image The updated link to an image to be associated with the Open Graph object. + @param url The updated url to be associated with the Open Graph object. + @param description The object's description. + @param objectProperties Any additional properties to update for the Open Graph object. + @param handler The handler block to call when the request completes with a success, error, or cancel action. + */ ++ (FBRequestConnection *)startForUpdateOpenGraphObjectWithId:(id)objectId + title:(NSString *)title + image:(id)image + url:(id)url + description:(NSString *)description + objectProperties:(NSDictionary *)objectProperties + completionHandler:(FBRequestHandler)handler; + +/*! + @method + + @abstract + Starts a request connection to upload an image + to create a staging resource. Staging resources allow you to post binary data + such as images, in preparation for a post of an open graph object or action + which references the image. The URI returned when uploading a staging resource + may be passed as the value for the image property of an open graph object or action. + + @discussion + This method simplifies the preparation of a Graph API call be creating the FBRequest + object and starting the request connection with a single method + + @param image A `UIImage` for the image to upload. + @param handler The handler block to call when the request completes. + */ ++ (FBRequestConnection *)startForUploadStagingResourceWithImage:(UIImage *)image + completionHandler:(FBRequestHandler)handler; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBSession.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBSession.h new file mode 100644 index 0000000..63b0187 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBSession.h @@ -0,0 +1,785 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +// up-front decl's +@class FBAccessTokenData; +@class FBSession; +@class FBSessionTokenCachingStrategy; + +#define FB_SESSIONSTATETERMINALBIT (1 << 8) + +#define FB_SESSIONSTATEOPENBIT (1 << 9) + +/* + * Constants used by NSNotificationCenter for active session notification + */ + +/*! NSNotificationCenter name indicating that a new active session was set */ +extern NSString *const FBSessionDidSetActiveSessionNotification; + +/*! NSNotificationCenter name indicating that an active session was unset */ +extern NSString *const FBSessionDidUnsetActiveSessionNotification; + +/*! NSNotificationCenter name indicating that the active session is open */ +extern NSString *const FBSessionDidBecomeOpenActiveSessionNotification; + +/*! NSNotificationCenter name indicating that there is no longer an open active session */ +extern NSString *const FBSessionDidBecomeClosedActiveSessionNotification; + +/*! + @typedef FBSessionState enum + + @abstract Passed to handler block each time a session state changes + + @discussion + */ +typedef enum { + /*! One of two initial states indicating that no valid cached token was found */ + FBSessionStateCreated = 0, + /*! One of two initial session states indicating that a cached token was loaded; + when a session is in this state, a call to open* will result in an open session, + without UX or app-switching*/ + FBSessionStateCreatedTokenLoaded = 1, + /*! One of three pre-open session states indicating that an attempt to open the session + is underway*/ + FBSessionStateCreatedOpening = 2, + + /*! Open session state indicating user has logged in or a cached token is available */ + FBSessionStateOpen = 1 | FB_SESSIONSTATEOPENBIT, + /*! Open session state indicating token has been extended */ + FBSessionStateOpenTokenExtended = 2 | FB_SESSIONSTATEOPENBIT, + + /*! Closed session state indicating that a login attempt failed */ + FBSessionStateClosedLoginFailed = 1 | FB_SESSIONSTATETERMINALBIT, // NSError obj w/more info + /*! Closed session state indicating that the session was closed, but the users token + remains cached on the device for later use */ + FBSessionStateClosed = 2 | FB_SESSIONSTATETERMINALBIT, // " +} FBSessionState; + +/*! helper macro to test for states that imply an open session */ +#define FB_ISSESSIONOPENWITHSTATE(state) (0 != (state & FB_SESSIONSTATEOPENBIT)) + +/*! helper macro to test for states that are terminal */ +#define FB_ISSESSIONSTATETERMINAL(state) (0 != (state & FB_SESSIONSTATETERMINALBIT)) + +/*! + @typedef FBSessionLoginBehavior enum + + @abstract + Passed to open to indicate whether Facebook Login should allow for fallback to be attempted. + + @discussion + Facebook Login authorizes the application to act on behalf of the user, using the user's + Facebook account. Usually a Facebook Login will rely on an account maintained outside of + the application, by the native Facebook application, the browser, or perhaps the device + itself. This avoids the need for a user to enter their username and password directly, and + provides the most secure and lowest friction way for a user to authorize the application to + interact with Facebook. If a Facebook Login is not possible, a fallback Facebook Login may be + attempted, where the user is prompted to enter their credentials in a web-view hosted directly + by the application. + + The `FBSessionLoginBehavior` enum specifies whether to allow fallback, disallow fallback, or + force fallback login behavior. Most applications will use the default, which attempts a normal + Facebook Login, and only falls back if needed. In rare cases, it may be preferable to disallow + fallback Facebook Login completely, or to force a fallback login. + */ +typedef enum { + /*! Attempt Facebook Login, ask user for credentials if necessary */ + FBSessionLoginBehaviorWithFallbackToWebView = 0, + /*! Attempt Facebook Login, no direct request for credentials will be made */ + FBSessionLoginBehaviorWithNoFallbackToWebView = 1, + /*! Only attempt WebView Login; ask user for credentials */ + FBSessionLoginBehaviorForcingWebView = 2, + /*! Attempt Facebook Login, prefering system account and falling back to fast app switch if necessary */ + FBSessionLoginBehaviorUseSystemAccountIfPresent = 3, +} FBSessionLoginBehavior; + +/*! + @typedef FBSessionDefaultAudience enum + + @abstract + Passed to open to indicate which default audience to use for sessions that post data to Facebook. + + @discussion + Certain operations such as publishing a status or publishing a photo require an audience. When the user + grants an application permission to perform a publish operation, a default audience is selected as the + publication ceiling for the application. This enumerated value allows the application to select which + audience to ask the user to grant publish permission for. + */ +typedef enum { + /*! No audience needed; this value is useful for cases where data will only be read from Facebook */ + FBSessionDefaultAudienceNone = 0, + /*! Indicates that only the user is able to see posts made by the application */ + FBSessionDefaultAudienceOnlyMe = 10, + /*! Indicates that the user's friends are able to see posts made by the application */ + FBSessionDefaultAudienceFriends = 20, + /*! Indicates that all Facebook users are able to see posts made by the application */ + FBSessionDefaultAudienceEveryone = 30, +} FBSessionDefaultAudience; + +/*! + @typedef FBSessionLoginType enum + + @abstract + Used as the type of the loginType property in order to specify what underlying technology was used to + login the user. + + @discussion + The FBSession object is an abstraction over five distinct mechanisms. This enum allows an application + to test for the mechanism used by a particular instance of FBSession. Usually the mechanism used for a + given login does not matter, however for certain capabilities, the type of login can impact the behavior + of other Facebook functionality. + */ +typedef enum { + /*! A login type has not yet been established */ + FBSessionLoginTypeNone = 0, + /*! A system integrated account was used to log the user into the application */ + FBSessionLoginTypeSystemAccount = 1, + /*! The Facebook native application was used to log the user into the application */ + FBSessionLoginTypeFacebookApplication = 2, + /*! Safari was used to log the user into the application */ + FBSessionLoginTypeFacebookViaSafari = 3, + /*! A web view was used to log the user into the application */ + FBSessionLoginTypeWebView = 4, + /*! A test user was used to create an open session */ + FBSessionLoginTypeTestUser = 5, +} FBSessionLoginType; + +/*! + @typedef + + @abstract Block type used to define blocks called by for state updates + @discussion See https://developers.facebook.com/docs/technical-guides/iossdk/errors/ + for error handling best practices. + + Requesting additional permissions inside this handler (such as by calling + `requestNewPublishPermissions`) should be avoided because it is a poor user + experience and its behavior may vary depending on the login type. You should + request the permissions closer to the operation that requires it (e.g., when + the user performs some action). + */ +typedef void (^FBSessionStateHandler)(FBSession *session, + FBSessionState status, + NSError *error); + +/*! + @typedef + + @abstract Block type used to define blocks called by <[FBSession requestNewReadPermissions:completionHandler:]> + and <[FBSession requestNewPublishPermissions:defaultAudience:completionHandler:]>. + + @discussion See https://developers.facebook.com/docs/technical-guides/iossdk/errors/ + for error handling best practices. + + Requesting additional permissions inside this handler (such as by calling + `requestNewPublishPermissions`) should be avoided because it is a poor user + experience and its behavior may vary depending on the login type. You should + request the permissions closer to the operation that requires it (e.g., when + the user performs some action). + */ +typedef void (^FBSessionRequestPermissionResultHandler)(FBSession *session, + NSError *error); + +/*! + @typedef + + @abstract Block type used to define blocks called by <[FBSession reauthorizeWithPermissions]>. + + @discussion You should use the preferred FBSessionRequestPermissionHandler typedef rather than + this synonym, which has been deprecated. + */ +typedef FBSessionRequestPermissionResultHandler FBSessionReauthorizeResultHandler __attribute__((deprecated)); + +/*! + @typedef + + @abstract Block type used to define blocks called for system credential renewals. + @discussion + */ +typedef void (^FBSessionRenewSystemCredentialsHandler)(ACAccountCredentialRenewResult result, NSError *error) ; + +/*! + @class FBSession + + @abstract + The `FBSession` object is used to authenticate a user and manage the user's session. After + initializing a `FBSession` object the Facebook App ID and desired permissions are stored. + Opening the session will initiate the authentication flow after which a valid user session + should be available and subsequently cached. Closing the session can optionally clear the + cache. + + If an request requires user authorization then an `FBSession` object should be used. + + + @discussion + Instances of the `FBSession` class provide notification of state changes in the following ways: + + 1. Callers of certain `FBSession` methods may provide a block that will be called + back in the course of state transitions for the session (e.g. login or session closed). + + 2. The object supports Key-Value Observing (KVO) for property changes. + */ +@interface FBSession : NSObject + +/*! + @methodgroup Creating a session + */ + +/*! + @method + + @abstract + Returns a newly initialized Facebook session with default values for the parameters + to . + */ +- (id)init; + +/*! + @method + + @abstract + Returns a newly initialized Facebook session with the specified permissions and other + default values for parameters to . + + @param permissions An array of strings representing the permissions to request during the + authentication flow. The basic_info permission must be explicitly requested at first login, and is no + longer inferred, (subject to an active migration.) The default is nil. + + @discussion + It is required that any single permission request request (including initial log in) represent read-only permissions + or publish permissions only; not both. The permissions passed here should reflect this requirement. + + */ +- (id)initWithPermissions:(NSArray*)permissions; + +/*! + @method + + @abstract + Following are the descriptions of the arguments along with their + defaults when ommitted. + + @param permissions An array of strings representing the permissions to request during the + authentication flow. The basic_info permission must be explicitly requested at first login, and is no longer inferred, (subject to an active migration.) The default is nil. + @param appID The Facebook App ID for the session. If nil is passed in the default App ID will be obtained from a call to <[FBSession defaultAppID]>. The default is nil. + @param urlSchemeSuffix The URL Scheme Suffix to be used in scenarious where multiple iOS apps use one Facebook App ID. A value of nil indicates that this information should be pulled from [FBSettings defaultUrlSchemeSuffix]. The default is nil. + @param tokenCachingStrategy Specifies a key name to use for cached token information in NSUserDefaults, nil + indicates a default value of @"FBAccessTokenInformationKey". + + @discussion + It is required that any single permission request request (including initial log in) represent read-only permissions + or publish permissions only; not both. The permissions passed here should reflect this requirement. + */ +- (id)initWithAppID:(NSString*)appID + permissions:(NSArray*)permissions + urlSchemeSuffix:(NSString*)urlSchemeSuffix + tokenCacheStrategy:(FBSessionTokenCachingStrategy*)tokenCachingStrategy; + +/*! + @method + + @abstract + Following are the descriptions of the arguments along with their + defaults when ommitted. + + @param permissions An array of strings representing the permissions to request during the + authentication flow. The basic_info permission must be explicitly requested at first login, and is no longer inferred, (subject to an active migration.) The default is nil. + @param defaultAudience Most applications use FBSessionDefaultAudienceNone here, only specifying an audience when using reauthorize to request publish permissions. + @param appID The Facebook App ID for the session. If nil is passed in the default App ID will be obtained from a call to <[FBSession defaultAppID]>. The default is nil. + @param urlSchemeSuffix The URL Scheme Suffix to be used in scenarious where multiple iOS apps use one Facebook App ID. A value of nil indicates that this information should be pulled from [FBSettings defaultUrlSchemeSuffix]. The default is nil. + @param tokenCachingStrategy Specifies a key name to use for cached token information in NSUserDefaults, nil + indicates a default value of @"FBAccessTokenInformationKey". + + @discussion + It is required that any single permission request request (including initial log in) represent read-only permissions + or publish permissions only; not both. The permissions passed here should reflect this requirement. If publish permissions + are used, then the audience must also be specified. + */ +- (id)initWithAppID:(NSString*)appID + permissions:(NSArray*)permissions + defaultAudience:(FBSessionDefaultAudience)defaultAudience + urlSchemeSuffix:(NSString*)urlSchemeSuffix + tokenCacheStrategy:(FBSessionTokenCachingStrategy*)tokenCachingStrategy; + +// instance readonly properties + +/*! @abstract Indicates whether the session is open and ready for use. */ +@property (readonly) BOOL isOpen; + +/*! @abstract Detailed session state */ +@property (readonly) FBSessionState state; + +/*! @abstract Identifies the Facebook app which the session object represents. */ +@property (readonly, copy) NSString *appID; + +/*! @abstract Identifies the URL Scheme Suffix used by the session. This is used when multiple iOS apps share a single Facebook app ID. */ +@property (readonly, copy) NSString *urlSchemeSuffix; + +/*! @abstract The access token for the session object. + @discussion Deprecated. Use the `accessTokenData` property. */ +@property(readonly, copy) NSString *accessToken +__attribute__((deprecated)); + +/*! @abstract The expiration date of the access token for the session object. + @discussion Deprecated. Use the `accessTokenData` property. */ +@property(readonly, copy) NSDate *expirationDate +__attribute__((deprecated)); + +/*! @abstract The permissions granted to the access token during the authentication flow. */ +@property (readonly, copy) NSArray *permissions; + +/*! @abstract Specifies the login type used to authenticate the user. + @discussion Deprecated. Use the `accessTokenData` property. */ +@property(readonly) FBSessionLoginType loginType +__attribute__((deprecated)); + +/*! @abstract Gets the FBAccessTokenData for the session */ +@property (readonly, copy) FBAccessTokenData *accessTokenData; + +/*! + @methodgroup Instance methods + */ + +/*! + @method + + @abstract Opens a session for the Facebook. + + @discussion + A session may not be used with and other classes in the SDK until it is open. If, prior + to calling open, the session is in the state, then no UX occurs, and + the session becomes available for use. If the session is in the state, prior + to calling open, then a call to open causes login UX to occur, either via the Facebook application + or via mobile Safari. + + Open may be called at most once and must be called after the `FBSession` is initialized. Open must + be called before the session is closed. Calling an open method at an invalid time will result in + an exception. The open session methods may be passed a block that will be called back when the session + state changes. The block will be released when the session is closed. + + @param handler A block to call with the state changes. The default is nil. +*/ +- (void)openWithCompletionHandler:(FBSessionStateHandler)handler; + +/*! + @method + + @abstract Logs a user on to Facebook. + + @discussion + A session may not be used with and other classes in the SDK until it is open. If, prior + to calling open, the session is in the state, then no UX occurs, and + the session becomes available for use. If the session is in the state, prior + to calling open, then a call to open causes login UX to occur, either via the Facebook application + or via mobile Safari. + + The method may be called at most once and must be called after the `FBSession` is initialized. It must + be called before the session is closed. Calling the method at an invalid time will result in + an exception. The open session methods may be passed a block that will be called back when the session + state changes. The block will be released when the session is closed. + + @param behavior Controls whether to allow, force, or prohibit Facebook Login or Inline Facebook Login. The default + is to allow Facebook Login, with fallback to Inline Facebook Login. + @param handler A block to call with session state changes. The default is nil. + */ +- (void)openWithBehavior:(FBSessionLoginBehavior)behavior + completionHandler:(FBSessionStateHandler)handler; + +/*! + @method + + @abstract Imports an existing access token and opens the session with it. + + @discussion + The method attempts to open the session using an existing access token. No UX will occur. If + successful, the session with be in an Open state and the method will return YES; otherwise, NO. + + The method may be called at most once and must be called after the `FBSession` is initialized (see below). + It must be called before the session is closed. Calling the method at an invalid time will result in + an exception. The open session methods may be passed a block that will be called back when the session + state changes. The block will be released when the session is closed. + + The initialized session must not have already been initialized from a cache (for example, you could use + the `[FBSessionTokenCachingStrategy nullCacheInstance]` instance). + + @param accessTokenData The token data. See `FBAccessTokenData` for construction methods. + @param handler A block to call with session state changes. The default is nil. + */ +- (BOOL)openFromAccessTokenData:(FBAccessTokenData *)accessTokenData completionHandler:(FBSessionStateHandler) handler; + +/*! + @abstract + Closes the local in-memory session object, but does not clear the persisted token cache. + */ +- (void)close; + +/*! + @abstract + Closes the in-memory session, and clears any persisted cache related to the session. +*/ +- (void)closeAndClearTokenInformation; + +/*! + @abstract + Reauthorizes the session, with additional permissions. + + @param permissions An array of strings representing the permissions to request during the + authentication flow. A value of nil indicates basic permissions. The default is nil. + @param behavior Controls whether to allow, force, or prohibit Facebook Login. The default + is to allow Facebook Login and fall back to Inline Facebook Login if needed. + @param handler A block to call with session state changes. The default is nil. + + @discussion Methods and properties that specify permissions without a read or publish + qualification are deprecated; use of a read-qualified or publish-qualified alternative is preferred + (e.g. reauthorizeWithReadPermissions or reauthorizeWithPublishPermissions) + */ +- (void)reauthorizeWithPermissions:(NSArray*)permissions + behavior:(FBSessionLoginBehavior)behavior + completionHandler:(FBSessionReauthorizeResultHandler)handler + __attribute__((deprecated)); + +/*! + @abstract + Reauthorizes the session, with additional permissions. + + @param readPermissions An array of strings representing the permissions to request during the + authentication flow. A value of nil indicates basic permissions. + + @param handler A block to call with session state changes. The default is nil. + + @discussion This method is a deprecated alias of <[FBSession requestNewReadPermissions:completionHandler:]>. Consider + using <[FBSession requestNewReadPermissions:completionHandler:]>, which is preferred for readability. + */ +- (void)reauthorizeWithReadPermissions:(NSArray*)readPermissions + completionHandler:(FBSessionReauthorizeResultHandler)handler +__attribute__((deprecated)); + +/*! + @abstract + Reauthorizes the session, with additional permissions. + + @param writePermissions An array of strings representing the permissions to request during the + authentication flow. + + @param defaultAudience Specifies the audience for posts. + + @param handler A block to call with session state changes. The default is nil. + + @discussion This method is a deprecated alias of <[FBSession requestNewPublishPermissions:defaultAudience:completionHandler:]>. + Consider using <[FBSession requestNewPublishPermissions:defaultAudience:completionHandler:]>, which is preferred for readability. + */ +- (void)reauthorizeWithPublishPermissions:(NSArray*)writePermissions + defaultAudience:(FBSessionDefaultAudience)defaultAudience + completionHandler:(FBSessionReauthorizeResultHandler)handler +__attribute__((deprecated)); + +/*! + @abstract + Requests new or additional read permissions for the session. + + @param readPermissions An array of strings representing the permissions to request during the + authentication flow. A value of nil indicates basic permissions. + + @param handler A block to call with session state changes. The default is nil. + + @discussion The handler, if non-nil, is called once the operation has completed or failed. This is in contrast to the + state completion handler used in <[FBSession openWithCompletionHandler:]> (and other `open*` methods) which is called + for each state-change for the session. + */ +- (void)requestNewReadPermissions:(NSArray*)readPermissions + completionHandler:(FBSessionRequestPermissionResultHandler)handler; + +/*! + @abstract + Requests new or additional write permissions for the session. + + @param writePermissions An array of strings representing the permissions to request during the + authentication flow. + + @param defaultAudience Specifies the audience for posts. + + @param handler A block to call with session state changes. The default is nil. + + @discussion The handler, if non-nil, is called once the operation has completed or failed. This is in contrast to the + state completion handler used in <[FBSession openWithCompletionHandler:]> (and other `open*` methods) which is called + for each state-change for the session. + */ +- (void)requestNewPublishPermissions:(NSArray*)writePermissions + defaultAudience:(FBSessionDefaultAudience)defaultAudience + completionHandler:(FBSessionRequestPermissionResultHandler)handler; + +/*! + @abstract + A helper method that is used to provide an implementation for + [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. It should be invoked during + the Facebook Login flow and will update the session information based on the incoming URL. + + @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. +*/ +- (BOOL)handleOpenURL:(NSURL*)url; + +/*! + @abstract + A helper method that is used to provide an implementation for + [UIApplicationDelegate applicationDidBecomeActive:] to properly resolve session state for + the Facebook Login flow, specifically to support app-switch login. +*/ +- (void)handleDidBecomeActive; + +/*! + @abstract + Assign the block to be invoked for session state changes. + + @discussion + This will overwrite any state change handler that was already assigned. Typically, + you should only use this setter if you were unable to assign a state change handler explicitly. + One example of this is if you are not opening the session (e.g., using the `open*`) + but still want to assign a `FBSessionStateHandler` block. This can happen when the SDK + opens a session from an app link. +*/ +- (void)setStateChangeHandler:(FBSessionStateHandler)stateChangeHandler; + +/*! + @methodgroup Class methods + */ + +/*! + @abstract + This is the simplest method for opening a session with Facebook. Using sessionOpen logs on a user, + and sets the static activeSession which becomes the default session object for any Facebook UI widgets + used by the application. This session becomes the active session, whether open succeeds or fails. + + Note, if there is not a cached token available, this method will present UI to the user in order to + open the session via explicit login by the user. + + @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if + no login UI will be required to accomplish the operation. For example, at application startup it may not + be disirable to transition to login UI for the user, and yet an open session is desired so long as a cached + token can be used to open the session. Passing NO to this argument, assures the method will not present UI + to the user in order to open the session. + + @discussion + Returns YES if the session was opened synchronously without presenting UI to the user. This occurs + when there is a cached token available from a previous run of the application. If NO is returned, this indicates + that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is + possible that the user will login, and the session will become open asynchronously. The primary use for + this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session + is opened via cache. + */ ++ (BOOL)openActiveSessionWithAllowLoginUI:(BOOL)allowLoginUI; + +/*! + @abstract + This is a simple method for opening a session with Facebook. Using sessionOpen logs on a user, + and sets the static activeSession which becomes the default session object for any Facebook UI widgets + used by the application. This session becomes the active session, whether open succeeds or fails. + + @param permissions An array of strings representing the permissions to request during the + authentication flow. A value of nil indicates basic permissions. A nil value specifies + default permissions. + + @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if + no login UI will be required to accomplish the operation. For example, at application startup it may not + be desirable to transition to login UI for the user, and yet an open session is desired so long as a cached + token can be used to open the session. Passing NO to this argument, assures the method will not present UI + to the user in order to open the session. + + @param handler Many applications will benefit from notification when a session becomes invalid + or undergoes other state transitions. If a block is provided, the FBSession + object will call the block each time the session changes state. + + @discussion + Returns true if the session was opened synchronously without presenting UI to the user. This occurs + when there is a cached token available from a previous run of the application. If NO is returned, this indicates + that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is + possible that the user will login, and the session will become open asynchronously. The primary use for + this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session + is opened via cache. + + It is required that initial permissions requests represent read-only permissions only. If publish + permissions are needed, you may use reauthorizeWithPermissions to specify additional permissions as + well as an audience. Use of this method will result in a legacy fast-app-switch Facebook Login due to + the requirement to separate read and publish permissions for newer applications. Methods and properties + that specify permissions without a read or publish qualification are deprecated; use of a read-qualified + or publish-qualified alternative is preferred. + */ ++ (BOOL)openActiveSessionWithPermissions:(NSArray*)permissions + allowLoginUI:(BOOL)allowLoginUI + completionHandler:(FBSessionStateHandler)handler + __attribute__((deprecated)); + +/*! + @abstract + This is a simple method for opening a session with Facebook. Using sessionOpen logs on a user, + and sets the static activeSession which becomes the default session object for any Facebook UI widgets + used by the application. This session becomes the active session, whether open succeeds or fails. + + @param readPermissions An array of strings representing the read permissions to request during the + authentication flow. The basic_info permission must be explicitly requested at first login, and is no longer + inferred, (subject to an active migration.) It is not allowed to pass publish permissions to this method. + + @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if + no login UI will be required to accomplish the operation. For example, at application startup it may not + be desirable to transition to login UI for the user, and yet an open session is desired so long as a cached + token can be used to open the session. Passing NO to this argument, assures the method will not present UI + to the user in order to open the session. + + @param handler Many applications will benefit from notification when a session becomes invalid + or undergoes other state transitions. If a block is provided, the FBSession + object will call the block each time the session changes state. + + @discussion + Returns true if the session was opened synchronously without presenting UI to the user. This occurs + when there is a cached token available from a previous run of the application. If NO is returned, this indicates + that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is + possible that the user will login, and the session will become open asynchronously. The primary use for + this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session + is opened via cache. + + */ ++ (BOOL)openActiveSessionWithReadPermissions:(NSArray*)readPermissions + allowLoginUI:(BOOL)allowLoginUI + completionHandler:(FBSessionStateHandler)handler; + +/*! + @abstract + This is a simple method for opening a session with Facebook. Using sessionOpen logs on a user, + and sets the static activeSession which becomes the default session object for any Facebook UI widgets + used by the application. This session becomes the active session, whether open succeeds or fails. + + @param publishPermissions An array of strings representing the publish permissions to request during the + authentication flow. + + @param defaultAudience Anytime an app publishes on behalf of a user, the post must have an audience (e.g. me, my friends, etc.) + The default audience is used to notify the user of the cieling that the user agrees to grant to the app for the provided permissions. + + @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if + no login UI will be required to accomplish the operation. For example, at application startup it may not + be desirable to transition to login UI for the user, and yet an open session is desired so long as a cached + token can be used to open the session. Passing NO to this argument, assures the method will not present UI + to the user in order to open the session. + + @param handler Many applications will benefit from notification when a session becomes invalid + or undergoes other state transitions. If a block is provided, the FBSession + object will call the block each time the session changes state. + + @discussion + Returns true if the session was opened synchronously without presenting UI to the user. This occurs + when there is a cached token available from a previous run of the application. If NO is returned, this indicates + that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is + possible that the user will login, and the session will become open asynchronously. The primary use for + this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session + is opened via cache. + + */ ++ (BOOL)openActiveSessionWithPublishPermissions:(NSArray*)publishPermissions + defaultAudience:(FBSessionDefaultAudience)defaultAudience + allowLoginUI:(BOOL)allowLoginUI + completionHandler:(FBSessionStateHandler)handler; + +/*! + @abstract + An application may get or set the current active session. Certain high-level components in the SDK + will use the activeSession to set default session (e.g. `FBLoginView`, `FBFriendPickerViewController`) + + @discussion + If sessionOpen* is called, the resulting `FBSession` object also becomes the activeSession. If another + session was active at the time, it is closed automatically. If activeSession is called when no session + is active, a session object is instatiated and returned; in this case open must be called on the session + in order for it to be useable for communication with Facebook. + */ ++ (FBSession*)activeSession; + +/*! + @abstract + An application may get or set the current active session. Certain high-level components in the SDK + will use the activeSession to set default session (e.g. `FBLoginView`, `FBFriendPickerViewController`) + + @param session The FBSession object to become the active session + + @discussion + If an application prefers the flexibilility of directly instantiating a session object, an active + session can be set directly. + */ ++ (FBSession*)setActiveSession:(FBSession*)session; + +/*! + @method + + @abstract Set the default Facebook App ID to use for sessions. The app ID may be + overridden on a per session basis. + + @discussion This method has been deprecated in favor of [FBSettings setDefaultAppID]. + + @param appID The default Facebook App ID to use for methods. + */ ++ (void)setDefaultAppID:(NSString*)appID __attribute__((deprecated)); + +/*! + @method + + @abstract Get the default Facebook App ID to use for sessions. If not explicitly + set, the default will be read from the application's plist. The app ID may be + overridden on a per session basis. + + @discussion This method has been deprecated in favor of [FBSettings defaultAppID]. +*/ ++ (NSString*)defaultAppID __attribute__((deprecated)); + +/*! + @method + + @abstract Set the default url scheme suffix to use for sessions. The url + scheme suffix may be overridden on a per session basis. + + @discussion This method has been deprecated in favor of [FBSettings setDefaultUrlSchemeSuffix]. + + @param urlSchemeSuffix The default url scheme suffix to use for methods. + */ ++ (void)setDefaultUrlSchemeSuffix:(NSString*)urlSchemeSuffix __attribute__((deprecated)); + +/*! + @method + + @abstract Get the default url scheme suffix used for sessions. If not + explicitly set, the default will be read from the application's plist. The + url scheme suffix may be overridden on a per session basis. + + @discussion This method has been deprecated in favor of [FBSettings defaultUrlSchemeSuffix]. + */ ++ (NSString*)defaultUrlSchemeSuffix __attribute__((deprecated)); + +/*! + @method + + @abstract Issues an asychronous renewCredentialsForAccount call to the device Facebook account store. + + @param handler The completion handler to call when the renewal is completed. The handler will be + invoked on the main thread. + + @discussion This can be used to explicitly renew account credentials on iOS 6 devices and is provided + as a convenience wrapper around `[ACAccountStore renewCredentialsForAccount:completion]`. Note the + method will not issue the renewal call if the the Facebook account has not been set on the device, or + if access had not been granted to the account (though the handler wil receive an error). + + This is safe to call (and will surface an error to the handler) on versions of iOS before 6 or if the user + logged in via Safari or Facebook SSO. +*/ ++ (void)renewSystemCredentials:(FBSessionRenewSystemCredentialsHandler)handler; +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBSessionTokenCachingStrategy.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBSessionTokenCachingStrategy.h new file mode 100644 index 0000000..6190e53 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBSessionTokenCachingStrategy.h @@ -0,0 +1,160 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBAccessTokenData.h" + +/*! + @class + + @abstract + The `FBSessionTokenCachingStrategy` class is responsible for persisting and retrieving cached data related to + an object, including the user's Facebook access token. + + @discussion + `FBSessionTokenCachingStrategy` is designed to be instantiated directly or used as a base class. Usually default + token caching behavior is sufficient, and you do not need to interface directly with `FBSessionTokenCachingStrategy` objects. + However, if you need to control where or how `FBSession` information is cached, then you may take one of two approaches. + + The first and simplest approach is to instantiate an instance of `FBSessionTokenCachingStrategy`, and then pass + the instance to `FBSession` class' `init` method. This enables your application to control the key name used in + `NSUserDefaults` to store session information. You may consider this approach if you plan to cache session information + for multiple users. + + The second and more advanced approached is to derive a custom class from `FBSessionTokenCachingStrategy`, which will + be responsible for caching behavior of your application. This approach is useful if you need to change where the + information is cached, for example if you prefer to use the filesystem or make a network connection to fetch and + persist cached tokens. Inheritors should override the cacheTokenInformation, fetchTokenInformation, and clearToken methods. + Doing this enables your application to implement any token caching scheme, including no caching at all (see + `[FBSessionTokenCachingStrategy* nullCacheInstance ]`. + + Direct use of `FBSessionTokenCachingStrategy`is an advanced technique. Most applications use objects without + passing an `FBSessionTokenCachingStrategy`, which yields default caching to `NSUserDefaults`. + */ +@interface FBSessionTokenCachingStrategy : NSObject + +/*! + @abstract Initializes and returns an instance + */ +- (id)init; + +/*! + @abstract + Initializes and returns an instance + + @param tokenInformationKeyName Specifies a key name to use for cached token information in NSUserDefaults, nil + indicates a default value of @"FBAccessTokenInformationKey" + */ +- (id)initWithUserDefaultTokenInformationKeyName:(NSString*)tokenInformationKeyName; + +/*! + @abstract + Called by (and overridden by inheritors), in order to cache token information. + + @param tokenInformation Dictionary containing token information to be cached by the method + @discussion You should favor overriding this instead of `cacheFBAccessTokenData` only if you intend + to cache additional data not captured by the FBAccessTokenData type. + */ +- (void)cacheTokenInformation:(NSDictionary*)tokenInformation; + +/*! + @abstract Cache the supplied token. + @param accessToken The token instance. + @discussion This essentially wraps a call to `cacheTokenInformation` so you should + override this when providing a custom token caching strategy. +*/ +- (void)cacheFBAccessTokenData:(FBAccessTokenData *)accessToken; + +/*! + @abstract + Called by (and overridden by inheritors), in order to fetch cached token information + + @discussion + An overriding implementation should only return a token if it + can also return an expiration date, otherwise return nil. + You should favor overriding this instead of `fetchFBAccessTokenData` only if you intend + to cache additional data not captured by the FBAccessTokenData type. + + */ +- (NSDictionary*)fetchTokenInformation; + +/*! + @abstract + Fetches the cached token instance. + + @discussion + This essentially wraps a call to `fetchTokenInformation` so you should + override this when providing a custom token caching strategy. + + In order for an `FBSession` instance to be able to use a cached token, + the token must be not be expired (see `+isValidTokenInformation:`) and + must also contain all permissions in the initialized session instance. + */ +- (FBAccessTokenData *)fetchFBAccessTokenData; + +/*! + @abstract + Called by (and overridden by inheritors), in order delete any cached information for the current token + */ +- (void)clearToken; + +/*! + @abstract + Helper function called by the SDK as well as apps, in order to fetch the default strategy instance. + */ ++ (FBSessionTokenCachingStrategy*)defaultInstance; + +/*! + @abstract + Helper function to return a FBSessionTokenCachingStrategy instance that does not perform any caching. + */ ++ (FBSessionTokenCachingStrategy*)nullCacheInstance; + +/*! + @abstract + Helper function called by the SDK as well as application code, used to determine whether a given dictionary + contains the minimum token information usable by the . + + @param tokenInformation Dictionary containing token information to be validated + */ ++ (BOOL)isValidTokenInformation:(NSDictionary*)tokenInformation; + +@end + +// The key to use with token information dictionaries to get and set the token value +extern NSString *const FBTokenInformationTokenKey; + +// The to use with token information dictionaries to get and set the expiration date +extern NSString *const FBTokenInformationExpirationDateKey; + +// The to use with token information dictionaries to get and set the refresh date +extern NSString *const FBTokenInformationRefreshDateKey; + +// The key to use with token information dictionaries to get the related user's fbid +extern NSString *const FBTokenInformationUserFBIDKey; + +// The key to use with token information dictionaries to determine whether the token was fetched via Facebook Login +extern NSString *const FBTokenInformationIsFacebookLoginKey; + +// The key to use with token information dictionaries to determine whether the token was fetched via the OS +extern NSString *const FBTokenInformationLoginTypeLoginKey; + +// The key to use with token information dictionaries to get the latest known permissions +extern NSString *const FBTokenInformationPermissionsKey; + +// The key to use with token information dictionaries to get the date the permissions were last refreshed. +extern NSString *const FBTokenInformationPermissionsRefreshDateKey; diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBSettings.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBSettings.h new file mode 100644 index 0000000..a9fc57b --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBSettings.h @@ -0,0 +1,327 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +/* + * Constants defining logging behavior. Use with <[FBSettings setLoggingBehavior]>. + */ + +/*! Log requests from FBRequest* classes */ +extern NSString *const FBLoggingBehaviorFBRequests; + +/*! Log requests from FBURLConnection* classes */ +extern NSString *const FBLoggingBehaviorFBURLConnections; + +/*! Include access token in logging. */ +extern NSString *const FBLoggingBehaviorAccessTokens; + +/*! Log session state transitions. */ +extern NSString *const FBLoggingBehaviorSessionStateTransitions; + +/*! Log performance characteristics */ +extern NSString *const FBLoggingBehaviorPerformanceCharacteristics; + +/*! Log FBAppEvents interactions */ +extern NSString *const FBLoggingBehaviorAppEvents; + +/*! Log Informational occurrences */ +extern NSString *const FBLoggingBehaviorInformational; + +/*! Log errors likely to be preventable by the developer. This is in the default set of enabled logging behaviors. */ +extern NSString *const FBLoggingBehaviorDeveloperErrors; + +@class FBGraphObject; + +/*! + @typedef + + @abstract Block type used to get install data that is returned by server when publishInstall is called + @discussion + */ +typedef void (^FBInstallResponseDataHandler)(FBGraphObject *response, NSError *error); + +/*! + @typedef + + @abstract A list of beta features that can be enabled for the SDK. Beta features are for evaluation only, + and are therefore only enabled for DEBUG builds. Beta features should not be enabled + in release builds. + */ +typedef enum : NSUInteger { + FBBetaFeaturesNone = 0, +#if defined(DEBUG) || defined(FB_BUILD_ONLY) + FBBetaFeaturesShareDialog = 1 << 0, + FBBetaFeaturesOpenGraphShareDialog = 1 << 1, +#endif +} FBBetaFeatures; + +/*! + @typedef + @abstract Indicates if this app should be restricted + */ +typedef NS_ENUM(NSUInteger, FBRestrictedTreatment) { + /*! The default treatment indicating the app is not restricted. */ + FBRestrictedTreatmentNO = 0, + + /*! Indicates the app is restricted. */ + FBRestrictedTreatmentYES = 1 +}; + +@interface FBSettings : NSObject + +/*! + @method + + @abstract Retrieve the current iOS SDK version. + + */ ++ (NSString *)sdkVersion; + +/*! + @method + + @abstract Retrieve the current Facebook SDK logging behavior. + + */ ++ (NSSet *)loggingBehavior; + +/*! + @method + + @abstract Set the current Facebook SDK logging behavior. This should consist of strings defined as + constants with FBLogBehavior*, and can be constructed with, e.g., [NSSet initWithObjects:]. + + @param loggingBehavior A set of strings indicating what information should be logged. If nil is provided, the logging + behavior is reset to the default set of enabled behaviors. Set in an empty set in order to disable all logging. + */ ++ (void)setLoggingBehavior:(NSSet *)loggingBehavior; + +/*! @abstract deprecated method */ ++ (BOOL)shouldAutoPublishInstall __attribute__ ((deprecated)); + +/*! @abstract deprecated method */ ++ (void)setShouldAutoPublishInstall:(BOOL)autoPublishInstall __attribute__ ((deprecated)); + +/*! + @method + + @abstract This method has been replaced by [FBAppEvents activateApp] */ ++ (void)publishInstall:(NSString *)appID __attribute__ ((deprecated("use [FBAppEvents activateApp] instead"))); + +/*! + @method + + @abstract Manually publish an attributed install to the Facebook graph, and return the server response back in + the supplied handler. Calling this method will implicitly turn off auto-publish. This method acquires the + current attribution id from the facebook application, queries the graph API to determine if the application + has install attribution enabled, publishes the id, and records success to avoid reporting more than once. + + @param appID A specific appID to publish an install for. If nil, uses [FBSession defaultAppID]. + @param handler A block to call with the server's response. + */ ++ (void)publishInstall:(NSString *)appID + withHandler:(FBInstallResponseDataHandler)handler __attribute__ ((deprecated)); + + +/*! + @method + + @abstract + Gets the application version to the provided string. `FBAppEvents`, for instance, attaches the app version to + events that it logs, which are then available in App Insights. + */ ++ (NSString *)appVersion; + +/*! + @method + + @abstract + Sets the application version to the provided string. `FBAppEvents`, for instance, attaches the app version to + events that it logs, which are then available in App Insights. + + @param appVersion The version identifier of the iOS app. + */ ++ (void)setAppVersion:(NSString *)appVersion; + +/*! + @method + + @abstract Retrieve the Client Token that has been set via [FBSettings setClientToken] + */ ++ (NSString *)clientToken; + +/*! + @method + + @abstract Sets the Client Token for the Facebook App. This is needed for certain API calls when made anonymously, + without a user-based Session. + + @param clientToken The Facebook App's "client token", which, for a given appid can be found in the Security + section of the Advanced tab of the Facebook App settings found at + + */ ++ (void)setClientToken:(NSString *)clientToken; + +/*! + @method + + @abstract Set the default Facebook Display Name to be used by the SDK. This should match + the Display Name that has been set for the app with the corresponding Facebook App ID, in + the Facebook App Dashboard + + @param displayName The default Facebook Display Name to be used by the SDK. + */ ++ (void)setDefaultDisplayName:(NSString *)displayName; + +/*! + @method + + @abstract Get the default Facebook Display Name used by the SDK. If not explicitly + set, the default will be read from the application's plist. + */ ++ (NSString *)defaultDisplayName; + +/*! + @method + + @abstract Set the default Facebook App ID to use for sessions. The SDK allows the appID + to be overridden per instance in certain cases (e.g. per instance of FBSession) + + @param appID The default Facebook App ID to be used by the SDK. + */ ++ (void)setDefaultAppID:(NSString*)appID; + +/*! + @method + + @abstract Get the default Facebook App ID used by the SDK. If not explicitly + set, the default will be read from the application's plist. The SDK allows the appID + to be overridden per instance in certain cases (e.g. per instance of FBSession) + */ ++ (NSString*)defaultAppID; + +/*! + @method + + @abstract Set the default url scheme suffix used by the SDK. + + @param urlSchemeSuffix The default url scheme suffix to be used by the SDK. + */ ++ (void)setDefaultUrlSchemeSuffix:(NSString*)urlSchemeSuffix; + +/*! + @method + + @abstract Get the default url scheme suffix used for sessions. If not + explicitly set, the default will be read from the application's plist value for 'FacebookUrlSchemeSuffix'. + */ ++ (NSString*)defaultUrlSchemeSuffix; + +/*! + @method + + @abstract Set the bundle name from the SDK will try and load overrides of images and text + + @param bundleName The name of the bundle (MyFBBundle). + */ ++ (void)setResourceBundleName:(NSString*)bundleName; + +/*! + @method + + @abstract Get the name of the bundle to override the SDK images and text + */ ++ (NSString*)resourceBundleName; + +/*! + @method + + @abstract Set the subpart of the facebook domain (e.g. @"beta") so that requests will be sent to graph.beta.facebook.com + + @param facebookDomainPart The domain part to be inserted into facebook.com + */ ++ (void)setFacebookDomainPart:(NSString*)facebookDomainPart; + +/*! + @method + + @abstract Get the Facebook domain part + */ ++ (NSString*)facebookDomainPart; + +/*! + @method + + @abstract Enables the specified beta features. Beta features are for evaluation only, + and are therefore only enabled for debug builds. Beta features should not be enabled + in release builds. + + @param betaFeatures The beta features to enable (expects a bitwise OR of FBBetaFeatures) + */ ++ (void)enableBetaFeatures:(NSUInteger)betaFeatures; + +/*! + @method + + @abstract Enables a beta feature. Beta features are for evaluation only, + and are therefore only enabled for debug builds. Beta features should not be enabled + in release builds. + + @param betaFeature The beta feature to enable. + */ ++ (void)enableBetaFeature:(FBBetaFeatures)betaFeature; + +/*! + @method + + @abstract Disables a beta feature. + + @param betaFeature The beta feature to disable. + */ ++ (void)disableBetaFeature:(FBBetaFeatures)betaFeature; + +/*! + @method + + @abstract Determines whether a beta feature is enabled or not. + + @param betaFeature The beta feature to check. + + @return YES if the beta feature is enabled, NO if not. + */ ++ (BOOL)isBetaFeatureEnabled:(FBBetaFeatures)betaFeature; + +/*! + @method + + @abstract + Gets whether data such as that generated through FBAppEvents and sent to Facebook should be restricted from being used for other than analytics and conversions. Defaults to NO. This value is stored on the device and persists across app launches. + */ ++ (BOOL)limitEventAndDataUsage; + +/*! + @method + + @abstract + Sets whether data such as that generated through FBAppEvents and sent to Facebook should be restricted from being used for other than analytics and conversions. Defaults to NO. This value is stored on the device and persists across app launches. + + @param limitEventAndDataUsage The desired value. + */ ++ (void)setLimitEventAndDataUsage:(BOOL)limitEventAndDataUsage; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBShareDialogParams.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBShareDialogParams.h new file mode 100644 index 0000000..fc2832c --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBShareDialogParams.h @@ -0,0 +1,67 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBDialogsParams.h" + +/*! + @class FBShareDialogParams + + @abstract + This object is used to encapsulate state for parameters to a share dialog that + opens in the Facebook app. + */ +@interface FBShareDialogParams : FBDialogsParams + +/*! @abstract The URL link to be attached to the post. Only "http" or "https" + schemes are supported. */ +@property (nonatomic, copy) NSURL *link; + +/*! @abstract The name, or title associated with the link. Is only used if the + link is non-nil. */ +@property (nonatomic, copy) NSString *name; + +/*! @abstract The caption to be used with the link. Is only used if the link is + non-nil. */ +@property (nonatomic, copy) NSString *caption; + +/*! @abstract The description associated with the link. Is only used if the + link is non-nil. */ +@property (nonatomic, copy) NSString *description; + +/*! @abstract The link to a thumbnail to associate with the post. Is only used + if the link is non-nil. Only "http" or "https" schemes are supported.*/ +@property (nonatomic, copy) NSURL *picture; + +/*! @abstract An array of NSStrings or FBGraphUsers to tag in the post. + If using NSStrings, the values must represent the IDs of the users to tag. */ +@property (nonatomic, copy) NSArray *friends; + +/*! @abstract An NSString or FBGraphPlace to tag in the status update. If + NSString, the value must be the ID of the place to tag. */ +@property (nonatomic, copy) id place; + +/*! @abstract A text reference for the category of the post, used on Facebook + Insights. */ +@property (nonatomic, copy) NSString *ref; + +/*! @abstract If YES, treats any data failures (e.g. failures when getting + data for IDs passed through "friends" or "place") as a fatal error, and will not + continue with the status update. */ +@property (nonatomic, assign) BOOL dataFailuresFatal; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBTestSession.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBTestSession.h new file mode 100644 index 0000000..707dad5 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBTestSession.h @@ -0,0 +1,138 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "FBSession.h" + +#if defined (DEBUG) + #define SAFE_TO_USE_FBTESTSESSION +#endif + +#if !defined(SAFE_TO_USE_FBTESTSESSION) + #pragma message ("warning: using FBTestSession, which is designed for unit-testing uses only, in non-DEBUG code -- ensure this is what you really want") +#endif + +/*! + Consider using this tag to pass to sessionWithSharedUserWithPermissions:uniqueUserTag: when + you need a second unique test user in a test case. Using the same tag each time reduces + the proliferation of test users. + */ +extern NSString *kSecondTestUserTag; +/*! + Consider using this tag to pass to sessionWithSharedUserWithPermissions:uniqueUserTag: when + you need a third unique test user in a test case. Using the same tag each time reduces + the proliferation of test users. + */ +extern NSString *kThirdTestUserTag; + +/*! + @class FBTestSession + + @abstract + Implements an FBSession subclass that knows about test users for a particular + application. This should never be used from a real application, but may be useful + for writing unit tests, etc. + + @discussion + Facebook allows developers to create test accounts for testing their applications' + Facebook integration (see https://developers.facebook.com/docs/test_users/). This class + simplifies use of these accounts for writing unit tests. It is not designed for use in + production application code. + + The main use case for this class is using sessionForUnitTestingWithPermissions:mode: + to create a session for a test user. Two modes are supported. In "shared" mode, an attempt + is made to find an existing test user that has the required permissions and, if it is not + currently in use by another FBTestSession, just use that user. If no such user is available, + a new one is created with the required permissions. In "private" mode, designed for + scenarios which require a new user in a known clean state, a new test user will always be + created, and it will be automatically deleted when the FBTestSession is closed. + + Note that the shared test user functionality depends on a naming convention for the test users. + It is important that any testing of functionality which will mutate the permissions for a + test user NOT use a shared test user, or this scheme will break down. If a shared test user + seems to be in an invalid state, it can be deleted manually via the Web interface at + https://developers.facebook.com/apps/APP_ID/permissions?role=test+users. + */ +@interface FBTestSession : FBSession + +/// The app access token (composed of app ID and secret) to use for accessing test users. +@property (readonly, copy) NSString *appAccessToken; +/// The ID of the test user associated with this session. +@property (readonly, copy) NSString *testUserID; +/// The App ID of the test app as configured in the plist. +@property (readonly, copy) NSString *testAppID; +/// The App Secret of the test app as configured in the plist. +@property (readonly, copy) NSString *testAppSecret; +// Defaults to NO. If set to YES, reauthorize calls will fail with a nil token +// as if the user had cancelled it reauthorize. +@property (assign) BOOL disableReauthorize; + +/*! + @abstract + Constructor helper to create a session for use in unit tests + + @discussion + This method creates a session object which uses a shared test user with the right permissions, + creating one if necessary on open (but not deleting it on close, so it can be re-used in later + tests). Calling this method multiple times may return sessions with the same user. If this is not + desired, use the variant sessionWithSharedUserWithPermissions:uniqueUserTag:. + + This method should not be used in application code -- but is useful for creating unit tests + that use the Facebook SDK. + + @param permissions array of strings naming permissions to authorize; nil indicates + a common default set of permissions should be used for unit testing + */ ++ (id)sessionWithSharedUserWithPermissions:(NSArray*)permissions; + +/*! + @abstract + Constructor helper to create a session for use in unit tests + + @discussion + This method creates a session object which uses a shared test user with the right permissions, + creating one if necessary on open (but not deleting it on close, so it can be re-used in later + tests). + + This method should not be used in application code -- but is useful for creating unit tests + that use the Facebook SDK. + + @param permissions array of strings naming permissions to authorize; nil indicates + a common default set of permissions should be used for unit testing + + @param uniqueUserTag a string which will be used to make this user unique among other + users with the same permissions. Useful for tests which require two or more users to interact + with each other, and which therefore must have sessions associated with different users. For + this case, consider using kSecondTestUserTag and kThirdTestUserTag so these users can be shared + with other, similar, tests. + */ ++ (id)sessionWithSharedUserWithPermissions:(NSArray*)permissions + uniqueUserTag:(NSString*)uniqueUserTag; + +/*! + @abstract + Constructor helper to create a session for use in unit tests + + @discussion + This method creates a session object which creates a test user on open, and destroys the user on + close; This method should not be used in application code -- but is useful for creating unit tests + that use the Facebook SDK. + + @param permissions array of strings naming permissions to authorize; nil indicates + a common default set of permissions should be used for unit testing + */ ++ (id)sessionWithPrivateUserWithPermissions:(NSArray*)permissions; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBUserSettingsViewController.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBUserSettingsViewController.h new file mode 100644 index 0000000..5df08e7 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBUserSettingsViewController.h @@ -0,0 +1,128 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "FBSession.h" +#import "FBViewController.h" + +/*! + @protocol + + @abstract + The `FBUserSettingsDelegate` protocol defines the methods called by a . + */ +@protocol FBUserSettingsDelegate + +@optional + +/*! + @abstract + Called when the view controller will log the user out in response to a button press. + + @param sender The view controller sending the message. + */ +- (void)loginViewControllerWillLogUserOut:(id)sender; + +/*! + @abstract + Called after the view controller logged the user out in response to a button press. + + @param sender The view controller sending the message. + */ +- (void)loginViewControllerDidLogUserOut:(id)sender; + +/*! + @abstract + Called when the view controller will log the user in in response to a button press. + Note that logging in can fail for a number of reasons, so there is no guarantee that this + will be followed by a call to loginViewControllerDidLogUserIn:. Callers wanting more granular + notification of the session state changes can use KVO or the NSNotificationCenter to observe them. + + @param sender The view controller sending the message. + */ +- (void)loginViewControllerWillAttemptToLogUserIn:(id)sender; + +/*! + @abstract + Called after the view controller successfully logged the user in in response to a button press. + + @param sender The view controller sending the message. + */ +- (void)loginViewControllerDidLogUserIn:(id)sender; + +/*! + @abstract + Called if the view controller encounters an error while trying to log a user in. + + @param sender The view controller sending the message. + @param error The error encountered. + @discussion See https://developers.facebook.com/docs/technical-guides/iossdk/errors/ + for error handling best practices. + */ +- (void)loginViewController:(id)sender receivedError:(NSError *)error; + +@end + + +/*! + @class FBUserSettingsViewController + + @abstract + The `FBUserSettingsViewController` class provides a user interface exposing a user's + Facebook-related settings. Currently, this is limited to whether they are logged in or out + of Facebook. + + Because of the size of some graphics used in this view, its resources are packaged as a separate + bundle. In order to use `FBUserSettingsViewController`, drag the `FBUserSettingsViewResources.bundle` + from the SDK directory into your Xcode project. + */ +@interface FBUserSettingsViewController : FBViewController + +/*! + @abstract + The permissions to request if the user logs in via this view. + */ +@property (nonatomic, copy) NSArray *permissions __attribute__((deprecated)); + +/*! + @abstract + The read permissions to request if the user logs in via this view. + + @discussion + Note, that if read permissions are specified, then publish permissions should not be specified. + */ +@property (nonatomic, copy) NSArray *readPermissions; + +/*! + @abstract + The publish permissions to request if the user logs in via this view. + + @discussion + Note, that a defaultAudience value of FBSessionDefaultAudienceOnlyMe, FBSessionDefaultAudienceEveryone, or + FBSessionDefaultAudienceFriends should be set if publish permissions are specified. Additionally, when publish + permissions are specified, then read should not be specified. + */ +@property (nonatomic, copy) NSArray *publishPermissions; + +/*! + @abstract + The default audience to use, if publish permissions are requested at login time. + */ +@property (nonatomic, assign) FBSessionDefaultAudience defaultAudience; + +@end + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBViewController.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBViewController.h new file mode 100644 index 0000000..3025fd8 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBViewController.h @@ -0,0 +1,118 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@class FBViewController; + +/*! + @typedef FBModalCompletionHandler + + @abstract + A block that is passed to [FBViewController presentModallyInViewController:animated:handler:] + and called when the view controller is dismissed via either Done or Cancel. + + @param sender The that is being dismissed. + + @param donePressed If YES, Done was pressed. If NO, Cancel was pressed. + */ +typedef void (^FBModalCompletionHandler)(FBViewController *sender, BOOL donePressed); + +/*! + @protocol + + @abstract + The `FBViewControllerDelegate` protocol defines the methods called when the Cancel or Done + buttons are pressed in a . + */ +@protocol FBViewControllerDelegate + +@optional + +/*! + @abstract + Called when the Cancel button is pressed on a modally-presented . + + @param sender The view controller sending the message. + */ +- (void)facebookViewControllerCancelWasPressed:(id)sender; + +/*! + @abstract + Called when the Done button is pressed on a modally-presented . + + @param sender The view controller sending the message. + */ +- (void)facebookViewControllerDoneWasPressed:(id)sender; + +@end + + +/*! + @class FBViewController + + @abstract + The `FBViewController` class is a base class encapsulating functionality common to several + other view controller classes. Specifically, it provides UI when a view controller is presented + modally, in the form of optional Cancel and Done buttons. + */ +@interface FBViewController : UIViewController + +/*! + @abstract + The Cancel button to display when presented modally. If nil, no Cancel button is displayed. + If this button is provided, its target and action will be redirected to internal handlers, replacing + any previous target that may have been set. + */ +@property (nonatomic, retain) IBOutlet UIBarButtonItem *cancelButton; + +/*! + @abstract + The Done button to display when presented modally. If nil, no Done button is displayed. + If this button is provided, its target and action will be redirected to internal handlers, replacing + any previous target that may have been set. + */ +@property (nonatomic, retain) IBOutlet UIBarButtonItem *doneButton; + +/*! + @abstract + The delegate that will be called when Cancel or Done is pressed. Derived classes may specify + derived types for their delegates that provide additional functionality. + */ +@property (nonatomic, assign) IBOutlet id delegate; + +/*! + @abstract + The view into which derived classes should put their subviews. This view will be resized correctly + depending on whether or not a toolbar is displayed. + */ +@property (nonatomic, readonly, retain) UIView *canvasView; + +/*! + @abstract + Provides a wrapper that presents the view controller modally and automatically dismisses it + when either the Done or Cancel button is pressed. + + @param viewController The view controller that is presenting this view controller. + @param animated If YES, presenting and dismissing the view controller is animated. + @param handler The block called when the Done or Cancel button is pressed. + */ +- (void)presentModallyFromViewController:(UIViewController*)viewController + animated:(BOOL)animated + handler:(FBModalCompletionHandler)handler; + +@end + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBWebDialogs.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBWebDialogs.h new file mode 100644 index 0000000..8b0429e --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FBWebDialogs.h @@ -0,0 +1,234 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@class FBFrictionlessRecipientCache; +@class FBSession; +@protocol FBWebDialogsDelegate; + +/*! + @typedef FBWebDialogResult enum + + @abstract + Passed to a handler to indicate the result of a dialog being displayed to the user. +*/ +typedef enum { + /*! Indicates that the dialog action completed successfully. Note, that cancel operations represent completed dialog operations. + The url argument may be used to distinguish between success and user-cancelled cases */ + FBWebDialogResultDialogCompleted, + /*! Indicates that the dialog operation was not completed. This occurs in cases such as the closure of the web-view using the X in the upper left corner. */ + FBWebDialogResultDialogNotCompleted +} FBWebDialogResult; + +/*! + @typedef + + @abstract Defines a handler that will be called in response to the web dialog + being dismissed + */ +typedef void (^FBWebDialogHandler)( + FBWebDialogResult result, + NSURL *resultURL, + NSError *error); + +/*! + @class FBWebDialogs + + @abstract + Provides methods to display web based dialogs to the user. +*/ +@interface FBWebDialogs : NSObject + +/*! + @abstract + Presents a Facebook web dialog (https://developers.facebook.com/docs/reference/dialogs/ ) + such as feed or apprequest. + + @param session Represents the session to use for the dialog. May be nil, which uses + the active session if present, or returns NO, if not. + + @param dialog Represents the dialog or method name, such as @"feed" + + @param parameters A dictionary of parameters to be passed to the dialog + + @param handler An optional handler that will be called when the dialog is dismissed. Note, + that if the method returns NO, the handler is not called. May be nil. + */ ++ (void)presentDialogModallyWithSession:(FBSession *)session + dialog:(NSString *)dialog + parameters:(NSDictionary *)parameters + handler:(FBWebDialogHandler)handler; + +/*! + @abstract + Presents a Facebook web dialog (https://developers.facebook.com/docs/reference/dialogs/ ) + such as feed or apprequest. + + @param session Represents the session to use for the dialog. May be nil, which uses + the active session if present, or returns NO, if not. + + @param dialog Represents the dialog or method name, such as @"feed" + + @param parameters A dictionary of parameters to be passed to the dialog + + @param handler An optional handler that will be called when the dialog is dismissed. Note, + that if the method returns NO, the handler is not called. May be nil. + + @param delegate An optional delegate to allow for advanced processing of web based + dialogs. See 'FBWebDialogsDelegate' for more details. + */ ++ (void)presentDialogModallyWithSession:(FBSession *)session + dialog:(NSString *)dialog + parameters:(NSDictionary *)parameters + handler:(FBWebDialogHandler)handler + delegate:(id)delegate; + +/*! + @abstract + Presents a Facebook apprequest dialog. + + @param session Represents the session to use for the dialog. May be nil, which uses + the active session if present. + + @param message The required message for the dialog. + + @param title An optional title for the dialog. + + @param parameters A dictionary of additional parameters to be passed to the dialog. May be nil + + @param handler An optional handler that will be called when the dialog is dismissed. May be nil. + */ ++ (void)presentRequestsDialogModallyWithSession:(FBSession *)session + message:(NSString *)message + title:(NSString *)title + parameters:(NSDictionary *)parameters + handler:(FBWebDialogHandler)handler; + +/*! + @abstract + Presents a Facebook apprequest dialog. + + @param session Represents the session to use for the dialog. May be nil, which uses + the active session if present. + + @param message The required message for the dialog. + + @param title An optional title for the dialog. + + @param parameters A dictionary of additional parameters to be passed to the dialog. May be nil + + @param handler An optional handler that will be called when the dialog is dismissed. May be nil. + + @param friendCache An optional cache object used to enable frictionless sharing for a known set of friends. The + cache instance should be preserved for the life of the session and reused for multiple calls to the present method. + As the users set of friends enabled for frictionless sharing changes, this method auto-updates the cache. + */ ++ (void)presentRequestsDialogModallyWithSession:(FBSession *)session + message:(NSString *)message + title:(NSString *)title + parameters:(NSDictionary *)parameters + handler:(FBWebDialogHandler)handler + friendCache:(FBFrictionlessRecipientCache *)friendCache; + +/*! + @abstract + Presents a Facebook feed dialog. + + @param session Represents the session to use for the dialog. May be nil, which uses + the active session if present. + + @param parameters A dictionary of additional parameters to be passed to the dialog. May be nil + + @param handler An optional handler that will be called when the dialog is dismissed. May be nil. + */ ++ (void)presentFeedDialogModallyWithSession:(FBSession *)session + parameters:(NSDictionary *)parameters + handler:(FBWebDialogHandler)handler; + +@end + +/*! + @protocol + + @abstract + The `FBWebDialogsDelegate` protocol enables the plugging of advanced behaviors into + the presentation flow of a Facebook web dialog. Advanced uses include modification + of parameters and application-level handling of links on the dialog. The + `FBFrictionlessRequestFriendCache` class implements this protocol to add frictionless + behaviors to a presentation of the request dialog. + */ +@protocol FBWebDialogsDelegate + +@optional + +/*! + @abstract + Called prior to the presentation of a web dialog + + @param dialog A string representing the method or dialog name of the dialog being presented. + + @param parameters A mutable dictionary of parameters which will be sent to the dialog. + + @param session The session object to use with the dialog. + */ +- (void)webDialogsWillPresentDialog:(NSString *)dialog + parameters:(NSMutableDictionary *)parameters + session:(FBSession *)session; + +/*! + @abstract + Called when the user of a dialog clicks a link that would cause a transition away from the application. + Your application may handle this method, and return NO if the URL handling will be performed by the application. + + @param dialog A string representing the method or dialog name of the dialog being presented. + + @param parameters A dictionary of parameters which were sent to the dialog. + + @param session The session object to use with the dialog. + + @param url The url in question, which will not be handled by the SDK if this method NO + */ +- (BOOL)webDialogsDialog:(NSString *)dialog + parameters:(NSDictionary *)parameters + session:(FBSession *)session + shouldAutoHandleURL:(NSURL *)url; + +/*! + @abstract + Called when the dialog is about to be dismissed + + @param dialog A string representing the method or dialog name of the dialog being presented. + + @param parameters A dictionary of parameters which were sent to the dialog. + + @param session The session object to use with the dialog. + + @param result A pointer to a result, which may be read or changed by the handling method as needed + + @param url A pointer to a pointer to a URL representing the URL returned by the dialog, which may be read or changed by this mehthod + + @param error A pointer to a pointer to an error object which may be read or changed by this method as needed + */ +- (void)webDialogsWillDismissDialog:(NSString *)dialog + parameters:(NSDictionary *)parameters + session:(FBSession *)session + result:(FBWebDialogResult *)result + url:(NSURL **)url + error:(NSError **)error; + +@end + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FacebookSDK.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FacebookSDK.h new file mode 100644 index 0000000..40147ef --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/FacebookSDK.h @@ -0,0 +1,139 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// core +#import "FBAccessTokenData.h" +#import "FBAppCall.h" +#import "FBAppEvents.h" +#import "FBCacheDescriptor.h" +#import "FBDialogs.h" +#import "FBError.h" +#import "FBErrorUtility.h" +#import "FBFrictionlessRecipientCache.h" +#import "FBFriendPickerViewController.h" +#import "FBGraphLocation.h" +#import "FBGraphObject.h" // + design summary for graph component-group +#import "FBGraphPlace.h" +#import "FBGraphUser.h" +#import "FBInsights.h" +#import "FBLoginView.h" +#import "FBNativeDialogs.h" // deprecated, use FBDialogs.h +#import "FBOpenGraphAction.h" +#import "FBOpenGraphActionShareDialogParams.h" +#import "FBOpenGraphObject.h" +#import "FBPlacePickerViewController.h" +#import "FBProfilePictureView.h" +#import "FBRequest.h" +#import "FBSession.h" +#import "FBSessionTokenCachingStrategy.h" +#import "FBSettings.h" +#import "FBShareDialogParams.h" +#import "FBUserSettingsViewController.h" +#import "FBWebDialogs.h" +#import "NSError+FBError.h" + +/*! + @header + + @abstract Library header, import this to import all of the public types + in the Facebook SDK + + @discussion + +//////////////////////////////////////////////////////////////////////////////// + + + Summary: this header summarizes the structure and goals of the Facebook SDK for iOS. + Goals: + * Leverage and work well with modern features of iOS (e.g. blocks, ARC, etc.) + * Patterned after best of breed iOS frameworks (e.g. naming, pattern-use, etc.) + * Common integration experience is simple & easy to describe + * Factored to enable a growing list of scenarios over time + + Notes on approaches: + 1. We use a key scenario to drive prioritization of work for a given update + 2. We are building-atop and refactoring, rather than replacing, existing iOS SDK releases + 3. We use take an incremental approach where we can choose to maintain as little or as much compatibility with the existing SDK needed + a) and so we will be developing to this approach + b) and then at push-time for a release we will decide when/what to break + on a feature by feature basis + 4. Some light but critical infrastructure is needed to support both the goals + and the execution of this change (e.g. a build/package/deploy process) + + Design points: + We will move to a more object-oriented approach, in order to facilitate the + addition of a different class of objects, such as controls and visual helpers + (e.g. FBLikeView, FBPersonView), as well as sub-frameworks to enable scenarios + such (e.g. FBOpenGraphEntity, FBLocalEntityCache, etc.) + + As we add features, it will no longer be appropriate to host all functionality + in the Facebook class, though it will be maintained for some time for migration + purposes. Instead functionality lives in related collections of classes. + +
+ @textblock
+
+               *------------* *----------*  *----------------* *---*
+  Scenario --> |FBPersonView| |FBLikeView|  | FBPlacePicker  | | F |
+               *------------* *----------*  *----------------* | a |
+               *-------------------*  *----------*  *--------* | c |
+ Component --> |   FBGraphObject   |  | FBDialog |  | FBView | | e |
+               *-------------------*  *----------*  *--------* | b |
+               *---------* *---------* *---------------------* | o |
+      Core --> |FBSession| |FBRequest| |Utilities (e.g. JSON)| | o |
+               *---------* *---------* *---------------------* * k *
+
+ @/textblock
+ 
+ + The figure above describes three layers of functionality, with the existing + Facebook on the side as a helper proxy to a subset of the overall SDK. The + layers loosely organize the SDK into *Core Objects* necessary to interface + with Facebook, higher-level *Framework Components* that feel like natural + extensions to existing frameworks such as UIKit and Foundation, but which + surface behavior broadly applicable to Facebook, and finally the + *Scenario Objects*, which provide deeper turn-key capibilities for useful + mobile scenarios. + + Use example (low barrier use case): + +
+ @textblock
+
+// log on to Facebook
+[FBSession sessionOpenWithPermissions:nil
+                    completionHandler:^(FBSession *session,
+                                        FBSessionState status,
+                                        NSError *error) {
+                        if (session.isOpen) {
+                            // request basic information for the user
+                            [FBRequestConnection startWithGraphPath:@"me"
+                                                  completionHandler:^void(FBRequestConnection *request,
+                                                                          id result,
+                                                                          NSError *error) {
+                                                      if (!error) {
+                                                          // get json from result
+                                                      }
+                                                  }];
+                        }
+                    }];
+ @/textblock
+ 
+ + */ + +#define FB_IOS_SDK_VERSION_STRING @"3.11.1" + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/NSError+FBError.h b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/NSError+FBError.h new file mode 100644 index 0000000..61659a5 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Headers/NSError+FBError.h @@ -0,0 +1,59 @@ +/* + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "FBError.h" + +/*! + @category NSError(FBError) + + @abstract + Adds additional properties to NSError to provide more information for Facebook related errors. + */ +@interface NSError (FBError) + +/*! + @abstract + Categorizes the error, if it is Facebook related, to simplify application mitigation behavior + + @discussion + In general, in response to an error connecting to Facebook, an application should, retry the + operation, request permissions, reconnect the application, or prompt the user to take an action. + The error category can be used to understand the class of error received from Facebook. For more infomation on this + see https://developers.facebook.com/docs/reference/api/errors/ + */ +@property (readonly) FBErrorCategory fberrorCategory; + +/*! + @abstract + If YES indicates that a user action is required in order to successfully continue with the facebook operation + + @discussion + In general if fberrorShouldNotifyUser is NO, then the application has a straightforward mitigation, such as + retry the operation or request permissions from the user, etc. In some cases it is necessary for the user to + take an action before the application continues to attempt a Facebook connection. For more infomation on this + see https://developers.facebook.com/docs/reference/api/errors/ + */ +@property (readonly) BOOL fberrorShouldNotifyUser; + +/*! + @abstract + A message suitable for display to the user, describing a user action necessary to enable Facebook functionality. + Not all Facebook errors yield a message suitable for user display; however in all cases where + fberrorShouldNotifyUser is YES, this property returns a localizable message suitable for display. + */ +@property (readonly, copy) NSString *fberrorUserMessage; + +@end diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/Contents/Resources/en.lproj/Localizable.strings b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/Contents/Resources/en.lproj/Localizable.strings new file mode 100644 index 0000000..7fd7575 Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/Contents/Resources/en.lproj/Localizable.strings differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/Contents/Resources/he.lproj/Localizable.strings b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/Contents/Resources/he.lproj/Localizable.strings new file mode 100644 index 0000000..bb3ba24 Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/Contents/Resources/he.lproj/Localizable.strings differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/facebook-logo.png b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/facebook-logo.png new file mode 100644 index 0000000..be1dccd Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/facebook-logo.png differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/facebook-logo@2x.png b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/facebook-logo@2x.png new file mode 100644 index 0000000..4b03929 Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/facebook-logo@2x.png differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadLandscape.jpg b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadLandscape.jpg new file mode 100644 index 0000000..f056b80 Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadLandscape.jpg differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadLandscape@2x.jpg b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadLandscape@2x.jpg new file mode 100644 index 0000000..abde7eb Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadLandscape@2x.jpg differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadPortrait.jpg b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadPortrait.jpg new file mode 100644 index 0000000..2c16bd4 Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadPortrait.jpg differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadPortrait@2x.jpg b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadPortrait@2x.jpg new file mode 100644 index 0000000..ae3e2bd Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPadPortrait@2x.jpg differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPhonePortrait.jpg b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPhonePortrait.jpg new file mode 100644 index 0000000..f4d31c5 Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPhonePortrait.jpg differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPhonePortrait@2x.jpg b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPhonePortrait@2x.jpg new file mode 100644 index 0000000..8eba2f1 Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/loginBackgroundIPhonePortrait@2x.jpg differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-normal.png b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-normal.png new file mode 100644 index 0000000..892419f Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-normal.png differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-normal@2x.png b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-normal@2x.png new file mode 100644 index 0000000..daa4ba6 Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-normal@2x.png differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-pressed.png b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-pressed.png new file mode 100644 index 0000000..3f862c8 Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-pressed.png differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-pressed@2x.png b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-pressed@2x.png new file mode 100644 index 0000000..7866e3d Binary files /dev/null and b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle/images/silver-button-pressed@2x.png differ diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FacebookSDKResources.bundle.README b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FacebookSDKResources.bundle.README new file mode 100644 index 0000000..3ae35b4 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/FacebookSDKResources.bundle.README @@ -0,0 +1,44 @@ +The FacebookSDKResources.bundle is no longer required in order to use the SDK. You may provide a bundle in cases where you need to override strings or images (e.g. internationalization, etc.) See https://developers.facebook.com/docs/reference/ios/current/constants/FBSettings#resourceBundleName for more information. + +The following is a list of keys for string localization: + +/* FBLoginView (aka FBLV) */ +"FBLV:LogOutButton" = "Log Out"; +"FBLV:LogInButton" = "Log In"; +"FBLV:LoggedInAs" = "Logged in as: %@"; +"FBLV:LoggedInUsingFacebook" = "Logged in using Facebook"; +"FBLV:LogOutAction" = "Log Out"; +"FBLV:CancelAction" = "Cancel"; + +/* FBPlacePickerViewController (FBPPVC) */ +"FBPPVC:NumWereHere" = "%@ were here"; + +/* FBError (aka FBE) */ +"FBE:ReconnectApplication" = "Please log into this app again to reconnect your Facebook account."; +"FBE:PasswordChangedDevice" = "Your Facebook password has changed. To confirm your password, open Settings > Facebook and tap your name."; +"FBE:PasswordChanged" = "Your Facebook password has changed. Please log into this app again to reconnect your Facebook account."; +"FBE:WebLogIn" = "Your Facebook account is locked. Please log into www.facebook.com to continue."; +"FBE:AppNotInstalled" = "Please log into this app again to reconnect your Facebook account."; +"FBE:GrantPermission" = "This app doesn’t have permission to do this. To change permissions, try logging into the app again."; +"FBE:Unconfirmed" = "Your Facebook account is locked. Please log into www.facebook.com to continue."; +"FBE:OAuthDevice" = "To use your Facebook account with this app, open Settings > Facebook and make sure this app is turned on."; +"FBE:DeviceError"= "Something went wrong. Please make sure you're connected to the internet and try again."; +"FBE:AlertMessageButton" = "OK"; + +Images should be placed in a directory called FacebookSDKImages in the bundle. Note that images will support @2x and -568h@2x. + +The following is a list of images supported: + +FacebookSDKImages\ + + FBDialogClose.png + + FBFriendPickerViewDefault.png + + FBLoginViewLoginButtonSmall.png + FBLoginViewLoginButtonSmallPressed.png + + FBPlacePickerViewGenericPlace.png + + FBProfilePictureViewBlankProfileSquare.png + FBProfilePictureViewBlankProfilePortrait.png diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/Info.plist b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/Info.plist new file mode 100644 index 0000000..0dd599a --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/A/Resources/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + FacebookSDK + CFBundleIdentifier + com.facebook.sdk + CFBundleInfoDictionaryVersion + 1.0 + CFBundlePackageType + FMWK + CFBundleSignature + ???? + CFBundleVersion + 1.0 + + diff --git a/client/ios/Hackpad/FacebookSDK.framework/Versions/Current b/client/ios/Hackpad/FacebookSDK.framework/Versions/Current new file mode 120000 index 0000000..044dcb9 --- /dev/null +++ b/client/ios/Hackpad/FacebookSDK.framework/Versions/Current @@ -0,0 +1 @@ +./A \ No newline at end of file diff --git a/client/ios/Hackpad/Flurry/Flurry.h b/client/ios/Hackpad/Flurry/Flurry.h new file mode 100755 index 0000000..f046105 --- /dev/null +++ b/client/ios/Hackpad/Flurry/Flurry.h @@ -0,0 +1,747 @@ +// +// Flurry.h +// Flurry iOS Analytics Agent +// +// Copyright 2009-2012 Flurry, Inc. All rights reserved. +// +// Methods in this header file are for use with Flurry Analytics + +#import + +/*! + * @brief Provides all available methods for defining and reporting Analytics from use + * of your app. + * + * Set of methods that allow developers to capture detailed, aggregate information + * regarding the use of their app by end users. + * + * @note This class provides methods necessary for correct function of FlurryAds.h. + * For information on how to use Flurry's Ads SDK to + * attract high-quality users and monetize your user base see Support Center - Publishers. + * + * @author 2009 - 2013 Flurry, Inc. All Rights Reserved. + * @version 4.3.0 + * + */ + +/*! + * @brief Enum for setting up log output level. + * @since 4.2.0 + * + */ +typedef enum { + FlurryLogLevelNone = 0, //No output + FlurryLogLevelCriticalOnly, //Default, outputs only critical log events + FlurryLogLevelDebug, //Debug level, outputs critical and main log events + FlurryLogLevelAll //Highest level, outputs all log events +} FlurryLogLevel; + + +@interface Flurry : NSObject { +} + +/** @name Pre-Session Calls + * Optional sdk settings that should be called before start session. + */ +//@{ + +/*! + * @brief Explicitly specifies the App Version that Flurry will use to group Analytics data. + * @since 2.7 + * + * This is an optional method that overrides the App Version Flurry uses for reporting. Flurry will + * use the CFBundleVersion in your info.plist file when this method is not invoked. + * + * @note There is a maximum of 605 versions allowed for a single app. \n + * This method must be called prior to invoking #startSession:. + * + * @param version The custom version name. + */ + ++ (void)setAppVersion:(NSString *)version; + +/*! + * @brief Retrieves the Flurry Agent Build Version. + * @since 2.7 + * + * This is an optional method that retrieves the Flurry Agent Version the app is running under. + * It is most often used if reporting an unexpected behavior of the SDK to + * Flurry Support + * + * @note This method must be called prior to invoking #startSession:. \n + * FAQ for the iPhone SDK is located at + * Support Center - iPhone FAQ. + * + * @see #setLogLevel: for information on how to view debugging information on your console. + * + * @return The agent version of the Flurry SDK. + * + */ ++ (NSString *)getFlurryAgentVersion; + +/*! + * @brief Displays an exception in the debug log if thrown during a Session. + * @since 2.7 + * + * This is an optional method that augments the debug logs with exceptions that occur during the session. + * You must both capture exceptions to Flurry and set debug logging to enabled for this method to + * display information to the console. The default setting for this method is @c NO. + * + * @note This method must be called prior to invoking #startSession:. + * + * @see #setLogLevel: for information on how to view debugging information on your console. \n + * #logError:message:exception: for details on logging exceptions. \n + * #logError:message:error: for details on logging errors. + * + * @param value @c YES to show errors in debug logs, @c NO to omit errors in debug logs. + */ ++ (void)setShowErrorInLogEnabled:(BOOL)value; + +/*! + * @brief Generates debug logs to console. + * @since 2.7 + * + * This is an optional method that displays debug information related to the Flurry SDK. + * display information to the console. The default setting for this method is @c NO + * which sets the log level to @c FlurryLogLevelCriticalOnly. + * When set to @c YES the debug log level is set to @c FlurryLogLevelDebug + * + * @note This method must be called prior to invoking #startSession:. If the method, setLogLevel is called later in the code, debug logging will be automatically enabled. + * + * @param value @c YES to show debug logs, @c NO to omit debug logs. + * + */ ++ (void)setDebugLogEnabled:(BOOL)value; + +/*! + * @brief Generates debug logs to console. + * @since 4.2.2 + * + * This is an optional method that displays debug information related to the Flurry SDK. + * display information to the console. The default setting for this method is @c FlurryLogLevelCritycalOnly. + * + * @note Its good practice to call this method prior to invoking #startSession:. If debug logging is disabled earlier, this method will enable it. + * + * @param value Log level + * + */ ++ (void)setLogLevel:(FlurryLogLevel)value; + +/*! + * @brief Set the timeout for expiring a Flurry session. + * @since 2.7 + * + * This is an optional method that sets the time the app may be in the background before + * starting a new session upon resume. The default value for the session timeout is 10 + * seconds in the background. + * + * @note This method must be called prior to invoking #startSession:. + * + * @param seconds The time in seconds to set the session timeout to. + */ ++ (void)setSessionContinueSeconds:(int)seconds; + +/*! + * @brief Send data over a secure transport. + * @since 3.0 + * + * This is an optional method that sends data over an SSL connection when enabled. The + * default value is @c NO. + * + * @note This method must be called prior to invoking #startSession:. + * + * @param value @c YES to send data over secure connection. + */ ++ (void)setSecureTransportEnabled:(BOOL)value; + +/*! + * @brief Enable automatic collection of crash reports. + * @since 4.1 + * + * This is an optional method that collects crash reports when enabled. The + * default value is @c NO. + * + * @note This method must be called prior to invoking #startSession:. + * + * @param value @c YES to enable collection of crash reports. + */ ++ (void)setCrashReportingEnabled:(BOOL)value; + +//@} + +/*! + * @brief Start a Flurry session for the project denoted by @c apiKey. + * @since 2.6 + * + * This method serves as the entry point to Flurry Analytics collection. It must be + * called in the scope of @c applicationDidFinishLaunching. The session will continue + * for the period the app is in the foreground until your app is backgrounded for the + * time specified in #setSessionContinueSeconds:. If the app is resumed in that period + * the session will continue, otherwise a new session will begin. + * + * Crash reporting will not be enabled. See #setCrashReportingEnabled: for + * more information. + * + * @note If testing on a simulator, please be sure to send App to background via home + * button. Flurry depends on the iOS lifecycle to be complete for full reporting. + * + * @see #setSessionContinueSeconds: for details on setting a custom session timeout. + * + * @code + * - (void)applicationDidFinishLaunching:(UIApplication *)application + { + // Optional Flurry startup methods + [Flurry startSession:@"YOUR_API_KEY"]; + // .... + } + * @endcode + * + * @param apiKey The API key for this project. + */ + ++ (void)startSession:(NSString *)apiKey; + + +/*! + * @brief Start a Flurry session for the project denoted by @c apiKey. + * @since 4.0.8 + * + * This method serves as the entry point to Flurry Analytics collection. It must be + * called in the scope of @c applicationDidFinishLaunching passing in the launchOptions param. + * The session will continue + * for the period the app is in the foreground until your app is backgrounded for the + * time specified in #setSessionContinueSeconds:. If the app is resumed in that period + * the session will continue, otherwise a new session will begin. + * + * @note If testing on a simulator, please be sure to send App to background via home + * button. Flurry depends on the iOS lifecycle to be complete for full reporting. + * + * @see #setSessionContinueSeconds: for details on setting a custom session timeout. + * + * @code + * - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions + { + // Optional Flurry startup methods + [Flurry startSession:@"YOUR_API_KEY" withOptions:launchOptions]; + // .... + } + * @endcode + * + * @param apiKey The API key for this project. + * @param options passed launchOptions from the applicatin's didFinishLaunchingWithOptions:(NSDictionary *)launchOptions + + */ ++ (void) startSession:(NSString *)apiKey withOptions:(id)options; + + +/*! + * @brief Pauses a Flurry session left running in background. + * @since 4.2.2 + * + * This method should be used in case of #setBackgroundSessionEnabled: set to YES. It can be + * called when application finished all background tasks (such as playing music) to pause session. + * + * @see #setBackgroundSessionEnabled: for details on setting a custom behaviour on resigning activity. + * + * @code + * - (void)allBackgroundTasksFinished + { + // .... + [Flurry pauseBackgroundSession]; + // .... + } + * @endcode + * + */ ++ (void)pauseBackgroundSession; + + +/** @name Event and Error Logging + * Methods for reporting custom events and errors during the session. + */ +//@{ + +/*! + * @brief Records a custom event specified by @c eventName. + * @since 2.8.4 + * + * This method allows you to specify custom events within your app. As a general rule + * you should capture events related to user navigation within your app, any action + * around monetization, and other events as they are applicable to tracking progress + * towards your business goals. + * + * @note You should not pass private or confidential information about your users in a + * custom event. \n + * Where applicable, you should make a concerted effort to use timed events with + * parameters (#logEvent:withParameters:timed:) or events with parameters + * (#logEvent:withParameters:). This provides valuable information around the time the user + * spends within an action (e.g. - time spent on a level or viewing a page) or characteristics + * of an action (e.g. - Buy Event that has a Parameter of Widget with Value Golden Sword). + * + * @see #logEvent:withParameters: for details on storing events with parameters. \n + * #logEvent:timed: for details on storing timed events. \n + * #logEvent:withParameters:timed: for details on storing timed events with parameters. \n + * #endTimedEvent:withParameters: for details on stopping a timed event and (optionally) updating + * parameters. + * + * @code + * - (void)interestingAppAction + { + [Flurry logEvent:@"Interesting_Action"]; + // Perform interesting action + } + * @endcode + * + * @param eventName Name of the event. For maximum effectiveness, we recommend using a naming scheme + * that can be easily understood by non-technical people in your business domain. + */ ++ (void)logEvent:(NSString *)eventName; + +/*! + * @brief Records a custom parameterized event specified by @c eventName with @c parameters. + * @since 2.8.4 + * + * This method overrides #logEvent to allow you to associate parameters with an event. Parameters + * are extremely valuable as they allow you to store characteristics of an action. For example, + * if a user purchased an item it may be helpful to know what level that user was on. + * By setting this parameter you will be able to view a distribution of levels for the purcahsed + * event on the Flurrly Dev Portal. + * + * @note You should not pass private or confidential information about your users in a + * custom event. \n + * A maximum of 10 parameter names may be associated with any event. Sending + * over 10 parameter names with a single event will result in no parameters being logged + * for that event. You may specify an infinite number of Parameter values. For example, + * a Search Box would have 1 parameter name (e.g. - Search Box) and many values, which would + * allow you to see what values users look for the most in your app. \n + * Where applicable, you should make a concerted effort to use timed events with + * parameters (#logEvent:withParameters:timed:). This provides valuable information + * around the time the user spends within an action (e.g. - time spent on a level or + * viewing a page). + * + * @see #logEvent:withParameters:timed: for details on storing timed events with parameters. \n + * #endTimedEvent:withParameters: for details on stopping a timed event and (optionally) updating + * parameters. + * + * @code + * - (void)userPurchasedSomethingCool + { + NSDictionary *params = + [NSDictionary dictionaryWithObjectsAndKeys:@"Cool Item", // Parameter Value + @"Item Purchased", // Parameter Name + nil]; + [Flurry logEvent:@"Something Cool Purchased" withParameters:params]; + // Give user cool item + } + * @endcode + * + * @param eventName Name of the event. For maximum effectiveness, we recommend using a naming scheme + * that can be easily understood by non-technical people in your business domain. + * @param parameters A map containing Name-Value pairs of parameters. + */ ++ (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters; + +/*! + * @brief Records an app exception. Commonly used to catch unhandled exceptions. + * @since 2.7 + * + * This method captures an exception for reporting to Flurry. We recommend adding an uncaught + * exception listener to capture any exceptions that occur during usage that is not + * anticipated by your app. + * + * @see #logError:message:error: for details on capturing errors. + * + * @code + * - (void) uncaughtExceptionHandler(NSException *exception) + { + [Flurry logError:@"Uncaught" message:@"Crash!" exception:exception]; + } + + - (void)applicationDidFinishLaunching:(UIApplication *)application + { + NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); + [Flurry startSession:@"YOUR_API_KEY"]; + // .... + } + * @endcode + * + * @param errorID Name of the error. + * @param message The message to associate with the error. + * @param exception The exception object to report. + */ ++ (void)logError:(NSString *)errorID message:(NSString *)message exception:(NSException *)exception; + +/*! + * @brief Records an app error. + * @since 2.7 + * + * This method captures an error for reporting to Flurry. + * + * @see #logError:message:exception: for details on capturing exceptions. + * + * @code + * - (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error + { + [Flurry logError:@"WebView No Load" message:[error localizedDescription] error:error]; + } + * @endcode + * + * @param errorID Name of the error. + * @param message The message to associate with the error. + * @param error The error object to report. + */ ++ (void)logError:(NSString *)errorID message:(NSString *)message error:(NSError *)error; + +/*! + * @brief Records a timed event specified by @c eventName. + * @since 2.8.4 + * + * This method overrides #logEvent to allow you to capture the length of an event. This can + * be extremely valuable to understand the level of engagement with a particular action. For + * example, you can capture how long a user spends on a level or reading an article. + * + * @note You should not pass private or confidential information about your users in a + * custom event. \n + * Where applicable, you should make a concerted effort to use parameters with your timed + * events (#logEvent:withParameters:timed:). This provides valuable information + * around the characteristics of an action (e.g. - Buy Event that has a Parameter of Widget with + * Value Golden Sword). + * + * @see #logEvent:withParameters:timed: for details on storing timed events with parameters. \n + * #endTimedEvent:withParameters: for details on stopping a timed event and (optionally) updating + * parameters. + * + * @code + * - (void)startLevel + { + [Flurry logEvent:@"Level Played" timed:YES]; + // Start user on level + } + + - (void)endLevel + { + [Flurry endTimedEvent:@"Level Played" withParameters:nil]; + // User done with level + } + * @endcode + * + * @param eventName Name of the event. For maximum effectiveness, we recommend using a naming scheme + * that can be easily understood by non-technical people in your business domain. + * @param timed Specifies the event will be timed. + */ ++ (void)logEvent:(NSString *)eventName timed:(BOOL)timed; + +/*! + * @brief Records a custom parameterized timed event specified by @c eventName with @c parameters. + * @since 2.8.4 + * + * This method overrides #logEvent to allow you to capture the length of an event with parameters. + * This can be extremely valuable to understand the level of engagement with a particular action + * and the characteristics associated with that action. For example, you can capture how long a user + * spends on a level or reading an article. Parameters can be used to capture, for example, the + * author of an article or if something was purchased while on the level. + * + * @note You should not pass private or confidential information about your users in a + * custom event. + * + * @see #endTimedEvent:withParameters: for details on stopping a timed event and (optionally) updating + * parameters. + * + * @code + * - (void)startLevel + { + NSDictionary *params = + [NSDictionary dictionaryWithObjectsAndKeys:@"100", // Parameter Value + @"Current Points", // Parameter Name + nil]; + + [Flurry logEvent:@"Level Played" withParameters:params timed:YES]; + // Start user on level + } + + - (void)endLevel + { + // User gained additional 100 points in Level + NSDictionary *params = + [NSDictionary dictionaryWithObjectsAndKeys:@"200", // Parameter Value + @"Current Points", // Parameter Name + nil]; + [Flurry endTimedEvent:@"Level Played" withParameters:params]; + // User done with level + } + * @endcode + * + * @param eventName Name of the event. For maximum effectiveness, we recommend using a naming scheme + * that can be easily understood by non-technical people in your business domain. + * @param parameters A map containing Name-Value pairs of parameters. + * @param timed Specifies the event will be timed. + */ ++ (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters timed:(BOOL)timed; + +/*! + * @brief Ends a timed event specified by @c eventName and optionally updates parameters with @c parameters. + * @since 2.8.4 + * + * This method ends an existing timed event. If parameters are provided, this will overwrite existing + * parameters with the same name or create new parameters if the name does not exist in the parameter + * map set by #logEvent:withParameters:timed:. + * + * @note You should not pass private or confidential information about your users in a + * custom event. \n + * If the app is backgrounded prior to ending a timed event, the Flurry SDK will automatically + * end the timer on the event. \n + * #endTimedEvent:withParameters: is ignored if called on a previously + * terminated event. + * + * @see #logEvent:withParameters:timed: for details on starting a timed event with parameters. + * + * @code + * - (void)startLevel + { + NSDictionary *params = + [NSDictionary dictionaryWithObjectsAndKeys:@"100", // Parameter Value + @"Current Points", // Parameter Name + nil]; + + [Flurry logEvent:@"Level Played" withParameters:params timed:YES]; + // Start user on level + } + + - (void)endLevel + { + // User gained additional 100 points in Level + NSDictionary *params = + [NSDictionary dictionaryWithObjectsAndKeys:@"200", // Parameter Value + @"Current Points", // Parameter Name + nil]; + [Flurry endTimedEvent:@"Level Played" withParameters:params]; + // User done with level + } + * @endcode + * + * @param eventName Name of the event. For maximum effectiveness, we recommend using a naming scheme + * that can be easily understood by non-technical people in your business domain. + * @param parameters A map containing Name-Value pairs of parameters. + */ ++ (void)endTimedEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters; // non-nil parameters will update the parameters + +//@} + + +/** @name Page View Methods + * Count page views. + */ +//@{ + +/*! + * @brief Automatically track page views on a @c UINavigationController or @c UITabBarController. + * @since 2.7 + * + * This method increments the page view count for a session based on traversing a UINavigationController + * or UITabBarController. The page view count is only a counter for the number of transitions in your + * app. It does not associate a name with the page count. To associate a name with a count of occurences + * see #logEvent:. + * + * @note Please make sure you assign the Tab and Navigation controllers to the view controllers before + * passing them to this method. + * + * @see #logPageView for details on explictly incrementing page view count. + * + * @code + * -(void) trackViewsFromTabBar:(UITabBarController*) tabBar + { + [Flurry logAllPageViews:tabBar]; + } + * @endcode + * + * @param target The navigation or tab bar controller. + */ ++ (void)logAllPageViews:(id)target; + +/*! + * @brief Explicitly track a page view during a session. + * @since 2.7 + * + * This method increments the page view count for a session when invoked. It does not associate a name + * with the page count. To associate a name with a count of occurences see #logEvent:. + * + * @see #logAllPageViews for details on automatically incrementing page view count based on user + * traversing navigation or tab bar controller. + * + * @code + * -(void) trackView + { + [Flurry logPageView]; + } + * @endcode + * + */ ++ (void)logPageView; + +//@} + +/** @name User Info + * Methods to set user information. + */ +//@{ + +/*! + * @brief Assign a unique id for a user in your app. + * @since 2.7 + * + * @note Please be sure not to use this method to pass any private or confidential information + * about the user. + * + * @param userID The app id for a user. + */ ++ (void)setUserID:(NSString *)userID; + +/*! + * @brief Set your user's age in years. + * @since 2.7 + * + * Use this method to capture the age of your user. Only use this method if you collect this + * information explictly from your user (i.e. - there is no need to set a default value). + * + * @note The age is aggregated across all users of your app and not available on a per user + * basis. + * + * @param age Reported age of user. + * + */ ++ (void)setAge:(int)age; + +/*! + * @brief Set your user's gender. + * @since 2.7 + * + * Use this method to capture the gender of your user. Only use this method if you collect this + * information explictly from your user (i.e. - there is no need to set a default value). Allowable + * values are @c @"m" or @c @"f" + * + * @note The gender is aggregated across all users of your app and not available on a per user + * basis. + * + * @param gender Reported gender of user. + * + */ ++ (void)setGender:(NSString *)gender; // user's gender m or f + +//@} + +/** @name Location Reporting + * Methods for setting location information. + */ +//@{ +/*! + * @brief Set the location of the session. + * @since 2.7 + * + * Use information from the CLLocationManager to specify the location of the session. Flurry does not + * automatically track this information or include the CLLocation framework. + * + * @note Only the last location entered is captured per session. \n + * Regardless of accuracy specified, the Flurry SDK will only report location at city level or higher. \n + * Location is aggregated across all users of your app and not available on a per user basis. \n + * This information should only be captured if it is germaine to the use of your app. + * + * @code + CLLocationManager *locationManager = [[CLLocationManager alloc] init]; + [locationManager startUpdatingLocation]; + * @endcode + * + * After starting the location manager, you can set the location with Flurry. You can implement + * CLLocationManagerDelegate to be aware of when the location is updated. Below is an example + * of how to use this method, after you have recieved a location update from the locationManager. + * + * @code + CLLocation *location = locationManager.location; + [Flurry setLatitude:location.coordinate.latitude + longitude:location.coordinate.longitude + horizontalAccuracy:location.horizontalAccuracy + verticalAccuracy:location.verticalAccuracy]; + * @endcode + * @param latitude The latitude. + * @param longitude The longitude. + * @param horizontalAccuracy The radius of uncertainty for the location in meters. + * @param verticalAccuracy The accuracy of the altitude value in meters. + * + */ ++ (void)setLatitude:(double)latitude longitude:(double)longitude horizontalAccuracy:(float)horizontalAccuracy verticalAccuracy:(float)verticalAccuracy; + +//@} + +/** @name Session Reporting Calls + * Optional methods that can be called at any point to control session reporting. + */ +//@{ + +/*! + * @brief Set session to report when app closes. + * @since 2.7 + * + * Use this method report session data when the app is closed. The default value is @c YES. + * + * @note This method is rarely invoked in iOS >= 3.2 due to the updated iOS lifecycle. + * + * @see #setSessionReportsOnPauseEnabled: + * + * @param sendSessionReportsOnClose YES to send on close, NO to omit reporting on close. + * + */ ++ (void)setSessionReportsOnCloseEnabled:(BOOL)sendSessionReportsOnClose; + +/*! + * @brief Set session to report when app is sent to the background. + * @since 2.7 + * + * Use this method report session data when the app is paused. The default value is @c YES. + * + * @param setSessionReportsOnPauseEnabled YES to send on pause, NO to omit reporting on pause. + * + */ ++ (void)setSessionReportsOnPauseEnabled:(BOOL)setSessionReportsOnPauseEnabled; + +/*! + * @brief Set session to support background execution. + * @since 4.2.2 + * + * Use this method to enable reporting of errors and events when application is + * running in backgorund (such applications have UIBackgroundModes in Info.plist). + * You should call #pauseBackgroundSession when appropriate in background mode to + * pause the session (for example when played song completed in background) + * + * Default value is @c NO + * + * @see #pauseBackgroundSession for details + * + * @param setBackgroundSessionEnabled YES to enbale background support and + * continue log events and errors for running session. + */ ++ (void)setBackgroundSessionEnabled:(BOOL)setBackgroundSessionEnabled; + +/*! + * @brief Enable custom event logging. + * @since 2.7 + * + * Use this method to allow the capture of custom events. The default value is @c YES. + * + * @param value YES to enable event logging, NO to stop custom logging. + * + */ ++ (void)setEventLoggingEnabled:(BOOL)value; + +/*! + * @brief Set device push token. + * @since 2.7 + * + * After the device has successfully registered with APNS, call this method to set the push token received from APNS. + * + * + */ ++ (void)setPushToken:(NSString *)pushToken; + + +//@} + +@end diff --git a/client/ios/Hackpad/Flurry/libFlurry_4.3.2.a b/client/ios/Hackpad/Flurry/libFlurry_4.3.2.a new file mode 100755 index 0000000..7e71ac9 Binary files /dev/null and b/client/ios/Hackpad/Flurry/libFlurry_4.3.2.a differ diff --git a/client/ios/Hackpad/GoogleToolbox/GTMDefines.h b/client/ios/Hackpad/GoogleToolbox/GTMDefines.h new file mode 100644 index 0000000..c295848 --- /dev/null +++ b/client/ios/Hackpad/GoogleToolbox/GTMDefines.h @@ -0,0 +1,441 @@ +// +// GTMDefines.h +// +// Copyright 2008 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +// + +// ============================================================================ + +#include +#include + +#ifdef __OBJC__ +#include +#endif // __OBJC__ + +#if TARGET_OS_IPHONE +#include +#endif // TARGET_OS_IPHONE + +// Not all MAC_OS_X_VERSION_10_X macros defined in past SDKs +#ifndef MAC_OS_X_VERSION_10_5 + #define MAC_OS_X_VERSION_10_5 1050 +#endif +#ifndef MAC_OS_X_VERSION_10_6 + #define MAC_OS_X_VERSION_10_6 1060 +#endif +#ifndef MAC_OS_X_VERSION_10_7 + #define MAC_OS_X_VERSION_10_7 1070 +#endif + +// Not all __IPHONE_X macros defined in past SDKs +#ifndef __IPHONE_3_0 + #define __IPHONE_3_0 30000 +#endif +#ifndef __IPHONE_3_1 + #define __IPHONE_3_1 30100 +#endif +#ifndef __IPHONE_3_2 + #define __IPHONE_3_2 30200 +#endif +#ifndef __IPHONE_4_0 + #define __IPHONE_4_0 40000 +#endif +#ifndef __IPHONE_4_3 + #define __IPHONE_4_3 40300 +#endif +#ifndef __IPHONE_5_0 + #define __IPHONE_5_0 50000 +#endif + +// ---------------------------------------------------------------------------- +// CPP symbols that can be overridden in a prefix to control how the toolbox +// is compiled. +// ---------------------------------------------------------------------------- + + +// By setting the GTM_CONTAINERS_VALIDATION_FAILED_LOG and +// GTM_CONTAINERS_VALIDATION_FAILED_ASSERT macros you can control what happens +// when a validation fails. If you implement your own validators, you may want +// to control their internals using the same macros for consistency. +#ifndef GTM_CONTAINERS_VALIDATION_FAILED_ASSERT + #define GTM_CONTAINERS_VALIDATION_FAILED_ASSERT 0 +#endif + +// Give ourselves a consistent way to do inlines. Apple's macros even use +// a few different actual definitions, so we're based off of the foundation +// one. +#if !defined(GTM_INLINE) + #if (defined (__GNUC__) && (__GNUC__ == 4)) || defined (__clang__) + #define GTM_INLINE static __inline__ __attribute__((always_inline)) + #else + #define GTM_INLINE static __inline__ + #endif +#endif + +// Give ourselves a consistent way of doing externs that links up nicely +// when mixing objc and objc++ +#if !defined (GTM_EXTERN) + #if defined __cplusplus + #define GTM_EXTERN extern "C" + #define GTM_EXTERN_C_BEGIN extern "C" { + #define GTM_EXTERN_C_END } + #else + #define GTM_EXTERN extern + #define GTM_EXTERN_C_BEGIN + #define GTM_EXTERN_C_END + #endif +#endif + +// Give ourselves a consistent way of exporting things if we have visibility +// set to hidden. +#if !defined (GTM_EXPORT) + #define GTM_EXPORT __attribute__((visibility("default"))) +#endif + +// Give ourselves a consistent way of declaring something as unused. This +// doesn't use __unused because that is only supported in gcc 4.2 and greater. +#if !defined (GTM_UNUSED) +#define GTM_UNUSED(x) ((void)(x)) +#endif + +// _GTMDevLog & _GTMDevAssert +// +// _GTMDevLog & _GTMDevAssert are meant to be a very lightweight shell for +// developer level errors. This implementation simply macros to NSLog/NSAssert. +// It is not intended to be a general logging/reporting system. +// +// Please see http://code.google.com/p/google-toolbox-for-mac/wiki/DevLogNAssert +// for a little more background on the usage of these macros. +// +// _GTMDevLog log some error/problem in debug builds +// _GTMDevAssert assert if conditon isn't met w/in a method/function +// in all builds. +// +// To replace this system, just provide different macro definitions in your +// prefix header. Remember, any implementation you provide *must* be thread +// safe since this could be called by anything in what ever situtation it has +// been placed in. +// + +// We only define the simple macros if nothing else has defined this. +#ifndef _GTMDevLog + +#ifdef DEBUG + #define _GTMDevLog(...) NSLog(__VA_ARGS__) +#else + #define _GTMDevLog(...) do { } while (0) +#endif + +#endif // _GTMDevLog + +#ifndef _GTMDevAssert +// we directly invoke the NSAssert handler so we can pass on the varargs +// (NSAssert doesn't have a macro we can use that takes varargs) +#if !defined(NS_BLOCK_ASSERTIONS) + #define _GTMDevAssert(condition, ...) \ + do { \ + if (!(condition)) { \ + [[NSAssertionHandler currentHandler] \ + handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \ + file:[NSString stringWithUTF8String:__FILE__] \ + lineNumber:__LINE__ \ + description:__VA_ARGS__]; \ + } \ + } while(0) +#else // !defined(NS_BLOCK_ASSERTIONS) + #define _GTMDevAssert(condition, ...) do { } while (0) +#endif // !defined(NS_BLOCK_ASSERTIONS) + +#endif // _GTMDevAssert + +// _GTMCompileAssert +// _GTMCompileAssert is an assert that is meant to fire at compile time if you +// want to check things at compile instead of runtime. For example if you +// want to check that a wchar is 4 bytes instead of 2 you would use +// _GTMCompileAssert(sizeof(wchar_t) == 4, wchar_t_is_4_bytes_on_OS_X) +// Note that the second "arg" is not in quotes, and must be a valid processor +// symbol in it's own right (no spaces, punctuation etc). + +// Wrapping this in an #ifndef allows external groups to define their own +// compile time assert scheme. +#ifndef _GTMCompileAssert + // We got this technique from here: + // http://unixjunkie.blogspot.com/2007/10/better-compile-time-asserts_29.html + + #define _GTMCompileAssertSymbolInner(line, msg) _GTMCOMPILEASSERT ## line ## __ ## msg + #define _GTMCompileAssertSymbol(line, msg) _GTMCompileAssertSymbolInner(line, msg) + #define _GTMCompileAssert(test, msg) \ + typedef char _GTMCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ] +#endif // _GTMCompileAssert + +// ---------------------------------------------------------------------------- +// CPP symbols defined based on the project settings so the GTM code has +// simple things to test against w/o scattering the knowledge of project +// setting through all the code. +// ---------------------------------------------------------------------------- + +// Provide a single constant CPP symbol that all of GTM uses for ifdefing +// iPhone code. +#if TARGET_OS_IPHONE // iPhone SDK + // For iPhone specific stuff + #define GTM_IPHONE_SDK 1 + #if TARGET_IPHONE_SIMULATOR + #define GTM_IPHONE_SIMULATOR 1 + #else + #define GTM_IPHONE_DEVICE 1 + #endif // TARGET_IPHONE_SIMULATOR + // By default, GTM has provided it's own unittesting support, define this + // to use the support provided by Xcode, especially for the Xcode4 support + // for unittesting. + #ifndef GTM_IPHONE_USE_SENTEST + #define GTM_IPHONE_USE_SENTEST 0 + #endif +#else + // For MacOS specific stuff + #define GTM_MACOS_SDK 1 +#endif + +// Some of our own availability macros +#if GTM_MACOS_SDK +#define GTM_AVAILABLE_ONLY_ON_IPHONE UNAVAILABLE_ATTRIBUTE +#define GTM_AVAILABLE_ONLY_ON_MACOS +#else +#define GTM_AVAILABLE_ONLY_ON_IPHONE +#define GTM_AVAILABLE_ONLY_ON_MACOS UNAVAILABLE_ATTRIBUTE +#endif + +// GC was dropped by Apple, define the old constant incase anyone still keys +// off of it. +#ifndef GTM_SUPPORT_GC + #define GTM_SUPPORT_GC 0 +#endif + +// To simplify support for 64bit (and Leopard in general), we provide the type +// defines for non Leopard SDKs +#if !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) + // NSInteger/NSUInteger and Max/Mins + #ifndef NSINTEGER_DEFINED + #if __LP64__ || NS_BUILD_32_LIKE_64 + typedef long NSInteger; + typedef unsigned long NSUInteger; + #else + typedef int NSInteger; + typedef unsigned int NSUInteger; + #endif + #define NSIntegerMax LONG_MAX + #define NSIntegerMin LONG_MIN + #define NSUIntegerMax ULONG_MAX + #define NSINTEGER_DEFINED 1 + #endif // NSINTEGER_DEFINED + // CGFloat + #ifndef CGFLOAT_DEFINED + #if defined(__LP64__) && __LP64__ + // This really is an untested path (64bit on Tiger?) + typedef double CGFloat; + #define CGFLOAT_MIN DBL_MIN + #define CGFLOAT_MAX DBL_MAX + #define CGFLOAT_IS_DOUBLE 1 + #else /* !defined(__LP64__) || !__LP64__ */ + typedef float CGFloat; + #define CGFLOAT_MIN FLT_MIN + #define CGFLOAT_MAX FLT_MAX + #define CGFLOAT_IS_DOUBLE 0 + #endif /* !defined(__LP64__) || !__LP64__ */ + #define CGFLOAT_DEFINED 1 + #endif // CGFLOAT_DEFINED +#endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 + +// Some support for advanced clang static analysis functionality +// See http://clang-analyzer.llvm.org/annotations.html +#ifndef __has_feature // Optional. + #define __has_feature(x) 0 // Compatibility with non-clang compilers. +#endif + +#ifndef NS_RETURNS_RETAINED + #if __has_feature(attribute_ns_returns_retained) + #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained)) + #else + #define NS_RETURNS_RETAINED + #endif +#endif + +#ifndef NS_RETURNS_NOT_RETAINED + #if __has_feature(attribute_ns_returns_not_retained) + #define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained)) + #else + #define NS_RETURNS_NOT_RETAINED + #endif +#endif + +#ifndef CF_RETURNS_RETAINED + #if __has_feature(attribute_cf_returns_retained) + #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained)) + #else + #define CF_RETURNS_RETAINED + #endif +#endif + +#ifndef CF_RETURNS_NOT_RETAINED + #if __has_feature(attribute_cf_returns_not_retained) + #define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained)) + #else + #define CF_RETURNS_NOT_RETAINED + #endif +#endif + +#ifndef NS_CONSUMED + #if __has_feature(attribute_ns_consumed) + #define NS_CONSUMED __attribute__((ns_consumed)) + #else + #define NS_CONSUMED + #endif +#endif + +#ifndef CF_CONSUMED + #if __has_feature(attribute_cf_consumed) + #define CF_CONSUMED __attribute__((cf_consumed)) + #else + #define CF_CONSUMED + #endif +#endif + +#ifndef NS_CONSUMES_SELF + #if __has_feature(attribute_ns_consumes_self) + #define NS_CONSUMES_SELF __attribute__((ns_consumes_self)) + #else + #define NS_CONSUMES_SELF + #endif +#endif + +// Defined on 10.6 and above. +#ifndef NS_FORMAT_ARGUMENT + #define NS_FORMAT_ARGUMENT(A) +#endif + +// Defined on 10.6 and above. +#ifndef NS_FORMAT_FUNCTION + #define NS_FORMAT_FUNCTION(F,A) +#endif + +// Defined on 10.6 and above. +#ifndef CF_FORMAT_ARGUMENT + #define CF_FORMAT_ARGUMENT(A) +#endif + +// Defined on 10.6 and above. +#ifndef CF_FORMAT_FUNCTION + #define CF_FORMAT_FUNCTION(F,A) +#endif + +#ifndef GTM_NONNULL + #if defined(__has_attribute) + #if __has_attribute(nonnull) + #define GTM_NONNULL(x) __attribute__((nonnull x)) + #else + #define GTM_NONNULL(x) + #endif + #else + #define GTM_NONNULL(x) + #endif +#endif + +// Invalidates the initializer from which it's called. +#ifndef GTMInvalidateInitializer + #if __has_feature(objc_arc) + #define GTMInvalidateInitializer() \ + do { \ + [self class]; /* Avoid warning of dead store to |self|. */ \ + _GTMDevAssert(NO, @"Invalid initializer."); \ + return nil; \ + } while (0) + #else + #define GTMInvalidateInitializer() \ + do { \ + [self release]; \ + _GTMDevAssert(NO, @"Invalid initializer."); \ + return nil; \ + } while (0) + #endif +#endif + +#ifdef __OBJC__ + +// Declared here so that it can easily be used for logging tracking if +// necessary. See GTMUnitTestDevLog.h for details. +@class NSString; +GTM_EXTERN void _GTMUnitTestDevLog(NSString *format, ...) NS_FORMAT_FUNCTION(1, 2); + +// Macro to allow you to create NSStrings out of other macros. +// #define FOO foo +// NSString *fooString = GTM_NSSTRINGIFY(FOO); +#if !defined (GTM_NSSTRINGIFY) + #define GTM_NSSTRINGIFY_INNER(x) @#x + #define GTM_NSSTRINGIFY(x) GTM_NSSTRINGIFY_INNER(x) +#endif + +// Macro to allow fast enumeration when building for 10.5 or later, and +// reliance on NSEnumerator for 10.4. Remember, NSDictionary w/ FastEnumeration +// does keys, so pick the right thing, nothing is done on the FastEnumeration +// side to be sure you're getting what you wanted. +#ifndef GTM_FOREACH_OBJECT + #if TARGET_OS_IPHONE || !(MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) + #define GTM_FOREACH_ENUMEREE(element, enumeration) \ + for (element in enumeration) + #define GTM_FOREACH_OBJECT(element, collection) \ + for (element in collection) + #define GTM_FOREACH_KEY(element, collection) \ + for (element in collection) + #else + #define GTM_FOREACH_ENUMEREE(element, enumeration) \ + for (NSEnumerator *_ ## element ## _enum = enumeration; \ + (element = [_ ## element ## _enum nextObject]) != nil; ) + #define GTM_FOREACH_OBJECT(element, collection) \ + GTM_FOREACH_ENUMEREE(element, [collection objectEnumerator]) + #define GTM_FOREACH_KEY(element, collection) \ + GTM_FOREACH_ENUMEREE(element, [collection keyEnumerator]) + #endif +#endif + +// ============================================================================ + +// To simplify support for both Leopard and Snow Leopard we declare +// the Snow Leopard protocols that we need here. +#if !defined(GTM_10_6_PROTOCOLS_DEFINED) && !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) +#define GTM_10_6_PROTOCOLS_DEFINED 1 +@protocol NSConnectionDelegate +@end +@protocol NSAnimationDelegate +@end +@protocol NSImageDelegate +@end +@protocol NSTabViewDelegate +@end +#endif // !defined(GTM_10_6_PROTOCOLS_DEFINED) && !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) + +// GTM_SEL_STRING is for specifying selector (usually property) names to KVC +// or KVO methods. +// In debug it will generate warnings for undeclared selectors if +// -Wunknown-selector is turned on. +// In release it will have no runtime overhead. +#ifndef GTM_SEL_STRING + #ifdef DEBUG + #define GTM_SEL_STRING(selName) NSStringFromSelector(@selector(selName)) + #else + #define GTM_SEL_STRING(selName) @#selName + #endif // DEBUG +#endif // GTM_SEL_STRING + +#endif // __OBJC__ diff --git a/client/ios/Hackpad/GoogleToolbox/GTMHTTPFetcher.h b/client/ios/Hackpad/GoogleToolbox/GTMHTTPFetcher.h new file mode 100644 index 0000000..e497737 --- /dev/null +++ b/client/ios/Hackpad/GoogleToolbox/GTMHTTPFetcher.h @@ -0,0 +1,748 @@ +/* Copyright (c) 2011 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// GTMHTTPFetcher.h +// + +// This is essentially a wrapper around NSURLConnection for POSTs and GETs. +// If setPostData: is called, then POST is assumed. +// +// When would you use this instead of NSURLConnection? +// +// - When you just want the result from a GET, POST, or PUT +// - When you want the "standard" behavior for connections (redirection handling +// an so on) +// - When you want automatic retry on failures +// - When you want to avoid cookie collisions with Safari and other applications +// - When you are fetching resources with ETags and want to avoid the overhead +// of repeated fetches of unchanged data +// - When you need to set a credential for the http operation +// +// This is assumed to be a one-shot fetch request; don't reuse the object +// for a second fetch. +// +// The fetcher may be created auto-released, in which case it will release +// itself after the fetch completion callback. The fetcher is implicitly +// retained as long as a connection is pending. +// +// But if you may need to cancel the fetcher, retain it and have the delegate +// release the fetcher in the callbacks. +// +// Sample usage: +// +// NSURLRequest *request = [NSURLRequest requestWithURL:myURL]; +// GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request]; +// +// // optional upload body data +// [myFetcher setPostData:[postString dataUsingEncoding:NSUTF8StringEncoding]]; +// +// [myFetcher beginFetchWithDelegate:self +// didFinishSelector:@selector(myFetcher:finishedWithData:error:)]; +// +// Upon fetch completion, the callback selector is invoked; it should have +// this signature (you can use any callback method name you want so long as +// the signature matches this): +// +// - (void)myFetcher:(GTMHTTPFetcher *)fetcher finishedWithData:(NSData *)retrievedData error:(NSError *)error; +// +// The block callback version looks like: +// +// [myFetcher beginFetchWithCompletionHandler:^(NSData *retrievedData, NSError *error) { +// if (error != nil) { +// // status code or network error +// } else { +// // succeeded +// } +// }]; + +// +// NOTE: Fetches may retrieve data from the server even though the server +// returned an error. The failure selector is called when the server +// status is >= 300, with an NSError having domain +// kGTMHTTPFetcherStatusDomain and code set to the server status. +// +// Status codes are at +// +// +// Threading and queue support: +// +// Callbacks require either that the thread used to start the fetcher have a run +// loop spinning (typically the main thread), or that an NSOperationQueue be +// provided upon which the delegate callbacks will be called. Starting with +// iOS 6 and Mac OS X 10.7, clients may simply create an operation queue for +// callbacks on a background thread: +// +// fetcher.delegateQueue = [[[NSOperationQueue alloc] init] autorelease]; +// +// or specify the main queue for callbacks on the main thread: +// +// fetcher.delegateQueue = [NSOperationQueue mainQueue]; +// +// The client may also re-dispatch from the callbacks and notifications to +// a known dispatch queue: +// +// [myFetcher beginFetchWithCompletionHandler:^(NSData *retrievedData, NSError *error) { +// if (error == nil) { +// dispatch_async(myDispatchQueue, ^{ +// ... +// }); +// } +// }]; +// +// +// +// Downloading to disk: +// +// To have downloaded data saved directly to disk, specify either a path for the +// downloadPath property, or a file handle for the downloadFileHandle property. +// When downloading to disk, callbacks will be passed a nil for the NSData* +// arguments. +// +// +// HTTP methods and headers: +// +// Alternative HTTP methods, like PUT, and custom headers can be specified by +// creating the fetcher with an appropriate NSMutableURLRequest +// +// +// Proxies: +// +// Proxy handling is invisible so long as the system has a valid credential in +// the keychain, which is normally true (else most NSURL-based apps would have +// difficulty.) But when there is a proxy authetication error, the the fetcher +// will call the failedWithError: method with the NSURLChallenge in the error's +// userInfo. The error method can get the challenge info like this: +// +// NSURLAuthenticationChallenge *challenge +// = [[error userInfo] objectForKey:kGTMHTTPFetcherErrorChallengeKey]; +// BOOL isProxyChallenge = [[challenge protectionSpace] isProxy]; +// +// If a proxy error occurs, you can ask the user for the proxy username/password +// and call fetcher's setProxyCredential: to provide those for the +// next attempt to fetch. +// +// +// Cookies: +// +// There are three supported mechanisms for remembering cookies between fetches. +// +// By default, GTMHTTPFetcher uses a mutable array held statically to track +// cookies for all instantiated fetchers. This avoids server cookies being set +// by servers for the application from interfering with Safari cookie settings, +// and vice versa. The fetcher cookies are lost when the application quits. +// +// To rely instead on WebKit's global NSHTTPCookieStorage, call +// setCookieStorageMethod: with kGTMHTTPFetcherCookieStorageMethodSystemDefault. +// +// If the fetcher is created from a GTMHTTPFetcherService object +// then the cookie storage mechanism is set to use the cookie storage in the +// service object rather than the static storage. +// +// +// Fetching for periodic checks: +// +// The fetcher object tracks ETag headers from responses and +// provide an "If-None-Match" header. This allows the server to save +// bandwidth by providing a status message instead of repeated response +// data. +// +// To get this behavior, create the fetcher from an GTMHTTPFetcherService object +// and look for a fetch callback error with code 304 +// (kGTMHTTPFetcherStatusNotModified) like this: +// +// - (void)myFetcher:(GTMHTTPFetcher *)fetcher finishedWithData:(NSData *)data error:(NSError *)error { +// if ([error code] == kGTMHTTPFetcherStatusNotModified) { +// // |data| is empty; use the data from the previous finishedWithData: for this URL +// } else { +// // handle other server status code +// } +// } +// +// +// Monitoring received data +// +// The optional received data selector can be set with setReceivedDataSelector: +// and should have the signature +// +// - (void)myFetcher:(GTMHTTPFetcher *)fetcher receivedData:(NSData *)dataReceivedSoFar; +// +// The number bytes received so far is available as [fetcher downloadedLength]. +// This number may go down if a redirect causes the download to begin again from +// a new server. +// +// If supplied by the server, the anticipated total download size is available +// as [[myFetcher response] expectedContentLength] (and may be -1 for unknown +// download sizes.) +// +// +// Automatic retrying of fetches +// +// The fetcher can optionally create a timer and reattempt certain kinds of +// fetch failures (status codes 408, request timeout; 503, service unavailable; +// 504, gateway timeout; networking errors NSURLErrorTimedOut and +// NSURLErrorNetworkConnectionLost.) The user may set a retry selector to +// customize the type of errors which will be retried. +// +// Retries are done in an exponential-backoff fashion (that is, after 1 second, +// 2, 4, 8, and so on.) +// +// Enabling automatic retries looks like this: +// [myFetcher setRetryEnabled:YES]; +// +// With retries enabled, the success or failure callbacks are called only +// when no more retries will be attempted. Calling the fetcher's stopFetching +// method will terminate the retry timer, without the finished or failure +// selectors being invoked. +// +// Optionally, the client may set the maximum retry interval: +// [myFetcher setMaxRetryInterval:60.0]; // in seconds; default is 60 seconds +// // for downloads, 600 for uploads +// +// Also optionally, the client may provide a callback selector to determine +// if a status code or other error should be retried. +// [myFetcher setRetrySelector:@selector(myFetcher:willRetry:forError:)]; +// +// If set, the retry selector should have the signature: +// -(BOOL)fetcher:(GTMHTTPFetcher *)fetcher willRetry:(BOOL)suggestedWillRetry forError:(NSError *)error +// and return YES to set the retry timer or NO to fail without additional +// fetch attempts. +// +// The retry method may return the |suggestedWillRetry| argument to get the +// default retry behavior. Server status codes are present in the +// error argument, and have the domain kGTMHTTPFetcherStatusDomain. The +// user's method may look something like this: +// +// -(BOOL)myFetcher:(GTMHTTPFetcher *)fetcher willRetry:(BOOL)suggestedWillRetry forError:(NSError *)error { +// +// // perhaps examine [error domain] and [error code], or [fetcher retryCount] +// // +// // return YES to start the retry timer, NO to proceed to the failure +// // callback, or |suggestedWillRetry| to get default behavior for the +// // current error domain and code values. +// return suggestedWillRetry; +// } + + + +#pragma once + +#import + +#if defined(GTL_TARGET_NAMESPACE) + // we're using target namespace macros + #import "GTLDefines.h" +#elif defined(GDATA_TARGET_NAMESPACE) + #import "GDataDefines.h" +#else + #if TARGET_OS_IPHONE + #ifndef GTM_FOUNDATION_ONLY + #define GTM_FOUNDATION_ONLY 1 + #endif + #ifndef GTM_IPHONE + #define GTM_IPHONE 1 + #endif + #endif +#endif + +#if TARGET_OS_IPHONE && (__IPHONE_OS_VERSION_MAX_ALLOWED >= 40000) + #define GTM_BACKGROUND_FETCHING 1 +#endif + +#undef _EXTERN +#undef _INITIALIZE_AS +#ifdef GTMHTTPFETCHER_DEFINE_GLOBALS + #define _EXTERN + #define _INITIALIZE_AS(x) =x +#else + #if defined(__cplusplus) + #define _EXTERN extern "C" + #else + #define _EXTERN extern + #endif + #define _INITIALIZE_AS(x) +#endif + +// notifications +// +// fetch started and stopped, and fetch retry delay started and stopped +_EXTERN NSString* const kGTMHTTPFetcherStartedNotification _INITIALIZE_AS(@"kGTMHTTPFetcherStartedNotification"); +_EXTERN NSString* const kGTMHTTPFetcherStoppedNotification _INITIALIZE_AS(@"kGTMHTTPFetcherStoppedNotification"); +_EXTERN NSString* const kGTMHTTPFetcherRetryDelayStartedNotification _INITIALIZE_AS(@"kGTMHTTPFetcherRetryDelayStartedNotification"); +_EXTERN NSString* const kGTMHTTPFetcherRetryDelayStoppedNotification _INITIALIZE_AS(@"kGTMHTTPFetcherRetryDelayStoppedNotification"); + +// callback constants +_EXTERN NSString* const kGTMHTTPFetcherErrorDomain _INITIALIZE_AS(@"com.google.GTMHTTPFetcher"); +_EXTERN NSString* const kGTMHTTPFetcherStatusDomain _INITIALIZE_AS(@"com.google.HTTPStatus"); +_EXTERN NSString* const kGTMHTTPFetcherErrorChallengeKey _INITIALIZE_AS(@"challenge"); +_EXTERN NSString* const kGTMHTTPFetcherStatusDataKey _INITIALIZE_AS(@"data"); // data returned with a kGTMHTTPFetcherStatusDomain error + +enum { + kGTMHTTPFetcherErrorDownloadFailed = -1, + kGTMHTTPFetcherErrorAuthenticationChallengeFailed = -2, + kGTMHTTPFetcherErrorChunkUploadFailed = -3, + kGTMHTTPFetcherErrorFileHandleException = -4, + kGTMHTTPFetcherErrorBackgroundExpiration = -6, + + // The code kGTMHTTPFetcherErrorAuthorizationFailed (-5) has been removed; + // look for status 401 instead. + + kGTMHTTPFetcherStatusNotModified = 304, + kGTMHTTPFetcherStatusBadRequest = 400, + kGTMHTTPFetcherStatusUnauthorized = 401, + kGTMHTTPFetcherStatusForbidden = 403, + kGTMHTTPFetcherStatusPreconditionFailed = 412 +}; + +// cookie storage methods +enum { + kGTMHTTPFetcherCookieStorageMethodStatic = 0, + kGTMHTTPFetcherCookieStorageMethodFetchHistory = 1, + kGTMHTTPFetcherCookieStorageMethodSystemDefault = 2, + kGTMHTTPFetcherCookieStorageMethodNone = 3 +}; + +#ifdef __cplusplus +extern "C" { +#endif + +void GTMAssertSelectorNilOrImplementedWithArgs(id obj, SEL sel, ...); + +// Utility functions for applications self-identifying to servers via a +// user-agent header + +// Make a proper app name without whitespace from the given string, removing +// whitespace and other characters that may be special parsed marks of +// the full user-agent string. +NSString *GTMCleanedUserAgentString(NSString *str); + +// Make an identifier like "MacOSX/10.7.1" or "iPod_Touch/4.1" +NSString *GTMSystemVersionString(void); + +// Make a generic name and version for the current application, like +// com.example.MyApp/1.2.3 relying on the bundle identifier and the +// CFBundleShortVersionString or CFBundleVersion. If no bundle ID +// is available, the process name preceded by "proc_" is used. +NSString *GTMApplicationIdentifier(NSBundle *bundle); + +#ifdef __cplusplus +} // extern "C" +#endif + +@class GTMHTTPFetcher; + +@protocol GTMCookieStorageProtocol +// This protocol allows us to call into the service without requiring +// GTMCookieStorage sources in this project +// +// The public interface for cookie handling is the GTMCookieStorage class, +// accessible from a fetcher service object's fetchHistory or from the fetcher's +// +staticCookieStorage method. +- (NSArray *)cookiesForURL:(NSURL *)theURL; +- (void)setCookies:(NSArray *)newCookies; +@end + +@protocol GTMHTTPFetchHistoryProtocol +// This protocol allows us to call the fetch history object without requiring +// GTMHTTPFetchHistory sources in this project +- (void)updateRequest:(NSMutableURLRequest *)request isHTTPGet:(BOOL)isHTTPGet; +- (BOOL)shouldCacheETaggedData; +- (NSData *)cachedDataForRequest:(NSURLRequest *)request; +- (id )cookieStorage; +- (void)updateFetchHistoryWithRequest:(NSURLRequest *)request + response:(NSURLResponse *)response + downloadedData:(NSData *)downloadedData; +- (void)removeCachedDataForRequest:(NSURLRequest *)request; +@end + +@protocol GTMHTTPFetcherServiceProtocol +// This protocol allows us to call into the service without requiring +// GTMHTTPFetcherService sources in this project + +@property (retain) NSOperationQueue *delegateQueue; + +- (BOOL)fetcherShouldBeginFetching:(GTMHTTPFetcher *)fetcher; +- (void)fetcherDidStop:(GTMHTTPFetcher *)fetcher; + +- (GTMHTTPFetcher *)fetcherWithRequest:(NSURLRequest *)request; +- (BOOL)isDelayingFetcher:(GTMHTTPFetcher *)fetcher; +@end + +@protocol GTMFetcherAuthorizationProtocol +@required +// This protocol allows us to call the authorizer without requiring its sources +// in this project +- (void)authorizeRequest:(NSMutableURLRequest *)request + delegate:(id)delegate + didFinishSelector:(SEL)sel; + +- (void)stopAuthorization; + +- (void)stopAuthorizationForRequest:(NSURLRequest *)request; + +- (BOOL)isAuthorizingRequest:(NSURLRequest *)request; + +- (BOOL)isAuthorizedRequest:(NSURLRequest *)request; + +- (NSString *)userEmail; + +@optional +@property (assign) id fetcherService; // WEAK + +- (BOOL)primeForRefresh; +@end + +// GTMHTTPFetcher objects are used for async retrieval of an http get or post +// +// See additional comments at the beginning of this file +@interface GTMHTTPFetcher : NSObject { + @protected + NSMutableURLRequest *request_; + NSURLConnection *connection_; + NSMutableData *downloadedData_; + NSString *downloadPath_; + NSString *temporaryDownloadPath_; + NSFileHandle *downloadFileHandle_; + unsigned long long downloadedLength_; + NSURLCredential *credential_; // username & password + NSURLCredential *proxyCredential_; // credential supplied to proxy servers + NSData *postData_; + NSInputStream *postStream_; + NSMutableData *loggedStreamData_; + NSURLResponse *response_; // set in connection:didReceiveResponse: + id delegate_; + SEL finishedSel_; // should by implemented by delegate + SEL sentDataSel_; // optional, set with setSentDataSelector + SEL receivedDataSel_; // optional, set with setReceivedDataSelector +#if NS_BLOCKS_AVAILABLE + void (^completionBlock_)(NSData *, NSError *); + void (^receivedDataBlock_)(NSData *); + void (^sentDataBlock_)(NSInteger, NSInteger, NSInteger); + BOOL (^retryBlock_)(BOOL, NSError *); +#elif !__LP64__ + // placeholders: for 32-bit builds, keep the size of the object's ivar section + // the same with and without blocks + id completionPlaceholder_; + id receivedDataPlaceholder_; + id sentDataPlaceholder_; + id retryPlaceholder_; +#endif + BOOL hasConnectionEnded_; // set if the connection need not be cancelled + BOOL isCancellingChallenge_; // set only when cancelling an auth challenge + BOOL isStopNotificationNeeded_; // set when start notification has been sent + BOOL shouldFetchInBackground_; +#if GTM_BACKGROUND_FETCHING + NSUInteger backgroundTaskIdentifer_; // UIBackgroundTaskIdentifier +#endif + id userData_; // retained, if set by caller + NSMutableDictionary *properties_; // more data retained for caller + NSArray *runLoopModes_; // optional + NSOperationQueue *delegateQueue_; // optional; available iOS 6/10.7 and later + id fetchHistory_; // if supplied by the caller, used for Last-Modified-Since checks and cookies + NSInteger cookieStorageMethod_; // constant from above + id cookieStorage_; + + id authorizer_; + + // the service object that created and monitors this fetcher, if any + id service_; + NSString *serviceHost_; + NSInteger servicePriority_; + NSThread *thread_; + + BOOL isRetryEnabled_; // user wants auto-retry + SEL retrySel_; // optional; set with setRetrySelector + NSTimer *retryTimer_; + NSUInteger retryCount_; + NSTimeInterval maxRetryInterval_; // default 600 seconds + NSTimeInterval minRetryInterval_; // random between 1 and 2 seconds + NSTimeInterval retryFactor_; // default interval multiplier is 2 + NSTimeInterval lastRetryInterval_; + BOOL hasAttemptedAuthRefresh_; + + NSString *comment_; // comment for log + NSString *log_; +#if !STRIP_GTM_FETCH_LOGGING + NSString *logRequestBody_; + NSString *logResponseBody_; + BOOL shouldDeferResponseBodyLogging_; +#endif +} + +// Create a fetcher +// +// fetcherWithRequest will return an autoreleased fetcher, but if +// the connection is successfully created, the connection should retain the +// fetcher for the life of the connection as well. So the caller doesn't have +// to retain the fetcher explicitly unless they want to be able to cancel it. ++ (GTMHTTPFetcher *)fetcherWithRequest:(NSURLRequest *)request; + +// Convenience methods that make a request, like +fetcherWithRequest ++ (GTMHTTPFetcher *)fetcherWithURL:(NSURL *)requestURL; ++ (GTMHTTPFetcher *)fetcherWithURLString:(NSString *)requestURLString; + +// Designated initializer +- (id)initWithRequest:(NSURLRequest *)request; + +// Fetcher request +// +// The underlying request is mutable and may be modified by the caller +@property (retain) NSMutableURLRequest *mutableRequest; + +// Setting the credential is optional; it is used if the connection receives +// an authentication challenge +@property (retain) NSURLCredential *credential; + +// Setting the proxy credential is optional; it is used if the connection +// receives an authentication challenge from a proxy +@property (retain) NSURLCredential *proxyCredential; + +// If post data or stream is not set, then a GET retrieval method is assumed +@property (retain) NSData *postData; +@property (retain) NSInputStream *postStream; + +// The default cookie storage method is kGTMHTTPFetcherCookieStorageMethodStatic +// without a fetch history set, and kGTMHTTPFetcherCookieStorageMethodFetchHistory +// with a fetch history set +// +// Applications needing control of cookies across a sequence of fetches should +// create fetchers from a GTMHTTPFetcherService object (which encapsulates +// fetch history) for a well-defined cookie store +@property (assign) NSInteger cookieStorageMethod; + ++ (id )staticCookieStorage; + +// Object to add authorization to the request, if needed +@property (retain) id authorizer; + +// The service object that created and monitors this fetcher, if any +@property (retain) id service; + +// The host, if any, used to classify this fetcher in the fetcher service +@property (copy) NSString *serviceHost; + +// The priority, if any, used for starting fetchers in the fetcher service +// +// Lower values are higher priority; the default is 0, and values may +// be negative or positive. This priority affects only the start order of +// fetchers that are being delayed by a fetcher service. +@property (assign) NSInteger servicePriority; + +// The thread used to run this fetcher in the fetcher service when no operation +// queue is provided. +@property (retain) NSThread *thread; + +// The delegate is retained during the connection +@property (retain) id delegate; + +// On iOS 4 and later, the fetch may optionally continue while the app is in the +// background until finished or stopped by OS expiration +// +// The default value is NO +// +// For Mac OS X, background fetches are always supported, and this property +// is ignored +@property (assign) BOOL shouldFetchInBackground; + +// The delegate's optional sentData selector may be used to monitor upload +// progress. It should have a signature like: +// - (void)myFetcher:(GTMHTTPFetcher *)fetcher +// didSendBytes:(NSInteger)bytesSent +// totalBytesSent:(NSInteger)totalBytesSent +// totalBytesExpectedToSend:(NSInteger)totalBytesExpectedToSend; +// +// +doesSupportSentDataCallback indicates if this delegate method is supported ++ (BOOL)doesSupportSentDataCallback; + +@property (assign) SEL sentDataSelector; + +// The delegate's optional receivedData selector may be used to monitor download +// progress. It should have a signature like: +// - (void)myFetcher:(GTMHTTPFetcher *)fetcher +// receivedData:(NSData *)dataReceivedSoFar; +// +// The dataReceived argument will be nil when downloading to a path or to a +// file handle. +// +// Applications should not use this method to accumulate the received data; +// the callback method or block supplied to the beginFetch call will have +// the complete NSData received. +@property (assign) SEL receivedDataSelector; + +#if NS_BLOCKS_AVAILABLE +// The full interface to the block is provided rather than just a typedef for +// its parameter list in order to get more useful code completion in the Xcode +// editor +@property (copy) void (^sentDataBlock)(NSInteger bytesSent, NSInteger totalBytesSent, NSInteger bytesExpectedToSend); + +// The dataReceived argument will be nil when downloading to a path or to +// a file handle +@property (copy) void (^receivedDataBlock)(NSData *dataReceivedSoFar); +#endif + +// retrying; see comments at the top of the file. Calling +// setRetryEnabled(YES) resets the min and max retry intervals. +@property (assign, getter=isRetryEnabled) BOOL retryEnabled; + +// Retry selector or block is optional for retries. +// +// If present, it should have the signature: +// -(BOOL)fetcher:(GTMHTTPFetcher *)fetcher willRetry:(BOOL)suggestedWillRetry forError:(NSError *)error +// and return YES to cause a retry. See comments at the top of this file. +@property (assign) SEL retrySelector; + +#if NS_BLOCKS_AVAILABLE +@property (copy) BOOL (^retryBlock)(BOOL suggestedWillRetry, NSError *error); +#endif + +// Retry intervals must be strictly less than maxRetryInterval, else +// they will be limited to maxRetryInterval and no further retries will +// be attempted. Setting maxRetryInterval to 0.0 will reset it to the +// default value, 600 seconds. + +@property (assign) NSTimeInterval maxRetryInterval; + +// Starting retry interval. Setting minRetryInterval to 0.0 will reset it +// to a random value between 1.0 and 2.0 seconds. Clients should normally not +// call this except for unit testing. +@property (assign) NSTimeInterval minRetryInterval; + +// Multiplier used to increase the interval between retries, typically 2.0. +// Clients should not need to call this. +@property (assign) double retryFactor; + +// Number of retries attempted +@property (readonly) NSUInteger retryCount; + +// interval delay to precede next retry +@property (readonly) NSTimeInterval nextRetryInterval; + +// Begin fetching the request +// +// The delegate can optionally implement the finished selectors or pass NULL +// for it. +// +// Returns YES if the fetch is initiated. The delegate is retained between +// the beginFetch call until after the finish callback. +// +// An error is passed to the callback for server statuses 300 or +// higher, with the status stored as the error object's code. +// +// finishedSEL has a signature like: +// - (void)fetcher:(GTMHTTPFetcher *)fetcher finishedWithData:(NSData *)data error:(NSError *)error; +// +// If the application has specified a downloadPath or downloadFileHandle +// for the fetcher, the data parameter passed to the callback will be nil. + +- (BOOL)beginFetchWithDelegate:(id)delegate + didFinishSelector:(SEL)finishedSEL; + +#if NS_BLOCKS_AVAILABLE +- (BOOL)beginFetchWithCompletionHandler:(void (^)(NSData *data, NSError *error))handler; +#endif + + +// Returns YES if this is in the process of fetching a URL +- (BOOL)isFetching; + +// Cancel the fetch of the request that's currently in progress +- (void)stopFetching; + +// Return the status code from the server response +@property (readonly) NSInteger statusCode; + +// Return the http headers from the response +@property (retain, readonly) NSDictionary *responseHeaders; + +// The response, once it's been received +@property (retain) NSURLResponse *response; + +// Bytes downloaded so far +@property (readonly) unsigned long long downloadedLength; + +// Buffer of currently-downloaded data +@property (readonly, retain) NSData *downloadedData; + +// Path in which to non-atomically create a file for storing the downloaded data +// +// The path must be set before fetching begins. The download file handle +// will be created for the path, and can be used to monitor progress. If a file +// already exists at the path, it will be overwritten. +@property (copy) NSString *downloadPath; + +// If downloadFileHandle is set, data received is immediately appended to +// the file handle rather than being accumulated in the downloadedData property +// +// The file handle supplied must allow writing and support seekToFileOffset:, +// and must be set before fetching begins. Setting a download path will +// override the file handle property. +@property (retain) NSFileHandle *downloadFileHandle; + +// The optional fetchHistory object is used for a sequence of fetchers to +// remember ETags, cache ETagged data, and store cookies. Typically, this +// is set by a GTMFetcherService object when it creates a fetcher. +// +// Side effect: setting fetch history implicitly calls setCookieStorageMethod: +@property (retain) id fetchHistory; + +// userData is retained for the convenience of the caller +@property (retain) id userData; + +// Stored property values are retained for the convenience of the caller +@property (copy) NSMutableDictionary *properties; + +- (void)setProperty:(id)obj forKey:(NSString *)key; // pass nil obj to remove property +- (id)propertyForKey:(NSString *)key; + +- (void)addPropertiesFromDictionary:(NSDictionary *)dict; + +// Comments are useful for logging +@property (copy) NSString *comment; + +- (void)setCommentWithFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2); + +// Log of request and response, if logging is enabled +@property (copy) NSString *log; + +// Callbacks can be invoked on an operation queue rather than via the run loop, +// starting on 10.7 and iOS 6. If a delegate queue is supplied. the run loop +// modes are ignored. +@property (retain) NSOperationQueue *delegateQueue; + +// Using the fetcher while a modal dialog is displayed requires setting the +// run-loop modes to include NSModalPanelRunLoopMode +@property (retain) NSArray *runLoopModes; + +// Users who wish to replace GTMHTTPFetcher's use of NSURLConnection +// can do so globally here. The replacement should be a subclass of +// NSURLConnection. ++ (Class)connectionClass; ++ (void)setConnectionClass:(Class)theClass; + +// Spin the run loop, discarding events, until the fetch has completed +// +// This is only for use in testing or in tools without a user interface. +// +// Synchronous fetches should never be done by shipping apps; they are +// sufficient reason for rejection from the app store. +- (void)waitForCompletionWithTimeout:(NSTimeInterval)timeoutInSeconds; + +#if STRIP_GTM_FETCH_LOGGING +// if logging is stripped, provide a stub for the main method +// for controlling logging ++ (void)setLoggingEnabled:(BOOL)flag; +#endif // STRIP_GTM_FETCH_LOGGING + +@end diff --git a/client/ios/Hackpad/GoogleToolbox/GTMHTTPFetcher.m b/client/ios/Hackpad/GoogleToolbox/GTMHTTPFetcher.m new file mode 100644 index 0000000..b97024b --- /dev/null +++ b/client/ios/Hackpad/GoogleToolbox/GTMHTTPFetcher.m @@ -0,0 +1,1886 @@ +/* Copyright (c) 2011 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// GTMHTTPFetcher.m +// + +#define GTMHTTPFETCHER_DEFINE_GLOBALS 1 + +#import "GTMHTTPFetcher.h" + +#if GTM_BACKGROUND_FETCHING +#import +#endif + +static id gGTMFetcherStaticCookieStorage = nil; +static Class gGTMFetcherConnectionClass = nil; + +// The default max retry interview is 10 minutes for uploads (POST/PUT/PATCH), +// 1 minute for downloads. +static const NSTimeInterval kUnsetMaxRetryInterval = -1; +static const NSTimeInterval kDefaultMaxDownloadRetryInterval = 60.0; +static const NSTimeInterval kDefaultMaxUploadRetryInterval = 60.0 * 10.; + +// delegateQueue callback parameters +static NSString *const kCallbackData = @"data"; +static NSString *const kCallbackError = @"error"; + +// +// GTMHTTPFetcher +// + +@interface GTMHTTPFetcher () + +@property (copy) NSString *temporaryDownloadPath; +@property (retain) id cookieStorage; +@property (readwrite, retain) NSData *downloadedData; +#if NS_BLOCKS_AVAILABLE +@property (copy) void (^completionBlock)(NSData *, NSError *); +#endif + +- (BOOL)beginFetchMayDelay:(BOOL)mayDelay + mayAuthorize:(BOOL)mayAuthorize; +- (void)failToBeginFetchWithError:(NSError *)error; +- (void)failToBeginFetchDeferWithError:(NSError *)error; + +#if GTM_BACKGROUND_FETCHING +- (void)endBackgroundTask; +- (void)backgroundFetchExpired; +#endif + +- (BOOL)authorizeRequest; +- (void)authorizer:(id )auth + request:(NSMutableURLRequest *)request + finishedWithError:(NSError *)error; + +- (NSString *)createTempDownloadFilePathForPath:(NSString *)targetPath; +- (void)stopFetchReleasingCallbacks:(BOOL)shouldReleaseCallbacks; +- (BOOL)shouldReleaseCallbacksUponCompletion; + +- (void)addCookiesToRequest:(NSMutableURLRequest *)request; +- (void)handleCookiesForResponse:(NSURLResponse *)response; + +- (void)invokeFetchCallbacksWithData:(NSData *)data + error:(NSError *)error; +- (void)invokeFetchCallback:(SEL)sel + target:(id)target + data:(NSData *)data + error:(NSError *)error; +- (void)invokeFetchCallbacksOnDelegateQueueWithData:(NSData *)data + error:(NSError *)error; +- (void)releaseCallbacks; + +- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error; + +- (BOOL)shouldRetryNowForStatus:(NSInteger)status error:(NSError *)error; +- (void)destroyRetryTimer; +- (void)beginRetryTimer; +- (void)primeRetryTimerWithNewTimeInterval:(NSTimeInterval)secs; +- (void)sendStopNotificationIfNeeded; +- (void)retryFetch; +- (void)retryTimerFired:(NSTimer *)timer; +@end + +@interface GTMHTTPFetcher (GTMHTTPFetcherLoggingInternal) +- (void)setupStreamLogging; +- (void)logFetchWithError:(NSError *)error; +@end + +@implementation GTMHTTPFetcher + ++ (GTMHTTPFetcher *)fetcherWithRequest:(NSURLRequest *)request { + return [[[[self class] alloc] initWithRequest:request] autorelease]; +} + ++ (GTMHTTPFetcher *)fetcherWithURL:(NSURL *)requestURL { + return [self fetcherWithRequest:[NSURLRequest requestWithURL:requestURL]]; +} + ++ (GTMHTTPFetcher *)fetcherWithURLString:(NSString *)requestURLString { + return [self fetcherWithURL:[NSURL URLWithString:requestURLString]]; +} + ++ (void)initialize { + // initialize is guaranteed by the runtime to be called in a + // thread-safe manner + if (!gGTMFetcherStaticCookieStorage) { + Class cookieStorageClass = NSClassFromString(@"GTMCookieStorage"); + if (cookieStorageClass) { + gGTMFetcherStaticCookieStorage = [[cookieStorageClass alloc] init]; + } + } +} + +- (id)init { + return [self initWithRequest:nil]; +} + +- (id)initWithRequest:(NSURLRequest *)request { + self = [super init]; + if (self) { + request_ = [request mutableCopy]; + + if (gGTMFetcherStaticCookieStorage != nil) { + // The user has compiled with the cookie storage class available; + // default to static cookie storage, so our cookies are independent + // of the cookies of other apps. + [self setCookieStorageMethod:kGTMHTTPFetcherCookieStorageMethodStatic]; + } else { + // Default to system default cookie storage + [self setCookieStorageMethod:kGTMHTTPFetcherCookieStorageMethodSystemDefault]; + } + } + return self; +} + +- (id)copyWithZone:(NSZone *)zone { + // disallow use of fetchers in a copy property + [self doesNotRecognizeSelector:_cmd]; + return nil; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"%@ %p (%@)", + [self class], self, [self.mutableRequest URL]]; +} + +#if !GTM_IPHONE +- (void)finalize { + [self stopFetchReleasingCallbacks:YES]; // releases connection_, destroys timers + [super finalize]; +} +#endif + +- (void)dealloc { +#if DEBUG + NSAssert(!isStopNotificationNeeded_, + @"unbalanced fetcher notification for %@", [request_ URL]); +#endif + + // Note: if a connection or a retry timer was pending, then this instance + // would be retained by those so it wouldn't be getting dealloc'd, + // hence we don't need to stopFetch here + [request_ release]; + [connection_ release]; + [downloadedData_ release]; + [downloadPath_ release]; + [temporaryDownloadPath_ release]; + [downloadFileHandle_ release]; + [credential_ release]; + [proxyCredential_ release]; + [postData_ release]; + [postStream_ release]; + [loggedStreamData_ release]; + [response_ release]; +#if NS_BLOCKS_AVAILABLE + [completionBlock_ release]; + [receivedDataBlock_ release]; + [sentDataBlock_ release]; + [retryBlock_ release]; +#endif + [userData_ release]; + [properties_ release]; + [delegateQueue_ release]; + [runLoopModes_ release]; + [fetchHistory_ release]; + [cookieStorage_ release]; + [authorizer_ release]; + [service_ release]; + [serviceHost_ release]; + [thread_ release]; + [retryTimer_ release]; + [comment_ release]; + [log_ release]; +#if !STRIP_GTM_FETCH_LOGGING + [logRequestBody_ release]; + [logResponseBody_ release]; +#endif + + [super dealloc]; +} + +#pragma mark - + +// Begin fetching the URL (or begin a retry fetch). The delegate is retained +// for the duration of the fetch connection. + +- (BOOL)beginFetchWithDelegate:(id)delegate + didFinishSelector:(SEL)finishedSelector { + GTMAssertSelectorNilOrImplementedWithArgs(delegate, finishedSelector, @encode(GTMHTTPFetcher *), @encode(NSData *), @encode(NSError *), 0); + GTMAssertSelectorNilOrImplementedWithArgs(delegate, receivedDataSel_, @encode(GTMHTTPFetcher *), @encode(NSData *), 0); + GTMAssertSelectorNilOrImplementedWithArgs(delegate, retrySel_, @encode(GTMHTTPFetcher *), @encode(BOOL), @encode(NSError *), 0); + + // We'll retain the delegate only during the outstanding connection (similar + // to what Cocoa does with performSelectorOnMainThread:) and during + // authorization or delays, since the app would crash + // if the delegate was released before the fetch calls back + [self setDelegate:delegate]; + finishedSel_ = finishedSelector; + + return [self beginFetchMayDelay:YES + mayAuthorize:YES]; +} + +- (BOOL)beginFetchMayDelay:(BOOL)mayDelay + mayAuthorize:(BOOL)mayAuthorize { + // This is the internal entry point for re-starting fetches + NSError *error = nil; + + if (connection_ != nil) { + NSAssert1(connection_ != nil, @"fetch object %@ being reused; this should never happen", self); + goto CannotBeginFetch; + } + + if (request_ == nil || [request_ URL] == nil) { + NSAssert(request_ != nil, @"beginFetchWithDelegate requires a request with a URL"); + goto CannotBeginFetch; + } + + self.downloadedData = nil; + downloadedLength_ = 0; + + if (mayDelay && service_) { + BOOL shouldFetchNow = [service_ fetcherShouldBeginFetching:self]; + if (!shouldFetchNow) { + // the fetch is deferred, but will happen later + return YES; + } + } + + NSString *effectiveHTTPMethod = [request_ valueForHTTPHeaderField:@"X-HTTP-Method-Override"]; + if (effectiveHTTPMethod == nil) { + effectiveHTTPMethod = [request_ HTTPMethod]; + } + BOOL isEffectiveHTTPGet = (effectiveHTTPMethod == nil + || [effectiveHTTPMethod isEqual:@"GET"]); + + if (postData_ || postStream_) { + if (isEffectiveHTTPGet) { + [request_ setHTTPMethod:@"POST"]; + isEffectiveHTTPGet = NO; + } + + if (postData_) { + [request_ setHTTPBody:postData_]; + } else { + if ([self respondsToSelector:@selector(setupStreamLogging)]) { + [self performSelector:@selector(setupStreamLogging)]; + } + + [request_ setHTTPBodyStream:postStream_]; + } + } + + // We authorize after setting up the http method and body in the request + // because OAuth 1 may need to sign the request body + if (mayAuthorize && authorizer_) { + BOOL isAuthorized = [authorizer_ isAuthorizedRequest:request_]; + if (!isAuthorized) { + // authorization needed + return [self authorizeRequest]; + } + } + + [fetchHistory_ updateRequest:request_ isHTTPGet:isEffectiveHTTPGet]; + + // set the default upload or download retry interval, if necessary + if (isRetryEnabled_ + && maxRetryInterval_ <= kUnsetMaxRetryInterval) { + if (isEffectiveHTTPGet || [effectiveHTTPMethod isEqual:@"HEAD"]) { + [self setMaxRetryInterval:kDefaultMaxDownloadRetryInterval]; + } else { + [self setMaxRetryInterval:kDefaultMaxUploadRetryInterval]; + } + } + + [self addCookiesToRequest:request_]; + + if (downloadPath_ != nil) { + // downloading to a path, so create a temporary file and a file handle for + // downloading + NSString *tempPath = [self createTempDownloadFilePathForPath:downloadPath_]; + + BOOL didCreate = [[NSData data] writeToFile:tempPath + options:0 + error:&error]; + if (!didCreate) goto CannotBeginFetch; + + [self setTemporaryDownloadPath:tempPath]; + + NSFileHandle *fh = [NSFileHandle fileHandleForWritingAtPath:tempPath]; + if (fh == nil) goto CannotBeginFetch; + + [self setDownloadFileHandle:fh]; + } + + // finally, start the connection + + Class connectionClass = [[self class] connectionClass]; + + NSOperationQueue *delegateQueue = delegateQueue_; + if (delegateQueue && + ![connectionClass instancesRespondToSelector:@selector(setDelegateQueue:)]) { + // NSURLConnection has no setDelegateQueue: on iOS 4 and Mac OS X 10.5. + delegateQueue = nil; + self.delegateQueue = nil; + } + +#if DEBUG && TARGET_OS_IPHONE + BOOL isPreIOS6 = (NSFoundationVersionNumber <= 890.1); + if (isPreIOS6 && delegateQueue) { + NSLog(@"GTMHTTPFetcher delegateQueue not safe in iOS 5"); + } +#endif + + if ([runLoopModes_ count] == 0 && delegateQueue == nil) { + // No custom callback modes or queue were specified, so start the connection + // on the current run loop in the current mode + connection_ = [[connectionClass connectionWithRequest:request_ + delegate:self] retain]; + } else { + // Specify callbacks be on an operation queue or on the current run loop + // in the specified modes + connection_ = [[connectionClass alloc] initWithRequest:request_ + delegate:self + startImmediately:NO]; + if (delegateQueue) { + [connection_ performSelector:@selector(setDelegateQueue:) + withObject:delegateQueue]; + } else if (runLoopModes_) { + NSRunLoop *rl = [NSRunLoop currentRunLoop]; + for (NSString *mode in runLoopModes_) { + [connection_ scheduleInRunLoop:rl forMode:mode]; + } + } + [connection_ start]; + } + hasConnectionEnded_ = NO; + + if (!connection_) { + NSAssert(connection_ != nil, @"beginFetchWithDelegate could not create a connection"); + goto CannotBeginFetch; + } + + if (downloadFileHandle_ != nil) { + // downloading to a file, so downloadedData_ remains nil + } else { + self.downloadedData = [NSMutableData data]; + } + +#if GTM_BACKGROUND_FETCHING + backgroundTaskIdentifer_ = 0; // UIBackgroundTaskInvalid is 0 on iOS 4 + if (shouldFetchInBackground_) { + // For iOS 3 compatibility, ensure that UIApp supports backgrounding + UIApplication *app = [UIApplication sharedApplication]; + if ([app respondsToSelector:@selector(beginBackgroundTaskWithExpirationHandler:)]) { + // Tell UIApplication that we want to continue even when the app is in the + // background. + NSThread *thread = [NSThread currentThread]; + backgroundTaskIdentifer_ = [app beginBackgroundTaskWithExpirationHandler:^{ + // Callback - this block is always invoked by UIApplication on the main + // thread, but we want to run the user's callbacks on the thread used + // to start the fetch. + [self performSelector:@selector(backgroundFetchExpired) + onThread:thread + withObject:nil + waitUntilDone:YES]; + }]; + } + } +#endif + + // Once connection_ is non-nil we can send the start notification + isStopNotificationNeeded_ = YES; + NSNotificationCenter *defaultNC = [NSNotificationCenter defaultCenter]; + [defaultNC postNotificationName:kGTMHTTPFetcherStartedNotification + object:self]; + return YES; + +CannotBeginFetch: + [self failToBeginFetchDeferWithError:error]; + return NO; +} + +- (void)failToBeginFetchDeferWithError:(NSError *)error { + if (delegateQueue_) { + // Deferring will happen by the callback being invoked on the specified + // queue. + [self failToBeginFetchWithError:error]; + } else { + // No delegate queue has been specified, so put the callback + // on an appropriate run loop. + NSArray *modes = (runLoopModes_ ? runLoopModes_ : + [NSArray arrayWithObject:NSRunLoopCommonModes]); + [self performSelector:@selector(failToBeginFetchWithError:) + onThread:[NSThread currentThread] + withObject:error + waitUntilDone:NO + modes:modes]; + } +} + +- (void)failToBeginFetchWithError:(NSError *)error { + if (error == nil) { + error = [NSError errorWithDomain:kGTMHTTPFetcherErrorDomain + code:kGTMHTTPFetcherErrorDownloadFailed + userInfo:nil]; + } + + [[self retain] autorelease]; // In case the callback releases us + + [self invokeFetchCallbacksOnDelegateQueueWithData:nil + error:error]; + + [self releaseCallbacks]; + + [service_ fetcherDidStop:self]; + + self.authorizer = nil; + + if (temporaryDownloadPath_) { + [[NSFileManager defaultManager] removeItemAtPath:temporaryDownloadPath_ + error:NULL]; + self.temporaryDownloadPath = nil; + } +} + +#if GTM_BACKGROUND_FETCHING +- (void)backgroundFetchExpired { + @synchronized(self) { + // On background expiration, we stop the fetch and invoke the callbacks + NSError *error = [NSError errorWithDomain:kGTMHTTPFetcherErrorDomain + code:kGTMHTTPFetcherErrorBackgroundExpiration + userInfo:nil]; + [self invokeFetchCallbacksOnDelegateQueueWithData:nil + error:error]; + + // Stopping the fetch here will indirectly call endBackgroundTask + [self stopFetchReleasingCallbacks:NO]; + + [self releaseCallbacks]; + self.authorizer = nil; + } +} + +- (void)endBackgroundTask { + // Whenever the connection stops or background execution expires, + // we need to tell UIApplication we're done + if (backgroundTaskIdentifer_) { + // If backgroundTaskIdentifer_ is non-zero, we know we're on iOS 4 + UIApplication *app = [UIApplication sharedApplication]; + [app endBackgroundTask:backgroundTaskIdentifer_]; + + backgroundTaskIdentifer_ = 0; + } +} +#endif // GTM_BACKGROUND_FETCHING + +- (BOOL)authorizeRequest { + id authorizer = self.authorizer; + SEL asyncAuthSel = @selector(authorizeRequest:delegate:didFinishSelector:); + if ([authorizer respondsToSelector:asyncAuthSel]) { + SEL callbackSel = @selector(authorizer:request:finishedWithError:); + [authorizer authorizeRequest:request_ + delegate:self + didFinishSelector:callbackSel]; + return YES; + } else { + NSAssert(authorizer == nil, @"invalid authorizer for fetch"); + + // No authorizing possible, and authorizing happens only after any delay; + // just begin fetching + return [self beginFetchMayDelay:NO + mayAuthorize:NO]; + } +} + +- (void)authorizer:(id )auth + request:(NSMutableURLRequest *)request + finishedWithError:(NSError *)error { + if (error != nil) { + // We can't fetch without authorization + [self failToBeginFetchDeferWithError:error]; + } else { + [self beginFetchMayDelay:NO + mayAuthorize:NO]; + } +} + +#if NS_BLOCKS_AVAILABLE +- (BOOL)beginFetchWithCompletionHandler:(void (^)(NSData *data, NSError *error))handler { + self.completionBlock = handler; + + // The user may have called setDelegate: earlier if they want to use other + // delegate-style callbacks during the fetch; otherwise, the delegate is nil, + // which is fine. + return [self beginFetchWithDelegate:[self delegate] + didFinishSelector:nil]; +} +#endif + +- (NSString *)createTempDownloadFilePathForPath:(NSString *)targetPath { + NSString *tempDir = nil; + +#if (!TARGET_OS_IPHONE && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)) + // Find an appropriate directory for the download, ideally on the same disk + // as the final target location so the temporary file won't have to be moved + // to a different disk. + // + // Available in SDKs for 10.6 and iOS 4 + // + // Oct 2011: We previously also used URLForDirectory for + // (TARGET_OS_IPHONE && (__IPHONE_OS_VERSION_MAX_ALLOWED >= 40000)) + // but that is returning a non-temporary directory for iOS, unfortunately + + SEL sel = @selector(URLForDirectory:inDomain:appropriateForURL:create:error:); + if ([NSFileManager instancesRespondToSelector:sel]) { + NSError *error = nil; + NSURL *targetURL = [NSURL fileURLWithPath:targetPath]; + NSFileManager *fileMgr = [NSFileManager defaultManager]; + + NSURL *tempDirURL = [fileMgr URLForDirectory:NSItemReplacementDirectory + inDomain:NSUserDomainMask + appropriateForURL:targetURL + create:YES + error:&error]; + tempDir = [tempDirURL path]; + } +#endif + + if (tempDir == nil) { + tempDir = NSTemporaryDirectory(); + } + + static unsigned int counter = 0; + NSString *name = [NSString stringWithFormat:@"gtmhttpfetcher_%u_%u", + ++counter, (unsigned int) arc4random()]; + NSString *result = [tempDir stringByAppendingPathComponent:name]; + return result; +} + +- (void)addCookiesToRequest:(NSMutableURLRequest *)request { + // Get cookies for this URL from our storage array, if + // we have a storage array + if (cookieStorageMethod_ != kGTMHTTPFetcherCookieStorageMethodSystemDefault + && cookieStorageMethod_ != kGTMHTTPFetcherCookieStorageMethodNone) { + + NSArray *cookies = [cookieStorage_ cookiesForURL:[request URL]]; + if ([cookies count] > 0) { + + NSDictionary *headerFields = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies]; + NSString *cookieHeader = [headerFields objectForKey:@"Cookie"]; // key used in header dictionary + if (cookieHeader) { + [request addValue:cookieHeader forHTTPHeaderField:@"Cookie"]; // header name + } + } + } +} + +// Returns YES if this is in the process of fetching a URL, or waiting to +// retry, or waiting for authorization, or waiting to be issued by the +// service object +- (BOOL)isFetching { + if (connection_ != nil || retryTimer_ != nil) return YES; + + BOOL isAuthorizing = [authorizer_ isAuthorizingRequest:request_]; + if (isAuthorizing) return YES; + + BOOL isDelayed = [service_ isDelayingFetcher:self]; + return isDelayed; +} + +// Returns the status code set in connection:didReceiveResponse: +- (NSInteger)statusCode { + + NSInteger statusCode; + + if (response_ != nil + && [response_ respondsToSelector:@selector(statusCode)]) { + + statusCode = [(NSHTTPURLResponse *)response_ statusCode]; + } else { + // Default to zero, in hopes of hinting "Unknown" (we can't be + // sure that things are OK enough to use 200). + statusCode = 0; + } + return statusCode; +} + +- (NSDictionary *)responseHeaders { + if (response_ != nil + && [response_ respondsToSelector:@selector(allHeaderFields)]) { + + NSDictionary *headers = [(NSHTTPURLResponse *)response_ allHeaderFields]; + return headers; + } + return nil; +} + +- (void)releaseCallbacks { + [delegate_ autorelease]; + delegate_ = nil; + + [delegateQueue_ autorelease]; + delegateQueue_ = nil; + +#if NS_BLOCKS_AVAILABLE + self.completionBlock = nil; + self.sentDataBlock = nil; + self.receivedDataBlock = nil; + self.retryBlock = nil; +#endif +} + +// Cancel the fetch of the URL that's currently in progress. +- (void)stopFetchReleasingCallbacks:(BOOL)shouldReleaseCallbacks { + // if the connection or the retry timer is all that's retaining the fetcher, + // we want to be sure this instance survives stopping at least long enough for + // the stack to unwind + [[self retain] autorelease]; + + [self destroyRetryTimer]; + + if (connection_) { + // in case cancelling the connection calls this recursively, we want + // to ensure that we'll only release the connection and delegate once, + // so first set connection_ to nil + NSURLConnection* oldConnection = connection_; + connection_ = nil; + + if (!hasConnectionEnded_) { + [oldConnection cancel]; + } + + // this may be called in a callback from the connection, so use autorelease + [oldConnection autorelease]; + } + + // send the stopped notification + [self sendStopNotificationIfNeeded]; + + [authorizer_ stopAuthorizationForRequest:request_]; + + if (shouldReleaseCallbacks) { + [self releaseCallbacks]; + + self.authorizer = nil; + } + + [service_ fetcherDidStop:self]; + + if (temporaryDownloadPath_) { + [[NSFileManager defaultManager] removeItemAtPath:temporaryDownloadPath_ + error:NULL]; + self.temporaryDownloadPath = nil; + } + +#if GTM_BACKGROUND_FETCHING + [self endBackgroundTask]; +#endif +} + +// External stop method +- (void)stopFetching { + @synchronized(self) { + [self stopFetchReleasingCallbacks:YES]; + } +} + +- (void)sendStopNotificationIfNeeded { + if (isStopNotificationNeeded_) { + isStopNotificationNeeded_ = NO; + + NSNotificationCenter *defaultNC = [NSNotificationCenter defaultCenter]; + [defaultNC postNotificationName:kGTMHTTPFetcherStoppedNotification + object:self]; + } +} + +- (void)retryFetch { + [self stopFetchReleasingCallbacks:NO]; + + [self beginFetchWithDelegate:delegate_ + didFinishSelector:finishedSel_]; +} + +- (void)waitForCompletionWithTimeout:(NSTimeInterval)timeoutInSeconds { + NSDate* giveUpDate = [NSDate dateWithTimeIntervalSinceNow:timeoutInSeconds]; + + // Loop until the callbacks have been called and released, and until + // the connection is no longer pending, or until the timeout has expired + BOOL isMainThread = [NSThread isMainThread]; + + while ((!hasConnectionEnded_ +#if NS_BLOCKS_AVAILABLE + || completionBlock_ != nil +#endif + || delegate_ != nil) + && [giveUpDate timeIntervalSinceNow] > 0) { + + // Run the current run loop 1/1000 of a second to give the networking + // code a chance to work + if (isMainThread || delegateQueue_ == nil) { + NSDate *stopDate = [NSDate dateWithTimeIntervalSinceNow:0.001]; + [[NSRunLoop currentRunLoop] runUntilDate:stopDate]; + } else { + [NSThread sleepForTimeInterval:0.001]; + } + } +} + +#pragma mark NSURLConnection Delegate Methods + +// +// NSURLConnection Delegate Methods +// + +// This method just says "follow all redirects", which _should_ be the default behavior, +// According to file:///Developer/ADC%20Reference%20Library/documentation/Cocoa/Conceptual/URLLoadingSystem +// but the redirects were not being followed until I added this method. May be +// a bug in the NSURLConnection code, or the documentation. +// +// In OS X 10.4.8 and earlier, the redirect request doesn't +// get the original's headers and body. This causes POSTs to fail. +// So we construct a new request, a copy of the original, with overrides from the +// redirect. +// +// Docs say that if redirectResponse is nil, just return the redirectRequest. + +- (NSURLRequest *)connection:(NSURLConnection *)connection + willSendRequest:(NSURLRequest *)redirectRequest + redirectResponse:(NSURLResponse *)redirectResponse { + @synchronized(self) { + if (redirectRequest && redirectResponse) { + // save cookies from the response + [self handleCookiesForResponse:redirectResponse]; + + NSMutableURLRequest *newRequest = [[request_ mutableCopy] autorelease]; + // copy the URL + NSURL *redirectURL = [redirectRequest URL]; + NSURL *url = [newRequest URL]; + + // disallow scheme changes (say, from https to http) + NSString *redirectScheme = [url scheme]; + NSString *newScheme = [redirectURL scheme]; + NSString *newResourceSpecifier = [redirectURL resourceSpecifier]; + + if ([redirectScheme caseInsensitiveCompare:@"http"] == NSOrderedSame + && newScheme != nil + && [newScheme caseInsensitiveCompare:@"https"] == NSOrderedSame) { + + // allow the change from http to https + redirectScheme = newScheme; + } + + NSString *newUrlString = [NSString stringWithFormat:@"%@:%@", + redirectScheme, newResourceSpecifier]; + + NSURL *newURL = [NSURL URLWithString:newUrlString]; + [newRequest setURL:newURL]; + + // any headers in the redirect override headers in the original. + NSDictionary *redirectHeaders = [redirectRequest allHTTPHeaderFields]; + for (NSString *key in redirectHeaders) { + NSString *value = [redirectHeaders objectForKey:key]; + [newRequest setValue:value forHTTPHeaderField:key]; + } + + [self addCookiesToRequest:newRequest]; + + redirectRequest = newRequest; + + // log the response we just received + [self setResponse:redirectResponse]; + [self logNowWithError:nil]; + + // update the request for future logging + NSMutableURLRequest *mutable = [[redirectRequest mutableCopy] autorelease]; + [self setMutableRequest:mutable]; + } + return redirectRequest; + } +} + +- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { + @synchronized(self) { + // This method is called when the server has determined that it + // has enough information to create the NSURLResponse + // it can be called multiple times, for example in the case of a + // redirect, so each time we reset the data. + [downloadedData_ setLength:0]; + [downloadFileHandle_ truncateFileAtOffset:0]; + downloadedLength_ = 0; + + [self setResponse:response]; + + // Save cookies from the response + [self handleCookiesForResponse:response]; + } +} + + +// handleCookiesForResponse: handles storage of cookies for responses passed to +// connection:willSendRequest:redirectResponse: and connection:didReceiveResponse: +- (void)handleCookiesForResponse:(NSURLResponse *)response { + + if (cookieStorageMethod_ == kGTMHTTPFetcherCookieStorageMethodSystemDefault + || cookieStorageMethod_ == kGTMHTTPFetcherCookieStorageMethodNone) { + + // do nothing special for NSURLConnection's default storage mechanism + // or when we're ignoring cookies + + } else if ([response respondsToSelector:@selector(allHeaderFields)]) { + + // grab the cookies from the header as NSHTTPCookies and store them either + // into our static array or into the fetchHistory + + NSDictionary *responseHeaderFields = [(NSHTTPURLResponse *)response allHeaderFields]; + if (responseHeaderFields) { + + NSArray *cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:responseHeaderFields + forURL:[response URL]]; + if ([cookies count] > 0) { + [cookieStorage_ setCookies:cookies]; + } + } + } +} + +-(void)connection:(NSURLConnection *)connection +didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { + @synchronized(self) { + if ([challenge previousFailureCount] <= 2) { + + NSURLCredential *credential = credential_; + + if ([[challenge protectionSpace] isProxy] && proxyCredential_ != nil) { + credential = proxyCredential_; + } + + // Here, if credential is still nil, then we *could* try to get it from + // NSURLCredentialStorage's defaultCredentialForProtectionSpace:. + // We don't, because we're assuming: + // + // - for server credentials, we only want ones supplied by the program + // calling http fetcher + // - for proxy credentials, if one were necessary and available in the + // keychain, it would've been found automatically by NSURLConnection + // and this challenge delegate method never would've been called + // anyway + + if (credential) { + // try the credential + [[challenge sender] useCredential:credential + forAuthenticationChallenge:challenge]; + return; + } + } + + // If we don't have credentials, or we've already failed auth 3x, + // report the error, putting the challenge as a value in the userInfo + // dictionary. +#if DEBUG + NSAssert(!isCancellingChallenge_, @"isCancellingChallenge_ unexpected"); +#endif + NSDictionary *userInfo = [NSDictionary dictionaryWithObject:challenge + forKey:kGTMHTTPFetcherErrorChallengeKey]; + NSError *error = [NSError errorWithDomain:kGTMHTTPFetcherErrorDomain + code:kGTMHTTPFetcherErrorAuthenticationChallengeFailed + userInfo:userInfo]; + + // cancelAuthenticationChallenge seems to indirectly call + // connection:didFailWithError: now, though that isn't documented + // + // We'll use an ivar to make the indirect invocation of the + // delegate method do nothing. + isCancellingChallenge_ = YES; + [[challenge sender] cancelAuthenticationChallenge:challenge]; + isCancellingChallenge_ = NO; + + [self connection:connection didFailWithError:error]; + } +} + +- (void)invokeFetchCallbacksWithData:(NSData *)data + error:(NSError *)error { + [[self retain] autorelease]; // In case the callback releases us + + [self invokeFetchCallback:finishedSel_ + target:delegate_ + data:data + error:error]; + +#if NS_BLOCKS_AVAILABLE + if (completionBlock_) { + completionBlock_(data, error); + } +#endif +} + +- (void)invokeFetchCallback:(SEL)sel + target:(id)target + data:(NSData *)data + error:(NSError *)error { + // This method is available to subclasses which may provide a customized + // target pointer. + if (target && sel) { + NSMethodSignature *sig = [target methodSignatureForSelector:sel]; + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig]; + [invocation setSelector:sel]; + [invocation setTarget:target]; + [invocation setArgument:&self atIndex:2]; + [invocation setArgument:&data atIndex:3]; + [invocation setArgument:&error atIndex:4]; + [invocation invoke]; + } +} + +- (void)invokeFetchCallbacksOnDelegateQueueWithData:(NSData *)data + error:(NSError *)error { + // This is called by methods that are not already on the delegateQueue + // (as NSURLConnection callbacks should already be, but other failures + // are not.) + if (!delegateQueue_) { + [self invokeFetchCallbacksWithData:data error:error]; + } + + // Values may be nil. + NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:2]; + [dict setValue:data forKey:kCallbackData]; + [dict setValue:error forKey:kCallbackError]; + NSInvocationOperation *op = + [[[NSInvocationOperation alloc] initWithTarget:self + selector:@selector(invokeOnQueueWithDictionary:) + object:dict] autorelease]; + [delegateQueue_ addOperation:op]; +} + +- (void)invokeOnQueueWithDictionary:(NSDictionary *)dict { + NSData *data = [dict objectForKey:kCallbackData]; + NSError *error = [dict objectForKey:kCallbackError]; + + [self invokeFetchCallbacksWithData:data error:error]; +} + + +- (void)invokeSentDataCallback:(SEL)sel + target:(id)target + didSendBodyData:(NSInteger)bytesWritten + totalBytesWritten:(NSInteger)totalBytesWritten + totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite { + if (target && sel) { + NSMethodSignature *sig = [target methodSignatureForSelector:sel]; + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig]; + [invocation setSelector:sel]; + [invocation setTarget:target]; + [invocation setArgument:&self atIndex:2]; + [invocation setArgument:&bytesWritten atIndex:3]; + [invocation setArgument:&totalBytesWritten atIndex:4]; + [invocation setArgument:&totalBytesExpectedToWrite atIndex:5]; + [invocation invoke]; + } +} + +- (BOOL)invokeRetryCallback:(SEL)sel + target:(id)target + willRetry:(BOOL)willRetry + error:(NSError *)error { + if (target && sel) { + NSMethodSignature *sig = [target methodSignatureForSelector:sel]; + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig]; + [invocation setSelector:sel]; + [invocation setTarget:target]; + [invocation setArgument:&self atIndex:2]; + [invocation setArgument:&willRetry atIndex:3]; + [invocation setArgument:&error atIndex:4]; + [invocation invoke]; + + [invocation getReturnValue:&willRetry]; + } + return willRetry; +} + +- (void)connection:(NSURLConnection *)connection + didSendBodyData:(NSInteger)bytesWritten + totalBytesWritten:(NSInteger)totalBytesWritten +totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite { + @synchronized(self) { + SEL sel = [self sentDataSelector]; + [self invokeSentDataCallback:sel + target:delegate_ + didSendBodyData:bytesWritten + totalBytesWritten:totalBytesWritten + totalBytesExpectedToWrite:totalBytesExpectedToWrite]; + +#if NS_BLOCKS_AVAILABLE + if (sentDataBlock_) { + sentDataBlock_(bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); + } +#endif + } +} + +- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { + @synchronized(self) { +#if DEBUG + // The download file handle should be set before the fetch is started, not + // after + NSAssert((downloadFileHandle_ == nil) != (downloadedData_ == nil), + @"received data accumulates as NSData or NSFileHandle, not both"); +#endif + + if (downloadFileHandle_ != nil) { + // Append to file + @try { + [downloadFileHandle_ writeData:data]; + + downloadedLength_ = [downloadFileHandle_ offsetInFile]; + } + @catch (NSException *exc) { + // Couldn't write to file, probably due to a full disk + NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[exc reason] + forKey:NSLocalizedDescriptionKey]; + NSError *error = [NSError errorWithDomain:kGTMHTTPFetcherStatusDomain + code:kGTMHTTPFetcherErrorFileHandleException + userInfo:userInfo]; + [self connection:connection didFailWithError:error]; + return; + } + } else { + // append to mutable data + [downloadedData_ appendData:data]; + + downloadedLength_ = [downloadedData_ length]; + } + + if (receivedDataSel_) { + [delegate_ performSelector:receivedDataSel_ + withObject:self + withObject:downloadedData_]; + } + +#if NS_BLOCKS_AVAILABLE + if (receivedDataBlock_) { + receivedDataBlock_(downloadedData_); + } +#endif + } +} + +// For error 304's ("Not Modified") where we've cached the data, return +// status 200 ("OK") to the caller (but leave the fetcher status as 304) +// and copy the cached data. +// +// For other errors or if there's no cached data, just return the actual status. +- (NSData *)cachedDataForStatus { + if ([self statusCode] == kGTMHTTPFetcherStatusNotModified + && [fetchHistory_ shouldCacheETaggedData]) { + NSData *cachedData = [fetchHistory_ cachedDataForRequest:request_]; + return cachedData; + } + return nil; +} + +- (NSInteger)statusAfterHandlingNotModifiedError { + NSInteger status = [self statusCode]; + NSData *cachedData = [self cachedDataForStatus]; + if (cachedData) { + // Forge the status to pass on to the delegate + status = 200; + + // Copy our stored data + if (downloadFileHandle_ != nil) { + @try { + // Downloading to a file handle won't save to the cache (the data is + // likely inappropriately large for caching), but will still read from + // the cache, on the unlikely chance that the response was Not Modified + // and the URL response was indeed present in the cache. + [downloadFileHandle_ truncateFileAtOffset:0]; + [downloadFileHandle_ writeData:cachedData]; + downloadedLength_ = [downloadFileHandle_ offsetInFile]; + } + @catch (NSException *) { + // Failed to write data, likely due to lack of disk space + status = kGTMHTTPFetcherErrorFileHandleException; + } + } else { + [downloadedData_ setData:cachedData]; + downloadedLength_ = [cachedData length]; + } + } + return status; +} + +- (void)connectionDidFinishLoading:(NSURLConnection *)connection { + @synchronized(self) { + // We no longer need to cancel the connection + hasConnectionEnded_ = YES; + + // Skip caching ETagged results when the data is being saved to a file + if (downloadFileHandle_ == nil) { + [fetchHistory_ updateFetchHistoryWithRequest:request_ + response:response_ + downloadedData:downloadedData_]; + } else { + [fetchHistory_ removeCachedDataForRequest:request_]; + } + + [[self retain] autorelease]; // in case the callback releases us + + BOOL hasLogged = NO; + NSInteger status = [self statusCode]; + if ([self cachedDataForStatus] != nil) { + // Log the pre-cache response. + [self logNowWithError:nil]; + hasLogged = YES; + status = [self statusAfterHandlingNotModifiedError]; + } + + // We want to send the stop notification before calling the delegate's + // callback selector, since the callback selector may release all of + // the fetcher properties that the client is using to track the fetches. + // + // We'll also stop now so that, to any observers watching the notifications, + // it doesn't look like our wait for a retry (which may be long, + // 30 seconds or more) is part of the network activity. + [self sendStopNotificationIfNeeded]; + + BOOL shouldStopFetching = YES; + NSError *error = nil; + + if (status >= 0 && status < 300) { + // success + if (downloadPath_) { + // Avoid deleting the downloaded file when the fetch stops + [downloadFileHandle_ closeFile]; + self.downloadFileHandle = nil; + + NSFileManager *fileMgr = [NSFileManager defaultManager]; + [fileMgr removeItemAtPath:downloadPath_ + error:NULL]; + + if ([fileMgr moveItemAtPath:temporaryDownloadPath_ + toPath:downloadPath_ + error:&error]) { + self.temporaryDownloadPath = nil; + } + } + } else { + // unsuccessful + if (!hasLogged) { + [self logNowWithError:nil]; + hasLogged = YES; + } + // Status over 300; retry or notify the delegate of failure + if ([self shouldRetryNowForStatus:status error:nil]) { + // retrying + [self beginRetryTimer]; + shouldStopFetching = NO; + } else { + NSDictionary *userInfo = nil; + if ([downloadedData_ length] > 0) { + userInfo = [NSDictionary dictionaryWithObject:downloadedData_ + forKey:kGTMHTTPFetcherStatusDataKey]; + } + error = [NSError errorWithDomain:kGTMHTTPFetcherStatusDomain + code:status + userInfo:userInfo]; + } + } + + if (shouldStopFetching) { + // Call the callbacks + [self invokeFetchCallbacksWithData:downloadedData_ + error:error]; + BOOL shouldRelease = [self shouldReleaseCallbacksUponCompletion]; + [self stopFetchReleasingCallbacks:shouldRelease]; + } + + BOOL shouldLogNow = !hasLogged; +#if !STRIP_GTM_FETCH_LOGGING + if (shouldDeferResponseBodyLogging_) shouldLogNow = NO; +#endif + if (shouldLogNow) { + [self logNowWithError:nil]; + } + } +} + +- (BOOL)shouldReleaseCallbacksUponCompletion { + // A subclass can override this to keep callbacks around after the + // connection has finished successfully + return YES; +} + +- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { + @synchronized(self) { + // Prevent the failure callback from being called twice, since the stopFetch + // call below (either the explicit one at the end of this method, or the + // implicit one when the retry occurs) will release the delegate. + if (connection_ == nil) return; + + // If this method was invoked indirectly by cancellation of an authentication + // challenge, defer this until it is called again with the proper error object + if (isCancellingChallenge_) return; + + // We no longer need to cancel the connection + hasConnectionEnded_ = YES; + + [self logNowWithError:error]; + + // See comment about sendStopNotificationIfNeeded + // in connectionDidFinishLoading: + [self sendStopNotificationIfNeeded]; + + if ([self shouldRetryNowForStatus:0 error:error]) { + + [self beginRetryTimer]; + + } else { + + [[self retain] autorelease]; // in case the callback releases us + + [self invokeFetchCallbacksWithData:nil + error:error]; + + [self stopFetchReleasingCallbacks:YES]; + } + } +} + +- (void)logNowWithError:(NSError *)error { + // If the logging category is available, then log the current request, + // response, data, and error + if ([self respondsToSelector:@selector(logFetchWithError:)]) { + [self performSelector:@selector(logFetchWithError:) withObject:error]; + } +} + +#pragma mark Retries + +- (BOOL)isRetryError:(NSError *)error { + + struct retryRecord { + NSString *const domain; + int code; + }; + + struct retryRecord retries[] = { + { kGTMHTTPFetcherStatusDomain, 408 }, // request timeout + { kGTMHTTPFetcherStatusDomain, 503 }, // service unavailable + { kGTMHTTPFetcherStatusDomain, 504 }, // request timeout + { NSURLErrorDomain, NSURLErrorTimedOut }, + { NSURLErrorDomain, NSURLErrorNetworkConnectionLost }, + { nil, 0 } + }; + + // NSError's isEqual always returns false for equal but distinct instances + // of NSError, so we have to compare the domain and code values explicitly + + for (int idx = 0; retries[idx].domain != nil; idx++) { + + if ([[error domain] isEqual:retries[idx].domain] + && [error code] == retries[idx].code) { + + return YES; + } + } + return NO; +} + + +// shouldRetryNowForStatus:error: returns YES if the user has enabled retries +// and the status or error is one that is suitable for retrying. "Suitable" +// means either the isRetryError:'s list contains the status or error, or the +// user's retrySelector: is present and returns YES when called, or the +// authorizer may be able to fix. +- (BOOL)shouldRetryNowForStatus:(NSInteger)status + error:(NSError *)error { + // Determine if a refreshed authorizer may avoid an authorization error + BOOL shouldRetryForAuthRefresh = NO; + BOOL isFirstAuthError = (authorizer_ != nil) + && !hasAttemptedAuthRefresh_ + && (status == kGTMHTTPFetcherStatusUnauthorized); // 401 + + if (isFirstAuthError) { + if ([authorizer_ respondsToSelector:@selector(primeForRefresh)]) { + BOOL hasPrimed = [authorizer_ primeForRefresh]; + if (hasPrimed) { + shouldRetryForAuthRefresh = YES; + hasAttemptedAuthRefresh_ = YES; + [request_ setValue:nil forHTTPHeaderField:@"Authorization"]; + } + } + } + + // Determine if we're doing exponential backoff retries + BOOL shouldDoIntervalRetry = [self isRetryEnabled] + && ([self nextRetryInterval] < [self maxRetryInterval]); + + BOOL willRetry = NO; + BOOL canRetry = shouldRetryForAuthRefresh || shouldDoIntervalRetry; + if (canRetry) { + // Check if this is a retryable error + if (error == nil) { + // Make an error for the status + NSDictionary *userInfo = nil; + if ([downloadedData_ length] > 0) { + userInfo = [NSDictionary dictionaryWithObject:downloadedData_ + forKey:kGTMHTTPFetcherStatusDataKey]; + } + error = [NSError errorWithDomain:kGTMHTTPFetcherStatusDomain + code:status + userInfo:userInfo]; + } + + willRetry = shouldRetryForAuthRefresh || [self isRetryError:error]; + + // If the user has installed a retry callback, consult that + willRetry = [self invokeRetryCallback:retrySel_ + target:delegate_ + willRetry:willRetry + error:error]; +#if NS_BLOCKS_AVAILABLE + if (retryBlock_) { + willRetry = retryBlock_(willRetry, error); + } +#endif + } + return willRetry; +} + +- (void)beginRetryTimer { + @synchronized(self) { + if (delegateQueue_ != nil && ![NSThread isMainThread]) { + // A delegate queue is set, so the thread we're running on may not + // have a run loop. We'll defer creating and starting the timer + // until we're on the main thread to ensure it has a run loop. + // (If we weren't supporting 10.5, we could use dispatch_after instead + // of an NSTimer.) + [self performSelectorOnMainThread:_cmd + withObject:nil + waitUntilDone:NO]; + return; + } + + NSTimeInterval nextInterval = [self nextRetryInterval]; + NSTimeInterval maxInterval = [self maxRetryInterval]; + + NSTimeInterval newInterval = MIN(nextInterval, maxInterval); + + [self primeRetryTimerWithNewTimeInterval:newInterval]; + } +} + +- (void)primeRetryTimerWithNewTimeInterval:(NSTimeInterval)secs { + + [self destroyRetryTimer]; + + lastRetryInterval_ = secs; + + retryTimer_ = [NSTimer timerWithTimeInterval:secs + target:self + selector:@selector(retryTimerFired:) + userInfo:nil + repeats:NO]; + [retryTimer_ retain]; + + NSRunLoop *timerRL = (self.delegateQueue ? + [NSRunLoop mainRunLoop] : [NSRunLoop currentRunLoop]); + [timerRL addTimer:retryTimer_ + forMode:NSDefaultRunLoopMode]; + + NSNotificationCenter *defaultNC = [NSNotificationCenter defaultCenter]; + [defaultNC postNotificationName:kGTMHTTPFetcherRetryDelayStartedNotification + object:self]; +} + +- (void)retryTimerFired:(NSTimer *)timer { + @synchronized(self) { + [self destroyRetryTimer]; + + retryCount_++; + + [self retryFetch]; + } +} + +- (void)destroyRetryTimer { + if (retryTimer_) { + [retryTimer_ invalidate]; + [retryTimer_ autorelease]; + retryTimer_ = nil; + + NSNotificationCenter *defaultNC = [NSNotificationCenter defaultCenter]; + [defaultNC postNotificationName:kGTMHTTPFetcherRetryDelayStoppedNotification + object:self]; + } +} + +- (NSUInteger)retryCount { + return retryCount_; +} + +- (NSTimeInterval)nextRetryInterval { + // The next wait interval is the factor (2.0) times the last interval, + // but never less than the minimum interval. + NSTimeInterval secs = lastRetryInterval_ * retryFactor_; + secs = MIN(secs, maxRetryInterval_); + secs = MAX(secs, minRetryInterval_); + + return secs; +} + +- (BOOL)isRetryEnabled { + return isRetryEnabled_; +} + +- (void)setRetryEnabled:(BOOL)flag { + + if (flag && !isRetryEnabled_) { + // We defer initializing these until the user calls setRetryEnabled + // to avoid using the random number generator if it's not needed. + // However, this means min and max intervals for this fetcher are reset + // as a side effect of calling setRetryEnabled. + // + // Make an initial retry interval random between 1.0 and 2.0 seconds + [self setMinRetryInterval:0.0]; + [self setMaxRetryInterval:kUnsetMaxRetryInterval]; + [self setRetryFactor:2.0]; + lastRetryInterval_ = 0.0; + } + isRetryEnabled_ = flag; +}; + +- (NSTimeInterval)maxRetryInterval { + return maxRetryInterval_; +} + +- (void)setMaxRetryInterval:(NSTimeInterval)secs { + if (secs > 0) { + maxRetryInterval_ = secs; + } else { + maxRetryInterval_ = kUnsetMaxRetryInterval; + } +} + +- (double)minRetryInterval { + return minRetryInterval_; +} + +- (void)setMinRetryInterval:(NSTimeInterval)secs { + if (secs > 0) { + minRetryInterval_ = secs; + } else { + // Set min interval to a random value between 1.0 and 2.0 seconds + // so that if multiple clients start retrying at the same time, they'll + // repeat at different times and avoid overloading the server + minRetryInterval_ = 1.0 + ((double)(arc4random() & 0x0FFFF) / (double) 0x0FFFF); + } +} + +#pragma mark Getters and Setters + +@dynamic cookieStorageMethod, + retryEnabled, + maxRetryInterval, + minRetryInterval, + retryCount, + nextRetryInterval, + statusCode, + responseHeaders, + fetchHistory, + userData, + properties; + +@synthesize mutableRequest = request_, + credential = credential_, + proxyCredential = proxyCredential_, + postData = postData_, + postStream = postStream_, + delegate = delegate_, + authorizer = authorizer_, + service = service_, + serviceHost = serviceHost_, + servicePriority = servicePriority_, + thread = thread_, + sentDataSelector = sentDataSel_, + receivedDataSelector = receivedDataSel_, + retrySelector = retrySel_, + retryFactor = retryFactor_, + response = response_, + downloadedLength = downloadedLength_, + downloadedData = downloadedData_, + downloadPath = downloadPath_, + temporaryDownloadPath = temporaryDownloadPath_, + downloadFileHandle = downloadFileHandle_, + delegateQueue = delegateQueue_, + runLoopModes = runLoopModes_, + comment = comment_, + log = log_, + cookieStorage = cookieStorage_; + +#if NS_BLOCKS_AVAILABLE +@synthesize completionBlock = completionBlock_, + sentDataBlock = sentDataBlock_, + receivedDataBlock = receivedDataBlock_, + retryBlock = retryBlock_; +#endif + +@synthesize shouldFetchInBackground = shouldFetchInBackground_; + +- (NSInteger)cookieStorageMethod { + return cookieStorageMethod_; +} + +- (void)setCookieStorageMethod:(NSInteger)method { + + cookieStorageMethod_ = method; + + if (method == kGTMHTTPFetcherCookieStorageMethodSystemDefault) { + // System default + [request_ setHTTPShouldHandleCookies:YES]; + + // No need for a cookie storage object + self.cookieStorage = nil; + + } else { + // Not system default + [request_ setHTTPShouldHandleCookies:NO]; + + if (method == kGTMHTTPFetcherCookieStorageMethodStatic) { + // Store cookies in the static array + NSAssert(gGTMFetcherStaticCookieStorage != nil, + @"cookie storage requires GTMHTTPFetchHistory"); + + self.cookieStorage = gGTMFetcherStaticCookieStorage; + } else if (method == kGTMHTTPFetcherCookieStorageMethodFetchHistory) { + // store cookies in the fetch history + self.cookieStorage = [fetchHistory_ cookieStorage]; + } else { + // kGTMHTTPFetcherCookieStorageMethodNone - ignore cookies + self.cookieStorage = nil; + } + } +} + ++ (id )staticCookieStorage { + return gGTMFetcherStaticCookieStorage; +} + ++ (BOOL)doesSupportSentDataCallback { +#if GTM_IPHONE + // NSURLConnection's didSendBodyData: delegate support appears to be + // available starting in iPhone OS 3.0 + return (NSFoundationVersionNumber >= 678.47); +#else + // Per WebKit's MaxFoundationVersionWithoutdidSendBodyDataDelegate + // + // Indicates if NSURLConnection will invoke the didSendBodyData: delegate + // method + return (NSFoundationVersionNumber > 677.21); +#endif +} + +- (id )fetchHistory { + return fetchHistory_; +} + +- (void)setFetchHistory:(id )fetchHistory { + [fetchHistory_ autorelease]; + fetchHistory_ = [fetchHistory retain]; + + if (fetchHistory_ != nil) { + // set the fetch history's cookie array to be the cookie store + [self setCookieStorageMethod:kGTMHTTPFetcherCookieStorageMethodFetchHistory]; + + } else { + // The fetch history was removed + if (cookieStorageMethod_ == kGTMHTTPFetcherCookieStorageMethodFetchHistory) { + // Fall back to static storage + [self setCookieStorageMethod:kGTMHTTPFetcherCookieStorageMethodStatic]; + } + } +} + +- (id)userData { + @synchronized(self) { + return userData_; + } +} + +- (void)setUserData:(id)theObj { + @synchronized(self) { + [userData_ autorelease]; + userData_ = [theObj retain]; + } +} + +- (void)setProperties:(NSMutableDictionary *)dict { + @synchronized(self) { + [properties_ autorelease]; + + // This copies rather than retains the parameter for compatiblity with + // an earlier version that took an immutable parameter and copied it. + properties_ = [dict mutableCopy]; + } +} + +- (NSMutableDictionary *)properties { + @synchronized(self) { + return properties_; + } +} + +- (void)setProperty:(id)obj forKey:(NSString *)key { + @synchronized(self) { + if (properties_ == nil && obj != nil) { + [self setProperties:[NSMutableDictionary dictionary]]; + } + [properties_ setValue:obj forKey:key]; + } +} + +- (id)propertyForKey:(NSString *)key { + @synchronized(self) { + return [properties_ objectForKey:key]; + } +} + +- (void)addPropertiesFromDictionary:(NSDictionary *)dict { + @synchronized(self) { + if (properties_ == nil && dict != nil) { + [self setProperties:[[dict mutableCopy] autorelease]]; + } else { + [properties_ addEntriesFromDictionary:dict]; + } + } +} + +- (void)setCommentWithFormat:(id)format, ... { +#if !STRIP_GTM_FETCH_LOGGING + NSString *result = format; + if (format) { + va_list argList; + va_start(argList, format); + + result = [[[NSString alloc] initWithFormat:format + arguments:argList] autorelease]; + va_end(argList); + } + [self setComment:result]; +#endif +} + ++ (Class)connectionClass { + if (gGTMFetcherConnectionClass == nil) { + gGTMFetcherConnectionClass = [NSURLConnection class]; + } + return gGTMFetcherConnectionClass; +} + ++ (void)setConnectionClass:(Class)theClass { + gGTMFetcherConnectionClass = theClass; +} + +#if STRIP_GTM_FETCH_LOGGING ++ (void)setLoggingEnabled:(BOOL)flag { +} +#endif // STRIP_GTM_FETCH_LOGGING + +@end + +void GTMAssertSelectorNilOrImplementedWithArgs(id obj, SEL sel, ...) { + + // Verify that the object's selector is implemented with the proper + // number and type of arguments +#if DEBUG + va_list argList; + va_start(argList, sel); + + if (obj && sel) { + // Check that the selector is implemented + if (![obj respondsToSelector:sel]) { + NSLog(@"\"%@\" selector \"%@\" is unimplemented or misnamed", + NSStringFromClass([obj class]), + NSStringFromSelector(sel)); + NSCAssert(0, @"callback selector unimplemented or misnamed"); + } else { + const char *expectedArgType; + unsigned int argCount = 2; // skip self and _cmd + NSMethodSignature *sig = [obj methodSignatureForSelector:sel]; + + // Check that each expected argument is present and of the correct type + while ((expectedArgType = va_arg(argList, const char*)) != 0) { + + if ([sig numberOfArguments] > argCount) { + const char *foundArgType = [sig getArgumentTypeAtIndex:argCount]; + + if(0 != strncmp(foundArgType, expectedArgType, strlen(expectedArgType))) { + NSLog(@"\"%@\" selector \"%@\" argument %d should be type %s", + NSStringFromClass([obj class]), + NSStringFromSelector(sel), (argCount - 2), expectedArgType); + NSCAssert(0, @"callback selector argument type mistake"); + } + } + argCount++; + } + + // Check that the proper number of arguments are present in the selector + if (argCount != [sig numberOfArguments]) { + NSLog( @"\"%@\" selector \"%@\" should have %d arguments", + NSStringFromClass([obj class]), + NSStringFromSelector(sel), (argCount - 2)); + NSCAssert(0, @"callback selector arguments incorrect"); + } + } + } + + va_end(argList); +#endif +} + +NSString *GTMCleanedUserAgentString(NSString *str) { + // Reference http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html + // and http://www-archive.mozilla.org/build/user-agent-strings.html + + if (str == nil) return nil; + + NSMutableString *result = [NSMutableString stringWithString:str]; + + // Replace spaces with underscores + [result replaceOccurrencesOfString:@" " + withString:@"_" + options:0 + range:NSMakeRange(0, [result length])]; + + // Delete http token separators and remaining whitespace + static NSCharacterSet *charsToDelete = nil; + if (charsToDelete == nil) { + // Make a set of unwanted characters + NSString *const kSeparators = @"()<>@,;:\\\"/[]?={}"; + + NSMutableCharacterSet *mutableChars; + mutableChars = [[[NSCharacterSet whitespaceAndNewlineCharacterSet] mutableCopy] autorelease]; + [mutableChars addCharactersInString:kSeparators]; + charsToDelete = [mutableChars copy]; // hang on to an immutable copy + } + + while (1) { + NSRange separatorRange = [result rangeOfCharacterFromSet:charsToDelete]; + if (separatorRange.location == NSNotFound) break; + + [result deleteCharactersInRange:separatorRange]; + }; + + return result; +} + +NSString *GTMSystemVersionString(void) { + NSString *systemString = @""; + +#if TARGET_OS_MAC && !TARGET_OS_IPHONE + // Mac build + static NSString *savedSystemString = nil; + if (savedSystemString == nil) { + // With Gestalt inexplicably deprecated in 10.8, we're reduced to reading + // the system plist file. + NSString *const kPath = @"/System/Library/CoreServices/SystemVersion.plist"; + NSDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:kPath]; + NSString *versString = [plist objectForKey:@"ProductVersion"]; + if ([versString length] == 0) { + versString = @"10.?.?"; + } + savedSystemString = [[NSString alloc] initWithFormat:@"MacOSX/%@", versString]; + } + systemString = savedSystemString; +#elif TARGET_OS_IPHONE + // Compiling against the iPhone SDK + + static NSString *savedSystemString = nil; + if (savedSystemString == nil) { + // Avoid the slowness of calling currentDevice repeatedly on the iPhone + UIDevice* currentDevice = [UIDevice currentDevice]; + + NSString *rawModel = [currentDevice model]; + NSString *model = GTMCleanedUserAgentString(rawModel); + + NSString *systemVersion = [currentDevice systemVersion]; + + savedSystemString = [[NSString alloc] initWithFormat:@"%@/%@", + model, systemVersion]; // "iPod_Touch/2.2" + } + systemString = savedSystemString; + +#elif (GTL_IPHONE || GDATA_IPHONE) + // Compiling iOS libraries against the Mac SDK + systemString = @"iPhone/x.x"; + +#elif defined(_SYS_UTSNAME_H) + // Foundation-only build + struct utsname unameRecord; + uname(&unameRecord); + + systemString = [NSString stringWithFormat:@"%s/%s", + unameRecord.sysname, unameRecord.release]; // "Darwin/8.11.1" +#endif + + return systemString; +} + +// Return a generic name and version for the current application; this avoids +// anonymous server transactions. +NSString *GTMApplicationIdentifier(NSBundle *bundle) { + static NSString *sAppID = nil; + if (sAppID != nil) return sAppID; + + // If there's a bundle ID, use that; otherwise, use the process name + if (bundle == nil) { + bundle = [NSBundle mainBundle]; + } + + NSString *identifier; + NSString *bundleID = [bundle bundleIdentifier]; + if ([bundleID length] > 0) { + identifier = bundleID; + } else { + // Fall back on the procname, prefixed by "proc" to flag that it's + // autogenerated and perhaps unreliable + NSString *procName = [[NSProcessInfo processInfo] processName]; + identifier = [NSString stringWithFormat:@"proc_%@", procName]; + } + + // Clean up whitespace and special characters + identifier = GTMCleanedUserAgentString(identifier); + + // If there's a version number, append that + NSString *version = [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; + if ([version length] == 0) { + version = [bundle objectForInfoDictionaryKey:@"CFBundleVersion"]; + } + + // Clean up whitespace and special characters + version = GTMCleanedUserAgentString(version); + + // Glue the two together (cleanup done above or else cleanup would strip the + // slash) + if ([version length] > 0) { + identifier = [identifier stringByAppendingFormat:@"/%@", version]; + } + + sAppID = [identifier copy]; + return sAppID; +} diff --git a/client/ios/Hackpad/GoogleToolbox/GTMNSString+HTML.h b/client/ios/Hackpad/GoogleToolbox/GTMNSString+HTML.h new file mode 100644 index 0000000..1273cc3 --- /dev/null +++ b/client/ios/Hackpad/GoogleToolbox/GTMNSString+HTML.h @@ -0,0 +1,66 @@ +// +// GTMNSString+HTML.h +// Dealing with NSStrings that contain HTML +// +// Copyright 2006-2008 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +// + +#import + +/// Utilities for NSStrings containing HTML +@interface NSString (GTMNSStringHTMLAdditions) + +/// Get a string where internal characters that need escaping for HTML are escaped +// +/// For example, '&' become '&'. This will only cover characters from table +/// A.2.2 of http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_Special_characters +/// which is what you want for a unicode encoded webpage. If you have a ascii +/// or non-encoded webpage, please use stringByEscapingAsciiHTML which will +/// encode all characters. +/// +/// For obvious reasons this call is only safe once. +// +// Returns: +// Autoreleased NSString +// +- (NSString *)gtm_stringByEscapingForHTML; + +/// Get a string where internal characters that need escaping for HTML are escaped +// +/// For example, '&' become '&' +/// All non-mapped characters (unicode that don't have a &keyword; mapping) +/// will be converted to the appropriate &#xxx; value. If your webpage is +/// unicode encoded (UTF16 or UTF8) use stringByEscapingHTML instead as it is +/// faster, and produces less bloated and more readable HTML (as long as you +/// are using a unicode compliant HTML reader). +/// +/// For obvious reasons this call is only safe once. +// +// Returns: +// Autoreleased NSString +// +- (NSString *)gtm_stringByEscapingForAsciiHTML; + +/// Get a string where internal characters that are escaped for HTML are unescaped +// +/// For example, '&' becomes '&' +/// Handles and 2 cases as well +/// +// Returns: +// Autoreleased NSString +// +- (NSString *)gtm_stringByUnescapingFromHTML; + +@end diff --git a/client/ios/Hackpad/GoogleToolbox/GTMNSString+HTML.m b/client/ios/Hackpad/GoogleToolbox/GTMNSString+HTML.m new file mode 100644 index 0000000..d580b9e --- /dev/null +++ b/client/ios/Hackpad/GoogleToolbox/GTMNSString+HTML.m @@ -0,0 +1,522 @@ +// +// GTMNSString+HTML.m +// Dealing with NSStrings that contain HTML +// +// Copyright 2006-2008 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +// + +#import "GTMDefines.h" +#import "GTMNSString+HTML.h" + +typedef struct { + NSString *escapeSequence; + unichar uchar; +} HTMLEscapeMap; + +// Taken from http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_Special_characters +// Ordered by uchar lowest to highest for bsearching +static HTMLEscapeMap gAsciiHTMLEscapeMap[] = { + // A.2.2. Special characters + { @""", 34 }, + { @"&", 38 }, + { @"'", 39 }, + { @"<", 60 }, + { @">", 62 }, + + // A.2.1. Latin-1 characters + { @" ", 160 }, + { @"¡", 161 }, + { @"¢", 162 }, + { @"£", 163 }, + { @"¤", 164 }, + { @"¥", 165 }, + { @"¦", 166 }, + { @"§", 167 }, + { @"¨", 168 }, + { @"©", 169 }, + { @"ª", 170 }, + { @"«", 171 }, + { @"¬", 172 }, + { @"­", 173 }, + { @"®", 174 }, + { @"¯", 175 }, + { @"°", 176 }, + { @"±", 177 }, + { @"²", 178 }, + { @"³", 179 }, + { @"´", 180 }, + { @"µ", 181 }, + { @"¶", 182 }, + { @"·", 183 }, + { @"¸", 184 }, + { @"¹", 185 }, + { @"º", 186 }, + { @"»", 187 }, + { @"¼", 188 }, + { @"½", 189 }, + { @"¾", 190 }, + { @"¿", 191 }, + { @"À", 192 }, + { @"Á", 193 }, + { @"Â", 194 }, + { @"Ã", 195 }, + { @"Ä", 196 }, + { @"Å", 197 }, + { @"Æ", 198 }, + { @"Ç", 199 }, + { @"È", 200 }, + { @"É", 201 }, + { @"Ê", 202 }, + { @"Ë", 203 }, + { @"Ì", 204 }, + { @"Í", 205 }, + { @"Î", 206 }, + { @"Ï", 207 }, + { @"Ð", 208 }, + { @"Ñ", 209 }, + { @"Ò", 210 }, + { @"Ó", 211 }, + { @"Ô", 212 }, + { @"Õ", 213 }, + { @"Ö", 214 }, + { @"×", 215 }, + { @"Ø", 216 }, + { @"Ù", 217 }, + { @"Ú", 218 }, + { @"Û", 219 }, + { @"Ü", 220 }, + { @"Ý", 221 }, + { @"Þ", 222 }, + { @"ß", 223 }, + { @"à", 224 }, + { @"á", 225 }, + { @"â", 226 }, + { @"ã", 227 }, + { @"ä", 228 }, + { @"å", 229 }, + { @"æ", 230 }, + { @"ç", 231 }, + { @"è", 232 }, + { @"é", 233 }, + { @"ê", 234 }, + { @"ë", 235 }, + { @"ì", 236 }, + { @"í", 237 }, + { @"î", 238 }, + { @"ï", 239 }, + { @"ð", 240 }, + { @"ñ", 241 }, + { @"ò", 242 }, + { @"ó", 243 }, + { @"ô", 244 }, + { @"õ", 245 }, + { @"ö", 246 }, + { @"÷", 247 }, + { @"ø", 248 }, + { @"ù", 249 }, + { @"ú", 250 }, + { @"û", 251 }, + { @"ü", 252 }, + { @"ý", 253 }, + { @"þ", 254 }, + { @"ÿ", 255 }, + + // A.2.2. Special characters cont'd + { @"Œ", 338 }, + { @"œ", 339 }, + { @"Š", 352 }, + { @"š", 353 }, + { @"Ÿ", 376 }, + + // A.2.3. Symbols + { @"ƒ", 402 }, + + // A.2.2. Special characters cont'd + { @"ˆ", 710 }, + { @"˜", 732 }, + + // A.2.3. Symbols cont'd + { @"Α", 913 }, + { @"Β", 914 }, + { @"Γ", 915 }, + { @"Δ", 916 }, + { @"Ε", 917 }, + { @"Ζ", 918 }, + { @"Η", 919 }, + { @"Θ", 920 }, + { @"Ι", 921 }, + { @"Κ", 922 }, + { @"Λ", 923 }, + { @"Μ", 924 }, + { @"Ν", 925 }, + { @"Ξ", 926 }, + { @"Ο", 927 }, + { @"Π", 928 }, + { @"Ρ", 929 }, + { @"Σ", 931 }, + { @"Τ", 932 }, + { @"Υ", 933 }, + { @"Φ", 934 }, + { @"Χ", 935 }, + { @"Ψ", 936 }, + { @"Ω", 937 }, + { @"α", 945 }, + { @"β", 946 }, + { @"γ", 947 }, + { @"δ", 948 }, + { @"ε", 949 }, + { @"ζ", 950 }, + { @"η", 951 }, + { @"θ", 952 }, + { @"ι", 953 }, + { @"κ", 954 }, + { @"λ", 955 }, + { @"μ", 956 }, + { @"ν", 957 }, + { @"ξ", 958 }, + { @"ο", 959 }, + { @"π", 960 }, + { @"ρ", 961 }, + { @"ς", 962 }, + { @"σ", 963 }, + { @"τ", 964 }, + { @"υ", 965 }, + { @"φ", 966 }, + { @"χ", 967 }, + { @"ψ", 968 }, + { @"ω", 969 }, + { @"ϑ", 977 }, + { @"ϒ", 978 }, + { @"ϖ", 982 }, + + // A.2.2. Special characters cont'd + { @" ", 8194 }, + { @" ", 8195 }, + { @" ", 8201 }, + { @"‌", 8204 }, + { @"‍", 8205 }, + { @"‎", 8206 }, + { @"‏", 8207 }, + { @"–", 8211 }, + { @"—", 8212 }, + { @"‘", 8216 }, + { @"’", 8217 }, + { @"‚", 8218 }, + { @"“", 8220 }, + { @"”", 8221 }, + { @"„", 8222 }, + { @"†", 8224 }, + { @"‡", 8225 }, + // A.2.3. Symbols cont'd + { @"•", 8226 }, + { @"…", 8230 }, + + // A.2.2. Special characters cont'd + { @"‰", 8240 }, + + // A.2.3. Symbols cont'd + { @"′", 8242 }, + { @"″", 8243 }, + + // A.2.2. Special characters cont'd + { @"‹", 8249 }, + { @"›", 8250 }, + + // A.2.3. Symbols cont'd + { @"‾", 8254 }, + { @"⁄", 8260 }, + + // A.2.2. Special characters cont'd + { @"€", 8364 }, + + // A.2.3. Symbols cont'd + { @"ℑ", 8465 }, + { @"℘", 8472 }, + { @"ℜ", 8476 }, + { @"™", 8482 }, + { @"ℵ", 8501 }, + { @"←", 8592 }, + { @"↑", 8593 }, + { @"→", 8594 }, + { @"↓", 8595 }, + { @"↔", 8596 }, + { @"↵", 8629 }, + { @"⇐", 8656 }, + { @"⇑", 8657 }, + { @"⇒", 8658 }, + { @"⇓", 8659 }, + { @"⇔", 8660 }, + { @"∀", 8704 }, + { @"∂", 8706 }, + { @"∃", 8707 }, + { @"∅", 8709 }, + { @"∇", 8711 }, + { @"∈", 8712 }, + { @"∉", 8713 }, + { @"∋", 8715 }, + { @"∏", 8719 }, + { @"∑", 8721 }, + { @"−", 8722 }, + { @"∗", 8727 }, + { @"√", 8730 }, + { @"∝", 8733 }, + { @"∞", 8734 }, + { @"∠", 8736 }, + { @"∧", 8743 }, + { @"∨", 8744 }, + { @"∩", 8745 }, + { @"∪", 8746 }, + { @"∫", 8747 }, + { @"∴", 8756 }, + { @"∼", 8764 }, + { @"≅", 8773 }, + { @"≈", 8776 }, + { @"≠", 8800 }, + { @"≡", 8801 }, + { @"≤", 8804 }, + { @"≥", 8805 }, + { @"⊂", 8834 }, + { @"⊃", 8835 }, + { @"⊄", 8836 }, + { @"⊆", 8838 }, + { @"⊇", 8839 }, + { @"⊕", 8853 }, + { @"⊗", 8855 }, + { @"⊥", 8869 }, + { @"⋅", 8901 }, + { @"⌈", 8968 }, + { @"⌉", 8969 }, + { @"⌊", 8970 }, + { @"⌋", 8971 }, + { @"⟨", 9001 }, + { @"⟩", 9002 }, + { @"◊", 9674 }, + { @"♠", 9824 }, + { @"♣", 9827 }, + { @"♥", 9829 }, + { @"♦", 9830 } +}; + +// Taken from http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_Special_characters +// This is table A.2.2 Special Characters +static HTMLEscapeMap gUnicodeHTMLEscapeMap[] = { + // C0 Controls and Basic Latin + { @""", 34 }, + { @"&", 38 }, + { @"'", 39 }, + { @"<", 60 }, + { @">", 62 }, + + // Latin Extended-A + { @"Œ", 338 }, + { @"œ", 339 }, + { @"Š", 352 }, + { @"š", 353 }, + { @"Ÿ", 376 }, + + // Spacing Modifier Letters + { @"ˆ", 710 }, + { @"˜", 732 }, + + // General Punctuation + { @" ", 8194 }, + { @" ", 8195 }, + { @" ", 8201 }, + { @"‌", 8204 }, + { @"‍", 8205 }, + { @"‎", 8206 }, + { @"‏", 8207 }, + { @"–", 8211 }, + { @"—", 8212 }, + { @"‘", 8216 }, + { @"’", 8217 }, + { @"‚", 8218 }, + { @"“", 8220 }, + { @"”", 8221 }, + { @"„", 8222 }, + { @"†", 8224 }, + { @"‡", 8225 }, + { @"‰", 8240 }, + { @"‹", 8249 }, + { @"›", 8250 }, + { @"€", 8364 }, +}; + + +// Utility function for Bsearching table above +static int EscapeMapCompare(const void *ucharVoid, const void *mapVoid) { + const unichar *uchar = (const unichar*)ucharVoid; + const HTMLEscapeMap *map = (const HTMLEscapeMap*)mapVoid; + int val; + if (*uchar > map->uchar) { + val = 1; + } else if (*uchar < map->uchar) { + val = -1; + } else { + val = 0; + } + return val; +} + +@implementation NSString (GTMNSStringHTMLAdditions) + +- (NSString *)gtm_stringByEscapingHTMLUsingTable:(HTMLEscapeMap*)table + ofSize:(NSUInteger)size + escapingUnicode:(BOOL)escapeUnicode { + NSUInteger length = [self length]; + if (!length) { + return self; + } + + NSMutableString *finalString = [NSMutableString string]; + NSMutableData *data2 = [NSMutableData dataWithCapacity:sizeof(unichar) * length]; + + // this block is common between GTMNSString+HTML and GTMNSString+XML but + // it's so short that it isn't really worth trying to share. + const unichar *buffer = CFStringGetCharactersPtr((CFStringRef)self); + if (!buffer) { + // We want this buffer to be autoreleased. + NSMutableData *data = [NSMutableData dataWithLength:length * sizeof(UniChar)]; + if (!data) { + // COV_NF_START - Memory fail case + _GTMDevLog(@"couldn't alloc buffer"); + return nil; + // COV_NF_END + } + [self getCharacters:[data mutableBytes]]; + buffer = [data bytes]; + } + + if (!buffer || !data2) { + // COV_NF_START + _GTMDevLog(@"Unable to allocate buffer or data2"); + return nil; + // COV_NF_END + } + + unichar *buffer2 = (unichar *)[data2 mutableBytes]; + + NSUInteger buffer2Length = 0; + + for (NSUInteger i = 0; i < length; ++i) { + HTMLEscapeMap *val = bsearch(&buffer[i], table, + size / sizeof(HTMLEscapeMap), + sizeof(HTMLEscapeMap), EscapeMapCompare); + if (val || (escapeUnicode && buffer[i] > 127)) { + if (buffer2Length) { + CFStringAppendCharacters((CFMutableStringRef)finalString, + buffer2, + buffer2Length); + buffer2Length = 0; + } + if (val) { + [finalString appendString:val->escapeSequence]; + } + else { + _GTMDevAssert(escapeUnicode && buffer[i] > 127, @"Illegal Character"); + [finalString appendFormat:@"&#%d;", buffer[i]]; + } + } else { + buffer2[buffer2Length] = buffer[i]; + buffer2Length += 1; + } + } + if (buffer2Length) { + CFStringAppendCharacters((CFMutableStringRef)finalString, + buffer2, + buffer2Length); + } + return finalString; +} + +- (NSString *)gtm_stringByEscapingForHTML { + return [self gtm_stringByEscapingHTMLUsingTable:gUnicodeHTMLEscapeMap + ofSize:sizeof(gUnicodeHTMLEscapeMap) + escapingUnicode:NO]; +} // gtm_stringByEscapingHTML + +- (NSString *)gtm_stringByEscapingForAsciiHTML { + return [self gtm_stringByEscapingHTMLUsingTable:gAsciiHTMLEscapeMap + ofSize:sizeof(gAsciiHTMLEscapeMap) + escapingUnicode:YES]; +} // gtm_stringByEscapingAsciiHTML + +- (NSString *)gtm_stringByUnescapingFromHTML { + NSRange range = NSMakeRange(0, [self length]); + NSRange subrange = [self rangeOfString:@"&" options:NSBackwardsSearch range:range]; + + // if no ampersands, we've got a quick way out + if (subrange.length == 0) return self; + NSMutableString *finalString = [NSMutableString stringWithString:self]; + do { + NSRange semiColonRange = NSMakeRange(subrange.location, NSMaxRange(range) - subrange.location); + semiColonRange = [self rangeOfString:@";" options:0 range:semiColonRange]; + range = NSMakeRange(0, subrange.location); + // if we don't find a semicolon in the range, we don't have a sequence + if (semiColonRange.location == NSNotFound) { + continue; + } + NSRange escapeRange = NSMakeRange(subrange.location, semiColonRange.location - subrange.location + 1); + NSString *escapeString = [self substringWithRange:escapeRange]; + NSUInteger length = [escapeString length]; + // a squence must be longer than 3 (<) and less than 11 (ϑ) + if (length > 3 && length < 11) { + if ([escapeString characterAtIndex:1] == '#') { + unichar char2 = [escapeString characterAtIndex:2]; + if (char2 == 'x' || char2 == 'X') { + // Hex escape squences £ + NSString *hexSequence = [escapeString substringWithRange:NSMakeRange(3, length - 4)]; + NSScanner *scanner = [NSScanner scannerWithString:hexSequence]; + unsigned value; + if ([scanner scanHexInt:&value] && + value < USHRT_MAX && + value > 0 + && [scanner scanLocation] == length - 4) { + unichar uchar = (unichar)value; + NSString *charString = [NSString stringWithCharacters:&uchar length:1]; + [finalString replaceCharactersInRange:escapeRange withString:charString]; + } + + } else { + // Decimal Sequences { + NSString *numberSequence = [escapeString substringWithRange:NSMakeRange(2, length - 3)]; + NSScanner *scanner = [NSScanner scannerWithString:numberSequence]; + int value; + if ([scanner scanInt:&value] && + value < USHRT_MAX && + value > 0 + && [scanner scanLocation] == length - 3) { + unichar uchar = (unichar)value; + NSString *charString = [NSString stringWithCharacters:&uchar length:1]; + [finalString replaceCharactersInRange:escapeRange withString:charString]; + } + } + } else { + // "standard" sequences + for (unsigned i = 0; i < sizeof(gAsciiHTMLEscapeMap) / sizeof(HTMLEscapeMap); ++i) { + if ([escapeString isEqualToString:gAsciiHTMLEscapeMap[i].escapeSequence]) { + [finalString replaceCharactersInRange:escapeRange withString:[NSString stringWithCharacters:&gAsciiHTMLEscapeMap[i].uchar length:1]]; + break; + } + } + } + } + } while ((subrange = [self rangeOfString:@"&" options:NSBackwardsSearch range:range]).length != 0); + return finalString; +} // gtm_stringByUnescapingHTML + + + +@end diff --git a/client/ios/Hackpad/GoogleToolbox/GTMOAuthAuthentication.h b/client/ios/Hackpad/GoogleToolbox/GTMOAuthAuthentication.h new file mode 100644 index 0000000..070b093 --- /dev/null +++ b/client/ios/Hackpad/GoogleToolbox/GTMOAuthAuthentication.h @@ -0,0 +1,235 @@ +/* Copyright (c) 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// This class implements the OAuth 1.0a protocol for creating and signing +// requests. http://oauth.net/core/1.0a/ +// +// Users can rely on +authForInstalledApp for creating a complete authentication +// object. +// +// The user (typically the GTMOAuthSignIn object) can call the methods +// - (void)setKeysForResponseData:(NSData *)data; +// - (void)setKeysForResponseString:(NSString *)str; +// +// to set the parameters following each server interaction, and then can use +// - (BOOL)authorizeRequest:(NSMutableURLRequest *)request +// +// to add the "Authorization: OAuth ..." header to future resource requests. + +#import + +#ifdef GTL_TARGET_NAMESPACE + #import "GTLDefines.h" +#endif + +#import "GTMHTTPFetcher.h" + +#undef _EXTERN +#undef _INITIALIZE_AS +#ifdef GTMOAUTHAUTHENTICATION_DEFINE_GLOBALS +#define _EXTERN +#define _INITIALIZE_AS(x) =x +#else +#define _EXTERN extern +#define _INITIALIZE_AS(x) +#endif + +_EXTERN NSString* const kGTMOAuthSignatureMethodHMAC_SHA1 _INITIALIZE_AS(@"HMAC-SHA1"); + +// +// GTMOAuthSignIn constants, included here for use by clients +// +_EXTERN NSString* const kGTMOAuthErrorDomain _INITIALIZE_AS(@"com.google.GTMOAuth"); + +// notifications for token fetches +_EXTERN NSString* const kGTMOAuthFetchStarted _INITIALIZE_AS(@"kGTMOAuthFetchStarted"); +_EXTERN NSString* const kGTMOAuthFetchStopped _INITIALIZE_AS(@"kGTMOAuthFetchStopped"); + +_EXTERN NSString* const kGTMOAuthFetchTypeKey _INITIALIZE_AS(@"FetchType"); +_EXTERN NSString* const kGTMOAuthFetchTypeRequest _INITIALIZE_AS(@"request"); +_EXTERN NSString* const kGTMOAuthFetchTypeAccess _INITIALIZE_AS(@"access"); +_EXTERN NSString* const kGTMOAuthFetchTypeUserInfo _INITIALIZE_AS(@"userInfo"); + +// Notification that sign-in has completed, and token fetches will begin (useful +// for hiding pre-sign in messages, and showing post-sign in messages +// during the access fetch) +_EXTERN NSString* const kGTMOAuthUserWillSignIn _INITIALIZE_AS(@"kGTMOAuthUserWillSignIn"); +_EXTERN NSString* const kGTMOAuthUserHasSignedIn _INITIALIZE_AS(@"kGTMOAuthUserHasSignedIn"); + +// notification for network loss during html sign-in display +_EXTERN NSString* const kGTMOAuthNetworkLost _INITIALIZE_AS(@"kGTMOAuthNetworkLost"); +_EXTERN NSString* const kGTMOAuthNetworkFound _INITIALIZE_AS(@"kGTMOAuthNetworkFound"); + +#if GTL_OAUTH_SUPPORTS_RSASHA1_SIGNING +_EXTERN NSString* const kGTMOAuthSignatureMethodRSA_SHA1 _INITIALIZE_AS(@"RSA-SHA1"); +#endif + +@interface GTMOAuthAuthentication : NSObject { +@private + // paramValues_ contains the parameters used in requests and responses + NSMutableDictionary *paramValues_; + + NSString *realm_; + NSString *privateKey_; + NSString *timestamp_; // set for testing only + NSString *nonce_; // set for testing only + + // flag indicating if the token in paramValues is a request token or an + // access token + BOOL hasAccessToken_; + + // flag indicating if authorizeRequest: adds a header or parameters + BOOL shouldUseParamsToAuthorize_; + + id userData_; +} + +// OAuth protocol parameters +// +// timestamp (seconds since 1970) and nonce (random number) are generated +// uniquely for each request, except during testing, when they may be set +// explicitly +// +// Note: we're using "assign" for these since they're stored inside +// the dictionary of param values rather than retained by ivars. +@property (nonatomic, copy) NSString *scope; +@property (nonatomic, copy) NSString *displayName; +@property (nonatomic, copy) NSString *hostedDomain; +@property (nonatomic, copy) NSString *domain; +@property (nonatomic, copy) NSString *iconURLString; +@property (nonatomic, copy) NSString *language; +@property (nonatomic, copy) NSString *mobile; +@property (nonatomic, copy) NSString *consumerKey; +@property (nonatomic, copy) NSString *signatureMethod; +@property (nonatomic, copy) NSString *version; +@property (nonatomic, copy) NSString *token; +@property (nonatomic, copy) NSString *callback; +@property (nonatomic, copy) NSString *verifier; +@property (nonatomic, copy) NSString *tokenSecret; +@property (nonatomic, copy) NSString *callbackConfirmed; +@property (nonatomic, copy) NSString *timestamp; +@property (nonatomic, copy) NSString *nonce; + +// other standard non-parameter OAuth protocol properties +@property (nonatomic, copy) NSString *realm; +@property (nonatomic, copy) NSString *privateKey; + +// service identifier, like "Twitter"; not used for authentication or signing +@property (nonatomic, copy) NSString *serviceProvider; + +// user email and verified status; not used for authentication or signing +// +// The verified string can be checked with -boolValue. If the result is false, +// then the email address is listed with the account on the server, but the +// address has not been confirmed as belonging to the owner of the account. +@property (nonatomic, copy) NSString *userEmail; +@property (nonatomic, copy) NSString *userEmailIsVerified; + +// property for using a previously-authorized access token +@property (nonatomic, copy) NSString *accessToken; + +// property indicating if authorization is done with parameters rather than a +// header +@property (nonatomic, assign) BOOL shouldUseParamsToAuthorize; + +// property indicating if this auth has an access token so is suitable for +// authorizing a request. This does not guarantee that the token is valid. +@property (nonatomic, readonly) BOOL canAuthorize; + +// userData is retained for the convenience of the caller +@property (nonatomic, retain) id userData; + + +// Create an authentication object, with hardcoded values for installed apps +// with HMAC-SHA1 as signature method, and "anonymous" as the consumer key and +// consumer secret (private key). ++ (GTMOAuthAuthentication *)authForInstalledApp; + +// Create an authentication object, specifying the consumer key and +// private key (both anonymous for installed apps) and the signature method +// ("HMAC-SHA1" for installed apps). +// +// For signature method "RSA-SHA1", a proper consumer key and private key +// may be supplied (and the GTL_OAUTH_SUPPORTS_RSASHA1_SIGNING compiler +// conditional must be set.) +- (id)initWithSignatureMethod:(NSString *)signatureMethod + consumerKey:(NSString *)consumerKey + privateKey:(NSString *)privateKey; + +// clear out any authentication values, prepare for a new request fetch +- (void)reset; + +// authorization entry point for GTL library +- (BOOL)authorizeRequest:(NSMutableURLRequest *)request; + +// add OAuth headers +// +// any non-OAuth parameters (such as scope) will be included in the signature +// but added as a URL parameter, not in the Auth header +- (void)addRequestTokenHeaderToRequest:(NSMutableURLRequest *)request; +- (void)addAuthorizeTokenHeaderToRequest:(NSMutableURLRequest *)request; +- (void)addAccessTokenHeaderToRequest:(NSMutableURLRequest *)request; +- (void)addResourceTokenHeaderToRequest:(NSMutableURLRequest *)request; + +// add OAuth URL params, as an alternative to adding headers +- (void)addRequestTokenParamsToRequest:(NSMutableURLRequest *)request; +- (void)addAuthorizeTokenParamsToRequest:(NSMutableURLRequest *)request; +- (void)addAccessTokenParamsToRequest:(NSMutableURLRequest *)request; +- (void)addResourceTokenParamsToRequest:(NSMutableURLRequest *)request; + +// parse and set token and token secret from response data +- (void)setKeysForResponseData:(NSData *)data; +- (void)setKeysForResponseString:(NSString *)str; + +// persistent token string for keychain storage +// +// we'll use the format "oauth_token=foo&oauth_token_secret=bar" so we can +// easily alter what portions of the auth data are stored +- (NSString *)persistenceResponseString; +- (void)setKeysForPersistenceResponseString:(NSString *)str; + +// method for distinguishing between the OAuth token being a request token and +// an access token; use the canAuthorize property to determine if the +// auth object has an access token +- (BOOL)hasAccessToken; +- (void)setHasAccessToken:(BOOL)flag; + +// methods for unit testing ++ (NSString *)normalizeQueryString:(NSString *)str; + +// +// utilities +// + ++ (NSString *)encodedOAuthParameterForString:(NSString *)str; ++ (NSString *)unencodedOAuthParameterForString:(NSString *)str; + ++ (NSDictionary *)dictionaryWithResponseData:(NSData *)data; ++ (NSDictionary *)dictionaryWithResponseString:(NSString *)responseStr; + ++ (NSString *)scopeWithStrings:(NSString *)str, ...; + ++ (NSString *)stringWithBase64ForData:(NSData *)data; + ++ (NSString *)HMACSHA1HashForConsumerSecret:(NSString *)consumerSecret + tokenSecret:(NSString *)tokenSecret + body:(NSString *)body; + +#if GTL_OAUTH_SUPPORTS_RSASHA1_SIGNING ++ (NSString *)RSASHA1HashForString:(NSString *)source + privateKeyPEMString:(NSString *)key; +#endif + +@end diff --git a/client/ios/Hackpad/GoogleToolbox/GTMOAuthAuthentication.m b/client/ios/Hackpad/GoogleToolbox/GTMOAuthAuthentication.m new file mode 100644 index 0000000..9f9a597 --- /dev/null +++ b/client/ios/Hackpad/GoogleToolbox/GTMOAuthAuthentication.m @@ -0,0 +1,1251 @@ +/* Copyright (c) 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// HMAC digest +#import + +// RSA SHA-1 signing +#if GTL_OAUTH_SUPPORTS_RSASHA1_SIGNING +#include +#include +#include +#endif + +#define GTMOAUTHAUTHENTICATION_DEFINE_GLOBALS 1 +#import "GTMOAuthAuthentication.h" + +// standard OAuth keys +static NSString *const kOAuthConsumerKey = @"oauth_consumer_key"; +static NSString *const kOAuthTokenKey = @"oauth_token"; +static NSString *const kOAuthCallbackKey = @"oauth_callback"; +static NSString *const kOAuthCallbackConfirmedKey = @"oauth_callback_confirmed"; +static NSString *const kOAuthTokenSecretKey = @"oauth_token_secret"; +static NSString *const kOAuthSignatureMethodKey = @"oauth_signature_method"; +static NSString *const kOAuthSignatureKey = @"oauth_signature"; +static NSString *const kOAuthTimestampKey = @"oauth_timestamp"; +static NSString *const kOAuthNonceKey = @"oauth_nonce"; +static NSString *const kOAuthVerifierKey = @"oauth_verifier"; +static NSString *const kOAuthVersionKey = @"oauth_version"; + +// GetRequestToken extensions +static NSString *const kOAuthDisplayNameKey = @"xoauth_displayname"; +static NSString *const kOAuthScopeKey = @"scope"; + +// AuthorizeToken extensions +static NSString *const kOAuthDomainKey = @"domain"; +static NSString *const kOAuthHostedDomainKey = @"hd"; +static NSString *const kOAuthIconURLKey = @"iconUrl"; +static NSString *const kOAuthLanguageKey = @"hl"; +static NSString *const kOAuthMobileKey = @"btmpl"; + +// additional persistent keys +static NSString *const kServiceProviderKey = @"serviceProvider"; +static NSString *const kUserEmailKey = @"email"; +static NSString *const kUserEmailIsVerifiedKey = @"isVerified"; + +@interface GTMOAuthAuthentication (PrivateMethods) + +- (void)addAuthorizationHeaderToRequest:(NSMutableURLRequest *)request + forKeys:(NSArray *)keys; +- (void)addParamsForKeys:(NSArray *)keys + toRequest:(NSMutableURLRequest *)request; + ++ (NSString *)paramStringForParams:(NSArray *)params + joiner:(NSString *)joiner + shouldQuote:(BOOL)shouldQuote + shouldSort:(BOOL)shouldSort; + +- (NSString *)normalizedRequestURLStringForRequest:(NSURLRequest *)request; + +- (NSString *)signatureForParams:(NSMutableArray *)params + request:(NSURLRequest *)request; + +@end + +// OAuthParameter is a local class that exists just to make it easier to +// sort descriptor pairs by name and encoded value +@interface OAuthParameter : NSObject { +@private + NSString *name_; + NSString *value_; +} + +@property (nonatomic, copy) NSString *name; +@property (nonatomic, copy) NSString *value; + ++ (OAuthParameter *)parameterWithName:(NSString *)name + value:(NSString *)value; + ++ (NSArray *)sortDescriptors; +@end + +@implementation GTMOAuthAuthentication + +@synthesize realm = realm_; +@synthesize privateKey = privateKey_; +@synthesize shouldUseParamsToAuthorize = shouldUseParamsToAuthorize_; +@synthesize userData = userData_; + +// create an authentication object, with hardcoded values for installed apps +// of HMAC-SHA1 as signature method, and "anonymous" as the consumer key and +// consumer secret (private key) ++ (GTMOAuthAuthentication *)authForInstalledApp { + // installed apps have fixed parameters + return [[[self alloc] initWithSignatureMethod:@"HMAC-SHA1" + consumerKey:@"anonymous" + privateKey:@"anonymous"] autorelease]; +} + +// create an authentication object, specifying the consumer key and +// private key (both "anonymous" for installed apps) and the signature method +// ("HMAC-SHA1" for installed apps) +// +// for signature method "RSA-SHA1", a proper consumer key and private key +// must be supplied +- (id)initWithSignatureMethod:(NSString *)signatureMethod + consumerKey:(NSString *)consumerKey + privateKey:(NSString *)privateKey { + + self = [super init]; + if (self != nil) { + paramValues_ = [[NSMutableDictionary alloc] init]; + + [self setConsumerKey:consumerKey]; + [self setSignatureMethod:signatureMethod]; + [self setPrivateKey:privateKey]; + + [self setVersion:@"1.0"]; + } + return self; +} + +- (void)dealloc { + [paramValues_ release]; + [realm_ release]; + [privateKey_ release]; + [timestamp_ release]; + [nonce_ release]; + [userData_ release]; + [super dealloc]; +} + +#pragma mark - + +- (NSMutableArray *)paramsForKeys:(NSArray *)keys + request:(NSURLRequest *)request { + // this is the magic routine that collects the parameters for the specified + // keys, and signs them + NSMutableArray *params = [NSMutableArray array]; + + for (NSString *key in keys) { + NSString *value = [paramValues_ objectForKey:key]; + if ([value length] > 0) { + [params addObject:[OAuthParameter parameterWithName:key + value:value]]; + } + } + + // nonce and timestamp are generated on-the-fly by the getters + if ([keys containsObject:kOAuthNonceKey]) { + NSString *nonce = [self nonce]; + [params addObject:[OAuthParameter parameterWithName:kOAuthNonceKey + value:nonce]]; + } + + if ([keys containsObject:kOAuthTimestampKey]) { + NSString *timestamp = [self timestamp]; + [params addObject:[OAuthParameter parameterWithName:kOAuthTimestampKey + value:timestamp]]; + } + + // finally, compute the signature, if requested; the params + // must be complete for this + if ([keys containsObject:kOAuthSignatureKey]) { + NSString *signature = [self signatureForParams:params + request:request]; + [params addObject:[OAuthParameter parameterWithName:kOAuthSignatureKey + value:signature]]; + } + + return params; +} + ++ (void)addQueryString:(NSString *)query + toParams:(NSMutableArray *)array { + // make param objects from the query parameters, and add them + // to the supplied array + + // look for a query like foo=cat&bar=dog + if ([query length] > 0) { + // the standard test cases insist that + in the query string + // be encoded as " " - http://wiki.oauth.net/TestCases + query = [query stringByReplacingOccurrencesOfString:@"+" + withString:@" "]; + + // separate and step through the query parameter assignments + NSArray *items = [query componentsSeparatedByString:@"&"]; + + for (NSString *item in items) { + NSString *name = nil; + NSString *value = @""; + + NSRange equalsRange = [item rangeOfString:@"="]; + if (equalsRange.location != NSNotFound) { + // the parameter has at least one '=' + name = [item substringToIndex:equalsRange.location]; + + if (equalsRange.location + 1 < [item length]) { + // there are characters after the '=' + value = [item substringFromIndex:(equalsRange.location + 1)]; + + // remove percent-escapes from the parameter value; they'll be + // added back by OAuthParameter + value = [self unencodedOAuthParameterForString:value]; + } else { + // no characters after the '=' + } + } else { + // the parameter has no '=' + name = item; + } + + // remove percent-escapes from the parameter name; they'll be + // added back by OAuthParameter + name = [self unencodedOAuthParameterForString:name]; + + OAuthParameter *param = [OAuthParameter parameterWithName:name + value:value]; + [array addObject:param]; + } + } +} + ++ (void)addQueryFromRequest:(NSURLRequest *)request + toParams:(NSMutableArray *)array { + // get the query string from the request + NSString *query = [[request URL] query]; + [self addQueryString:query toParams:array]; +} + ++ (void)addBodyFromRequest:(NSURLRequest *)request + toParams:(NSMutableArray *)array { + // add non-GET form parameters to the array of param objects + NSString *method = [request HTTPMethod]; + if (method != nil && ![method isEqual:@"GET"]) { + NSString *type = [request valueForHTTPHeaderField:@"Content-Type"]; + if ([type hasPrefix:@"application/x-www-form-urlencoded"]) { + NSData *data = [request HTTPBody]; + if ([data length] > 0) { + NSString *str = [[[NSString alloc] initWithData:data + encoding:NSUTF8StringEncoding] autorelease]; + if ([str length] > 0) { + [[self class] addQueryString:str toParams:array]; + } + } + } + } +} + +- (NSString *)signatureForParams:(NSMutableArray *)params + request:(NSURLRequest *)request { + // construct signature base string per + // http://oauth.net/core/1.0a/#signing_process + NSString *requestURLStr = [self normalizedRequestURLStringForRequest:request]; + NSString *method = [[request HTTPMethod] uppercaseString]; + if ([method length] == 0) { + method = @"GET"; + } + + // the signature params exclude the signature + NSMutableArray *signatureParams = [NSMutableArray arrayWithArray:params]; + + // add request query parameters + [[self class] addQueryFromRequest:request toParams:signatureParams]; + + // add parameters from the POST body, if any + [[self class] addBodyFromRequest:request toParams:signatureParams]; + + NSString *paramStr = [[self class] paramStringForParams:signatureParams + joiner:@"&" + shouldQuote:NO + shouldSort:YES]; + + // the base string includes the method, normalized request URL, and params + NSString *requestURLStrEnc = [[self class] encodedOAuthParameterForString:requestURLStr]; + NSString *paramStrEnc = [[self class] encodedOAuthParameterForString:paramStr]; + + NSString *sigBaseString = [NSString stringWithFormat:@"%@&%@&%@", + method, requestURLStrEnc, paramStrEnc]; + + NSString *privateKey = [self privateKey]; + NSString *signatureMethod = [self signatureMethod]; + NSString *signature = nil; + +#if GTL_DEBUG_OAUTH_SIGNING + NSLog(@"signing request: %@\n", request); + NSLog(@"signing params: %@\n", params); +#endif + + if ([signatureMethod isEqual:kGTMOAuthSignatureMethodHMAC_SHA1]) { + NSString *tokenSecret = [self tokenSecret]; + signature = [[self class] HMACSHA1HashForConsumerSecret:privateKey + tokenSecret:tokenSecret + body:sigBaseString]; +#if GTL_DEBUG_OAUTH_SIGNING + NSLog(@"hashing: %@&%@", + privateKey ? privateKey : @"", + tokenSecret ? tokenSecret : @""); + NSLog(@"base string: %@", sigBaseString); + NSLog(@"signature: %@", signature); +#endif + } + +#if GTL_OAUTH_SUPPORTS_RSASHA1_SIGNING + else if ([signatureMethod isEqual:kGTMOAuthSignatureMethodRSA_SHA1]) { + signature = [[self class] RSASHA1HashForString:sigBaseString + privateKeyPEMString:privateKey]; + } +#endif + + return signature; +} + ++ (NSString *)paramStringForParams:(NSArray *)params + joiner:(NSString *)joiner + shouldQuote:(BOOL)shouldQuote + shouldSort:(BOOL)shouldSort { + // create a string by joining the supplied param objects + + if (shouldSort) { + // sort params by name and value + NSArray *descs = [OAuthParameter sortDescriptors]; + params = [params sortedArrayUsingDescriptors:descs]; + } + + // make an array of the encoded name=value items + NSArray *encodedArray; + if (shouldQuote) { + encodedArray = [params valueForKey:@"quotedEncodedParam"]; + } else { + encodedArray = [params valueForKey:@"encodedParam"]; + } + + // join the items + NSString *result = [encodedArray componentsJoinedByString:joiner]; + return result; +} + +- (NSString *)normalizedRequestURLStringForRequest:(NSURLRequest *)request { + // http://oauth.net/core/1.0a/#anchor13 + + NSURL *url = [[request URL] absoluteURL]; + + NSString *scheme = [[url scheme] lowercaseString]; + NSString *host = [[url host] lowercaseString]; + int port = [[url port] intValue]; + + // NSURL's path method has an unfortunate side-effect of unescaping the path, + // but CFURLCopyPath does not + CFStringRef cfPath = CFURLCopyPath((CFURLRef)url); + NSString *path = [NSMakeCollectable(cfPath) autorelease]; + + // include only non-standard ports for http or https + NSString *portStr; + if (port == 0 + || ([scheme isEqual:@"http"] && port == 80) + || ([scheme isEqual:@"https"] && port == 443)) { + portStr = @""; + } else { + portStr = [NSString stringWithFormat:@":%u", port]; + } + + if ([path length] == 0) { + path = @"/"; + } + + NSString *result = [NSString stringWithFormat:@"%@://%@%@%@", + scheme, host, portStr, path]; + return result; +} + ++ (NSArray *)tokenRequestKeys { + // keys for obtaining a request token, http://oauth.net/core/1.0a/#auth_step1 + NSArray *keys = [NSArray arrayWithObjects: + kOAuthConsumerKey, + kOAuthSignatureMethodKey, + kOAuthSignatureKey, + kOAuthTimestampKey, + kOAuthNonceKey, + kOAuthVersionKey, + kOAuthCallbackKey, + // extensions + kOAuthDisplayNameKey, + kOAuthScopeKey, + nil]; + return keys; +} + ++ (NSArray *)tokenAuthorizeKeys { + // keys for opening the authorize page, http://oauth.net/core/1.0a/#auth_step2 + NSArray *keys = [NSArray arrayWithObjects: + kOAuthTokenKey, + // extensions + kOAuthDomainKey, + kOAuthHostedDomainKey, + kOAuthLanguageKey, + kOAuthMobileKey, + kOAuthScopeKey, + nil]; + return keys; +} + ++ (NSArray *)tokenAccessKeys { + // keys for obtaining an access token, http://oauth.net/core/1.0a/#auth_step3 + NSArray *keys = [NSArray arrayWithObjects: + kOAuthConsumerKey, + kOAuthTokenKey, + kOAuthSignatureMethodKey, + kOAuthSignatureKey, + kOAuthTimestampKey, + kOAuthNonceKey, + kOAuthVersionKey, + kOAuthVerifierKey, nil]; + return keys; +} + ++ (NSArray *)tokenResourceKeys { + // keys for accessing a protected resource, + // http://oauth.net/core/1.0a/#anchor12 + NSArray *keys = [NSArray arrayWithObjects: + kOAuthConsumerKey, + kOAuthTokenKey, + kOAuthSignatureMethodKey, + kOAuthSignatureKey, + kOAuthTimestampKey, + kOAuthNonceKey, + kOAuthVersionKey, nil]; + return keys; +} + +#pragma mark - + +- (void)setKeysForResponseDictionary:(NSDictionary *)dict { + NSString *token = [dict objectForKey:kOAuthTokenKey]; + if (token) { + [self setToken:token]; + } + + NSString *secret = [dict objectForKey:kOAuthTokenSecretKey]; + if (secret) { + [self setTokenSecret:secret]; + } + + NSString *callbackConfirmed = [dict objectForKey:kOAuthCallbackConfirmedKey]; + if (callbackConfirmed) { + [self setCallbackConfirmed:callbackConfirmed]; + } + + NSString *verifier = [dict objectForKey:kOAuthVerifierKey]; + if (verifier) { + [self setVerifier:verifier]; + } + + NSString *provider = [dict objectForKey:kServiceProviderKey]; + if (provider) { + [self setServiceProvider:provider]; + } + + NSString *email = [dict objectForKey:kUserEmailKey]; + if (email) { + [self setUserEmail:email]; + } + + NSString *verified = [dict objectForKey:kUserEmailIsVerifiedKey]; + if (verified) { + [self setUserEmailIsVerified:verified]; + } +} + +- (void)setKeysForResponseData:(NSData *)data { + NSDictionary *dict = [[self class] dictionaryWithResponseData:data]; + [self setKeysForResponseDictionary:dict]; +} + +- (void)setKeysForResponseString:(NSString *)str { + NSDictionary *dict = [[self class] dictionaryWithResponseString:str]; + [self setKeysForResponseDictionary:dict]; +} + +#pragma mark - + +// +// Methods for adding OAuth parameters either to queries or as a request header +// + +- (void)addRequestTokenHeaderToRequest:(NSMutableURLRequest *)request { + // add request token params to the request's header + NSArray *keys = [[self class] tokenRequestKeys]; + [self addAuthorizationHeaderToRequest:request + forKeys:keys]; +} + +- (void)addRequestTokenParamsToRequest:(NSMutableURLRequest *)request { + // add request token params to the request URL (not to the header) + NSArray *keys = [[self class] tokenRequestKeys]; + [self addParamsForKeys:keys toRequest:request]; +} + +- (void)addAuthorizeTokenHeaderToRequest:(NSMutableURLRequest *)request { + // add authorize token params to the request's header + NSArray *keys = [[self class] tokenAuthorizeKeys]; + [self addAuthorizationHeaderToRequest:request + forKeys:keys]; +} + +- (void)addAuthorizeTokenParamsToRequest:(NSMutableURLRequest *)request { + // add authorize token params to the request URL (not to the header) + NSArray *keys = [[self class] tokenAuthorizeKeys]; + [self addParamsForKeys:keys toRequest:request]; +} + +- (void)addAccessTokenHeaderToRequest:(NSMutableURLRequest *)request { + // add access token params to the request's header + NSArray *keys = [[self class] tokenAccessKeys]; + [self addAuthorizationHeaderToRequest:request + forKeys:keys]; +} + +- (void)addAccessTokenParamsToRequest:(NSMutableURLRequest *)request { + // add access token params to the request URL (not to the header) + NSArray *keys = [[self class] tokenAccessKeys]; + [self addParamsForKeys:keys toRequest:request]; +} + +- (void)addResourceTokenHeaderToRequest:(NSMutableURLRequest *)request { + // add resource access token params to the request's header + NSArray *keys = [[self class] tokenResourceKeys]; + [self addAuthorizationHeaderToRequest:request + forKeys:keys]; +} + +- (void)addResourceTokenParamsToRequest:(NSMutableURLRequest *)request { + // add resource access token params to the request URL (not to the header) + NSArray *keys = [[self class] tokenResourceKeys]; + [self addParamsForKeys:keys toRequest:request]; +} + +// +// underlying methods for constructing query parameters or request headers +// + +- (void)addParams:(NSArray *)params toRequest:(NSMutableURLRequest *)request { + NSString *paramStr = [[self class] paramStringForParams:params + joiner:@"&" + shouldQuote:NO + shouldSort:NO]; + NSURL *oldURL = [request URL]; + NSString *query = [oldURL query]; + if ([query length] > 0) { + query = [query stringByAppendingFormat:@"&%@", paramStr]; + } else { + query = paramStr; + } + + NSString *portStr = @""; + NSString *oldPort = [[oldURL port] stringValue]; + if ([oldPort length] > 0) { + portStr = [@":" stringByAppendingString:oldPort]; + } + + NSString *qMark = [query length] > 0 ? @"?" : @""; + NSString *newURLStr = [NSString stringWithFormat:@"%@://%@%@%@%@%@", + [oldURL scheme], [oldURL host], portStr, + [oldURL path], qMark, query]; + + [request setURL:[NSURL URLWithString:newURLStr]]; +} + +- (void)addParamsForKeys:(NSArray *)keys toRequest:(NSMutableURLRequest *)request { + // For the specified keys, add the keys and values to the request URL. + + NSMutableArray *params = [self paramsForKeys:keys request:request]; + [self addParams:params toRequest:request]; +} + +- (void)addAuthorizationHeaderToRequest:(NSMutableURLRequest *)request + forKeys:(NSArray *)keys { + // make all the parameters, including a signature for all + NSMutableArray *params = [self paramsForKeys:keys request:request]; + + // split the params into "oauth_" params which go into the Auth header + // and others which get added to the query + NSMutableArray *oauthParams = [NSMutableArray array]; + NSMutableArray *extendedParams = [NSMutableArray array]; + + for (OAuthParameter *param in params) { + NSString *name = [param name]; + BOOL hasPrefix = [name hasPrefix:@"oauth_"]; + if (hasPrefix) { + [oauthParams addObject:param]; + } else { + [extendedParams addObject:param]; + } + } + + NSString *paramStr = [[self class] paramStringForParams:oauthParams + joiner:@", " + shouldQuote:YES + shouldSort:NO]; + + // include the realm string, if any, in the auth header + // http://oauth.net/core/1.0a/#auth_header + NSString *realmParam = @""; + NSString *realm = [self realm]; + if ([realm length] > 0) { + NSString *encodedVal = [[self class] encodedOAuthParameterForString:realm]; + realmParam = [NSString stringWithFormat:@"realm=\"%@\", ", encodedVal]; + } + + // set the parameters for "oauth_" keys and the realm + // in the authorization header + NSString *authHdr = [NSString stringWithFormat:@"OAuth %@%@", + realmParam, paramStr]; + [request setValue:authHdr forHTTPHeaderField:@"Authorization"]; + + // add any other params as URL query parameters + if ([extendedParams count] > 0) { + [self addParams:extendedParams toRequest:request]; + } + +#if GTL_DEBUG_OAUTH_SIGNING + NSLog(@"adding auth header: %@", authHdr); + NSLog(@"final request: %@", request); +#endif +} + +// general entry point for GTL library +- (BOOL)authorizeRequest:(NSMutableURLRequest *)request { + NSString *token = [self token]; + if ([token length] == 0) { + return NO; + } else { + if ([self shouldUseParamsToAuthorize]) { + [self addResourceTokenParamsToRequest:request]; + } else { + [self addResourceTokenHeaderToRequest:request]; + } + return YES; + } +} + +- (BOOL)canAuthorize { + // this method's is just a higher-level version of hasAccessToken + return [self hasAccessToken]; +} + +#pragma mark GTMFetcherAuthorizationProtocol Methods + +// Implementation of GTMFetcherAuthorizationProtocol methods + +- (void)authorizeRequest:(NSMutableURLRequest *)request + delegate:(id)delegate + didFinishSelector:(SEL)sel { + // Authorization entry point with callback for OAuth 2 + NSError *error = nil; + if (![self authorizeRequest:request]) { + // failed + error = [NSError errorWithDomain:kGTMOAuthErrorDomain + code:-1 + userInfo:nil]; + } + + if (delegate && sel) { + NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]; + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig]; + [invocation setSelector:sel]; + [invocation setTarget:delegate]; + [invocation setArgument:&self atIndex:2]; + [invocation setArgument:&request atIndex:3]; + [invocation setArgument:&error atIndex:4]; + [invocation invoke]; + } +} + +- (void)stopAuthorization { + // nothing to do, since OAuth 1 authorization is synchronous +} + +- (void)stopAuthorizationForRequest:(NSURLRequest *)request { + // nothing to do, since OAuth 1 authorization is synchronous +} + +- (BOOL)isAuthorizingRequest:(NSURLRequest *)request { + // OAuth 1 auth is synchronous, so authorizations are never pending + return NO; +} + +- (BOOL)isAuthorizedRequest:(NSURLRequest *)request { + if ([self shouldUseParamsToAuthorize]) { + // look for query parameter authorization + NSString *query = [[request URL] query]; + NSDictionary *dict = [[self class] dictionaryWithResponseString:query]; + NSString *token = [dict valueForKey:kOAuthTokenKey]; + return ([token length] > 0); + } else { + // look for header authorization + NSString *authStr = [request valueForHTTPHeaderField:@"Authorization"]; + return ([authStr length] > 0); + } +} + +#pragma mark Persistence Response Strings + +- (void)setKeysForPersistenceResponseString:(NSString *)str { + // all persistence keys map directly to keys in paramValues_ + [self setKeysForResponseString:str]; +} + +// this returns a "response string" that can be passed later to +// setKeysForResponseString: to reuse an old access token in a new auth object +- (NSString *)persistenceResponseString { + // make an array of OAuthParameters for the actual parameters we're + // persisting + NSArray *persistenceKeys = [NSArray arrayWithObjects: + kOAuthTokenKey, + kOAuthTokenSecretKey, + kServiceProviderKey, + kUserEmailKey, + kUserEmailIsVerifiedKey, + nil]; + + NSMutableArray *params = [self paramsForKeys:persistenceKeys request:nil]; + + NSString *responseStr = [[self class] paramStringForParams:params + joiner:@"&" + shouldQuote:NO + shouldSort:NO]; + return responseStr; +} + +- (void)reset { + [self setHasAccessToken:NO]; + [self setToken:nil]; + [self setTokenSecret:nil]; + [self setUserEmail:nil]; + [self setUserEmailIsVerified:nil]; +} + +#pragma mark Accessors + +- (NSString *)scope { + return [paramValues_ objectForKey:kOAuthScopeKey]; +} + +- (void)setScope:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthScopeKey]; +} + +- (NSString *)displayName { + return [paramValues_ objectForKey:kOAuthDisplayNameKey]; +} + +- (void)setDisplayName:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthDisplayNameKey]; +} + +- (NSString *)hostedDomain { + return [paramValues_ objectForKey:kOAuthHostedDomainKey]; +} + +- (void)setHostedDomain:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthHostedDomainKey]; +} + +- (NSString *)domain { + return [paramValues_ objectForKey:kOAuthDomainKey]; +} + +- (void)setDomain:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthDomainKey]; +} + +- (NSString *)iconURLString { + return [paramValues_ objectForKey:kOAuthIconURLKey]; +} + +- (void)setIconURLString:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthIconURLKey]; +} + +- (NSString *)language { + return [paramValues_ objectForKey:kOAuthLanguageKey]; +} + +- (void)setLanguage:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthLanguageKey]; +} + +- (NSString *)mobile { + return [paramValues_ objectForKey:kOAuthMobileKey]; +} + +- (void)setMobile:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthMobileKey]; +} + +- (NSString *)signatureMethod { + return [paramValues_ objectForKey:kOAuthSignatureMethodKey]; +} + +- (void)setSignatureMethod:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthSignatureMethodKey]; +} + +- (NSString *)consumerKey { + return [paramValues_ objectForKey:kOAuthConsumerKey]; +} + +- (void)setConsumerKey:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthConsumerKey]; +} + +- (NSString *)token { + return [paramValues_ objectForKey:kOAuthTokenKey]; +} + +- (void)setToken:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthTokenKey]; +} + +- (NSString *)callback { + return [paramValues_ objectForKey:kOAuthCallbackKey]; +} + + +- (void)setCallback:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthCallbackKey]; +} + +- (NSString *)verifier { + return [paramValues_ objectForKey:kOAuthVerifierKey]; +} + +- (void)setVerifier:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthVerifierKey]; +} + +- (NSString *)serviceProvider { + return [paramValues_ objectForKey:kServiceProviderKey]; +} + +- (void)setServiceProvider:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kServiceProviderKey]; +} + +- (NSString *)userEmail { + return [paramValues_ objectForKey:kUserEmailKey]; +} + +- (void)setUserEmail:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kUserEmailKey]; +} + +- (NSString *)userEmailIsVerified { + return [paramValues_ objectForKey:kUserEmailIsVerifiedKey]; +} + +- (void)setUserEmailIsVerified:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kUserEmailIsVerifiedKey]; +} + +- (NSString *)tokenSecret { + return [paramValues_ objectForKey:kOAuthTokenSecretKey]; +} + +- (void)setTokenSecret:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthTokenSecretKey]; +} + +- (NSString *)callbackConfirmed { + return [paramValues_ objectForKey:kOAuthCallbackConfirmedKey]; +} + +- (void)setCallbackConfirmed:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthCallbackConfirmedKey]; +} + +- (NSString *)version { + return [paramValues_ objectForKey:kOAuthVersionKey]; +} + +- (void)setVersion:(NSString *)str { + [paramValues_ setValue:[[str copy] autorelease] + forKey:kOAuthVersionKey]; +} + +- (NSString *)timestamp { + + if (timestamp_) return timestamp_; // for testing only + + NSTimeInterval timeInterval = [[NSDate date] timeIntervalSince1970]; + unsigned long long timestampVal = (unsigned long long) timeInterval; + NSString *timestamp = [NSString stringWithFormat:@"%qu", timestampVal]; + return timestamp; +} + +- (void)setTimestamp:(NSString *)str { + // set a fixed timestamp, for testing only + [timestamp_ autorelease]; + timestamp_ = [str copy]; +} + +- (NSString *)nonce { + + if (nonce_) return nonce_; // for testing only + + // make a random 64-bit number + unsigned long long nonceVal = ((unsigned long long) arc4random()) << 32 + | (unsigned long long) arc4random(); + + NSString *nonce = [NSString stringWithFormat:@"%qu", nonceVal]; + return nonce; +} + +- (void)setNonce:(NSString *)str { + // set a fixed nonce, for testing only + [nonce_ autorelease]; + nonce_ = [str copy]; +} + +// to avoid the ambiguity between request and access flavors of tokens, +// we'll provide accessors solely for access tokens +- (BOOL)hasAccessToken { + return hasAccessToken_ && ([[self token] length] > 0); +} + +- (void)setHasAccessToken:(BOOL)flag { + hasAccessToken_ = flag; +} + +- (NSString *)accessToken { + if (hasAccessToken_) { + return [self token]; + } else { + return nil; + } +} + +- (void)setAccessToken:(NSString *)str { + [self setToken:str]; + [self setHasAccessToken:YES]; +} + +#pragma mark Utility Routines + ++ (NSString *)encodedOAuthParameterForString:(NSString *)str { + // http://oauth.net/core/1.0a/#encoding_parameters + + CFStringRef originalString = (CFStringRef) str; + + CFStringRef leaveUnescaped = CFSTR("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "-._~"); + CFStringRef forceEscaped = CFSTR("%!$&'()*+,/:;=?@"); + + CFStringRef escapedStr = NULL; + if (str) { + escapedStr = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, + originalString, + leaveUnescaped, + forceEscaped, + kCFStringEncodingUTF8); + [(id)CFMakeCollectable(escapedStr) autorelease]; + } + + return (NSString *)escapedStr; +} + ++ (NSString *)unencodedOAuthParameterForString:(NSString *)str { + NSString *plainStr = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + return plainStr; +} + ++ (NSDictionary *)dictionaryWithResponseString:(NSString *)responseStr { + // build a dictionary from a response string of the form + // "foo=cat&bar=dog". Missing or empty values are considered + // empty strings; keys and values are percent-decoded. + if (responseStr == nil) return nil; + + NSMutableDictionary *responseDict = [NSMutableDictionary dictionary]; + + NSArray *items = [responseStr componentsSeparatedByString:@"&"]; + for (NSString *item in items) { + NSScanner *scanner = [NSScanner scannerWithString:item]; + NSString *key; + + [scanner setCharactersToBeSkipped:nil]; + if ([scanner scanUpToString:@"=" intoString:&key]) { + // if there's an "=", then scan the value, too, if any + NSString *value = @""; + if ([scanner scanString:@"=" intoString:nil]) { + // scan the rest of the string + [scanner scanUpToString:@"&" intoString:&value]; + } + NSString *plainKey = [[self class] unencodedOAuthParameterForString:key]; + NSString *plainValue = [[self class] unencodedOAuthParameterForString:value]; + + [responseDict setObject:plainValue + forKey:plainKey]; + } + } + return responseDict; +} + ++ (NSDictionary *)dictionaryWithResponseData:(NSData *)data { + NSString *responseStr = [[[NSString alloc] initWithData:data + encoding:NSUTF8StringEncoding] autorelease]; + NSDictionary *dict = [self dictionaryWithResponseString:responseStr]; + return dict; +} + ++ (NSString *)scopeWithStrings:(NSString *)str, ... { + // concatenate the strings, joined by a single space + NSString *result = @""; + NSString *joiner = @""; + if (str) { + va_list argList; + va_start(argList, str); + while (str) { + result = [result stringByAppendingFormat:@"%@%@", joiner, str]; + joiner = @" "; + str = va_arg(argList, id); + } + va_end(argList); + } + return result; +} + +#pragma mark Signing Methods + ++ (NSString *)HMACSHA1HashForConsumerSecret:(NSString *)consumerSecret + tokenSecret:(NSString *)tokenSecret + body:(NSString *)body { + NSString *encodedConsumerSecret = [self encodedOAuthParameterForString:consumerSecret]; + NSString *encodedTokenSecret = [self encodedOAuthParameterForString:tokenSecret]; + + NSString *key = [NSString stringWithFormat:@"%@&%@", + encodedConsumerSecret ? encodedConsumerSecret : @"", + encodedTokenSecret ? encodedTokenSecret : @""]; + + NSMutableData *sigData = [NSMutableData dataWithLength:CC_SHA1_DIGEST_LENGTH]; + + CCHmac(kCCHmacAlgSHA1, + [key UTF8String], [key length], + [body UTF8String], [body length], + [sigData mutableBytes]); + + NSString *signature = [self stringWithBase64ForData:sigData]; + return signature; +} + +#if GTL_OAUTH_SUPPORTS_RSASHA1_SIGNING ++ (NSString *)RSASHA1HashForString:(NSString *)source + privateKeyPEMString:(NSString *)key { + if (source == nil || key == nil) return nil; + + OpenSSL_add_all_algorithms(); + // add EVP_cleanup + + NSString *signature = nil; + + // make a SHA-1 digest of the source string + const char* sourceChars = [source UTF8String]; + + unsigned char digest[SHA_DIGEST_LENGTH]; + SHA1((const unsigned char *)sourceChars, strlen(sourceChars), digest); + + // get an RSA from the private key PEM, and use it to sign the digest + const char* keyChars = [key UTF8String]; + BIO* keyBio = BIO_new_mem_buf((char *) keyChars, -1); // -1 = use strlen() + + + if (keyBio != NULL) { + // BIO_set_flags(keyBio, BIO_FLAGS_BASE64_NO_NL); + RSA *rsa_key = NULL; + + rsa_key = PEM_read_bio_RSAPrivateKey(keyBio, NULL, NULL, NULL); + if (rsa_key != NULL) { + + unsigned int sigLen = 0; + unsigned char *sigBuff = malloc(RSA_size(rsa_key)); + + int result = RSA_sign(NID_sha1, digest, (unsigned int) sizeof(digest), + sigBuff, &sigLen, rsa_key); + + if (result != 0) { + NSData *sigData = [NSData dataWithBytes:sigBuff length:sigLen]; + signature = [self stringWithBase64ForData:sigData]; + } + + free(sigBuff); + + RSA_free(rsa_key); + } + BIO_free(keyBio); + } + + return signature; +} +#endif // GTL_OAUTH_SUPPORTS_RSASHA1_SIGNING + ++ (NSString *)stringWithBase64ForData:(NSData *)data { + // Cyrus Najmabadi elegent little encoder from + // http://www.cocoadev.com/index.pl?BaseSixtyFour + if (data == nil) return nil; + + const uint8_t* input = [data bytes]; + NSUInteger length = [data length]; + + NSUInteger bufferSize = ((length + 2) / 3) * 4; + NSMutableData* buffer = [NSMutableData dataWithLength:bufferSize]; + + uint8_t* output = [buffer mutableBytes]; + + static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + for (NSUInteger i = 0; i < length; i += 3) { + NSInteger value = 0; + for (NSUInteger j = i; j < (i + 3); j++) { + value <<= 8; + + if (j < length) { + value |= (0xFF & input[j]); + } + } + + NSInteger idx = (i / 3) * 4; + output[idx + 0] = table[(value >> 18) & 0x3F]; + output[idx + 1] = table[(value >> 12) & 0x3F]; + output[idx + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '='; + output[idx + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '='; + } + + NSString *result = [[[NSString alloc] initWithData:buffer + encoding:NSASCIIStringEncoding] autorelease]; + return result; +} + +#pragma mark Unit Test Entry Points + ++ (NSString *)normalizeQueryString:(NSString *)str { + // unit testing method + + // convert the string of parameters to sortable param objects + NSMutableArray *params = [NSMutableArray array]; + [self addQueryString:str toParams:params]; + + // sort and join the param objects + NSString *paramStr = [self paramStringForParams:params + joiner:@"&" + shouldQuote:NO + shouldSort:YES]; + return paramStr; +} + +@end + +// This class represents key-value pairs so they can be sorted by both +// name and encoded value +@implementation OAuthParameter + +@synthesize name = name_; +@synthesize value = value_; + ++ (OAuthParameter *)parameterWithName:(NSString *)name + value:(NSString *)value { + OAuthParameter *obj = [[[self alloc] init] autorelease]; + [obj setName:name]; + [obj setValue:value]; + return obj; +} + +- (void)dealloc { + [name_ release]; + [value_ release]; + [super dealloc]; +} + +- (NSString *)encodedValue { + NSString *value = [self value]; + NSString *result = [GTMOAuthAuthentication encodedOAuthParameterForString:value]; + return result; +} + +- (NSString *)encodedName { + NSString *name = [self name]; + NSString *result = [GTMOAuthAuthentication encodedOAuthParameterForString:name]; + return result; +} + +- (NSString *)encodedParam { + NSString *str = [NSString stringWithFormat:@"%@=%@", + [self encodedName], [self encodedValue]]; + return str; +} + +- (NSString *)quotedEncodedParam { + NSString *str = [NSString stringWithFormat:@"%@=\"%@\"", + [self encodedName], [self encodedValue]]; + return str; +} + +- (NSString *)description { + return [self encodedParam]; +} + ++ (NSArray *)sortDescriptors { + // sort by name and value + SEL sel = @selector(compare:); + + NSSortDescriptor *desc1, *desc2; + desc1 = [[[NSSortDescriptor alloc] initWithKey:@"name" + ascending:YES + selector:sel] autorelease]; + desc2 = [[[NSSortDescriptor alloc] initWithKey:@"encodedValue" + ascending:YES + selector:sel] autorelease]; + + NSArray *sortDescriptors = [NSArray arrayWithObjects:desc1, desc2, nil]; + return sortDescriptors; +} + +@end diff --git a/client/ios/Hackpad/HPWhiteNavigationController.h b/client/ios/Hackpad/HPWhiteNavigationController.h new file mode 100644 index 0000000..10124ac --- /dev/null +++ b/client/ios/Hackpad/HPWhiteNavigationController.h @@ -0,0 +1,13 @@ +// +// HPWhiteNavigationController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPColoredAppearanceContainer.h" + +@interface HPWhiteNavigationController : UINavigationController + +@end diff --git a/client/ios/Hackpad/HPWhiteNavigationController.m b/client/ios/Hackpad/HPWhiteNavigationController.m new file mode 100644 index 0000000..8d48db4 --- /dev/null +++ b/client/ios/Hackpad/HPWhiteNavigationController.m @@ -0,0 +1,48 @@ +// +// HPWhiteNavigationController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPWhiteNavigationController.h" + +#import + +@implementation HPWhiteNavigationController + ++ (UIImage *)coloredBackgroundImage +{ + return [UIImage imageNamed:@"darkgreenbg"]; +} + ++ (UIColor *)coloredBarTintColor +{ + return HP_SYSTEM_MAJOR_VERSION() >= 7 ? [UIColor whiteColor] : [UIColor hp_darkGreenColor]; +} + ++ (UIColor *)coloredTintColor +{ + return HP_SYSTEM_MAJOR_VERSION() >= 7 ? [UIColor hp_darkGreenColor] : [UIColor whiteColor]; +} + ++ (UIColor *)navigationTitleColor +{ + return HP_SYSTEM_MAJOR_VERSION() >= 7 ? [UIColor hp_reallyDarkGrayColor] : [UIColor whiteColor]; +} + +#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleDefault; +} +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Translucent bars -> black search bars on iOS 7? + self.navigationBar.translucent = NO; +} +#endif + +@end diff --git a/client/ios/Hackpad/Hackpad.clr b/client/ios/Hackpad/Hackpad.clr new file mode 100644 index 0000000..e5e6cf6 Binary files /dev/null and b/client/ios/Hackpad/Hackpad.clr differ diff --git a/client/ios/Hackpad/Hackpad.xcodeproj/project.pbxproj b/client/ios/Hackpad/Hackpad.xcodeproj/project.pbxproj new file mode 100644 index 0000000..00b7bde --- /dev/null +++ b/client/ios/Hackpad/Hackpad.xcodeproj/project.pbxproj @@ -0,0 +1,3370 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 160129F817D9638C002B42AA /* NSManagedObjectContext+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 160129F717D9638C002B42AA /* NSManagedObjectContext+HackpadAdditions.m */; }; + 1605D85317D44A060057CE4A /* HPRollbackDeletedObjectsMergePolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1605D85217D44A060057CE4A /* HPRollbackDeletedObjectsMergePolicy.m */; }; + 16060B51172AED9C00451986 /* UIView+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 16060B50172AED9C00451986 /* UIView+HackpadAdditions.m */; }; + 16085C1B16D57D2300C81DB4 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 16085C1A16D57D2300C81DB4 /* Settings.bundle */; }; + 160C17C81861212600CC68DA /* UIFont+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 160C17C71861212600CC68DA /* UIFont+HackpadAdditions.m */; }; + 160CA7A417CFE54500DA1FA5 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 160CA7A217CFE54500DA1FA5 /* InfoPlist.strings */; }; + 160CA7B017CFE6BD00DA1FA5 /* HPPadScopeTableViewDataSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 160CA7AF17CFE6BD00DA1FA5 /* HPPadScopeTableViewDataSourceTests.m */; }; + 160CA7D817CFE9F200DA1FA5 /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16326931170CE773004C67EB /* Accounts.framework */; }; + 160CA7D917CFE9F800DA1FA5 /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16F54606175948DD00BD7754 /* AddressBook.framework */; }; + 160CA7DA17CFE9F800DA1FA5 /* AddressBookUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16F54604175947ED00BD7754 /* AddressBookUI.framework */; }; + 160CA7DD17CFEA0800DA1FA5 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C327FDE915E57F9B002819C7 /* UIKit.framework */; }; + 160CA7DE17CFEA5300DA1FA5 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16326932170CE773004C67EB /* AdSupport.framework */; }; + 160CA7DF17CFEA5300DA1FA5 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1627C50316B7547C00AA129F /* CoreData.framework */; }; + 160CA7E017CFEA5300DA1FA5 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C327FDED15E57F9B002819C7 /* CoreGraphics.framework */; }; + 160CA7E117CFEA5300DA1FA5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C327FDEB15E57F9B002819C7 /* Foundation.framework */; }; + 160CA7E217CFEA5300DA1FA5 /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CAF40317444DF30099310F /* libsqlite3.dylib */; }; + 160CA7E317CFEA5300DA1FA5 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CAF3FF17444CFE0099310F /* libz.dylib */; }; + 160CA7E417CFEA5300DA1FA5 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16BEFCE116CEC01800419A2D /* Security.framework */; }; + 160CA7E517CFEA5300DA1FA5 /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16326933170CE773004C67EB /* Social.framework */; }; + 160CA7E617CFEA5300DA1FA5 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1663EFD216E6707A00356387 /* SystemConfiguration.framework */; }; + 160CA7E717CFEA6C00DA1FA5 /* FacebookSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CAF3F917444C2E0099310F /* FacebookSDK.framework */; }; + 160CA7EE17CFEAD400DA1FA5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C327FDEB15E57F9B002819C7 /* Foundation.framework */; }; + 160CA7F317CFEAD400DA1FA5 /* HackpadTestingKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 160CA7F217CFEAD400DA1FA5 /* HackpadTestingKit.h */; }; + 160CA7FB17CFEBB100DA1FA5 /* libHackpadTestingKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 160CA7ED17CFEAD400DA1FA5 /* libHackpadTestingKit.a */; }; + 160CA7FC17CFEBB700DA1FA5 /* libHackpadTestingKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 160CA7ED17CFEAD400DA1FA5 /* libHackpadTestingKit.a */; }; + 160CA80517CFECD800DA1FA5 /* libOCMock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 160CA7FE17CFECA100DA1FA5 /* libOCMock.a */; }; + 160CA80617CFECE300DA1FA5 /* libOCMock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 160CA7FE17CFECA100DA1FA5 /* libOCMock.a */; }; + 160CA80917CFEFE300DA1FA5 /* HPCoreDataStackTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 16CB5EAD17C5568500511849 /* HPCoreDataStackTestCase.m */; }; + 160CA80F17CFF1DD00DA1FA5 /* libHackpadKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CB5E5917C551A000511849 /* libHackpadKit.a */; }; + 160CA85917CFFA6600DA1FA5 /* HPMockTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 160CA85817CFFA6600DA1FA5 /* HPMockTestCase.m */; }; + 160D04A3174A98F200C98325 /* SignIn_iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 160D04A1174A98F200C98325 /* SignIn_iPad.storyboard */; }; + 160D04B2174AED1100C98325 /* SignIn_iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 160D04B0174AED1100C98325 /* SignIn_iPhone.storyboard */; }; + 160E576517666F4100C063D8 /* HPUserInfoCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 160E576417666F4100C063D8 /* HPUserInfoCell.m */; }; + 16233846170B865200E2252C /* HPSignInController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16233845170B865100E2252C /* HPSignInController.m */; }; + 1627C50416B7547C00AA129F /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1627C50316B7547C00AA129F /* CoreData.framework */; }; + 16326934170CE773004C67EB /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16326931170CE773004C67EB /* Accounts.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; + 16326935170CE773004C67EB /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16326932170CE773004C67EB /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; + 16326936170CE773004C67EB /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16326933170CE773004C67EB /* Social.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; + 163489C318AC064E004972CB /* Hackpad12.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 163489C218AC064E004972CB /* Hackpad12.sqlite */; }; + 163623E116FA50ED00367769 /* HPPadScopeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 163623E016FA50ED00367769 /* HPPadScopeViewController.m */; }; + 1636245E17025B9C00367769 /* HPDrawerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1636245C17025B9B00367769 /* HPDrawerController.m */; }; + 163968D71834617D00DC5A4F /* MessageUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 163968D61834617D00DC5A4F /* MessageUI.framework */; }; + 164045891858D60D00D02B59 /* PadCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 164045881858D60D00D02B59 /* PadCell.xib */; }; + 1642A52F18359F8B00FADDFE /* HPGroupedToolbar.m in Sources */ = {isa = PBXBuildFile; fileRef = 1642A52E18359F8B00FADDFE /* HPGroupedToolbar.m */; }; + 1645D5C117D9203900D74527 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16AE68C017D91BA50031898F /* SenTestingKit.framework */; }; + 164B50681893569F005DCFDE /* email-button-white.png in Resources */ = {isa = PBXBuildFile; fileRef = 164B505D1893569F005DCFDE /* email-button-white.png */; }; + 164B50691893569F005DCFDE /* email-button-white@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 164B505E1893569F005DCFDE /* email-button-white@2x.png */; }; + 164B506F1893600D005DCFDE /* user-green@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 164B506D1893600D005DCFDE /* user-green@2x.png */; }; + 164B50701893600D005DCFDE /* user-green.png in Resources */ = {isa = PBXBuildFile; fileRef = 164B506E1893600D005DCFDE /* user-green.png */; }; + 164B507318971370005DCFDE /* facebook44@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 164B507118971370005DCFDE /* facebook44@2x.png */; }; + 164B507418971370005DCFDE /* facebook44.png in Resources */ = {isa = PBXBuildFile; fileRef = 164B507218971370005DCFDE /* facebook44.png */; }; + 164B5077189714A2005DCFDE /* google44@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 164B5075189714A2005DCFDE /* google44@2x.png */; }; + 164B5078189714A2005DCFDE /* google44.png in Resources */ = {isa = PBXBuildFile; fileRef = 164B5076189714A2005DCFDE /* google44.png */; }; + 164E44211870F960002657E2 /* ProximaNova-Bold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 164E44151870F934002657E2 /* ProximaNova-Bold.otf */; }; + 164E44221870F960002657E2 /* ProximaNova-Light.otf in Resources */ = {isa = PBXBuildFile; fileRef = 164E44161870F934002657E2 /* ProximaNova-Light.otf */; }; + 164E44231870F960002657E2 /* ProximaNova-LightIt.otf in Resources */ = {isa = PBXBuildFile; fileRef = 164E44171870F934002657E2 /* ProximaNova-LightIt.otf */; }; + 164E44241870F960002657E2 /* ProximaNova-Sbold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 164E44181870F934002657E2 /* ProximaNova-Sbold.otf */; }; + 164E44251870F960002657E2 /* ProximaNova-SboldIt.otf in Resources */ = {isa = PBXBuildFile; fileRef = 164E44191870F934002657E2 /* ProximaNova-SboldIt.otf */; }; + 164E44261870F960002657E2 /* ProximaNova-Xbold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 164E441A1870F934002657E2 /* ProximaNova-Xbold.otf */; }; + 1654C70218A96BA4007238FD /* libFlurry_4.3.2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1654C70018A96B20007238FD /* libFlurry_4.3.2.a */; }; + 165AA16C187F2FC800C7C80F /* HPCancelFreeSearchDisplayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 165AA16B187F2FC800C7C80F /* HPCancelFreeSearchDisplayController.m */; }; + 165AA16F187F360900C7C80F /* HPEmptySearchViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 165AA16E187F360900C7C80F /* HPEmptySearchViewController.m */; }; + 165AA172187F6E7A00C7C80F /* UIViewController+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 165AA171187F6E7A00C7C80F /* UIViewController+HackpadAdditions.m */; }; + 165AA1751880A29600C7C80F /* HPPopoverLayoutFixTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 165AA1741880A29600C7C80F /* HPPopoverLayoutFixTableView.m */; }; + 165C59CD17B32CCB001006D4 /* bluebg.png in Resources */ = {isa = PBXBuildFile; fileRef = 165C59CC17B32CCB001006D4 /* bluebg.png */; }; + 165C59CF17B331F5001006D4 /* graybg.png in Resources */ = {isa = PBXBuildFile; fileRef = 165C59CE17B331F5001006D4 /* graybg.png */; }; + 165C59D517B34782001006D4 /* HPBlueNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 165C59D417B34782001006D4 /* HPBlueNavigationController.m */; }; + 165C59D817B347A4001006D4 /* HPGrayNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 165C59D717B347A4001006D4 /* HPGrayNavigationController.m */; }; + 1663EFD316E6707A00356387 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1663EFD216E6707A00356387 /* SystemConfiguration.framework */; }; + 16650D0416A093BB00452A1F /* checked.png in Resources */ = {isa = PBXBuildFile; fileRef = 16650D0316A093BB00452A1F /* checked.png */; }; + 16650D0816A0977F00452A1F /* HPPadCollectionCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 16650D0716A0977F00452A1F /* HPPadCollectionCell.m */; }; + 16650D0A16A0C96C00452A1F /* unchecked.png in Resources */ = {isa = PBXBuildFile; fileRef = 16650D0916A0C96C00452A1F /* unchecked.png */; }; + 16650D0F16A0DF6600452A1F /* HPPadSharingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16650D0E16A0DF6600452A1F /* HPPadSharingViewController.m */; }; + 1667ACC217D0609100F777EE /* UIDevice+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1667ACC117D0609100F777EE /* UIDevice+HackpadAdditions.m */; }; + 166C112217F25FFC0004DF6E /* HPPadSearch.m in Sources */ = {isa = PBXBuildFile; fileRef = 166C112117F25FFC0004DF6E /* HPPadSearch.m */; }; + 166E7D131837061300C82013 /* HPPadAutocompleteTableViewDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 16A370A318284E2400731484 /* HPPadAutocompleteTableViewDataSource.m */; }; + 166E7D16183AC44D00C82013 /* HPWhiteNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 166E7D15183AC44D00C82013 /* HPWhiteNavigationController.m */; }; + 166E7D1A183ACA5D00C82013 /* whitebg.png in Resources */ = {isa = PBXBuildFile; fileRef = 166E7D17183ACA5D00C82013 /* whitebg.png */; }; + 166E7D1B183ACA5D00C82013 /* whiteback.png in Resources */ = {isa = PBXBuildFile; fileRef = 166E7D18183ACA5D00C82013 /* whiteback.png */; }; + 166E7D1C183ACA5D00C82013 /* whiteback@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 166E7D19183ACA5D00C82013 /* whiteback@2x.png */; }; + 166EF56718A444E800561F07 /* Hackpad10.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 166EF56618A444E800561F07 /* Hackpad10.sqlite */; }; + 166EF57A18A466A900561F07 /* Hackpad9.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 166EF57918A466A900561F07 /* Hackpad9.sqlite */; }; + 166EF57E18A4A8BC00561F07 /* HPMigrationTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 166EF57D18A4A8BC00561F07 /* HPMigrationTestCase.m */; }; + 166EF58618A4B36000561F07 /* HPPadEditor.m in Sources */ = {isa = PBXBuildFile; fileRef = 166EF58518A4B36000561F07 /* HPPadEditor.m */; }; + 166EF58A18A4C5C200561F07 /* Hackpad11.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 166EF58918A4C5C200561F07 /* Hackpad11.sqlite */; }; + 1673C04417986DCD005FED08 /* GetSnippetHeight.js in Resources */ = {isa = PBXBuildFile; fileRef = 1673C04317986DCD005FED08 /* GetSnippetHeight.js */; }; + 167DEF7217710FB300BE090C /* Hackpad.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 167DEF6F17710FB300BE090C /* Hackpad.xcdatamodeld */; }; + 167DEF7C17723DA100BE090C /* HPPadCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 167DEF7B17723DA100BE090C /* HPPadCell.m */; }; + 167E1E5117D91CB000AA30D9 /* libTestFlight.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CAF3FC17444C5E0099310F /* libTestFlight.a */; }; + 168786731821B4E30095428D /* NSURLResponse+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 168786721821B4E30095428D /* NSURLResponse+HackpadAdditions.m */; }; + 168786761821C67F0095428D /* HPPadWebController.m in Sources */ = {isa = PBXBuildFile; fileRef = 160428891811EA8C00D8D41C /* HPPadWebController.m */; }; + 168786771821C7240095428D /* UIWebView+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 16F62D6616C1CBB80034A6BD /* UIWebView+HackpadAdditions.m */; }; + 168786781821C7920095428D /* WebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 16B5ECE017A73D42004E3815 /* WebViewJavascriptBridge.m */; }; + 168786821822D8E10095428D /* HPImageUpload+Impl.m in Sources */ = {isa = PBXBuildFile; fileRef = 168786811822D8E10095428D /* HPImageUpload+Impl.m */; }; + 168905F1182D6D81002D95F2 /* HPInvitationTableViewDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 168905F0182D6D81002D95F2 /* HPInvitationTableViewDataSource.m */; }; + 168A196817EFE6A900A990F4 /* HPPadTableViewDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 168A196717EFE6A900A990F4 /* HPPadTableViewDataSource.m */; }; + 168A196B17EFED5B00A990F4 /* HPActionSheetBlockDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 168A196A17EFED5B00A990F4 /* HPActionSheetBlockDelegate.m */; }; + 168A196E17EFF40700A990F4 /* HPPadSearchTableViewDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 168A196D17EFF40700A990F4 /* HPPadSearchTableViewDataSource.m */; }; + 168DD542189857D0003E01BF /* dot44@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 168DD540189857D0003E01BF /* dot44@2x.png */; }; + 168DD543189857D0003E01BF /* dot44.png in Resources */ = {isa = PBXBuildFile; fileRef = 168DD541189857D0003E01BF /* dot44.png */; }; + 16919C82187C6F6D00EDF5AE /* HPSpaceCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 16919C81187C6F6D00EDF5AE /* HPSpaceCell.m */; }; + 1691CC981899686000CF121C /* x-red.png in Resources */ = {isa = PBXBuildFile; fileRef = 1691CC941899686000CF121C /* x-red.png */; }; + 1691CC991899686000CF121C /* check-green.png in Resources */ = {isa = PBXBuildFile; fileRef = 1691CC951899686000CF121C /* check-green.png */; }; + 1691CC9A1899686000CF121C /* check-green@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1691CC961899686000CF121C /* check-green@2x.png */; }; + 1691CC9B1899686000CF121C /* x-red@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1691CC971899686000CF121C /* x-red@2x.png */; }; + 1699F70A183C0F36001DAC1D /* darkgreenbg.png in Resources */ = {isa = PBXBuildFile; fileRef = 1699F709183C0F36001DAC1D /* darkgreenbg.png */; }; + 1699F70C183C10C8001DAC1D /* clearback@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1699F70B183C10C8001DAC1D /* clearback@2x.png */; }; + 1699F710183C114E001DAC1D /* clearbacklandscape.png in Resources */ = {isa = PBXBuildFile; fileRef = 1699F70D183C114E001DAC1D /* clearbacklandscape.png */; }; + 1699F711183C114E001DAC1D /* clearbacklandscape@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1699F70E183C114E001DAC1D /* clearbacklandscape@2x.png */; }; + 1699F712183C114E001DAC1D /* clearback.png in Resources */ = {isa = PBXBuildFile; fileRef = 1699F70F183C114E001DAC1D /* clearback.png */; }; + 169B0F56169E635800B65E11 /* HPPadCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 169B0F55169E635800B65E11 /* HPPadCollectionViewController.m */; }; + 169DD8651832D77200D0D528 /* groupbg.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8631832D77200D0D528 /* groupbg.png */; }; + 169DD8661832D77200D0D528 /* editorbg.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8641832D77200D0D528 /* editorbg.png */; }; + 169DD8951832F27200D0D528 /* check.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8671832F27100D0D528 /* check.png */; }; + 169DD8961832F27200D0D528 /* check@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8681832F27100D0D528 /* check@2x.png */; }; + 169DD8971832F27200D0D528 /* number.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8691832F27100D0D528 /* number.png */; }; + 169DD8981832F27200D0D528 /* number@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD86A1832F27100D0D528 /* number@2x.png */; }; + 169DD8991832F27200D0D528 /* bullet.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD86B1832F27100D0D528 /* bullet.png */; }; + 169DD89A1832F27200D0D528 /* bullet@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD86C1832F27100D0D528 /* bullet@2x.png */; }; + 169DD89B1832F27200D0D528 /* paragraph.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD86D1832F27100D0D528 /* paragraph.png */; }; + 169DD89C1832F27200D0D528 /* paragraph@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD86E1832F27100D0D528 /* paragraph@2x.png */; }; + 169DD89D1832F27200D0D528 /* outdent.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD86F1832F27100D0D528 /* outdent.png */; }; + 169DD89E1832F27200D0D528 /* outdent@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8701832F27100D0D528 /* outdent@2x.png */; }; + 169DD89F1832F27200D0D528 /* indent.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8711832F27100D0D528 /* indent.png */; }; + 169DD8A01832F27200D0D528 /* indent@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8721832F27100D0D528 /* indent@2x.png */; }; + 169DD8A11832F27200D0D528 /* tag.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8731832F27100D0D528 /* tag.png */; }; + 169DD8A21832F27200D0D528 /* tag@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8741832F27100D0D528 /* tag@2x.png */; }; + 169DD8A31832F27200D0D528 /* mention.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8751832F27100D0D528 /* mention.png */; }; + 169DD8A41832F27200D0D528 /* mention@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8761832F27100D0D528 /* mention@2x.png */; }; + 169DD8A51832F27200D0D528 /* dropbox.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8771832F27100D0D528 /* dropbox.png */; }; + 169DD8A61832F27200D0D528 /* dropbox@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8781832F27100D0D528 /* dropbox@2x.png */; }; + 169DD8A71832F27200D0D528 /* link.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8791832F27100D0D528 /* link.png */; }; + 169DD8A81832F27200D0D528 /* link@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD87A1832F27100D0D528 /* link@2x.png */; }; + 169DD8A91832F27200D0D528 /* table.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD87B1832F27100D0D528 /* table.png */; }; + 169DD8AA1832F27200D0D528 /* table@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD87C1832F27100D0D528 /* table@2x.png */; }; + 169DD8AB1832F27200D0D528 /* photo.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD87D1832F27100D0D528 /* photo.png */; }; + 169DD8AC1832F27200D0D528 /* photo@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD87E1832F27100D0D528 /* photo@2x.png */; }; + 169DD8AD1832F27200D0D528 /* header3.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD87F1832F27100D0D528 /* header3.png */; }; + 169DD8AE1832F27200D0D528 /* header3@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8801832F27100D0D528 /* header3@2x.png */; }; + 169DD8AF1832F27200D0D528 /* header2.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8811832F27100D0D528 /* header2.png */; }; + 169DD8B01832F27200D0D528 /* header2@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8821832F27100D0D528 /* header2@2x.png */; }; + 169DD8B11832F27200D0D528 /* header1.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8831832F27100D0D528 /* header1.png */; }; + 169DD8B21832F27200D0D528 /* header1@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8841832F27100D0D528 /* header1@2x.png */; }; + 169DD8B31832F27200D0D528 /* strikethrough.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8851832F27100D0D528 /* strikethrough.png */; }; + 169DD8B41832F27200D0D528 /* strikethrough@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8861832F27100D0D528 /* strikethrough@2x.png */; }; + 169DD8B51832F27200D0D528 /* underline.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8871832F27100D0D528 /* underline.png */; }; + 169DD8B61832F27200D0D528 /* underline@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8881832F27200D0D528 /* underline@2x.png */; }; + 169DD8B71832F27200D0D528 /* italic.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8891832F27200D0D528 /* italic.png */; }; + 169DD8B81832F27200D0D528 /* italic@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD88A1832F27200D0D528 /* italic@2x.png */; }; + 169DD8B91832F27200D0D528 /* bold.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD88B1832F27200D0D528 /* bold.png */; }; + 169DD8BA1832F27200D0D528 /* bold@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD88C1832F27200D0D528 /* bold@2x.png */; }; + 169DD8BB1832F27200D0D528 /* close.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD88D1832F27200D0D528 /* close.png */; }; + 169DD8BC1832F27200D0D528 /* close@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD88E1832F27200D0D528 /* close@2x.png */; }; + 169DD8BD1832F27200D0D528 /* insert.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD88F1832F27200D0D528 /* insert.png */; }; + 169DD8BE1832F27200D0D528 /* insert@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8901832F27200D0D528 /* insert@2x.png */; }; + 169DD8BF1832F27200D0D528 /* comment.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8911832F27200D0D528 /* comment.png */; }; + 169DD8C01832F27200D0D528 /* comment@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8921832F27200D0D528 /* comment@2x.png */; }; + 169DD8C11832F27200D0D528 /* textformat.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8931832F27200D0D528 /* textformat.png */; }; + 169DD8C21832F27200D0D528 /* textformat@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 169DD8941832F27200D0D528 /* textformat@2x.png */; }; + 16A55F4517601260001ED006 /* nophoto.png in Resources */ = {isa = PBXBuildFile; fileRef = 16A55F4417601260001ED006 /* nophoto.png */; }; + 16A55F74176140D9001ED006 /* online.png in Resources */ = {isa = PBXBuildFile; fileRef = 16A55F72176140D9001ED006 /* online.png */; }; + 16A55F75176140D9001ED006 /* online@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16A55F73176140D9001ED006 /* online@2x.png */; }; + 16A760BE18ADB19100821DB3 /* Hackpad13.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 16A760BD18ADB19100821DB3 /* Hackpad13.sqlite */; }; + 16A760C218AE9E9800821DB3 /* HPImageUpload.m in Sources */ = {isa = PBXBuildFile; fileRef = 16A760C118AE9E9800821DB3 /* HPImageUpload.m */; }; + 16A760C618AEA2F900821DB3 /* Hackpad14.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 16A760C518AEA2F900821DB3 /* Hackpad14.sqlite */; }; + 16A760C818AEA35000821DB3 /* HPMigrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 16A760C718AEA35000821DB3 /* HPMigrationTests.m */; }; + 16A760CA18AEB82F00821DB3 /* separator@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16A760C918AEB82F00821DB3 /* separator@2x.png */; }; + 16A760CC18AEB9DD00821DB3 /* separator.png in Resources */ = {isa = PBXBuildFile; fileRef = 16A760CB18AEB9DD00821DB3 /* separator.png */; }; + 16A760D018AEEEF600821DB3 /* HPSpace.m in Sources */ = {isa = PBXBuildFile; fileRef = 16A760CF18AEEEF600821DB3 /* HPSpace.m */; }; + 16A760D218AEF37100821DB3 /* Hackpad15.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 16A760D118AEF37100821DB3 /* Hackpad15.sqlite */; }; + 16A8417D17D1AC35007BEE69 /* NSError+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 16A8417C17D1AC35007BEE69 /* NSError+HackpadAdditions.m */; }; + 16A890EE186E33C10014EF45 /* HPAPITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 16A890ED186E33C10014EF45 /* HPAPITests.m */; }; + 16AA8C58171778CE00155C8F /* HPGoogleSignInViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16AA8C57171778CE00155C8F /* HPGoogleSignInViewController.m */; }; + 16AE68C317D91BD00031898F /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16AE68C017D91BA50031898F /* SenTestingKit.framework */; }; + 16AE8FE517BD7A1A0065020C /* HPPadSplitViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16AE8FE417BD7A1A0065020C /* HPPadSplitViewController.m */; }; + 16B0AF2C189DD3080072A725 /* HPSynchronizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 16B0AF2B189DD3080072A725 /* HPSynchronizer.m */; }; + 16B0AF2F189E07E80072A725 /* HPPadSynchronizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 16B0AF2E189E07E80072A725 /* HPPadSynchronizer.m */; }; + 16B0AF73189F820F0072A725 /* HPCollectionSynchronizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 16B0AF72189F820F0072A725 /* HPCollectionSynchronizer.m */; }; + 16B0AF76189F87E50072A725 /* HPSpaceSynchronizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 16B0AF75189F87E50072A725 /* HPSpaceSynchronizer.m */; }; + 16B2D39B16E7ED56006C20E6 /* HPBrowserViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16B2D39A16E7ED56006C20E6 /* HPBrowserViewController.m */; }; + 16B4AB5216F8FAD5007D0FAE /* HPSearchResultsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16B4AB5116F8FAD5007D0FAE /* HPSearchResultsController.m */; }; + 16B5ECE117A73D42004E3815 /* WebViewJavascriptBridge.js.txt in Resources */ = {isa = PBXBuildFile; fileRef = 16B5ECDF17A73D42004E3815 /* WebViewJavascriptBridge.js.txt */; }; + 16B7EED218932E4A00E8C574 /* pencilLove@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16B7EEC418932E4A00E8C574 /* pencilLove@2x.png */; }; + 16B7EED318932E4A00E8C574 /* pencilLove.png in Resources */ = {isa = PBXBuildFile; fileRef = 16B7EEC518932E4A00E8C574 /* pencilLove.png */; }; + 16B7EED818932E4A00E8C574 /* email-green.png in Resources */ = {isa = PBXBuildFile; fileRef = 16B7EECA18932E4A00E8C574 /* email-green.png */; }; + 16B7EED918932E4A00E8C574 /* email-green@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16B7EECB18932E4A00E8C574 /* email-green@2x.png */; }; + 16B7EEDA18932E4A00E8C574 /* password-green@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16B7EECC18932E4A00E8C574 /* password-green@2x.png */; }; + 16B7EEDB18932E4A00E8C574 /* password-green.png in Resources */ = {isa = PBXBuildFile; fileRef = 16B7EECD18932E4A00E8C574 /* password-green.png */; }; + 16BBF41E17F202BE00EFAE26 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CE464E2117E1D22D005227A9 /* libxml2.dylib */; }; + 16BE542B18ABEEB5003EBBCD /* HPPad.m in Sources */ = {isa = PBXBuildFile; fileRef = 16BE542A18ABEEB5003EBBCD /* HPPad.m */; }; + 16BEFCE216CEC01900419A2D /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16BEFCE116CEC01800419A2D /* Security.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; + 16CAF3FA17444C2E0099310F /* FacebookSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CAF3F917444C2E0099310F /* FacebookSDK.framework */; }; + 16CAF3FE17444C5E0099310F /* libTestFlight.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CAF3FC17444C5E0099310F /* libTestFlight.a */; }; + 16CAF40017444CFE0099310F /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CAF3FF17444CFE0099310F /* libz.dylib */; }; + 16CAF40417444DF30099310F /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CAF40317444DF30099310F /* libsqlite3.dylib */; settings = {ATTRIBUTES = (Weak, ); }; }; + 16CB5E5A17C551A000511849 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C327FDEB15E57F9B002819C7 /* Foundation.framework */; }; + 16CB5E6A17C551A000511849 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C327FDE915E57F9B002819C7 /* UIKit.framework */; }; + 16CB5E6B17C551A000511849 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C327FDEB15E57F9B002819C7 /* Foundation.framework */; }; + 16CB5E7417C551A100511849 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 16CB5E7217C551A100511849 /* InfoPlist.strings */; }; + 16CB5E8217C5520A00511849 /* libHackpadKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CB5E5917C551A000511849 /* libHackpadKit.a */; }; + 16CB5E8317C5521600511849 /* KeychainItemWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 16085C1516D53FE200C81DB4 /* KeychainItemWrapper.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + 16CB5E8417C5521600511849 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 1663EFD516E670C600356387 /* Reachability.m */; }; + 16CB5E8517C5524B00511849 /* GTMHTTPFetcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 16F4C1EA16B22520005CA606 /* GTMHTTPFetcher.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + 16CB5E8617C5524B00511849 /* GTMNSString+HTML.m in Sources */ = {isa = PBXBuildFile; fileRef = 16085C0B16D460BA00C81DB4 /* GTMNSString+HTML.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + 16CB5E8717C5524B00511849 /* GTMOAuthAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = 16F4C1ED16B22520005CA606 /* GTMOAuthAuthentication.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + 16CB5E8817C5524B00511849 /* RNCachingURLProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 160845BB16E9261D00D04253 /* RNCachingURLProtocol.m */; }; + 16CB5E8917C5529400511849 /* Hackpad.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 167DEF6F17710FB300BE090C /* Hackpad.xcdatamodeld */; }; + 16CB5E8B17C552B300511849 /* HPCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 164A86D617680324006C7174 /* HPCollection.m */; }; + 16CB5E8D17C552B300511849 /* HPSharingOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 164A86DC17680324006C7174 /* HPSharingOptions.m */; }; + 16CB5E8F17C552B300511849 /* HPAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 16A85D2016CC289C003DE09D /* HPAPI.m */; }; + 16CB5E9017C552B300511849 /* HPCoreDataStack.m in Sources */ = {isa = PBXBuildFile; fileRef = 16CB5E4117C54F0F00511849 /* HPCoreDataStack.m */; }; + 16CB5E9117C552B300511849 /* HPError.m in Sources */ = {isa = PBXBuildFile; fileRef = 16F62D6016C1B0B20034A6BD /* HPError.m */; }; + 16CB5E9217C552B300511849 /* HPPadCacheController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1699003316C9A7FC00F1408A /* HPPadCacheController.m */; }; + 16CB5E9317C552B300511849 /* HPPadScope.m in Sources */ = {isa = PBXBuildFile; fileRef = 1623383D1709F4AA00E2252C /* HPPadScope.m */; }; + 16CB5E9417C552B300511849 /* HPStaticCachingURLProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 160845BE16E9275D00D04253 /* HPStaticCachingURLProtocol.m */; }; + 16CB5E9517C552B300511849 /* HPUserInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 160E57611766551B00C063D8 /* HPUserInfo.m */; }; + 16CB5E9617C552B300511849 /* HPUserInfoCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 16EB3DB81762C722004CE346 /* HPUserInfoCollection.m */; }; + 16CB5E9717C552B300511849 /* HPCollection+Impl.m in Sources */ = {isa = PBXBuildFile; fileRef = 16EB889916C0688F00D90E14 /* HPCollection+Impl.m */; }; + 16CB5E9817C552B300511849 /* HPPad+Impl.m in Sources */ = {isa = PBXBuildFile; fileRef = 16A2785A16BA0D09004D4E81 /* HPPad+Impl.m */; }; + 16CB5E9917C552B300511849 /* HPSharingOptions+Impl.m in Sources */ = {isa = PBXBuildFile; fileRef = 163FA438173AB13B007746E0 /* HPSharingOptions+Impl.m */; }; + 16CB5E9A17C552B300511849 /* HPSpace+Impl.m in Sources */ = {isa = PBXBuildFile; fileRef = 16A2784E16B9EEA9004D4E81 /* HPSpace+Impl.m */; }; + 16CB5E9B17C552B300511849 /* HPEntityMigrationPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 169B4EC416EABA290051E197 /* HPEntityMigrationPolicy.m */; }; + 16CB5E9F17C5547600511849 /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CAF40317444DF30099310F /* libsqlite3.dylib */; }; + 16CB5EA017C5548200511849 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1627C50316B7547C00AA129F /* CoreData.framework */; }; + 16CB5EA117C554AA00511849 /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16326931170CE773004C67EB /* Accounts.framework */; }; + 16CB5EA217C554AA00511849 /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16F54606175948DD00BD7754 /* AddressBook.framework */; }; + 16CB5EA317C554AA00511849 /* AddressBookUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16F54604175947ED00BD7754 /* AddressBookUI.framework */; }; + 16CB5EA417C554AA00511849 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16326932170CE773004C67EB /* AdSupport.framework */; }; + 16CB5EA517C554AA00511849 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C327FDED15E57F9B002819C7 /* CoreGraphics.framework */; }; + 16CB5EA617C554AA00511849 /* FacebookSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CAF3F917444C2E0099310F /* FacebookSDK.framework */; }; + 16CB5EA817C554AA00511849 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CAF3FF17444CFE0099310F /* libz.dylib */; }; + 16CB5EA917C554AA00511849 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16BEFCE116CEC01800419A2D /* Security.framework */; }; + 16CB5EAA17C554AA00511849 /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16326933170CE773004C67EB /* Social.framework */; }; + 16CB5EAB17C554AA00511849 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1663EFD216E6707A00356387 /* SystemConfiguration.framework */; }; + 16CB5EB117C556C600511849 /* HPImportTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 16CB5EAF17C556C600511849 /* HPImportTests.m */; }; + 16CB5EB717C558DF00511849 /* NSManagedObject+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 16085C0F16D4631B00C81DB4 /* NSManagedObject+HackpadAdditions.m */; }; + 16CB5EB917C558DF00511849 /* NSString+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 167F40CC169F9F840091A089 /* NSString+HackpadAdditions.m */; }; + 16CB5EBA17C558DF00511849 /* NSURL+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 16A9CC3116963B56004EED16 /* NSURL+HackpadAdditions.m */; }; + 16CB5EBB17C558DF00511849 /* NSURLRequest+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1653DFEF171CB62400F33460 /* NSURLRequest+HackpadAdditions.m */; }; + 16CD479F1868C865002635BA /* back.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47951868C865002635BA /* back.png */; }; + 16CD47A01868C865002635BA /* back@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47961868C865002635BA /* back@2x.png */; }; + 16CD47A11868C865002635BA /* follow.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47971868C865002635BA /* follow.png */; }; + 16CD47A21868C865002635BA /* follow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47981868C865002635BA /* follow@2x.png */; }; + 16CD47A31868C865002635BA /* menu.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47991868C865002635BA /* menu.png */; }; + 16CD47A41868C865002635BA /* menu@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD479A1868C865002635BA /* menu@2x.png */; }; + 16CD47A51868C865002635BA /* search.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD479B1868C865002635BA /* search.png */; }; + 16CD47A61868C865002635BA /* search@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD479C1868C865002635BA /* search@2x.png */; }; + 16CD47A71868C865002635BA /* newpad.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD479D1868C865002635BA /* newpad.png */; }; + 16CD47A81868C865002635BA /* newpad@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD479E1868C865002635BA /* newpad@2x.png */; }; + 16CD47AB1868CB88002635BA /* forward.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47A91868CB88002635BA /* forward.png */; }; + 16CD47AC1868CB88002635BA /* forward@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47AA1868CB88002635BA /* forward@2x.png */; }; + 16CD47B31868FC56002635BA /* user.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47AD1868FC56002635BA /* user.png */; }; + 16CD47B41868FC56002635BA /* user@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47AE1868FC56002635BA /* user@2x.png */; }; + 16CD47B51868FC56002635BA /* gear.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47AF1868FC56002635BA /* gear.png */; }; + 16CD47B61868FC56002635BA /* gear@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47B01868FC56002635BA /* gear@2x.png */; }; + 16CD47B71868FC56002635BA /* down-chevron.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47B11868FC56002635BA /* down-chevron.png */; }; + 16CD47B81868FC56002635BA /* down-chevron@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47B21868FC56002635BA /* down-chevron@2x.png */; }; + 16CD47BB18691853002635BA /* up-chevron@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47B918691853002635BA /* up-chevron@2x.png */; }; + 16CD47BC18691853002635BA /* up-chevron.png in Resources */ = {isa = PBXBuildFile; fileRef = 16CD47BA18691853002635BA /* up-chevron.png */; }; + 16CF111F17D5ADD300C8FF10 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 16CF111E17D5ADD300C8FF10 /* Images.xcassets */; }; + 16D7A3C4177B7D2E00CBC44C /* Hackpad.js in Resources */ = {isa = PBXBuildFile; fileRef = 16D7A3BF177B7C8600CBC44C /* Hackpad.js */; }; + 16DE5C2118725A460026D792 /* NSData+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 16DE5C2018725A460026D792 /* NSData+HackpadAdditions.m */; }; + 16E156DA17E3C9710060B51E /* HPPadScopeTableViewDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 16E156D917E3C9710060B51E /* HPPadScopeTableViewDataSource.m */; }; + 16E156DD17E3DCFE0060B51E /* HPPadScopeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 16E156DC17E3DCFE0060B51E /* HPPadScopeTests.m */; }; + 16E2165C185F6590000FAA42 /* NSURLRequestHackpadAdditionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 16E2165B185F6590000FAA42 /* NSURLRequestHackpadAdditionsTests.m */; }; + 16E21661185F9C78000FAA42 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 16E2165E185F9C78000FAA42 /* LICENSE */; }; + 16E21662185F9C78000FAA42 /* MBProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = 16E21660185F9C78000FAA42 /* MBProgressHUD.m */; }; + 16E6F4FB1887183C00FD7486 /* ProximaNova-Reg.otf in Resources */ = {isa = PBXBuildFile; fileRef = 16E6F4FA1887183C00FD7486 /* ProximaNova-Reg.otf */; }; + 16E73BF317CBE62D0000A2E5 /* HPReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 16E73BF217CBE62D0000A2E5 /* HPReachability.m */; }; + 16EB3DBC17655F12004CE346 /* HPUserInfosViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16EB3DBB17655F12004CE346 /* HPUserInfosViewController.m */; }; + 16EB3DBF17656060004CE346 /* HPUserInfoImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 16EB3DBE17656060004CE346 /* HPUserInfoImageView.m */; }; + 16EB8411174C37A500A7DCD3 /* UIImage+Alpha.m in Sources */ = {isa = PBXBuildFile; fileRef = 16EB840C174C37A500A7DCD3 /* UIImage+Alpha.m */; }; + 16EB8412174C37A500A7DCD3 /* UIImage+Resize.m in Sources */ = {isa = PBXBuildFile; fileRef = 16EB840E174C37A500A7DCD3 /* UIImage+Resize.m */; }; + 16EB8413174C37A500A7DCD3 /* UIImage+RoundedCorner.m in Sources */ = {isa = PBXBuildFile; fileRef = 16EB8410174C37A500A7DCD3 /* UIImage+RoundedCorner.m */; }; + 16EEDE94175929E0006C9FDB /* HPInvitationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16EEDE93175929DF006C9FDB /* HPInvitationController.m */; }; + 16F154811824344100B481F0 /* HPImageUploadURLProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 16F154801824344100B481F0 /* HPImageUploadURLProtocol.m */; }; + 16F54605175947ED00BD7754 /* AddressBookUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16F54604175947ED00BD7754 /* AddressBookUI.framework */; }; + 16F54607175948DD00BD7754 /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16F54606175948DD00BD7754 /* AddressBook.framework */; }; + 16F550C717E1641400305AEA /* HPPadTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 16F550C617E1641400305AEA /* HPPadTests.m */; }; + 16F550CA17E24C6300305AEA /* hprecursiveblock.c in Sources */ = {isa = PBXBuildFile; fileRef = 16F550C917E24C6300305AEA /* hprecursiveblock.c */; }; + 16F62A2F183B042D0095DE12 /* UIColor+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 16F62A2E183B042D0095DE12 /* UIColor+HackpadAdditions.m */; }; + 16F62A32183B35BA0095DE12 /* HPPadCellBackgroundView.m in Sources */ = {isa = PBXBuildFile; fileRef = 16F62A31183B35BA0095DE12 /* HPPadCellBackgroundView.m */; }; + 16F62D6416C1B3590034A6BD /* HPSignInViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16F62D6316C1B3590034A6BD /* HPSignInViewController.m */; }; + 16F6657A17A05E3500362A8B /* HPAlertViewBlockDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 16F6657917A05E3500362A8B /* HPAlertViewBlockDelegate.m */; }; + C322B9AD1772733C00A2F1CE /* site-switcher.png in Resources */ = {isa = PBXBuildFile; fileRef = C322B9AC1772733B00A2F1CE /* site-switcher.png */; }; + C327FDEA15E57F9B002819C7 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C327FDE915E57F9B002819C7 /* UIKit.framework */; }; + C327FDEC15E57F9B002819C7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C327FDEB15E57F9B002819C7 /* Foundation.framework */; }; + C327FDEE15E57F9B002819C7 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C327FDED15E57F9B002819C7 /* CoreGraphics.framework */; }; + C327FDF415E57F9B002819C7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C327FDF215E57F9B002819C7 /* InfoPlist.strings */; }; + C327FDF615E57F9B002819C7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C327FDF515E57F9B002819C7 /* main.m */; }; + C327FDFA15E57F9B002819C7 /* HPAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C327FDF915E57F9B002819C7 /* HPAppDelegate.m */; }; + C327FDFD15E57F9B002819C7 /* MainStoryboard_iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C327FDFB15E57F9B002819C7 /* MainStoryboard_iPhone.storyboard */; }; + C327FE0015E57F9B002819C7 /* MainStoryboard_iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C327FDFE15E57F9B002819C7 /* MainStoryboard_iPad.storyboard */; }; + C327FE0315E57F9B002819C7 /* HPPadListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C327FE0215E57F9B002819C7 /* HPPadListViewController.m */; }; + C327FE0615E57F9B002819C7 /* HPPadEditorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C327FE0515E57F9B002819C7 /* HPPadEditorViewController.m */; }; + CE464E1B17E12586005227A9 /* HPSearchSnippetsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CE464E1A17E12586005227A9 /* HPSearchSnippetsTests.m */; }; + CE464E1F17E1D138005227A9 /* NSAttributedString+DDHTML.m in Sources */ = {isa = PBXBuildFile; fileRef = CE464E1E17E1D138005227A9 /* NSAttributedString+DDHTML.m */; }; + CE464E2517E1D494005227A9 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CE464E2117E1D22D005227A9 /* libxml2.dylib */; }; + CE464E2817E1D935005227A9 /* NSAttributedString+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = CE464E2717E1D935005227A9 /* NSAttributedString+HackpadAdditions.m */; }; + CE464E2917E1D935005227A9 /* NSAttributedString+HackpadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = CE464E2717E1D935005227A9 /* NSAttributedString+HackpadAdditions.m */; }; + F0E3B63A181FF13E008590C6 /* HPTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F0E3B638181FF13E008590C6 /* HPTextFieldCell.m */; }; + F0E3B63B181FF13E008590C6 /* HPTextFieldCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F0E3B639181FF13E008590C6 /* HPTextFieldCell.xib */; }; + F0E3B63E181FF157008590C6 /* HPAddSpaceViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F0E3B63D181FF157008590C6 /* HPAddSpaceViewController.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 160CA80717CFEDF800DA1FA5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C327FDDC15E57F9B002819C7 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 160CA7EC17CFEAD400DA1FA5; + remoteInfo = HackpadTestingKit; + }; + 160CA80C17CFF16A00DA1FA5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C327FDDC15E57F9B002819C7 /* Project object */; + proxyType = 1; + remoteGlobalIDString = C327FDE415E57F9B002819C7; + remoteInfo = Hackpad; + }; + 16CB5E6C17C551A000511849 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C327FDDC15E57F9B002819C7 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 16CB5E5817C551A000511849; + remoteInfo = HackpadKit; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 160CA7EB17CFEAD400DA1FA5 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/${PRODUCT_NAME}"; + dstSubfolderSpec = 16; + files = ( + 160CA7F317CFEAD400DA1FA5 /* HackpadTestingKit.h in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 16CB5E5717C551A000511849 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/${PRODUCT_NAME}"; + dstSubfolderSpec = 16; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 160129F617D9638C002B42AA /* NSManagedObjectContext+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSManagedObjectContext+HackpadAdditions.h"; sourceTree = ""; }; + 160129F717D9638C002B42AA /* NSManagedObjectContext+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSManagedObjectContext+HackpadAdditions.m"; sourceTree = ""; }; + 160428881811EA8C00D8D41C /* HPPadWebController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadWebController.h; sourceTree = ""; }; + 160428891811EA8C00D8D41C /* HPPadWebController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadWebController.m; sourceTree = ""; }; + 1605D85117D44A060057CE4A /* HPRollbackDeletedObjectsMergePolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPRollbackDeletedObjectsMergePolicy.h; sourceTree = ""; }; + 1605D85217D44A060057CE4A /* HPRollbackDeletedObjectsMergePolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPRollbackDeletedObjectsMergePolicy.m; sourceTree = ""; }; + 16060B4F172AED9C00451986 /* UIView+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = "UIView+HackpadAdditions.h"; path = "HackpadAdditions/UIView+HackpadAdditions.h"; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + 16060B50172AED9C00451986 /* UIView+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = "UIView+HackpadAdditions.m"; path = "HackpadAdditions/UIView+HackpadAdditions.m"; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 160845BA16E9261D00D04253 /* RNCachingURLProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNCachingURLProtocol.h; sourceTree = ""; }; + 160845BB16E9261D00D04253 /* RNCachingURLProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNCachingURLProtocol.m; sourceTree = ""; }; + 160845BD16E9275D00D04253 /* HPStaticCachingURLProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPStaticCachingURLProtocol.h; sourceTree = ""; }; + 160845BE16E9275D00D04253 /* HPStaticCachingURLProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPStaticCachingURLProtocol.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16085C0A16D460BA00C81DB4 /* GTMDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = GTMDefines.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + 16085C0B16D460BA00C81DB4 /* GTMNSString+HTML.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GTMNSString+HTML.m"; sourceTree = ""; }; + 16085C0C16D460BA00C81DB4 /* GTMNSString+HTML.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GTMNSString+HTML.h"; sourceTree = ""; }; + 16085C0E16D4631B00C81DB4 /* NSManagedObject+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSManagedObject+HackpadAdditions.h"; sourceTree = ""; }; + 16085C0F16D4631B00C81DB4 /* NSManagedObject+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSManagedObject+HackpadAdditions.m"; sourceTree = ""; }; + 16085C1416D53FE200C81DB4 /* KeychainItemWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeychainItemWrapper.h; sourceTree = ""; }; + 16085C1516D53FE200C81DB4 /* KeychainItemWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KeychainItemWrapper.m; sourceTree = ""; }; + 16085C1A16D57D2300C81DB4 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = ""; }; + 160C17C61861212600CC68DA /* UIFont+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIFont+HackpadAdditions.h"; sourceTree = ""; }; + 160C17C71861212600CC68DA /* UIFont+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIFont+HackpadAdditions.m"; sourceTree = ""; }; + 160CA79B17CFE54500DA1FA5 /* HackpadTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HackpadTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; + 160CA7A117CFE54500DA1FA5 /* HackpadTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "HackpadTests-Info.plist"; sourceTree = ""; }; + 160CA7A317CFE54500DA1FA5 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 160CA7A817CFE54500DA1FA5 /* HackpadTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "HackpadTests-Prefix.pch"; sourceTree = ""; }; + 160CA7AF17CFE6BD00DA1FA5 /* HPPadScopeTableViewDataSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadScopeTableViewDataSourceTests.m; sourceTree = ""; }; + 160CA7ED17CFEAD400DA1FA5 /* libHackpadTestingKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libHackpadTestingKit.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 160CA7F117CFEAD400DA1FA5 /* HackpadTestingKit-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "HackpadTestingKit-Prefix.pch"; sourceTree = ""; }; + 160CA7F217CFEAD400DA1FA5 /* HackpadTestingKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HackpadTestingKit.h; sourceTree = ""; }; + 160CA7FE17CFECA100DA1FA5 /* libOCMock.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libOCMock.a; sourceTree = ""; }; + 160CA7FF17CFECA100DA1FA5 /* NSNotificationCenter+OCMAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSNotificationCenter+OCMAdditions.h"; sourceTree = ""; }; + 160CA80017CFECA100DA1FA5 /* OCMArg.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCMArg.h; sourceTree = ""; }; + 160CA80117CFECA100DA1FA5 /* OCMConstraint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCMConstraint.h; sourceTree = ""; }; + 160CA80217CFECA100DA1FA5 /* OCMock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCMock.h; sourceTree = ""; }; + 160CA80317CFECA100DA1FA5 /* OCMockObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCMockObject.h; sourceTree = ""; }; + 160CA80417CFECA100DA1FA5 /* OCMockRecorder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCMockRecorder.h; sourceTree = ""; }; + 160CA85717CFFA6600DA1FA5 /* HPMockTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPMockTestCase.h; sourceTree = ""; }; + 160CA85817CFFA6600DA1FA5 /* HPMockTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPMockTestCase.m; sourceTree = ""; }; + 160D04A2174A98F200C98325 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/SignIn_iPad.storyboard; sourceTree = ""; }; + 160D04AB174AA92100C98325 /* Acknowledgements.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Acknowledgements.txt; sourceTree = ""; }; + 160D04B1174AED1100C98325 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/SignIn_iPhone.storyboard; sourceTree = ""; }; + 160E57601766551B00C063D8 /* HPUserInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPUserInfo.h; sourceTree = ""; }; + 160E57611766551B00C063D8 /* HPUserInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPUserInfo.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 160E576317666F4100C063D8 /* HPUserInfoCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPUserInfoCell.h; sourceTree = ""; }; + 160E576417666F4100C063D8 /* HPUserInfoCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPUserInfoCell.m; sourceTree = ""; }; + 1623383C1709F4AA00E2252C /* HPPadScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadScope.h; sourceTree = ""; }; + 1623383D1709F4AA00E2252C /* HPPadScope.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadScope.m; sourceTree = ""; }; + 16233844170B865100E2252C /* HPSignInController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPSignInController.h; sourceTree = ""; }; + 16233845170B865100E2252C /* HPSignInController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPSignInController.m; sourceTree = ""; }; + 1627C50316B7547C00AA129F /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; + 16326931170CE773004C67EB /* Accounts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accounts.framework; path = System/Library/Frameworks/Accounts.framework; sourceTree = SDKROOT; }; + 16326932170CE773004C67EB /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; }; + 16326933170CE773004C67EB /* Social.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Social.framework; path = System/Library/Frameworks/Social.framework; sourceTree = SDKROOT; }; + 163489C218AC064E004972CB /* Hackpad12.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = Hackpad12.sqlite; sourceTree = ""; }; + 163623DF16FA50ED00367769 /* HPPadScopeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadScopeViewController.h; sourceTree = ""; }; + 163623E016FA50ED00367769 /* HPPadScopeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPPadScopeViewController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 1636245C17025B9B00367769 /* HPDrawerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPDrawerController.m; sourceTree = ""; }; + 1636245D17025B9B00367769 /* HPDrawerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPDrawerController.h; sourceTree = ""; }; + 163968D61834617D00DC5A4F /* MessageUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MessageUI.framework; path = System/Library/Frameworks/MessageUI.framework; sourceTree = SDKROOT; }; + 163FA437173AB13B007746E0 /* HPSharingOptions+Impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HPSharingOptions+Impl.h"; sourceTree = ""; }; + 163FA438173AB13B007746E0 /* HPSharingOptions+Impl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "HPSharingOptions+Impl.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 164045881858D60D00D02B59 /* PadCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PadCell.xib; sourceTree = ""; }; + 1642A52D18359F8B00FADDFE /* HPGroupedToolbar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPGroupedToolbar.h; sourceTree = ""; }; + 1642A52E18359F8B00FADDFE /* HPGroupedToolbar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPGroupedToolbar.m; sourceTree = ""; }; + 164A86D517680324006C7174 /* HPCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPCollection.h; sourceTree = ""; }; + 164A86D617680324006C7174 /* HPCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPCollection.m; sourceTree = ""; }; + 164A86DB17680324006C7174 /* HPSharingOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPSharingOptions.h; sourceTree = ""; }; + 164A86DC17680324006C7174 /* HPSharingOptions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPSharingOptions.m; sourceTree = ""; }; + 164B505D1893569F005DCFDE /* email-button-white.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "email-button-white.png"; sourceTree = ""; }; + 164B505E1893569F005DCFDE /* email-button-white@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "email-button-white@2x.png"; sourceTree = ""; }; + 164B506D1893600D005DCFDE /* user-green@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "user-green@2x.png"; sourceTree = ""; }; + 164B506E1893600D005DCFDE /* user-green.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "user-green.png"; sourceTree = ""; }; + 164B507118971370005DCFDE /* facebook44@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "facebook44@2x.png"; sourceTree = ""; }; + 164B507218971370005DCFDE /* facebook44.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = facebook44.png; sourceTree = ""; }; + 164B5075189714A2005DCFDE /* google44@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "google44@2x.png"; sourceTree = ""; }; + 164B5076189714A2005DCFDE /* google44.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = google44.png; sourceTree = ""; }; + 164E44151870F934002657E2 /* ProximaNova-Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ProximaNova-Bold.otf"; sourceTree = ""; }; + 164E44161870F934002657E2 /* ProximaNova-Light.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ProximaNova-Light.otf"; sourceTree = ""; }; + 164E44171870F934002657E2 /* ProximaNova-LightIt.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ProximaNova-LightIt.otf"; sourceTree = ""; }; + 164E44181870F934002657E2 /* ProximaNova-Sbold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ProximaNova-Sbold.otf"; sourceTree = ""; }; + 164E44191870F934002657E2 /* ProximaNova-SboldIt.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ProximaNova-SboldIt.otf"; sourceTree = ""; }; + 164E441A1870F934002657E2 /* ProximaNova-Xbold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ProximaNova-Xbold.otf"; sourceTree = ""; }; + 1653DFEE171CB62400F33460 /* NSURLRequest+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "NSURLRequest+HackpadAdditions.h"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + 1653DFEF171CB62400F33460 /* NSURLRequest+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "NSURLRequest+HackpadAdditions.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 1654C70018A96B20007238FD /* libFlurry_4.3.2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libFlurry_4.3.2.a; sourceTree = ""; }; + 165AA16A187F2FC800C7C80F /* HPCancelFreeSearchDisplayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPCancelFreeSearchDisplayController.h; sourceTree = ""; }; + 165AA16B187F2FC800C7C80F /* HPCancelFreeSearchDisplayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPCancelFreeSearchDisplayController.m; sourceTree = ""; }; + 165AA16D187F360900C7C80F /* HPEmptySearchViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPEmptySearchViewController.h; sourceTree = ""; }; + 165AA16E187F360900C7C80F /* HPEmptySearchViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPEmptySearchViewController.m; sourceTree = ""; }; + 165AA170187F6E7A00C7C80F /* UIViewController+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+HackpadAdditions.h"; sourceTree = ""; }; + 165AA171187F6E7A00C7C80F /* UIViewController+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+HackpadAdditions.m"; sourceTree = ""; }; + 165AA1731880A29600C7C80F /* HPPopoverLayoutFixTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPopoverLayoutFixTableView.h; sourceTree = ""; }; + 165AA1741880A29600C7C80F /* HPPopoverLayoutFixTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPopoverLayoutFixTableView.m; sourceTree = ""; }; + 165C59CC17B32CCB001006D4 /* bluebg.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bluebg.png; sourceTree = ""; }; + 165C59CE17B331F5001006D4 /* graybg.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = graybg.png; sourceTree = ""; }; + 165C59D317B34782001006D4 /* HPBlueNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPBlueNavigationController.h; sourceTree = ""; }; + 165C59D417B34782001006D4 /* HPBlueNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPBlueNavigationController.m; sourceTree = ""; }; + 165C59D617B347A3001006D4 /* HPGrayNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPGrayNavigationController.h; sourceTree = ""; }; + 165C59D717B347A4001006D4 /* HPGrayNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPGrayNavigationController.m; sourceTree = ""; }; + 165C59D917B34B47001006D4 /* HPColoredAppearanceContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPColoredAppearanceContainer.h; sourceTree = ""; }; + 1663EFD216E6707A00356387 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; + 1663EFD416E670C600356387 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = ""; }; + 1663EFD516E670C600356387 /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = ""; }; + 16650D0316A093BB00452A1F /* checked.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = checked.png; path = ../../../etherpad/src/static/img/checked.png; sourceTree = SOURCE_ROOT; }; + 16650D0616A0977F00452A1F /* HPPadCollectionCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadCollectionCell.h; sourceTree = ""; }; + 16650D0716A0977F00452A1F /* HPPadCollectionCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadCollectionCell.m; sourceTree = ""; }; + 16650D0916A0C96C00452A1F /* unchecked.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = unchecked.png; path = ../../../etherpad/src/static/img/unchecked.png; sourceTree = SOURCE_ROOT; }; + 16650D0D16A0DF6600452A1F /* HPPadSharingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadSharingViewController.h; sourceTree = ""; }; + 16650D0E16A0DF6600452A1F /* HPPadSharingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadSharingViewController.m; sourceTree = ""; }; + 1667ACC017D0609100F777EE /* UIDevice+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "UIDevice+HackpadAdditions.h"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + 1667ACC117D0609100F777EE /* UIDevice+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "UIDevice+HackpadAdditions.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 166C111617F249230004DF6E /* Hackpad 7.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 7.xcdatamodel"; sourceTree = ""; }; + 166C112017F25FFC0004DF6E /* HPPadSearch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadSearch.h; sourceTree = ""; }; + 166C112117F25FFC0004DF6E /* HPPadSearch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadSearch.m; sourceTree = ""; }; + 166E7D14183AC44D00C82013 /* HPWhiteNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HPWhiteNavigationController.h; path = ../HPWhiteNavigationController.h; sourceTree = ""; }; + 166E7D15183AC44D00C82013 /* HPWhiteNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HPWhiteNavigationController.m; path = ../HPWhiteNavigationController.m; sourceTree = ""; }; + 166E7D17183ACA5D00C82013 /* whitebg.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = whitebg.png; sourceTree = ""; }; + 166E7D18183ACA5D00C82013 /* whiteback.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = whiteback.png; sourceTree = ""; }; + 166E7D19183ACA5D00C82013 /* whiteback@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "whiteback@2x.png"; sourceTree = ""; }; + 166EF52218A30BF400561F07 /* Hackpad 10.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 10.xcdatamodel"; sourceTree = ""; }; + 166EF56618A444E800561F07 /* Hackpad10.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = Hackpad10.sqlite; sourceTree = ""; }; + 166EF57918A466A900561F07 /* Hackpad9.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = Hackpad9.sqlite; sourceTree = ""; }; + 166EF57D18A4A8BC00561F07 /* HPMigrationTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPMigrationTestCase.m; sourceTree = ""; }; + 166EF57F18A4A8E400561F07 /* HPMigrationTestCase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HPMigrationTestCase.h; sourceTree = ""; }; + 166EF58018A4B24900561F07 /* Hackpad 11.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 11.xcdatamodel"; sourceTree = ""; }; + 166EF58418A4B36000561F07 /* HPPadEditor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadEditor.h; sourceTree = ""; }; + 166EF58518A4B36000561F07 /* HPPadEditor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadEditor.m; sourceTree = ""; }; + 166EF58918A4C5C200561F07 /* Hackpad11.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = Hackpad11.sqlite; sourceTree = ""; }; + 1673C04317986DCD005FED08 /* GetSnippetHeight.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = GetSnippetHeight.js; sourceTree = ""; }; + 167DEF7017710FB300BE090C /* Hackpad 2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 2.xcdatamodel"; sourceTree = ""; }; + 167DEF7117710FB300BE090C /* Hackpad.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Hackpad.xcdatamodel; sourceTree = ""; }; + 167DEF7317710FC100BE090C /* Hackpad 3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 3.xcdatamodel"; sourceTree = ""; }; + 167DEF7A17723DA100BE090C /* HPPadCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadCell.h; sourceTree = ""; }; + 167DEF7B17723DA100BE090C /* HPPadCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPPadCell.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 167F40CB169F9F840091A089 /* NSString+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+HackpadAdditions.h"; sourceTree = ""; }; + 167F40CC169F9F840091A089 /* NSString+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "NSString+HackpadAdditions.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 168786711821B4E30095428D /* NSURLResponse+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURLResponse+HackpadAdditions.h"; sourceTree = ""; }; + 168786721821B4E30095428D /* NSURLResponse+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURLResponse+HackpadAdditions.m"; sourceTree = ""; }; + 168786791822D4890095428D /* Hackpad 8.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 8.xcdatamodel"; sourceTree = ""; }; + 168786801822D8E10095428D /* HPImageUpload+Impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HPImageUpload+Impl.h"; sourceTree = ""; }; + 168786811822D8E10095428D /* HPImageUpload+Impl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "HPImageUpload+Impl.m"; sourceTree = ""; }; + 16888E2F1794C8AD000375B2 /* Hackpad 4.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 4.xcdatamodel"; sourceTree = ""; }; + 168905EF182D6D81002D95F2 /* HPInvitationTableViewDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPInvitationTableViewDataSource.h; sourceTree = ""; }; + 168905F0182D6D81002D95F2 /* HPInvitationTableViewDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPInvitationTableViewDataSource.m; sourceTree = ""; }; + 168A196617EFE6A900A990F4 /* HPPadTableViewDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadTableViewDataSource.h; sourceTree = ""; }; + 168A196717EFE6A900A990F4 /* HPPadTableViewDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadTableViewDataSource.m; sourceTree = ""; }; + 168A196917EFED5B00A990F4 /* HPActionSheetBlockDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPActionSheetBlockDelegate.h; sourceTree = ""; }; + 168A196A17EFED5B00A990F4 /* HPActionSheetBlockDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPActionSheetBlockDelegate.m; sourceTree = ""; }; + 168A196C17EFF40700A990F4 /* HPPadSearchTableViewDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadSearchTableViewDataSource.h; sourceTree = ""; }; + 168A196D17EFF40700A990F4 /* HPPadSearchTableViewDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPPadSearchTableViewDataSource.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 168DD540189857D0003E01BF /* dot44@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dot44@2x.png"; sourceTree = ""; }; + 168DD541189857D0003E01BF /* dot44.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = dot44.png; sourceTree = ""; }; + 16919C74187B617500EDF5AE /* Hackpad 9.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 9.xcdatamodel"; sourceTree = ""; }; + 16919C80187C6F6D00EDF5AE /* HPSpaceCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPSpaceCell.h; sourceTree = ""; }; + 16919C81187C6F6D00EDF5AE /* HPSpaceCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPSpaceCell.m; sourceTree = ""; }; + 1691CC941899686000CF121C /* x-red.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "x-red.png"; sourceTree = ""; }; + 1691CC951899686000CF121C /* check-green.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "check-green.png"; sourceTree = ""; }; + 1691CC961899686000CF121C /* check-green@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "check-green@2x.png"; sourceTree = ""; }; + 1691CC971899686000CF121C /* x-red@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "x-red@2x.png"; sourceTree = ""; }; + 1699003216C9A7FC00F1408A /* HPPadCacheController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadCacheController.h; sourceTree = ""; }; + 1699003316C9A7FC00F1408A /* HPPadCacheController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPPadCacheController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 1699F709183C0F36001DAC1D /* darkgreenbg.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = darkgreenbg.png; sourceTree = ""; }; + 1699F70B183C10C8001DAC1D /* clearback@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "clearback@2x.png"; sourceTree = ""; }; + 1699F70D183C114E001DAC1D /* clearbacklandscape.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = clearbacklandscape.png; sourceTree = ""; }; + 1699F70E183C114E001DAC1D /* clearbacklandscape@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "clearbacklandscape@2x.png"; sourceTree = ""; }; + 1699F70F183C114E001DAC1D /* clearback.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = clearback.png; sourceTree = ""; }; + 169B0F54169E635800B65E11 /* HPPadCollectionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadCollectionViewController.h; sourceTree = ""; }; + 169B0F55169E635800B65E11 /* HPPadCollectionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadCollectionViewController.m; sourceTree = ""; }; + 169B4EC316EABA290051E197 /* HPEntityMigrationPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPEntityMigrationPolicy.h; sourceTree = ""; }; + 169B4EC416EABA290051E197 /* HPEntityMigrationPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPEntityMigrationPolicy.m; sourceTree = ""; }; + 169C0B4517EB8DB400FF7B43 /* Hackpad 6.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 6.xcdatamodel"; sourceTree = ""; }; + 169DD8631832D77200D0D528 /* groupbg.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = groupbg.png; sourceTree = ""; }; + 169DD8641832D77200D0D528 /* editorbg.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = editorbg.png; sourceTree = ""; }; + 169DD8671832F27100D0D528 /* check.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = check.png; sourceTree = ""; }; + 169DD8681832F27100D0D528 /* check@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "check@2x.png"; sourceTree = ""; }; + 169DD8691832F27100D0D528 /* number.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = number.png; sourceTree = ""; }; + 169DD86A1832F27100D0D528 /* number@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "number@2x.png"; sourceTree = ""; }; + 169DD86B1832F27100D0D528 /* bullet.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bullet.png; sourceTree = ""; }; + 169DD86C1832F27100D0D528 /* bullet@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "bullet@2x.png"; sourceTree = ""; }; + 169DD86D1832F27100D0D528 /* paragraph.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = paragraph.png; sourceTree = ""; }; + 169DD86E1832F27100D0D528 /* paragraph@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "paragraph@2x.png"; sourceTree = ""; }; + 169DD86F1832F27100D0D528 /* outdent.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = outdent.png; sourceTree = ""; }; + 169DD8701832F27100D0D528 /* outdent@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "outdent@2x.png"; sourceTree = ""; }; + 169DD8711832F27100D0D528 /* indent.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = indent.png; sourceTree = ""; }; + 169DD8721832F27100D0D528 /* indent@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "indent@2x.png"; sourceTree = ""; }; + 169DD8731832F27100D0D528 /* tag.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tag.png; sourceTree = ""; }; + 169DD8741832F27100D0D528 /* tag@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tag@2x.png"; sourceTree = ""; }; + 169DD8751832F27100D0D528 /* mention.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = mention.png; sourceTree = ""; }; + 169DD8761832F27100D0D528 /* mention@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "mention@2x.png"; sourceTree = ""; }; + 169DD8771832F27100D0D528 /* dropbox.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = dropbox.png; sourceTree = ""; }; + 169DD8781832F27100D0D528 /* dropbox@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dropbox@2x.png"; sourceTree = ""; }; + 169DD8791832F27100D0D528 /* link.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = link.png; sourceTree = ""; }; + 169DD87A1832F27100D0D528 /* link@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "link@2x.png"; sourceTree = ""; }; + 169DD87B1832F27100D0D528 /* table.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = table.png; sourceTree = ""; }; + 169DD87C1832F27100D0D528 /* table@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "table@2x.png"; sourceTree = ""; }; + 169DD87D1832F27100D0D528 /* photo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = photo.png; sourceTree = ""; }; + 169DD87E1832F27100D0D528 /* photo@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "photo@2x.png"; sourceTree = ""; }; + 169DD87F1832F27100D0D528 /* header3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = header3.png; sourceTree = ""; }; + 169DD8801832F27100D0D528 /* header3@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "header3@2x.png"; sourceTree = ""; }; + 169DD8811832F27100D0D528 /* header2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = header2.png; sourceTree = ""; }; + 169DD8821832F27100D0D528 /* header2@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "header2@2x.png"; sourceTree = ""; }; + 169DD8831832F27100D0D528 /* header1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = header1.png; sourceTree = ""; }; + 169DD8841832F27100D0D528 /* header1@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "header1@2x.png"; sourceTree = ""; }; + 169DD8851832F27100D0D528 /* strikethrough.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = strikethrough.png; sourceTree = ""; }; + 169DD8861832F27100D0D528 /* strikethrough@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "strikethrough@2x.png"; sourceTree = ""; }; + 169DD8871832F27100D0D528 /* underline.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = underline.png; sourceTree = ""; }; + 169DD8881832F27200D0D528 /* underline@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "underline@2x.png"; sourceTree = ""; }; + 169DD8891832F27200D0D528 /* italic.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = italic.png; sourceTree = ""; }; + 169DD88A1832F27200D0D528 /* italic@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "italic@2x.png"; sourceTree = ""; }; + 169DD88B1832F27200D0D528 /* bold.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bold.png; sourceTree = ""; }; + 169DD88C1832F27200D0D528 /* bold@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "bold@2x.png"; sourceTree = ""; }; + 169DD88D1832F27200D0D528 /* close.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = close.png; sourceTree = ""; }; + 169DD88E1832F27200D0D528 /* close@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close@2x.png"; sourceTree = ""; }; + 169DD88F1832F27200D0D528 /* insert.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = insert.png; sourceTree = ""; }; + 169DD8901832F27200D0D528 /* insert@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "insert@2x.png"; sourceTree = ""; }; + 169DD8911832F27200D0D528 /* comment.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = comment.png; sourceTree = ""; }; + 169DD8921832F27200D0D528 /* comment@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "comment@2x.png"; sourceTree = ""; }; + 169DD8931832F27200D0D528 /* textformat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = textformat.png; sourceTree = ""; }; + 169DD8941832F27200D0D528 /* textformat@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "textformat@2x.png"; sourceTree = ""; }; + 16A2784D16B9EEA9004D4E81 /* HPSpace+Impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HPSpace+Impl.h"; sourceTree = ""; }; + 16A2784E16B9EEA9004D4E81 /* HPSpace+Impl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "HPSpace+Impl.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16A2785916BA0D09004D4E81 /* HPPad+Impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HPPad+Impl.h"; sourceTree = ""; }; + 16A2785A16BA0D09004D4E81 /* HPPad+Impl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "HPPad+Impl.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16A370A218284E2400731484 /* HPPadAutocompleteTableViewDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadAutocompleteTableViewDataSource.h; sourceTree = ""; }; + 16A370A318284E2400731484 /* HPPadAutocompleteTableViewDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadAutocompleteTableViewDataSource.m; sourceTree = ""; }; + 16A55F4417601260001ED006 /* nophoto.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = nophoto.png; sourceTree = ""; }; + 16A55F72176140D9001ED006 /* online.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = online.png; sourceTree = ""; }; + 16A55F73176140D9001ED006 /* online@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "online@2x.png"; sourceTree = ""; }; + 16A760B718AD800000821DB3 /* Hackpad 13.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 13.xcdatamodel"; sourceTree = ""; }; + 16A760BD18ADB19100821DB3 /* Hackpad13.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = Hackpad13.sqlite; sourceTree = ""; }; + 16A760BF18AE9B1700821DB3 /* Hackpad 14.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 14.xcdatamodel"; sourceTree = ""; }; + 16A760C018AE9E9800821DB3 /* HPImageUpload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPImageUpload.h; sourceTree = ""; }; + 16A760C118AE9E9800821DB3 /* HPImageUpload.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPImageUpload.m; sourceTree = ""; }; + 16A760C518AEA2F900821DB3 /* Hackpad14.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = Hackpad14.sqlite; sourceTree = ""; }; + 16A760C718AEA35000821DB3 /* HPMigrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPMigrationTests.m; sourceTree = ""; }; + 16A760C918AEB82F00821DB3 /* separator@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "separator@2x.png"; sourceTree = ""; }; + 16A760CB18AEB9DD00821DB3 /* separator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = separator.png; sourceTree = ""; }; + 16A760CD18AEED4000821DB3 /* Hackpad 15.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Hackpad 15.xcdatamodel"; sourceTree = ""; }; + 16A760CE18AEEEF600821DB3 /* HPSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPSpace.h; sourceTree = ""; }; + 16A760CF18AEEEF600821DB3 /* HPSpace.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPSpace.m; sourceTree = ""; }; + 16A760D118AEF37100821DB3 /* Hackpad15.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = Hackpad15.sqlite; sourceTree = ""; }; + 16A8417B17D1AC35007BEE69 /* NSError+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+HackpadAdditions.h"; sourceTree = ""; }; + 16A8417C17D1AC35007BEE69 /* NSError+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+HackpadAdditions.m"; sourceTree = ""; }; + 16A85D1F16CC289C003DE09D /* HPAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPAPI.h; sourceTree = ""; }; + 16A85D2016CC289C003DE09D /* HPAPI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPAPI.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16A890ED186E33C10014EF45 /* HPAPITests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPAPITests.m; sourceTree = ""; }; + 16A9CC3016963B56004EED16 /* NSURL+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "NSURL+HackpadAdditions.h"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + 16A9CC3116963B56004EED16 /* NSURL+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "NSURL+HackpadAdditions.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16AA8C55171778A800155C8F /* HPGoogleSignInViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPGoogleSignInViewController.h; sourceTree = ""; }; + 16AA8C57171778CE00155C8F /* HPGoogleSignInViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPGoogleSignInViewController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16AE68C017D91BA50031898F /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Developer/Library/Frameworks/SenTestingKit.framework; sourceTree = SDKROOT; }; + 16AE8FE317BD7A1A0065020C /* HPPadSplitViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadSplitViewController.h; sourceTree = ""; }; + 16AE8FE417BD7A1A0065020C /* HPPadSplitViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadSplitViewController.m; sourceTree = ""; }; + 16B0AF2A189DD3080072A725 /* HPSynchronizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPSynchronizer.h; sourceTree = ""; }; + 16B0AF2B189DD3080072A725 /* HPSynchronizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPSynchronizer.m; sourceTree = ""; }; + 16B0AF2D189E07E80072A725 /* HPPadSynchronizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadSynchronizer.h; sourceTree = ""; }; + 16B0AF2E189E07E80072A725 /* HPPadSynchronizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadSynchronizer.m; sourceTree = ""; }; + 16B0AF71189F820F0072A725 /* HPCollectionSynchronizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPCollectionSynchronizer.h; sourceTree = ""; }; + 16B0AF72189F820F0072A725 /* HPCollectionSynchronizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPCollectionSynchronizer.m; sourceTree = ""; }; + 16B0AF74189F87E50072A725 /* HPSpaceSynchronizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPSpaceSynchronizer.h; sourceTree = ""; }; + 16B0AF75189F87E50072A725 /* HPSpaceSynchronizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPSpaceSynchronizer.m; sourceTree = ""; }; + 16B2D39916E7ED56006C20E6 /* HPBrowserViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPBrowserViewController.h; sourceTree = ""; }; + 16B2D39A16E7ED56006C20E6 /* HPBrowserViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPBrowserViewController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16B4AB5016F8FAD5007D0FAE /* HPSearchResultsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPSearchResultsController.h; sourceTree = ""; }; + 16B4AB5116F8FAD5007D0FAE /* HPSearchResultsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPSearchResultsController.m; sourceTree = ""; }; + 16B5ECDE17A73D42004E3815 /* WebViewJavascriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridge.h; sourceTree = ""; }; + 16B5ECDF17A73D42004E3815 /* WebViewJavascriptBridge.js.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebViewJavascriptBridge.js.txt; sourceTree = ""; }; + 16B5ECE017A73D42004E3815 /* WebViewJavascriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridge.m; sourceTree = ""; }; + 16B7EEC418932E4A00E8C574 /* pencilLove@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "pencilLove@2x.png"; sourceTree = ""; }; + 16B7EEC518932E4A00E8C574 /* pencilLove.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pencilLove.png; sourceTree = ""; }; + 16B7EECA18932E4A00E8C574 /* email-green.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "email-green.png"; sourceTree = ""; }; + 16B7EECB18932E4A00E8C574 /* email-green@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "email-green@2x.png"; sourceTree = ""; }; + 16B7EECC18932E4A00E8C574 /* password-green@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "password-green@2x.png"; sourceTree = ""; }; + 16B7EECD18932E4A00E8C574 /* password-green.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "password-green.png"; sourceTree = ""; }; + 16BD64D517BD801C0038B0D0 /* TestFlight+AsyncLogging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TestFlight+AsyncLogging.h"; sourceTree = ""; }; + 16BD64D617BD801C0038B0D0 /* TestFlight+ManualSessions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TestFlight+ManualSessions.h"; sourceTree = ""; }; + 16BE542818ABEB12003EBBCD /* Hackpad 12.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 12.xcdatamodel"; sourceTree = ""; }; + 16BE542918ABEEB5003EBBCD /* HPPad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPad.h; sourceTree = ""; }; + 16BE542A18ABEEB5003EBBCD /* HPPad.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPad.m; sourceTree = ""; }; + 16BEFCE116CEC01800419A2D /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; + 16CAF3F917444C2E0099310F /* FacebookSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = FacebookSDK.framework; sourceTree = SOURCE_ROOT; }; + 16CAF3FC17444C5E0099310F /* libTestFlight.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libTestFlight.a; sourceTree = ""; }; + 16CAF3FD17444C5E0099310F /* TestFlight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestFlight.h; sourceTree = ""; }; + 16CAF3FF17444CFE0099310F /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; + 16CAF40317444DF30099310F /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; }; + 16CB5E4017C54F0F00511849 /* HPCoreDataStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPCoreDataStack.h; sourceTree = ""; }; + 16CB5E4117C54F0F00511849 /* HPCoreDataStack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPCoreDataStack.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16CB5E5917C551A000511849 /* libHackpadKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libHackpadKit.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 16CB5E5D17C551A000511849 /* HackpadKit-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "HackpadKit-Prefix.pch"; sourceTree = ""; }; + 16CB5E6717C551A000511849 /* HackpadKitTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HackpadKitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; + 16CB5E7117C551A100511849 /* HackpadKitTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "HackpadKitTests-Info.plist"; sourceTree = ""; }; + 16CB5E7317C551A100511849 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 16CB5EAC17C5568500511849 /* HPCoreDataStackTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPCoreDataStackTestCase.h; sourceTree = ""; }; + 16CB5EAD17C5568500511849 /* HPCoreDataStackTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPCoreDataStackTestCase.m; sourceTree = ""; }; + 16CB5EAF17C556C600511849 /* HPImportTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPImportTests.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16CB5EB417C558C200511849 /* HackpadUIAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HackpadUIAdditions.h; sourceTree = ""; }; + 16CD47951868C865002635BA /* back.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = back.png; sourceTree = ""; }; + 16CD47961868C865002635BA /* back@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "back@2x.png"; sourceTree = ""; }; + 16CD47971868C865002635BA /* follow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = follow.png; sourceTree = ""; }; + 16CD47981868C865002635BA /* follow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "follow@2x.png"; sourceTree = ""; }; + 16CD47991868C865002635BA /* menu.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = menu.png; sourceTree = ""; }; + 16CD479A1868C865002635BA /* menu@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "menu@2x.png"; sourceTree = ""; }; + 16CD479B1868C865002635BA /* search.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = search.png; sourceTree = ""; }; + 16CD479C1868C865002635BA /* search@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "search@2x.png"; sourceTree = ""; }; + 16CD479D1868C865002635BA /* newpad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = newpad.png; sourceTree = ""; }; + 16CD479E1868C865002635BA /* newpad@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "newpad@2x.png"; sourceTree = ""; }; + 16CD47A91868CB88002635BA /* forward.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = forward.png; sourceTree = ""; }; + 16CD47AA1868CB88002635BA /* forward@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "forward@2x.png"; sourceTree = ""; }; + 16CD47AD1868FC56002635BA /* user.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = user.png; sourceTree = ""; }; + 16CD47AE1868FC56002635BA /* user@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "user@2x.png"; sourceTree = ""; }; + 16CD47AF1868FC56002635BA /* gear.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = gear.png; sourceTree = ""; }; + 16CD47B01868FC56002635BA /* gear@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "gear@2x.png"; sourceTree = ""; }; + 16CD47B11868FC56002635BA /* down-chevron.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "down-chevron.png"; sourceTree = ""; }; + 16CD47B21868FC56002635BA /* down-chevron@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "down-chevron@2x.png"; sourceTree = ""; }; + 16CD47B918691853002635BA /* up-chevron@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "up-chevron@2x.png"; sourceTree = ""; }; + 16CD47BA18691853002635BA /* up-chevron.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "up-chevron.png"; sourceTree = ""; }; + 16CF111E17D5ADD300C8FF10 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + 16D7A3BF177B7C8600CBC44C /* Hackpad.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = Hackpad.js; sourceTree = ""; }; + 16DE5C1F18725A460026D792 /* NSData+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+HackpadAdditions.h"; sourceTree = ""; }; + 16DE5C2018725A460026D792 /* NSData+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+HackpadAdditions.m"; sourceTree = ""; }; + 16E156D817E3C9710060B51E /* HPPadScopeTableViewDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadScopeTableViewDataSource.h; sourceTree = ""; }; + 16E156D917E3C9710060B51E /* HPPadScopeTableViewDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadScopeTableViewDataSource.m; sourceTree = ""; }; + 16E156DC17E3DCFE0060B51E /* HPPadScopeTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadScopeTests.m; sourceTree = ""; }; + 16E21640185B9974000FAA42 /* HPLog.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HPLog.h; sourceTree = ""; }; + 16E2165B185F6590000FAA42 /* NSURLRequestHackpadAdditionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSURLRequestHackpadAdditionsTests.m; sourceTree = ""; }; + 16E2165E185F9C78000FAA42 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; + 16E2165F185F9C78000FAA42 /* MBProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBProgressHUD.h; sourceTree = ""; }; + 16E21660185F9C78000FAA42 /* MBProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBProgressHUD.m; sourceTree = ""; }; + 16E6F4FA1887183C00FD7486 /* ProximaNova-Reg.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ProximaNova-Reg.otf"; sourceTree = ""; }; + 16E73BEC17CBBDFE0000A2E5 /* Hackpad 5.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Hackpad 5.xcdatamodel"; sourceTree = ""; }; + 16E73BF117CBE62D0000A2E5 /* HPReachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPReachability.h; sourceTree = ""; }; + 16E73BF217CBE62D0000A2E5 /* HPReachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPReachability.m; sourceTree = ""; }; + 16EB3DB71762C722004CE346 /* HPUserInfoCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPUserInfoCollection.h; sourceTree = ""; }; + 16EB3DB81762C722004CE346 /* HPUserInfoCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPUserInfoCollection.m; sourceTree = ""; }; + 16EB3DBA17655F12004CE346 /* HPUserInfosViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPUserInfosViewController.h; sourceTree = ""; }; + 16EB3DBB17655F12004CE346 /* HPUserInfosViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPUserInfosViewController.m; sourceTree = ""; }; + 16EB3DBD17656060004CE346 /* HPUserInfoImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPUserInfoImageView.h; sourceTree = ""; }; + 16EB3DBE17656060004CE346 /* HPUserInfoImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPUserInfoImageView.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16EB840B174C37A500A7DCD3 /* UIImage+Alpha.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Alpha.h"; sourceTree = ""; }; + 16EB840C174C37A500A7DCD3 /* UIImage+Alpha.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Alpha.m"; sourceTree = ""; }; + 16EB840D174C37A500A7DCD3 /* UIImage+Resize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Resize.h"; sourceTree = ""; }; + 16EB840E174C37A500A7DCD3 /* UIImage+Resize.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Resize.m"; sourceTree = ""; }; + 16EB840F174C37A500A7DCD3 /* UIImage+RoundedCorner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+RoundedCorner.h"; sourceTree = ""; }; + 16EB8410174C37A500A7DCD3 /* UIImage+RoundedCorner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+RoundedCorner.m"; sourceTree = ""; }; + 16EB889816C0688E00D90E14 /* HPCollection+Impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HPCollection+Impl.h"; sourceTree = ""; }; + 16EB889916C0688F00D90E14 /* HPCollection+Impl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "HPCollection+Impl.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16EB889B16C071DA00D90E14 /* HackpadKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HackpadKit.h; sourceTree = ""; }; + 16EB889C16C0724000D90E14 /* HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HackpadAdditions.h; sourceTree = ""; }; + 16EEDE92175929DF006C9FDB /* HPInvitationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPInvitationController.h; sourceTree = ""; }; + 16EEDE93175929DF006C9FDB /* HPInvitationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPInvitationController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16F1547F1824344100B481F0 /* HPImageUploadURLProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPImageUploadURLProtocol.h; sourceTree = ""; }; + 16F154801824344100B481F0 /* HPImageUploadURLProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPImageUploadURLProtocol.m; sourceTree = ""; }; + 16F4C1EA16B22520005CA606 /* GTMHTTPFetcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = GTMHTTPFetcher.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16F4C1EB16B22520005CA606 /* GTMHTTPFetcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMHTTPFetcher.h; sourceTree = ""; }; + 16F4C1EC16B22520005CA606 /* GTMOAuthAuthentication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMOAuthAuthentication.h; sourceTree = ""; }; + 16F4C1ED16B22520005CA606 /* GTMOAuthAuthentication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = GTMOAuthAuthentication.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16F54604175947ED00BD7754 /* AddressBookUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBookUI.framework; path = System/Library/Frameworks/AddressBookUI.framework; sourceTree = SDKROOT; }; + 16F54606175948DD00BD7754 /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; }; + 16F550C617E1641400305AEA /* HPPadTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPPadTests.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16F550C817E24BBA00305AEA /* hprecursiveblock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = hprecursiveblock.h; sourceTree = ""; }; + 16F550C917E24C6300305AEA /* hprecursiveblock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hprecursiveblock.c; sourceTree = ""; }; + 16F62A2D183B042D0095DE12 /* UIColor+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+HackpadAdditions.h"; sourceTree = ""; }; + 16F62A2E183B042D0095DE12 /* UIColor+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+HackpadAdditions.m"; sourceTree = ""; }; + 16F62A30183B35BA0095DE12 /* HPPadCellBackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPPadCellBackgroundView.h; sourceTree = ""; }; + 16F62A31183B35BA0095DE12 /* HPPadCellBackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPPadCellBackgroundView.m; sourceTree = ""; }; + 16F62D5F16C1B0B20034A6BD /* HPError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPError.h; sourceTree = ""; }; + 16F62D6016C1B0B20034A6BD /* HPError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPError.m; sourceTree = ""; }; + 16F62D6216C1B3590034A6BD /* HPSignInViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPSignInViewController.h; sourceTree = ""; }; + 16F62D6316C1B3590034A6BD /* HPSignInViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPSignInViewController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16F62D6516C1CBB80034A6BD /* UIWebView+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = "UIWebView+HackpadAdditions.h"; path = "HackpadAdditions/UIWebView+HackpadAdditions.h"; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + 16F62D6616C1CBB80034A6BD /* UIWebView+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = "UIWebView+HackpadAdditions.m"; path = "HackpadAdditions/UIWebView+HackpadAdditions.m"; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 16F6657817A05E3500362A8B /* HPAlertViewBlockDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HPAlertViewBlockDelegate.h; path = HackpadKit/HPAlertViewBlockDelegate.h; sourceTree = SOURCE_ROOT; }; + 16F6657917A05E3500362A8B /* HPAlertViewBlockDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HPAlertViewBlockDelegate.m; path = HackpadKit/HPAlertViewBlockDelegate.m; sourceTree = SOURCE_ROOT; }; + C322B9AC1772733B00A2F1CE /* site-switcher.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "site-switcher.png"; sourceTree = ""; }; + C327FDE515E57F9B002819C7 /* Hackpad.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Hackpad.app; sourceTree = BUILT_PRODUCTS_DIR; }; + C327FDE915E57F9B002819C7 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + C327FDEB15E57F9B002819C7 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + C327FDED15E57F9B002819C7 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + C327FDF115E57F9B002819C7 /* Hackpad-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Hackpad-Info.plist"; sourceTree = ""; }; + C327FDF315E57F9B002819C7 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + C327FDF515E57F9B002819C7 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + C327FDF715E57F9B002819C7 /* Hackpad-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "Hackpad-Prefix.pch"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + C327FDF815E57F9B002819C7 /* HPAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HPAppDelegate.h; sourceTree = ""; }; + C327FDF915E57F9B002819C7 /* HPAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPAppDelegate.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + C327FDFC15E57F9B002819C7 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard_iPhone.storyboard; sourceTree = ""; }; + C327FDFF15E57F9B002819C7 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard_iPad.storyboard; sourceTree = ""; }; + C327FE0115E57F9B002819C7 /* HPPadListViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HPPadListViewController.h; sourceTree = ""; }; + C327FE0215E57F9B002819C7 /* HPPadListViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPPadListViewController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + C327FE0415E57F9B002819C7 /* HPPadEditorViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HPPadEditorViewController.h; sourceTree = ""; }; + C327FE0515E57F9B002819C7 /* HPPadEditorViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPPadEditorViewController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + CE464E1A17E12586005227A9 /* HPSearchSnippetsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HPSearchSnippetsTests.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + CE464E1D17E1D138005227A9 /* NSAttributedString+DDHTML.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSAttributedString+DDHTML.h"; sourceTree = ""; }; + CE464E1E17E1D138005227A9 /* NSAttributedString+DDHTML.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSAttributedString+DDHTML.m"; sourceTree = ""; }; + CE464E2117E1D22D005227A9 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; }; + CE464E2617E1D935005227A9 /* NSAttributedString+HackpadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSAttributedString+HackpadAdditions.h"; sourceTree = ""; }; + CE464E2717E1D935005227A9 /* NSAttributedString+HackpadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSAttributedString+HackpadAdditions.m"; sourceTree = ""; }; + F096FE63180F79A900E7B1F5 /* Flurry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Flurry.h; sourceTree = ""; }; + F096FE66180F7B9100E7B1F5 /* HPFlurryEventKeys.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HPFlurryEventKeys.h; sourceTree = ""; }; + F0E3B637181FF13E008590C6 /* HPTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPTextFieldCell.h; sourceTree = ""; }; + F0E3B638181FF13E008590C6 /* HPTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPTextFieldCell.m; sourceTree = ""; }; + F0E3B639181FF13E008590C6 /* HPTextFieldCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HPTextFieldCell.xib; sourceTree = ""; }; + F0E3B63C181FF157008590C6 /* HPAddSpaceViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPAddSpaceViewController.h; sourceTree = ""; }; + F0E3B63D181FF157008590C6 /* HPAddSpaceViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HPAddSpaceViewController.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 160CA79717CFE54500DA1FA5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 160CA7D817CFE9F200DA1FA5 /* Accounts.framework in Frameworks */, + 160CA7D917CFE9F800DA1FA5 /* AddressBook.framework in Frameworks */, + 160CA7DA17CFE9F800DA1FA5 /* AddressBookUI.framework in Frameworks */, + 160CA7DE17CFEA5300DA1FA5 /* AdSupport.framework in Frameworks */, + 160CA7DF17CFEA5300DA1FA5 /* CoreData.framework in Frameworks */, + 160CA7E017CFEA5300DA1FA5 /* CoreGraphics.framework in Frameworks */, + 160CA7E717CFEA6C00DA1FA5 /* FacebookSDK.framework in Frameworks */, + 160CA7E117CFEA5300DA1FA5 /* Foundation.framework in Frameworks */, + 160CA7E217CFEA5300DA1FA5 /* libsqlite3.dylib in Frameworks */, + 160CA7E317CFEA5300DA1FA5 /* libz.dylib in Frameworks */, + 160CA7E417CFEA5300DA1FA5 /* Security.framework in Frameworks */, + 1645D5C117D9203900D74527 /* SenTestingKit.framework in Frameworks */, + 160CA7E517CFEA5300DA1FA5 /* Social.framework in Frameworks */, + 160CA7E617CFEA5300DA1FA5 /* SystemConfiguration.framework in Frameworks */, + 160CA7DD17CFEA0800DA1FA5 /* UIKit.framework in Frameworks */, + 160CA7FB17CFEBB100DA1FA5 /* libHackpadTestingKit.a in Frameworks */, + 160CA80517CFECD800DA1FA5 /* libOCMock.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 160CA7EA17CFEAD400DA1FA5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 160CA7EE17CFEAD400DA1FA5 /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 16CB5E5617C551A000511849 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 16CB5E5A17C551A000511849 /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 16CB5E6317C551A000511849 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 16CB5EA117C554AA00511849 /* Accounts.framework in Frameworks */, + 16CB5EA217C554AA00511849 /* AddressBook.framework in Frameworks */, + 16CB5EA317C554AA00511849 /* AddressBookUI.framework in Frameworks */, + 16CB5EA417C554AA00511849 /* AdSupport.framework in Frameworks */, + 16CB5EA017C5548200511849 /* CoreData.framework in Frameworks */, + 16CB5EA517C554AA00511849 /* CoreGraphics.framework in Frameworks */, + 16CB5EA617C554AA00511849 /* FacebookSDK.framework in Frameworks */, + 16CB5E6B17C551A000511849 /* Foundation.framework in Frameworks */, + 16CB5EA917C554AA00511849 /* Security.framework in Frameworks */, + 16AE68C317D91BD00031898F /* SenTestingKit.framework in Frameworks */, + 16CB5EAA17C554AA00511849 /* Social.framework in Frameworks */, + 16CB5EAB17C554AA00511849 /* SystemConfiguration.framework in Frameworks */, + 16CB5E6A17C551A000511849 /* UIKit.framework in Frameworks */, + 160CA80617CFECE300DA1FA5 /* libOCMock.a in Frameworks */, + 167E1E5117D91CB000AA30D9 /* libTestFlight.a in Frameworks */, + 16CB5E9F17C5547600511849 /* libsqlite3.dylib in Frameworks */, + 16BBF41E17F202BE00EFAE26 /* libxml2.dylib in Frameworks */, + 16CB5EA817C554AA00511849 /* libz.dylib in Frameworks */, + 160CA7FC17CFEBB700DA1FA5 /* libHackpadTestingKit.a in Frameworks */, + 160CA80F17CFF1DD00DA1FA5 /* libHackpadKit.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C327FDE215E57F9B002819C7 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 16F54607175948DD00BD7754 /* AddressBook.framework in Frameworks */, + 16F54605175947ED00BD7754 /* AddressBookUI.framework in Frameworks */, + 1654C70218A96BA4007238FD /* libFlurry_4.3.2.a in Frameworks */, + 16326934170CE773004C67EB /* Accounts.framework in Frameworks */, + 16326935170CE773004C67EB /* AdSupport.framework in Frameworks */, + 1627C50416B7547C00AA129F /* CoreData.framework in Frameworks */, + C327FDEE15E57F9B002819C7 /* CoreGraphics.framework in Frameworks */, + 16CAF3FA17444C2E0099310F /* FacebookSDK.framework in Frameworks */, + C327FDEC15E57F9B002819C7 /* Foundation.framework in Frameworks */, + 163968D71834617D00DC5A4F /* MessageUI.framework in Frameworks */, + 16BEFCE216CEC01900419A2D /* Security.framework in Frameworks */, + 16326936170CE773004C67EB /* Social.framework in Frameworks */, + 1663EFD316E6707A00356387 /* SystemConfiguration.framework in Frameworks */, + C327FDEA15E57F9B002819C7 /* UIKit.framework in Frameworks */, + 16CAF40417444DF30099310F /* libsqlite3.dylib in Frameworks */, + 16CAF3FE17444C5E0099310F /* libTestFlight.a in Frameworks */, + CE464E2517E1D494005227A9 /* libxml2.dylib in Frameworks */, + 16CAF40017444CFE0099310F /* libz.dylib in Frameworks */, + 16CB5E8217C5520A00511849 /* libHackpadKit.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 160845B916E925FF00D04253 /* RNCachingURLProtocol */ = { + isa = PBXGroup; + children = ( + 160845BA16E9261D00D04253 /* RNCachingURLProtocol.h */, + 160845BB16E9261D00D04253 /* RNCachingURLProtocol.m */, + ); + path = RNCachingURLProtocol; + sourceTree = SOURCE_ROOT; + }; + 160CA79F17CFE54500DA1FA5 /* HackpadTests */ = { + isa = PBXGroup; + children = ( + 160CA7AF17CFE6BD00DA1FA5 /* HPPadScopeTableViewDataSourceTests.m */, + 160CA7A017CFE54500DA1FA5 /* Supporting Files */, + ); + path = HackpadTests; + sourceTree = SOURCE_ROOT; + }; + 160CA7A017CFE54500DA1FA5 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 160CA7A117CFE54500DA1FA5 /* HackpadTests-Info.plist */, + 160CA7A217CFE54500DA1FA5 /* InfoPlist.strings */, + 160CA7A817CFE54500DA1FA5 /* HackpadTests-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 160CA7EF17CFEAD400DA1FA5 /* HackpadTestingKit */ = { + isa = PBXGroup; + children = ( + 166EF57D18A4A8BC00561F07 /* HPMigrationTestCase.m */, + 166EF57F18A4A8E400561F07 /* HPMigrationTestCase.h */, + 160CA7F217CFEAD400DA1FA5 /* HackpadTestingKit.h */, + 16CB5EAC17C5568500511849 /* HPCoreDataStackTestCase.h */, + 16CB5EAD17C5568500511849 /* HPCoreDataStackTestCase.m */, + 160CA85717CFFA6600DA1FA5 /* HPMockTestCase.h */, + 160CA85817CFFA6600DA1FA5 /* HPMockTestCase.m */, + 160CA7F017CFEAD400DA1FA5 /* Supporting Files */, + ); + path = HackpadTestingKit; + sourceTree = ""; + }; + 160CA7F017CFEAD400DA1FA5 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 160CA7F117CFEAD400DA1FA5 /* HackpadTestingKit-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 160CA7FD17CFECA100DA1FA5 /* OCMock */ = { + isa = PBXGroup; + children = ( + 160CA7FE17CFECA100DA1FA5 /* libOCMock.a */, + 160CA7FF17CFECA100DA1FA5 /* NSNotificationCenter+OCMAdditions.h */, + 160CA80017CFECA100DA1FA5 /* OCMArg.h */, + 160CA80117CFECA100DA1FA5 /* OCMConstraint.h */, + 160CA80217CFECA100DA1FA5 /* OCMock.h */, + 160CA80317CFECA100DA1FA5 /* OCMockObject.h */, + 160CA80417CFECA100DA1FA5 /* OCMockRecorder.h */, + ); + path = OCMock; + sourceTree = ""; + }; + 164E44141870F907002657E2 /* Fonts */ = { + isa = PBXGroup; + children = ( + 16E6F4FA1887183C00FD7486 /* ProximaNova-Reg.otf */, + 164E44151870F934002657E2 /* ProximaNova-Bold.otf */, + 164E44161870F934002657E2 /* ProximaNova-Light.otf */, + 164E44171870F934002657E2 /* ProximaNova-LightIt.otf */, + 164E44181870F934002657E2 /* ProximaNova-Sbold.otf */, + 164E44191870F934002657E2 /* ProximaNova-SboldIt.otf */, + 164E441A1870F934002657E2 /* ProximaNova-Xbold.otf */, + ); + path = Fonts; + sourceTree = ""; + }; + 1684192516B321CF004B663D /* Impl */ = { + isa = PBXGroup; + children = ( + 16EB889816C0688E00D90E14 /* HPCollection+Impl.h */, + 16EB889916C0688F00D90E14 /* HPCollection+Impl.m */, + 168786801822D8E10095428D /* HPImageUpload+Impl.h */, + 168786811822D8E10095428D /* HPImageUpload+Impl.m */, + 16A2785916BA0D09004D4E81 /* HPPad+Impl.h */, + 16A2785A16BA0D09004D4E81 /* HPPad+Impl.m */, + 163FA437173AB13B007746E0 /* HPSharingOptions+Impl.h */, + 163FA438173AB13B007746E0 /* HPSharingOptions+Impl.m */, + 16A2784D16B9EEA9004D4E81 /* HPSpace+Impl.h */, + 16A2784E16B9EEA9004D4E81 /* HPSpace+Impl.m */, + ); + name = Impl; + sourceTree = ""; + }; + 1684192C16B35638004B663D /* Interface */ = { + isa = PBXGroup; + children = ( + 164045881858D60D00D02B59 /* PadCell.xib */, + 160D04AB174AA92100C98325 /* Acknowledgements.txt */, + C327FDFE15E57F9B002819C7 /* MainStoryboard_iPad.storyboard */, + C327FDFB15E57F9B002819C7 /* MainStoryboard_iPhone.storyboard */, + 16085C1A16D57D2300C81DB4 /* Settings.bundle */, + 160D04A1174A98F200C98325 /* SignIn_iPad.storyboard */, + 160D04B0174AED1100C98325 /* SignIn_iPhone.storyboard */, + ); + name = Interface; + sourceTree = ""; + }; + 1684192D16B35656004B663D /* Views */ = { + isa = PBXGroup; + children = ( + 165C59D917B34B47001006D4 /* HPColoredAppearanceContainer.h */, + 1642A52D18359F8B00FADDFE /* HPGroupedToolbar.h */, + 1642A52E18359F8B00FADDFE /* HPGroupedToolbar.m */, + 167DEF7A17723DA100BE090C /* HPPadCell.h */, + 167DEF7B17723DA100BE090C /* HPPadCell.m */, + 16F62A30183B35BA0095DE12 /* HPPadCellBackgroundView.h */, + 16F62A31183B35BA0095DE12 /* HPPadCellBackgroundView.m */, + 16650D0616A0977F00452A1F /* HPPadCollectionCell.h */, + 16650D0716A0977F00452A1F /* HPPadCollectionCell.m */, + 165AA1731880A29600C7C80F /* HPPopoverLayoutFixTableView.h */, + 165AA1741880A29600C7C80F /* HPPopoverLayoutFixTableView.m */, + 16919C80187C6F6D00EDF5AE /* HPSpaceCell.h */, + 16919C81187C6F6D00EDF5AE /* HPSpaceCell.m */, + 160E576317666F4100C063D8 /* HPUserInfoCell.h */, + 160E576417666F4100C063D8 /* HPUserInfoCell.m */, + 16EB3DBD17656060004CE346 /* HPUserInfoImageView.h */, + 16EB3DBE17656060004CE346 /* HPUserInfoImageView.m */, + ); + name = Views; + sourceTree = ""; + }; + 1684192E16B35668004B663D /* Controllers */ = { + isa = PBXGroup; + children = ( + F0E3B63F181FF164008590C6 /* Add Space */, + 168A196917EFED5B00A990F4 /* HPActionSheetBlockDelegate.h */, + 168A196A17EFED5B00A990F4 /* HPActionSheetBlockDelegate.m */, + 16F6657817A05E3500362A8B /* HPAlertViewBlockDelegate.h */, + 16F6657917A05E3500362A8B /* HPAlertViewBlockDelegate.m */, + 165C59D317B34782001006D4 /* HPBlueNavigationController.h */, + 165C59D417B34782001006D4 /* HPBlueNavigationController.m */, + 16B2D39916E7ED56006C20E6 /* HPBrowserViewController.h */, + 16B2D39A16E7ED56006C20E6 /* HPBrowserViewController.m */, + 165AA16A187F2FC800C7C80F /* HPCancelFreeSearchDisplayController.h */, + 165AA16B187F2FC800C7C80F /* HPCancelFreeSearchDisplayController.m */, + 1636245D17025B9B00367769 /* HPDrawerController.h */, + 1636245C17025B9B00367769 /* HPDrawerController.m */, + 165AA16D187F360900C7C80F /* HPEmptySearchViewController.h */, + 165AA16E187F360900C7C80F /* HPEmptySearchViewController.m */, + 16AA8C55171778A800155C8F /* HPGoogleSignInViewController.h */, + 16AA8C57171778CE00155C8F /* HPGoogleSignInViewController.m */, + 165C59D617B347A3001006D4 /* HPGrayNavigationController.h */, + 165C59D717B347A4001006D4 /* HPGrayNavigationController.m */, + 16EEDE92175929DF006C9FDB /* HPInvitationController.h */, + 16EEDE93175929DF006C9FDB /* HPInvitationController.m */, + 169B0F54169E635800B65E11 /* HPPadCollectionViewController.h */, + 169B0F55169E635800B65E11 /* HPPadCollectionViewController.m */, + C327FE0415E57F9B002819C7 /* HPPadEditorViewController.h */, + C327FE0515E57F9B002819C7 /* HPPadEditorViewController.m */, + C327FE0115E57F9B002819C7 /* HPPadListViewController.h */, + C327FE0215E57F9B002819C7 /* HPPadListViewController.m */, + 163623DF16FA50ED00367769 /* HPPadScopeViewController.h */, + 163623E016FA50ED00367769 /* HPPadScopeViewController.m */, + 16650D0D16A0DF6600452A1F /* HPPadSharingViewController.h */, + 16650D0E16A0DF6600452A1F /* HPPadSharingViewController.m */, + 16AE8FE317BD7A1A0065020C /* HPPadSplitViewController.h */, + 16AE8FE417BD7A1A0065020C /* HPPadSplitViewController.m */, + 16B4AB5016F8FAD5007D0FAE /* HPSearchResultsController.h */, + 16B4AB5116F8FAD5007D0FAE /* HPSearchResultsController.m */, + 16233844170B865100E2252C /* HPSignInController.h */, + 16233845170B865100E2252C /* HPSignInController.m */, + 16F62D6216C1B3590034A6BD /* HPSignInViewController.h */, + 16F62D6316C1B3590034A6BD /* HPSignInViewController.m */, + 16EB3DBA17655F12004CE346 /* HPUserInfosViewController.h */, + 16EB3DBB17655F12004CE346 /* HPUserInfosViewController.m */, + 166E7D14183AC44D00C82013 /* HPWhiteNavigationController.h */, + 166E7D15183AC44D00C82013 /* HPWhiteNavigationController.m */, + 16D7A3B8177B7A2100CBC44C /* JavaScript */, + ); + name = Controllers; + sourceTree = ""; + }; + 1697EC5F16EA985500B7D241 /* Schema & Migrations */ = { + isa = PBXGroup; + children = ( + 167DEF6F17710FB300BE090C /* Hackpad.xcdatamodeld */, + 169B4EC316EABA290051E197 /* HPEntityMigrationPolicy.h */, + 169B4EC416EABA290051E197 /* HPEntityMigrationPolicy.m */, + ); + name = "Schema & Migrations"; + sourceTree = ""; + }; + 16A9CC3716963D25004EED16 /* HackpadAdditions */ = { + isa = PBXGroup; + children = ( + 16EB889C16C0724000D90E14 /* HackpadAdditions.h */, + 16F550C917E24C6300305AEA /* hprecursiveblock.c */, + 16F550C817E24BBA00305AEA /* hprecursiveblock.h */, + CE464E2617E1D935005227A9 /* NSAttributedString+HackpadAdditions.h */, + CE464E2717E1D935005227A9 /* NSAttributedString+HackpadAdditions.m */, + 16DE5C1F18725A460026D792 /* NSData+HackpadAdditions.h */, + 16DE5C2018725A460026D792 /* NSData+HackpadAdditions.m */, + 16A8417B17D1AC35007BEE69 /* NSError+HackpadAdditions.h */, + 16A8417C17D1AC35007BEE69 /* NSError+HackpadAdditions.m */, + 16085C0E16D4631B00C81DB4 /* NSManagedObject+HackpadAdditions.h */, + 16085C0F16D4631B00C81DB4 /* NSManagedObject+HackpadAdditions.m */, + 160129F617D9638C002B42AA /* NSManagedObjectContext+HackpadAdditions.h */, + 160129F717D9638C002B42AA /* NSManagedObjectContext+HackpadAdditions.m */, + 167F40CB169F9F840091A089 /* NSString+HackpadAdditions.h */, + 167F40CC169F9F840091A089 /* NSString+HackpadAdditions.m */, + 16A9CC3016963B56004EED16 /* NSURL+HackpadAdditions.h */, + 16A9CC3116963B56004EED16 /* NSURL+HackpadAdditions.m */, + 1653DFEE171CB62400F33460 /* NSURLRequest+HackpadAdditions.h */, + 1653DFEF171CB62400F33460 /* NSURLRequest+HackpadAdditions.m */, + 168786711821B4E30095428D /* NSURLResponse+HackpadAdditions.h */, + 168786721821B4E30095428D /* NSURLResponse+HackpadAdditions.m */, + ); + path = HackpadAdditions; + sourceTree = SOURCE_ROOT; + }; + 16B5ECDD17A73D41004E3815 /* WebViewJavascriptBridge */ = { + isa = PBXGroup; + children = ( + 16B5ECDE17A73D42004E3815 /* WebViewJavascriptBridge.h */, + 16B5ECDF17A73D42004E3815 /* WebViewJavascriptBridge.js.txt */, + 16B5ECE017A73D42004E3815 /* WebViewJavascriptBridge.m */, + ); + path = WebViewJavascriptBridge; + sourceTree = ""; + }; + 16BEFCE016CEB7CD00419A2D /* Apple Sample Code */ = { + isa = PBXGroup; + children = ( + 16085C1416D53FE200C81DB4 /* KeychainItemWrapper.h */, + 16085C1516D53FE200C81DB4 /* KeychainItemWrapper.m */, + 1663EFD416E670C600356387 /* Reachability.h */, + 1663EFD516E670C600356387 /* Reachability.m */, + ); + name = "Apple Sample Code"; + path = AppleSampleCode; + sourceTree = SOURCE_ROOT; + }; + 16CAF3FB17444C5E0099310F /* TestFlight */ = { + isa = PBXGroup; + children = ( + 16CAF3FC17444C5E0099310F /* libTestFlight.a */, + 16BD64D517BD801C0038B0D0 /* TestFlight+AsyncLogging.h */, + 16BD64D617BD801C0038B0D0 /* TestFlight+ManualSessions.h */, + 16CAF3FD17444C5E0099310F /* TestFlight.h */, + ); + path = TestFlight; + sourceTree = ""; + }; + 16CB5E5C17C551A000511849 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 16CB5E5D17C551A000511849 /* HackpadKit-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 16CB5E6F17C551A000511849 /* HackpadKitTests */ = { + isa = PBXGroup; + children = ( + 16A890ED186E33C10014EF45 /* HPAPITests.m */, + 16A760C718AEA35000821DB3 /* HPMigrationTests.m */, + 16CB5EAF17C556C600511849 /* HPImportTests.m */, + 16E156DC17E3DCFE0060B51E /* HPPadScopeTests.m */, + 16F550C617E1641400305AEA /* HPPadTests.m */, + CE464E1A17E12586005227A9 /* HPSearchSnippetsTests.m */, + 16E2165B185F6590000FAA42 /* NSURLRequestHackpadAdditionsTests.m */, + 16CB5E7017C551A100511849 /* Supporting Files */, + ); + path = HackpadKitTests; + sourceTree = ""; + }; + 16CB5E7017C551A100511849 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 166EF56618A444E800561F07 /* Hackpad10.sqlite */, + 166EF58918A4C5C200561F07 /* Hackpad11.sqlite */, + 163489C218AC064E004972CB /* Hackpad12.sqlite */, + 16A760BD18ADB19100821DB3 /* Hackpad13.sqlite */, + 16A760C518AEA2F900821DB3 /* Hackpad14.sqlite */, + 16A760D118AEF37100821DB3 /* Hackpad15.sqlite */, + 166EF57918A466A900561F07 /* Hackpad9.sqlite */, + 16CB5E7117C551A100511849 /* HackpadKitTests-Info.plist */, + 16CB5E7217C551A100511849 /* InfoPlist.strings */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 16CB5EB317C5587E00511849 /* HackpadUIAdditions */ = { + isa = PBXGroup; + children = ( + 16CB5EB417C558C200511849 /* HackpadUIAdditions.h */, + 16F62A2D183B042D0095DE12 /* UIColor+HackpadAdditions.h */, + 16F62A2E183B042D0095DE12 /* UIColor+HackpadAdditions.m */, + 1667ACC017D0609100F777EE /* UIDevice+HackpadAdditions.h */, + 1667ACC117D0609100F777EE /* UIDevice+HackpadAdditions.m */, + 160C17C61861212600CC68DA /* UIFont+HackpadAdditions.h */, + 160C17C71861212600CC68DA /* UIFont+HackpadAdditions.m */, + 16060B4F172AED9C00451986 /* UIView+HackpadAdditions.h */, + 16060B50172AED9C00451986 /* UIView+HackpadAdditions.m */, + 165AA170187F6E7A00C7C80F /* UIViewController+HackpadAdditions.h */, + 165AA171187F6E7A00C7C80F /* UIViewController+HackpadAdditions.m */, + 16F62D6516C1CBB80034A6BD /* UIWebView+HackpadAdditions.h */, + 16F62D6616C1CBB80034A6BD /* UIWebView+HackpadAdditions.m */, + ); + name = HackpadUIAdditions; + path = HackpadAdditions; + sourceTree = SOURCE_ROOT; + }; + 16D7A3B8177B7A2100CBC44C /* JavaScript */ = { + isa = PBXGroup; + children = ( + 1673C04317986DCD005FED08 /* GetSnippetHeight.js */, + 16D7A3BF177B7C8600CBC44C /* Hackpad.js */, + ); + name = JavaScript; + sourceTree = ""; + }; + 16D9611B173445670043BD7C /* Icons */ = { + isa = PBXGroup; + children = ( + 16A760CB18AEB9DD00821DB3 /* separator.png */, + 16A760C918AEB82F00821DB3 /* separator@2x.png */, + 16CD47951868C865002635BA /* back.png */, + 16CD47961868C865002635BA /* back@2x.png */, + 165C59CC17B32CCB001006D4 /* bluebg.png */, + 169DD88B1832F27200D0D528 /* bold.png */, + 169DD88C1832F27200D0D528 /* bold@2x.png */, + 169DD86B1832F27100D0D528 /* bullet.png */, + 169DD86C1832F27100D0D528 /* bullet@2x.png */, + 1691CC951899686000CF121C /* check-green.png */, + 1691CC961899686000CF121C /* check-green@2x.png */, + 169DD8671832F27100D0D528 /* check.png */, + 169DD8681832F27100D0D528 /* check@2x.png */, + 16650D0316A093BB00452A1F /* checked.png */, + 1699F70F183C114E001DAC1D /* clearback.png */, + 1699F70B183C10C8001DAC1D /* clearback@2x.png */, + 1699F70D183C114E001DAC1D /* clearbacklandscape.png */, + 1699F70E183C114E001DAC1D /* clearbacklandscape@2x.png */, + 169DD88D1832F27200D0D528 /* close.png */, + 169DD88E1832F27200D0D528 /* close@2x.png */, + 169DD8911832F27200D0D528 /* comment.png */, + 169DD8921832F27200D0D528 /* comment@2x.png */, + 1699F709183C0F36001DAC1D /* darkgreenbg.png */, + 168DD541189857D0003E01BF /* dot44.png */, + 168DD540189857D0003E01BF /* dot44@2x.png */, + 16CD47B11868FC56002635BA /* down-chevron.png */, + 16CD47B21868FC56002635BA /* down-chevron@2x.png */, + 169DD8771832F27100D0D528 /* dropbox.png */, + 169DD8781832F27100D0D528 /* dropbox@2x.png */, + 169DD8641832D77200D0D528 /* editorbg.png */, + 164B505D1893569F005DCFDE /* email-button-white.png */, + 164B505E1893569F005DCFDE /* email-button-white@2x.png */, + 16B7EECA18932E4A00E8C574 /* email-green.png */, + 16B7EECB18932E4A00E8C574 /* email-green@2x.png */, + 164B507218971370005DCFDE /* facebook44.png */, + 164B507118971370005DCFDE /* facebook44@2x.png */, + 16CD47971868C865002635BA /* follow.png */, + 16CD47981868C865002635BA /* follow@2x.png */, + 16CD47A91868CB88002635BA /* forward.png */, + 16CD47AA1868CB88002635BA /* forward@2x.png */, + 16CD47AF1868FC56002635BA /* gear.png */, + 16CD47B01868FC56002635BA /* gear@2x.png */, + 164B5076189714A2005DCFDE /* google44.png */, + 164B5075189714A2005DCFDE /* google44@2x.png */, + 165C59CE17B331F5001006D4 /* graybg.png */, + 169DD8631832D77200D0D528 /* groupbg.png */, + 169DD8831832F27100D0D528 /* header1.png */, + 169DD8841832F27100D0D528 /* header1@2x.png */, + 169DD8811832F27100D0D528 /* header2.png */, + 169DD8821832F27100D0D528 /* header2@2x.png */, + 169DD87F1832F27100D0D528 /* header3.png */, + 169DD8801832F27100D0D528 /* header3@2x.png */, + 16CF111E17D5ADD300C8FF10 /* Images.xcassets */, + 169DD8711832F27100D0D528 /* indent.png */, + 169DD8721832F27100D0D528 /* indent@2x.png */, + 169DD88F1832F27200D0D528 /* insert.png */, + 169DD8901832F27200D0D528 /* insert@2x.png */, + 169DD8891832F27200D0D528 /* italic.png */, + 169DD88A1832F27200D0D528 /* italic@2x.png */, + 169DD8791832F27100D0D528 /* link.png */, + 169DD87A1832F27100D0D528 /* link@2x.png */, + 169DD8751832F27100D0D528 /* mention.png */, + 169DD8761832F27100D0D528 /* mention@2x.png */, + 16CD47991868C865002635BA /* menu.png */, + 16CD479A1868C865002635BA /* menu@2x.png */, + 16CD479D1868C865002635BA /* newpad.png */, + 16CD479E1868C865002635BA /* newpad@2x.png */, + 16A55F4417601260001ED006 /* nophoto.png */, + 169DD8691832F27100D0D528 /* number.png */, + 169DD86A1832F27100D0D528 /* number@2x.png */, + 16A55F72176140D9001ED006 /* online.png */, + 16A55F73176140D9001ED006 /* online@2x.png */, + 169DD86F1832F27100D0D528 /* outdent.png */, + 169DD8701832F27100D0D528 /* outdent@2x.png */, + 169DD86D1832F27100D0D528 /* paragraph.png */, + 169DD86E1832F27100D0D528 /* paragraph@2x.png */, + 16B7EECD18932E4A00E8C574 /* password-green.png */, + 16B7EECC18932E4A00E8C574 /* password-green@2x.png */, + 16B7EEC518932E4A00E8C574 /* pencilLove.png */, + 16B7EEC418932E4A00E8C574 /* pencilLove@2x.png */, + 169DD87D1832F27100D0D528 /* photo.png */, + 169DD87E1832F27100D0D528 /* photo@2x.png */, + 16CD479B1868C865002635BA /* search.png */, + 16CD479C1868C865002635BA /* search@2x.png */, + C322B9AC1772733B00A2F1CE /* site-switcher.png */, + 169DD8851832F27100D0D528 /* strikethrough.png */, + 169DD8861832F27100D0D528 /* strikethrough@2x.png */, + 169DD87B1832F27100D0D528 /* table.png */, + 169DD87C1832F27100D0D528 /* table@2x.png */, + 169DD8731832F27100D0D528 /* tag.png */, + 169DD8741832F27100D0D528 /* tag@2x.png */, + 169DD8931832F27200D0D528 /* textformat.png */, + 169DD8941832F27200D0D528 /* textformat@2x.png */, + 16650D0916A0C96C00452A1F /* unchecked.png */, + 169DD8871832F27100D0D528 /* underline.png */, + 169DD8881832F27200D0D528 /* underline@2x.png */, + 16CD47BA18691853002635BA /* up-chevron.png */, + 16CD47B918691853002635BA /* up-chevron@2x.png */, + 164B506E1893600D005DCFDE /* user-green.png */, + 164B506D1893600D005DCFDE /* user-green@2x.png */, + 16CD47AD1868FC56002635BA /* user.png */, + 16CD47AE1868FC56002635BA /* user@2x.png */, + 166E7D18183ACA5D00C82013 /* whiteback.png */, + 166E7D19183ACA5D00C82013 /* whiteback@2x.png */, + 166E7D17183ACA5D00C82013 /* whitebg.png */, + 1691CC941899686000CF121C /* x-red.png */, + 1691CC971899686000CF121C /* x-red@2x.png */, + ); + path = Icons; + sourceTree = SOURCE_ROOT; + }; + 16E156DB17E3C9790060B51E /* DataSources */ = { + isa = PBXGroup; + children = ( + 168905EF182D6D81002D95F2 /* HPInvitationTableViewDataSource.h */, + 168905F0182D6D81002D95F2 /* HPInvitationTableViewDataSource.m */, + 16A370A218284E2400731484 /* HPPadAutocompleteTableViewDataSource.h */, + 16A370A318284E2400731484 /* HPPadAutocompleteTableViewDataSource.m */, + 16E156D817E3C9710060B51E /* HPPadScopeTableViewDataSource.h */, + 16E156D917E3C9710060B51E /* HPPadScopeTableViewDataSource.m */, + 168A196C17EFF40700A990F4 /* HPPadSearchTableViewDataSource.h */, + 168A196D17EFF40700A990F4 /* HPPadSearchTableViewDataSource.m */, + 168A196617EFE6A900A990F4 /* HPPadTableViewDataSource.h */, + 168A196717EFE6A900A990F4 /* HPPadTableViewDataSource.m */, + ); + name = DataSources; + sourceTree = ""; + }; + 16E2165D185F9C78000FAA42 /* MBProgressHUD */ = { + isa = PBXGroup; + children = ( + 16E2165E185F9C78000FAA42 /* LICENSE */, + 16E2165F185F9C78000FAA42 /* MBProgressHUD.h */, + 16E21660185F9C78000FAA42 /* MBProgressHUD.m */, + ); + path = MBProgressHUD; + sourceTree = ""; + }; + 16EB840A174C37A500A7DCD3 /* vocaro.com */ = { + isa = PBXGroup; + children = ( + 16EB840B174C37A500A7DCD3 /* UIImage+Alpha.h */, + 16EB840C174C37A500A7DCD3 /* UIImage+Alpha.m */, + 16EB840D174C37A500A7DCD3 /* UIImage+Resize.h */, + 16EB840E174C37A500A7DCD3 /* UIImage+Resize.m */, + 16EB840F174C37A500A7DCD3 /* UIImage+RoundedCorner.h */, + 16EB8410174C37A500A7DCD3 /* UIImage+RoundedCorner.m */, + ); + path = vocaro.com; + sourceTree = ""; + }; + 16EB888E16C0351400D90E14 /* Generated Models */ = { + isa = PBXGroup; + children = ( + 164A86D517680324006C7174 /* HPCollection.h */, + 164A86D617680324006C7174 /* HPCollection.m */, + 16A760C018AE9E9800821DB3 /* HPImageUpload.h */, + 16A760C118AE9E9800821DB3 /* HPImageUpload.m */, + 16BE542918ABEEB5003EBBCD /* HPPad.h */, + 16BE542A18ABEEB5003EBBCD /* HPPad.m */, + 166EF58418A4B36000561F07 /* HPPadEditor.h */, + 166EF58518A4B36000561F07 /* HPPadEditor.m */, + 166C112017F25FFC0004DF6E /* HPPadSearch.h */, + 166C112117F25FFC0004DF6E /* HPPadSearch.m */, + 164A86DB17680324006C7174 /* HPSharingOptions.h */, + 164A86DC17680324006C7174 /* HPSharingOptions.m */, + 16A760CE18AEEEF600821DB3 /* HPSpace.h */, + 16A760CF18AEEEF600821DB3 /* HPSpace.m */, + ); + name = "Generated Models"; + sourceTree = ""; + }; + 16EB889516C03A4400D90E14 /* HackpadKit */ = { + isa = PBXGroup; + children = ( + 16EB888E16C0351400D90E14 /* Generated Models */, + 16A9CC3716963D25004EED16 /* HackpadAdditions */, + 16EB889B16C071DA00D90E14 /* HackpadKit.h */, + 16A85D1F16CC289C003DE09D /* HPAPI.h */, + 16A85D2016CC289C003DE09D /* HPAPI.m */, + 16B0AF71189F820F0072A725 /* HPCollectionSynchronizer.h */, + 16B0AF72189F820F0072A725 /* HPCollectionSynchronizer.m */, + 16CB5E4017C54F0F00511849 /* HPCoreDataStack.h */, + 16CB5E4117C54F0F00511849 /* HPCoreDataStack.m */, + 16F62D5F16C1B0B20034A6BD /* HPError.h */, + 16F62D6016C1B0B20034A6BD /* HPError.m */, + 16F1547F1824344100B481F0 /* HPImageUploadURLProtocol.h */, + 16F154801824344100B481F0 /* HPImageUploadURLProtocol.m */, + 16E21640185B9974000FAA42 /* HPLog.h */, + 1699003216C9A7FC00F1408A /* HPPadCacheController.h */, + 1699003316C9A7FC00F1408A /* HPPadCacheController.m */, + 1623383C1709F4AA00E2252C /* HPPadScope.h */, + 1623383D1709F4AA00E2252C /* HPPadScope.m */, + 16B0AF2D189E07E80072A725 /* HPPadSynchronizer.h */, + 16B0AF2E189E07E80072A725 /* HPPadSynchronizer.m */, + 160428881811EA8C00D8D41C /* HPPadWebController.h */, + 160428891811EA8C00D8D41C /* HPPadWebController.m */, + 16E73BF117CBE62D0000A2E5 /* HPReachability.h */, + 16E73BF217CBE62D0000A2E5 /* HPReachability.m */, + 1605D85117D44A060057CE4A /* HPRollbackDeletedObjectsMergePolicy.h */, + 1605D85217D44A060057CE4A /* HPRollbackDeletedObjectsMergePolicy.m */, + 16B0AF74189F87E50072A725 /* HPSpaceSynchronizer.h */, + 16B0AF75189F87E50072A725 /* HPSpaceSynchronizer.m */, + 160845BD16E9275D00D04253 /* HPStaticCachingURLProtocol.h */, + 160845BE16E9275D00D04253 /* HPStaticCachingURLProtocol.m */, + 16B0AF2A189DD3080072A725 /* HPSynchronizer.h */, + 16B0AF2B189DD3080072A725 /* HPSynchronizer.m */, + 160E57601766551B00C063D8 /* HPUserInfo.h */, + 160E57611766551B00C063D8 /* HPUserInfo.m */, + 16EB3DB71762C722004CE346 /* HPUserInfoCollection.h */, + 16EB3DB81762C722004CE346 /* HPUserInfoCollection.m */, + 1684192516B321CF004B663D /* Impl */, + 1697EC5F16EA985500B7D241 /* Schema & Migrations */, + 16CB5E5C17C551A000511849 /* Supporting Files */, + ); + path = HackpadKit; + sourceTree = SOURCE_ROOT; + }; + 16F4C1E916B224FE005CA606 /* Google Toolbox for Mac */ = { + isa = PBXGroup; + children = ( + 16085C0A16D460BA00C81DB4 /* GTMDefines.h */, + 16F4C1EB16B22520005CA606 /* GTMHTTPFetcher.h */, + 16F4C1EA16B22520005CA606 /* GTMHTTPFetcher.m */, + 16085C0C16D460BA00C81DB4 /* GTMNSString+HTML.h */, + 16085C0B16D460BA00C81DB4 /* GTMNSString+HTML.m */, + 16F4C1EC16B22520005CA606 /* GTMOAuthAuthentication.h */, + 16F4C1ED16B22520005CA606 /* GTMOAuthAuthentication.m */, + ); + name = "Google Toolbox for Mac"; + path = GoogleToolbox; + sourceTree = SOURCE_ROOT; + }; + C327FDDA15E57F9B002819C7 = { + isa = PBXGroup; + children = ( + C327FDEF15E57F9B002819C7 /* Hackpad */, + 160CA79F17CFE54500DA1FA5 /* HackpadTests */, + 16EB889516C03A4400D90E14 /* HackpadKit */, + 160CA7EF17CFEAD400DA1FA5 /* HackpadTestingKit */, + 16CB5E6F17C551A000511849 /* HackpadKitTests */, + 164E44141870F907002657E2 /* Fonts */, + 16D9611B173445670043BD7C /* Icons */, + 16BEFCE016CEB7CD00419A2D /* Apple Sample Code */, + F096FE62180F79A900E7B1F5 /* Flurry */, + 16F4C1E916B224FE005CA606 /* Google Toolbox for Mac */, + 16E2165D185F9C78000FAA42 /* MBProgressHUD */, + CE464E1C17E1D01D005227A9 /* NSAttributedString+DDHTML */, + 160CA7FD17CFECA100DA1FA5 /* OCMock */, + 160845B916E925FF00D04253 /* RNCachingURLProtocol */, + 16CAF3FB17444C5E0099310F /* TestFlight */, + 16EB840A174C37A500A7DCD3 /* vocaro.com */, + 16B5ECDD17A73D41004E3815 /* WebViewJavascriptBridge */, + C327FDE815E57F9B002819C7 /* Frameworks */, + C327FDE615E57F9B002819C7 /* Products */, + ); + sourceTree = ""; + }; + C327FDE615E57F9B002819C7 /* Products */ = { + isa = PBXGroup; + children = ( + C327FDE515E57F9B002819C7 /* Hackpad.app */, + 16CB5E5917C551A000511849 /* libHackpadKit.a */, + 16CB5E6717C551A000511849 /* HackpadKitTests.octest */, + 160CA79B17CFE54500DA1FA5 /* HackpadTests.octest */, + 160CA7ED17CFEAD400DA1FA5 /* libHackpadTestingKit.a */, + ); + name = Products; + sourceTree = ""; + }; + C327FDE815E57F9B002819C7 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 163968D61834617D00DC5A4F /* MessageUI.framework */, + 16326931170CE773004C67EB /* Accounts.framework */, + 16F54606175948DD00BD7754 /* AddressBook.framework */, + 16F54604175947ED00BD7754 /* AddressBookUI.framework */, + 16326932170CE773004C67EB /* AdSupport.framework */, + 1627C50316B7547C00AA129F /* CoreData.framework */, + C327FDED15E57F9B002819C7 /* CoreGraphics.framework */, + 16CAF3F917444C2E0099310F /* FacebookSDK.framework */, + C327FDEB15E57F9B002819C7 /* Foundation.framework */, + 16CAF40317444DF30099310F /* libsqlite3.dylib */, + CE464E2117E1D22D005227A9 /* libxml2.dylib */, + 16CAF3FF17444CFE0099310F /* libz.dylib */, + 16BEFCE116CEC01800419A2D /* Security.framework */, + 16AE68C017D91BA50031898F /* SenTestingKit.framework */, + 16326933170CE773004C67EB /* Social.framework */, + 1663EFD216E6707A00356387 /* SystemConfiguration.framework */, + C327FDE915E57F9B002819C7 /* UIKit.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + C327FDEF15E57F9B002819C7 /* Hackpad */ = { + isa = PBXGroup; + children = ( + 1684192E16B35668004B663D /* Controllers */, + 16E156DB17E3C9790060B51E /* DataSources */, + 16CB5EB317C5587E00511849 /* HackpadUIAdditions */, + C327FDF815E57F9B002819C7 /* HPAppDelegate.h */, + C327FDF915E57F9B002819C7 /* HPAppDelegate.m */, + F096FE66180F7B9100E7B1F5 /* HPFlurryEventKeys.h */, + 1684192C16B35638004B663D /* Interface */, + C327FDF015E57F9B002819C7 /* Supporting Files */, + 1684192D16B35656004B663D /* Views */, + ); + path = Hackpad; + sourceTree = SOURCE_ROOT; + }; + C327FDF015E57F9B002819C7 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + C327FDF115E57F9B002819C7 /* Hackpad-Info.plist */, + C327FDF215E57F9B002819C7 /* InfoPlist.strings */, + C327FDF515E57F9B002819C7 /* main.m */, + C327FDF715E57F9B002819C7 /* Hackpad-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + CE464E1C17E1D01D005227A9 /* NSAttributedString+DDHTML */ = { + isa = PBXGroup; + children = ( + CE464E1D17E1D138005227A9 /* NSAttributedString+DDHTML.h */, + CE464E1E17E1D138005227A9 /* NSAttributedString+DDHTML.m */, + ); + path = "NSAttributedString+DDHTML"; + sourceTree = ""; + }; + F096FE62180F79A900E7B1F5 /* Flurry */ = { + isa = PBXGroup; + children = ( + F096FE63180F79A900E7B1F5 /* Flurry.h */, + 1654C70018A96B20007238FD /* libFlurry_4.3.2.a */, + ); + path = Flurry; + sourceTree = ""; + }; + F0E3B63F181FF164008590C6 /* Add Space */ = { + isa = PBXGroup; + children = ( + F0E3B63C181FF157008590C6 /* HPAddSpaceViewController.h */, + F0E3B63D181FF157008590C6 /* HPAddSpaceViewController.m */, + F0E3B637181FF13E008590C6 /* HPTextFieldCell.h */, + F0E3B638181FF13E008590C6 /* HPTextFieldCell.m */, + F0E3B639181FF13E008590C6 /* HPTextFieldCell.xib */, + ); + name = "Add Space"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 160CA79A17CFE54500DA1FA5 /* HackpadTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 160CA7AD17CFE54500DA1FA5 /* Build configuration list for PBXNativeTarget "HackpadTests" */; + buildPhases = ( + 160CA79617CFE54500DA1FA5 /* Sources */, + 160CA79717CFE54500DA1FA5 /* Frameworks */, + 160CA79817CFE54500DA1FA5 /* Resources */, + 160CA79917CFE54500DA1FA5 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 160CA80D17CFF16A00DA1FA5 /* PBXTargetDependency */, + ); + name = HackpadTests; + productName = HackpadTests; + productReference = 160CA79B17CFE54500DA1FA5 /* HackpadTests.octest */; + productType = "com.apple.product-type.bundle"; + }; + 160CA7EC17CFEAD400DA1FA5 /* HackpadTestingKit */ = { + isa = PBXNativeTarget; + buildConfigurationList = 160CA7F617CFEAD400DA1FA5 /* Build configuration list for PBXNativeTarget "HackpadTestingKit" */; + buildPhases = ( + 160CA7E917CFEAD400DA1FA5 /* Sources */, + 160CA7EA17CFEAD400DA1FA5 /* Frameworks */, + 160CA7EB17CFEAD400DA1FA5 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = HackpadTestingKit; + productName = HackpadTestingKit; + productReference = 160CA7ED17CFEAD400DA1FA5 /* libHackpadTestingKit.a */; + productType = "com.apple.product-type.library.static"; + }; + 16CB5E5817C551A000511849 /* HackpadKit */ = { + isa = PBXNativeTarget; + buildConfigurationList = 16CB5E7817C551A100511849 /* Build configuration list for PBXNativeTarget "HackpadKit" */; + buildPhases = ( + 16CB5E5517C551A000511849 /* Sources */, + 16CB5E5617C551A000511849 /* Frameworks */, + 16CB5E5717C551A000511849 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = HackpadKit; + productName = HackpadKit; + productReference = 16CB5E5917C551A000511849 /* libHackpadKit.a */; + productType = "com.apple.product-type.library.static"; + }; + 16CB5E6617C551A000511849 /* HackpadKitTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 16CB5E7D17C551A100511849 /* Build configuration list for PBXNativeTarget "HackpadKitTests" */; + buildPhases = ( + 16CB5E6217C551A000511849 /* Sources */, + 16CB5E6317C551A000511849 /* Frameworks */, + 16CB5E6417C551A000511849 /* Resources */, + 16CB5E6517C551A000511849 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 160CA80817CFEDF800DA1FA5 /* PBXTargetDependency */, + 16CB5E6D17C551A000511849 /* PBXTargetDependency */, + ); + name = HackpadKitTests; + productName = HackpadKitTests; + productReference = 16CB5E6717C551A000511849 /* HackpadKitTests.octest */; + productType = "com.apple.product-type.bundle"; + }; + C327FDE415E57F9B002819C7 /* Hackpad */ = { + isa = PBXNativeTarget; + buildConfigurationList = C327FE0915E57F9B002819C7 /* Build configuration list for PBXNativeTarget "Hackpad" */; + buildPhases = ( + C327FDE115E57F9B002819C7 /* Sources */, + C327FDE215E57F9B002819C7 /* Frameworks */, + C327FDE315E57F9B002819C7 /* Resources */, + 169255D91745E5090086ADFC /* Set Build Number */, + 160D04AE174AB1EB00C98325 /* Acknowledgements */, + 160D04AF174AC9CD00C98325 /* Dev Server Pref */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Hackpad; + productName = Hackpad; + productReference = C327FDE515E57F9B002819C7 /* Hackpad.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + C327FDDC15E57F9B002819C7 /* Project object */ = { + isa = PBXProject; + attributes = { + CLASSPREFIX = HP; + LastUpgradeCheck = 0500; + ORGANIZATIONNAME = Hackpad; + TargetAttributes = { + C327FDE415E57F9B002819C7 = { + DevelopmentTeam = KPA39FTKP8; + SystemCapabilities = { + com.apple.BackgroundModes = { + enabled = 1; + }; + }; + }; + }; + }; + buildConfigurationList = C327FDDF15E57F9B002819C7 /* Build configuration list for PBXProject "Hackpad" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = C327FDDA15E57F9B002819C7; + productRefGroup = C327FDE615E57F9B002819C7 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + C327FDE415E57F9B002819C7 /* Hackpad */, + 160CA79A17CFE54500DA1FA5 /* HackpadTests */, + 16CB5E5817C551A000511849 /* HackpadKit */, + 16CB5E6617C551A000511849 /* HackpadKitTests */, + 160CA7EC17CFEAD400DA1FA5 /* HackpadTestingKit */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 160CA79817CFE54500DA1FA5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 160CA7A417CFE54500DA1FA5 /* InfoPlist.strings in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 16CB5E6417C551A000511849 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 166EF57A18A466A900561F07 /* Hackpad9.sqlite in Resources */, + 163489C318AC064E004972CB /* Hackpad12.sqlite in Resources */, + 16A760D218AEF37100821DB3 /* Hackpad15.sqlite in Resources */, + 16A760BE18ADB19100821DB3 /* Hackpad13.sqlite in Resources */, + 16CB5E7417C551A100511849 /* InfoPlist.strings in Resources */, + 166EF58A18A4C5C200561F07 /* Hackpad11.sqlite in Resources */, + 166EF56718A444E800561F07 /* Hackpad10.sqlite in Resources */, + 16A760C618AEA2F900821DB3 /* Hackpad14.sqlite in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C327FDE315E57F9B002819C7 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 169DD8A51832F27200D0D528 /* dropbox.png in Resources */, + 169DD8A71832F27200D0D528 /* link.png in Resources */, + 1673C04417986DCD005FED08 /* GetSnippetHeight.js in Resources */, + 16D7A3C4177B7D2E00CBC44C /* Hackpad.js in Resources */, + 16A760CA18AEB82F00821DB3 /* separator@2x.png in Resources */, + 169DD8A91832F27200D0D528 /* table.png in Resources */, + 1691CC991899686000CF121C /* check-green.png in Resources */, + 1699F70C183C10C8001DAC1D /* clearback@2x.png in Resources */, + 1699F712183C114E001DAC1D /* clearback.png in Resources */, + 169DD8981832F27200D0D528 /* number@2x.png in Resources */, + C327FDF415E57F9B002819C7 /* InfoPlist.strings in Resources */, + 169DD8661832D77200D0D528 /* editorbg.png in Resources */, + 16CD47B61868FC56002635BA /* gear@2x.png in Resources */, + 169DD89A1832F27200D0D528 /* bullet@2x.png in Resources */, + 1691CC9B1899686000CF121C /* x-red@2x.png in Resources */, + 169DD8A11832F27200D0D528 /* tag.png in Resources */, + 16CD47BB18691853002635BA /* up-chevron@2x.png in Resources */, + 169DD8A81832F27200D0D528 /* link@2x.png in Resources */, + 169DD8BA1832F27200D0D528 /* bold@2x.png in Resources */, + 164B50681893569F005DCFDE /* email-button-white.png in Resources */, + 169DD8A61832F27200D0D528 /* dropbox@2x.png in Resources */, + 16CD47A41868C865002635BA /* menu@2x.png in Resources */, + 169DD8BE1832F27200D0D528 /* insert@2x.png in Resources */, + 166E7D1C183ACA5D00C82013 /* whiteback@2x.png in Resources */, + C327FDFD15E57F9B002819C7 /* MainStoryboard_iPhone.storyboard in Resources */, + C327FE0015E57F9B002819C7 /* MainStoryboard_iPad.storyboard in Resources */, + 169DD8AD1832F27200D0D528 /* header3.png in Resources */, + 169DD8BF1832F27200D0D528 /* comment.png in Resources */, + 164B5078189714A2005DCFDE /* google44.png in Resources */, + 16650D0416A093BB00452A1F /* checked.png in Resources */, + 16650D0A16A0C96C00452A1F /* unchecked.png in Resources */, + 16B7EED218932E4A00E8C574 /* pencilLove@2x.png in Resources */, + 16CD47A71868C865002635BA /* newpad.png in Resources */, + 16085C1B16D57D2300C81DB4 /* Settings.bundle in Resources */, + 16B7EED918932E4A00E8C574 /* email-green@2x.png in Resources */, + 16CD47B51868FC56002635BA /* gear.png in Resources */, + 169DD8B61832F27200D0D528 /* underline@2x.png in Resources */, + 1699F70A183C0F36001DAC1D /* darkgreenbg.png in Resources */, + 169DD8971832F27200D0D528 /* number.png in Resources */, + 169DD8B71832F27200D0D528 /* italic.png in Resources */, + 169DD8B81832F27200D0D528 /* italic@2x.png in Resources */, + 16CD47A61868C865002635BA /* search@2x.png in Resources */, + 16B7EEDA18932E4A00E8C574 /* password-green@2x.png in Resources */, + 16CD47A11868C865002635BA /* follow.png in Resources */, + 1691CC9A1899686000CF121C /* check-green@2x.png in Resources */, + 16A760CC18AEB9DD00821DB3 /* separator.png in Resources */, + 16CF111F17D5ADD300C8FF10 /* Images.xcassets in Resources */, + 1699F711183C114E001DAC1D /* clearbacklandscape@2x.png in Resources */, + 168DD542189857D0003E01BF /* dot44@2x.png in Resources */, + 160D04A3174A98F200C98325 /* SignIn_iPad.storyboard in Resources */, + 160D04B2174AED1100C98325 /* SignIn_iPhone.storyboard in Resources */, + 16CD47BC18691853002635BA /* up-chevron.png in Resources */, + F0E3B63B181FF13E008590C6 /* HPTextFieldCell.xib in Resources */, + 169DD8AA1832F27200D0D528 /* table@2x.png in Resources */, + 169DD8A41832F27200D0D528 /* mention@2x.png in Resources */, + 169DD89F1832F27200D0D528 /* indent.png in Resources */, + 168DD543189857D0003E01BF /* dot44.png in Resources */, + 16CD47B81868FC56002635BA /* down-chevron@2x.png in Resources */, + 169DD8BD1832F27200D0D528 /* insert.png in Resources */, + 16CD47B71868FC56002635BA /* down-chevron.png in Resources */, + 169DD8B11832F27200D0D528 /* header1.png in Resources */, + 169DD8AB1832F27200D0D528 /* photo.png in Resources */, + 1699F710183C114E001DAC1D /* clearbacklandscape.png in Resources */, + 169DD89C1832F27200D0D528 /* paragraph@2x.png in Resources */, + 16CD47AB1868CB88002635BA /* forward.png in Resources */, + 169DD8961832F27200D0D528 /* check@2x.png in Resources */, + 169DD89E1832F27200D0D528 /* outdent@2x.png in Resources */, + 169DD89D1832F27200D0D528 /* outdent.png in Resources */, + 16A55F4517601260001ED006 /* nophoto.png in Resources */, + 16A55F74176140D9001ED006 /* online.png in Resources */, + 16B7EEDB18932E4A00E8C574 /* password-green.png in Resources */, + 169DD8951832F27200D0D528 /* check.png in Resources */, + 164B50701893600D005DCFDE /* user-green.png in Resources */, + 169DD8BB1832F27200D0D528 /* close.png in Resources */, + 16CD47A31868C865002635BA /* menu.png in Resources */, + 169DD8B51832F27200D0D528 /* underline.png in Resources */, + 16CD479F1868C865002635BA /* back.png in Resources */, + 169DD8C01832F27200D0D528 /* comment@2x.png in Resources */, + 16E6F4FB1887183C00FD7486 /* ProximaNova-Reg.otf in Resources */, + 16A55F75176140D9001ED006 /* online@2x.png in Resources */, + 169DD8A21832F27200D0D528 /* tag@2x.png in Resources */, + C322B9AD1772733C00A2F1CE /* site-switcher.png in Resources */, + 166E7D1A183ACA5D00C82013 /* whitebg.png in Resources */, + 16B5ECE117A73D42004E3815 /* WebViewJavascriptBridge.js.txt in Resources */, + 164B5077189714A2005DCFDE /* google44@2x.png in Resources */, + 169DD8B21832F27200D0D528 /* header1@2x.png in Resources */, + 16B7EED318932E4A00E8C574 /* pencilLove.png in Resources */, + 165C59CD17B32CCB001006D4 /* bluebg.png in Resources */, + 16CD47A01868C865002635BA /* back@2x.png in Resources */, + 1691CC981899686000CF121C /* x-red.png in Resources */, + 166E7D1B183ACA5D00C82013 /* whiteback.png in Resources */, + 169DD8651832D77200D0D528 /* groupbg.png in Resources */, + 169DD8AE1832F27200D0D528 /* header3@2x.png in Resources */, + 164B507418971370005DCFDE /* facebook44.png in Resources */, + 16CD47AC1868CB88002635BA /* forward@2x.png in Resources */, + 169DD89B1832F27200D0D528 /* paragraph.png in Resources */, + 16E21661185F9C78000FAA42 /* LICENSE in Resources */, + 169DD8C21832F27200D0D528 /* textformat@2x.png in Resources */, + 169DD8BC1832F27200D0D528 /* close@2x.png in Resources */, + 169DD8991832F27200D0D528 /* bullet.png in Resources */, + 16CD47A21868C865002635BA /* follow@2x.png in Resources */, + 165C59CF17B331F5001006D4 /* graybg.png in Resources */, + 164B507318971370005DCFDE /* facebook44@2x.png in Resources */, + 169DD8AC1832F27200D0D528 /* photo@2x.png in Resources */, + 169DD8B41832F27200D0D528 /* strikethrough@2x.png in Resources */, + 169DD8B01832F27200D0D528 /* header2@2x.png in Resources */, + 16CD47B41868FC56002635BA /* user@2x.png in Resources */, + 169DD8A01832F27200D0D528 /* indent@2x.png in Resources */, + 16CD47B31868FC56002635BA /* user.png in Resources */, + 169DD8B31832F27200D0D528 /* strikethrough.png in Resources */, + 169DD8AF1832F27200D0D528 /* header2.png in Resources */, + 16CD47A81868C865002635BA /* newpad@2x.png in Resources */, + 164045891858D60D00D02B59 /* PadCell.xib in Resources */, + 169DD8B91832F27200D0D528 /* bold.png in Resources */, + 164B506F1893600D005DCFDE /* user-green@2x.png in Resources */, + 169DD8A31832F27200D0D528 /* mention.png in Resources */, + 169DD8C11832F27200D0D528 /* textformat.png in Resources */, + 16B7EED818932E4A00E8C574 /* email-green.png in Resources */, + 16CD47A51868C865002635BA /* search.png in Resources */, + 164E44211870F960002657E2 /* ProximaNova-Bold.otf in Resources */, + 164E44221870F960002657E2 /* ProximaNova-Light.otf in Resources */, + 164E44231870F960002657E2 /* ProximaNova-LightIt.otf in Resources */, + 164E44241870F960002657E2 /* ProximaNova-Sbold.otf in Resources */, + 164B50691893569F005DCFDE /* email-button-white@2x.png in Resources */, + 164E44251870F960002657E2 /* ProximaNova-SboldIt.otf in Resources */, + 164E44261870F960002657E2 /* ProximaNova-Xbold.otf in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 160CA79917CFE54500DA1FA5 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n"; + }; + 160D04AE174AB1EB00C98325 /* Acknowledgements */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = Acknowledgements; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/bash; + shellScript = "PLIST_BUDDY=/usr/libexec/PlistBuddy\nIN=\"${SRCROOT}/Hackpad/Acknowledgements.txt\"\nOUT=\"${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/Settings.bundle/Acknowledgements.plist\"\n\n\"${PLIST_BUDDY}\" \"${OUT}\" < + + + + diff --git a/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/App Store.xcscheme b/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/App Store.xcscheme new file mode 100644 index 0000000..1e55b9d --- /dev/null +++ b/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/App Store.xcscheme @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Beta (Ad Hoc).xcscheme b/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Beta (Ad Hoc).xcscheme new file mode 100644 index 0000000..3ea1a7f --- /dev/null +++ b/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Beta (Ad Hoc).xcscheme @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Beta (Enterprise).xcscheme b/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Beta (Enterprise).xcscheme new file mode 100644 index 0000000..e7c88df --- /dev/null +++ b/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Beta (Enterprise).xcscheme @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Create Default Images.xcscheme b/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Create Default Images.xcscheme new file mode 100644 index 0000000..6ab7474 --- /dev/null +++ b/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Create Default Images.xcscheme @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Development.xcscheme b/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Development.xcscheme new file mode 100644 index 0000000..b015f76 --- /dev/null +++ b/client/ios/Hackpad/Hackpad.xcodeproj/xcshareddata/xcschemes/Development.xcscheme @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/ios/Hackpad/Hackpad/Acknowledgements.txt b/client/ios/Hackpad/Hackpad/Acknowledgements.txt new file mode 100644 index 0000000..1a10876 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/Acknowledgements.txt @@ -0,0 +1,50 @@ +Portions of this software may contain copyrighted material. + +Icons by Glyphish - http://glyphish.com/ + +RNCachingProtocol +Copyright (c) 2012 Rob Napier. All rights reserved. +This code is licensed under the MIT License: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +KeychainItem, Reachability +Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. +In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. +The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +Copyright (C) 2010 Apple Inc. All Rights Reserved. + +Google Toolbox for Mac +Copyright 2006-2008 Google Inc. +Copyright 2008 Google Inc. +Copyright (c) 2010 Google Inc. +Copyright (c) 2011 Google Inc. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + +FacebookSDK +Copyright 2010-present Facebook. + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + +Buttons +Copyright ©2010 Richard Moore +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +NSAttributedString+HTML.m +Copyright (c) 2012, Deloitte Digital. 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 the 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 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. + +MBProgressHUD +Copyright (c) 2013 Matej Bukovinski +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/client/ios/Hackpad/Hackpad/GetSnippetHeight.js b/client/ios/Hackpad/Hackpad/GetSnippetHeight.js new file mode 100644 index 0000000..1b4fb45 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/GetSnippetHeight.js @@ -0,0 +1,15 @@ +(function () { + var elems = document.body.getElementsByTagName('div'); + var min = 0; + var max = elems.length - 1; + var i, height; + while (min != max) { + i = Math.floor((min + max) >> 1); + if (elems[i].offsetTop + elems[i].offsetHeight < 160) { + min = i + 1; + } else { + max = i; + } + } + return elems[min].offsetTop + elems[min].offsetHeight; +})(); diff --git a/client/ios/Hackpad/Hackpad/HPActionSheetBlockDelegate.h b/client/ios/Hackpad/Hackpad/HPActionSheetBlockDelegate.h new file mode 100644 index 0000000..cb72104 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPActionSheetBlockDelegate.h @@ -0,0 +1,13 @@ +// +// HPActionSheetBlockDelegate.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface HPActionSheetBlockDelegate : NSObject +- (id)initWithBlock:(void (^)(UIActionSheet *, NSInteger))handler; +@end diff --git a/client/ios/Hackpad/Hackpad/HPActionSheetBlockDelegate.m b/client/ios/Hackpad/Hackpad/HPActionSheetBlockDelegate.m new file mode 100644 index 0000000..1c1b856 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPActionSheetBlockDelegate.m @@ -0,0 +1,36 @@ +// +// HPActionSheetBlockDelegate.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPActionSheetBlockDelegate.h" + +@interface HPActionSheetBlockDelegate () +@property (nonatomic, copy) void (^didDismissBlock)(UIActionSheet *, NSInteger); +@property (nonatomic, strong) HPActionSheetBlockDelegate *strongSelf; +@end + +@implementation HPActionSheetBlockDelegate + +- (id)initWithBlock:(void (^)(UIActionSheet *, NSInteger))handler +{ + self = [super init]; + if (self) { + self.strongSelf = self; + self.didDismissBlock = handler; + } + return self; +} + +- (void)actionSheet:(UIActionSheet *)actionSheet +didDismissWithButtonIndex:(NSInteger)buttonIndex +{ + actionSheet.delegate = nil; + self.didDismissBlock(actionSheet, buttonIndex); + self.strongSelf = nil; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPAddSpaceViewController.h b/client/ios/Hackpad/Hackpad/HPAddSpaceViewController.h new file mode 100644 index 0000000..6769723 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPAddSpaceViewController.h @@ -0,0 +1,26 @@ +// +// HPAddSpaceViewController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@protocol HPAddSpaceViewControllerDelegate; + +@interface HPAddSpaceViewController : UITableViewController + +@property (weak, nonatomic) id delegate; + +@end + +@protocol HPAddSpaceViewControllerDelegate + +- (void)addSpaceViewController:(HPAddSpaceViewController *)viewController didFinishWithSpaceName:(NSString *)name; +- (void)addSpaceViewControllerDidCancel:(HPAddSpaceViewController *)viewController; +// Return NO if the user has no spaces and needs to add one before proceeding. +- (BOOL)addSpaceViewControllerCanCancel:(HPAddSpaceViewController *)viewController; + +@end diff --git a/client/ios/Hackpad/Hackpad/HPAddSpaceViewController.m b/client/ios/Hackpad/Hackpad/HPAddSpaceViewController.m new file mode 100644 index 0000000..d4ed78c --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPAddSpaceViewController.m @@ -0,0 +1,101 @@ +// +// HPAddSpaceViewController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPAddSpaceViewController.h" +#import "HPTextFieldCell.h" + +static NSString * const HPTextFieldCellIdentifier = @"HPTextFieldCell"; + +@interface HPAddSpaceViewController () + +@end + +@implementation HPAddSpaceViewController + +- (id)init +{ + self = [super initWithStyle:UITableViewStyleGrouped]; + if (self != nil) { + ; + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.title = NSLocalizedString(@"Sign In", nil); + + UINib *cellNib = [UINib nibWithNibName:HPTextFieldCellIdentifier bundle:nil]; + [self.tableView registerNib:cellNib forCellReuseIdentifier:HPTextFieldCellIdentifier]; + + UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneAction:)]; + doneItem.enabled = NO; + self.navigationItem.rightBarButtonItem = doneItem; + + if ([self.delegate addSpaceViewControllerCanCancel:self]) { + UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAction:)]; + self.navigationItem.leftBarButtonItem = cancelItem; + } +} + +#pragma mark - Actions + +- (void)doneAction:(id)sender +{ + HPTextFieldCell *cell = (HPTextFieldCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; + NSString *name = cell.textField.text; + [self.delegate addSpaceViewController:self didFinishWithSpaceName:name]; +} + +- (void)cancelAction:(id)sender +{ + [self.delegate addSpaceViewControllerDidCancel:self]; +} + +#pragma mark - Table view data source + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return 1; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + HPTextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:HPTextFieldCellIdentifier forIndexPath:indexPath]; + cell.textField.placeholder = NSLocalizedString(@"your workspace", nil); + cell.textField.keyboardType = UIKeyboardTypeURL; + cell.textField.enablesReturnKeyAutomatically = YES; + cell.textField.delegate = self; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldTextDidChange:) name:UITextFieldTextDidChangeNotification object:cell.textField]; + [cell.textField becomeFirstResponder]; + return cell; +} + +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section +{ + return NSLocalizedString(@"Enter a Workspace name or address", nil); +} + +#pragma mark - UITextFieldDelegate + +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + [self doneAction:nil]; + return YES; +} + +#pragma mark - Notifications + +- (void)textFieldTextDidChange:(NSNotification *)notification +{ + self.navigationItem.rightBarButtonItem.enabled = [notification.object text].length > 0; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPAppDelegate.h b/client/ios/Hackpad/Hackpad/HPAppDelegate.h new file mode 100644 index 0000000..390ebdf --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPAppDelegate.h @@ -0,0 +1,13 @@ +// +// HPAppDelegate.h +// Hackpad +// +// +// Copyright (c) 2012 Hackpad. All rights reserved. +// + +#import + +@interface HPAppDelegate : UIResponder +@property (strong, nonatomic) UIWindow *window; +@end diff --git a/client/ios/Hackpad/Hackpad/HPAppDelegate.m b/client/ios/Hackpad/Hackpad/HPAppDelegate.m new file mode 100644 index 0000000..e0e69c5 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPAppDelegate.m @@ -0,0 +1,921 @@ +// +// HPAppDelegate.m +// Hackpad +// +// +// Copyright (c) 2012 Hackpad. All rights reserved. +// + +#import "HPAppDelegate.h" + +#import "HPPadEditorViewController.h" +#import "HPPadListViewController.h" +#import "HPSignInController.h" +#import "HPDrawerController.h" +#import "HPPadScopeViewController.h" +#import "HPBlueNavigationController.h" +#import "HPGrayNavigationController.h" +#import "HPPadSplitViewController.h" +#import "HPPadScopeTableViewDataSource.h" +#import "HPSignInViewController.h" +#import "HPWhiteNavigationController.h" + +#import "HackpadKit/HackpadKit.h" +#import "HackpadAdditions/HackpadUIAdditions.h" + +#import +#import +#import "TestFlight.h" +#import "WebViewJavascriptBridge.h" +#import "Flurry.h" + +static NSString * const InterfaceIdiomKey = @"interfaceIdiom"; +static NSString * const LayoutVersionKey = @"layoutVersion"; +static NSInteger const LayoutVersion = 2; +static NSString * const ResetOnLaunchKey = @"resetOnLaunch"; +static NSString * const ShownWelcomePad = @"shownWelcomePad"; +static NSString * const HPFlurryAnalyticsKey = @"PF8KBXHTPPPBTK3HV2RC"; + +#if DEBUG +static NSString * const TestFlightAppToken = @"61421fa6-591a-4a66-bbbd-64a3b218807f"; +#elif AD_HOC +static NSString * const TestFlightAppToken = @"373fd844-32de-4e5d-9d58-5ee608b0f500"; +#else +static NSString * const TestFlightAppToken = @"ab3a22d0-6771-4083-aa35-5ee800928409"; +#endif + +#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 +#if DEBUG || AD_HOC +@interface UIDevice (UniqueIdentifier) +@property (nonatomic, readonly, retain) NSString *uniqueIdentifier; +@end +#endif +#else +@protocol IOS7UIAppearance +- (void)setBarTintColor:(UIColor *)color; +@end + +@interface UIWindow (IOS7Additions) +- (void)setTintColor:(UIColor *)color; +@end +#endif + +@interface HPAppDelegate () + +@property (strong, nonatomic) HPCoreDataStack *coreDataStack; +@property (strong, nonatomic) HPPadListViewController *padListViewController; +@property (strong, nonatomic) HPPadScopeViewController *padScopeViewController; +@property (assign, nonatomic) BOOL resetStore; + +- (NSURL *)applicationDocumentsDirectory; +- (NSURL *)storeURL; + +@end + +@implementation HPAppDelegate + +- (BOOL)application:(UIApplication *)application +willFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + if ([self.class isRunningTests]) { + return YES; + } + +#if 0 + [self dumpFontsAndExit]; +#endif +#if !CREATE_DEFAULT_PNG +#if !DEBUG + [self initializeTestFlight]; +#endif + [self initializeCoreDataStack]; + [self initializeProtocols]; + [self setMobileCookie]; +#if DEBUG + [WebViewJavascriptBridge enableLogging]; +#endif +#endif + + [[HPSignInController defaultController] addObserversWithCoreDataStack:self.coreDataStack + rootViewController:self.window.rootViewController]; + + [self initializeUI]; + + return YES; +} + +- (BOOL)application:(UIApplication *)application +didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + [application registerForRemoteNotificationTypes: + (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | + UIRemoteNotificationTypeAlert)]; + [self configureAnalytics]; + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application +{ + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + [[HPPadCacheController sharedPadCacheController] setDisabled:YES]; + [self.coreDataStack.mainContext hp_saveToStore:nil]; +} + +- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application +{ + [[NSURLCache sharedURLCache] removeAllCachedResponses]; +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + [self.coreDataStack saveWithBlock:^(NSManagedObjectContext *localContext) { + [[HPPadCacheController sharedPadCacheController] setDisabled:YES]; + NSError *error = nil; + [HPSpace removeNonfollowedPadsInManagedObjectContext:localContext + error:&error]; + if (error) { + TFLog(@"Error Removing Non-Followed Pads: %@", error); + } + } completion:^(NSError *error) { + if (error) { + TFLog(@"Error pruning pads: %@", error); + } + }]; +} + +- (BOOL)application:(UIApplication *)application +shouldSaveApplicationState:(NSCoder *)coder +{ +#if CREATE_DEFAULT_PNG + return NO; +#else + [coder encodeInteger:UIDevice.currentDevice.userInterfaceIdiom + forKey:InterfaceIdiomKey]; + [coder encodeInteger:LayoutVersion + forKey:LayoutVersionKey]; + return YES; +#endif +} + +- (BOOL)application:(UIApplication *)application +shouldRestoreApplicationState:(NSCoder *)coder +{ +#if CREATE_DEFAULT_PNG + return NO; +#else + if (self.resetStore || + [coder decodeIntegerForKey:InterfaceIdiomKey] != UIDevice.currentDevice.userInterfaceIdiom || + [coder decodeIntegerForKey:LayoutVersionKey] != LayoutVersion) { + return NO; + } + [HPCoreDataStack setSharedStateRestorationCoreDataStack:self.coreDataStack]; + return YES; +#endif +} + +- (void)application:(UIApplication *)application +didDecodeRestorableStateWithCoder:(NSCoder *)coder +{ + [HPCoreDataStack setSharedStateRestorationCoreDataStack:nil]; +} + +- (void)applicationWillEnterForeground:(UIApplication *)application +{ + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application +{ + [FBSession.activeSession handleDidBecomeActive]; + [[HPPadCacheController sharedPadCacheController] setDisabled:NO]; +} + +- (void)applicationWillTerminate:(UIApplication *)application +{ + [FBSession.activeSession close]; +} + +- (void)application:(UIApplication *)application +didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken +{ + HPLog(@"Device notification token: %@", deviceToken.hp_hexEncodedString); + [HPAPI setSharedDeviceTokenData:deviceToken]; +} + +- (void)application:(UIApplication *)application +didFailToRegisterForRemoteNotificationsWithError:(NSError *)error +{ + TFLog(@"Failed to get device token, error: %@", error); +#if TARGET_IPHONE_SIMULATOR +// [HPAPI setSharedDeviceTokenData:[@"bogus token" dataUsingEncoding:NSUTF8StringEncoding]]; +#endif +} + +#pragma mark - UI + +- (void)initializeUI +{ + HPDrawerController *drawerViewController; + HPPadEditorViewController *padEditorViewController; + HPPadSplitViewController *splitViewController; + + UIFont *font = [UIFont hp_UITextFontOfSize:17]; + NSDictionary *attributes = @{NSFontAttributeName:font}; + + id appearance = [UILabel appearanceWhenContainedIn:[UITableViewCell class], [HPSignInViewController class], nil]; + [appearance setFont:font]; + + appearance = [UITextField appearanceWhenContainedIn:[HPSignInViewController class], nil]; + [appearance setFont:font]; + + if (HP_SYSTEM_MAJOR_VERSION() >= 7) { + // This triggers a failed assertion on iOS 6 when sharing a pad URL?! + appearance = [UIBarButtonItem appearance]; + [appearance setTitleTextAttributes:attributes + forState:UIControlStateNormal]; + } + + [self setupAppearanceWhenContainedIn:[HPWhiteNavigationController class] + titleBarFont:font]; + [self setupAppearanceWhenContainedIn:[HPGrayNavigationController class] + titleBarFont:font]; + [self setupAppearanceWhenContainedIn:[HPBlueNavigationController class] + titleBarFont:font]; + + font = [UIFont hp_UITextFontOfSize:14]; + appearance = [UILabel appearanceWhenContainedIn:[UITextField class], [UISearchBar class], nil]; + [appearance setFont:font]; + + appearance = [UITextField appearanceWhenContainedIn:[UISearchBar class], nil]; + [appearance setFont:font]; + + appearance = [UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil]; + [appearance setFont:font]; + +#if !CREATE_DEFAULT_PNG + HPPadScope *padScope = [[HPPadScope alloc] initWithCoreDataStack:self.coreDataStack]; +#endif + + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + splitViewController = (HPPadSplitViewController *)self.window.rootViewController; + drawerViewController = splitViewController.viewControllers[0]; + UINavigationController *detailNavigationController = splitViewController.viewControllers[1]; + padEditorViewController = (HPPadEditorViewController *)detailNavigationController.topViewController; +#if CREATE_DEFAULT_PNG + padEditorViewController.navigationItem.rightBarButtonItems = nil; +#endif + splitViewController.delegate = splitViewController; + detailNavigationController.delegate = splitViewController; + } else { + drawerViewController = (HPDrawerController *)self.window.rootViewController; + } + + drawerViewController.delegate = self; + + UINavigationController *navigationController = (UINavigationController *)drawerViewController.mainViewController; + self.padListViewController = (HPPadListViewController *)navigationController.topViewController; + self.padListViewController.editorViewController = padEditorViewController; + +#if CREATE_DEFAULT_PNG + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + self.padListViewController.title = @""; + self.padListViewController.navigationItem.rightBarButtonItem = nil; + } + if (!self.padListViewController.isViewLoaded) { + [self.padListViewController loadView]; + } + self.padListViewController.searchDisplayController.searchBar.placeholder = @""; +#else + self.padListViewController.padScope = padScope; + splitViewController.padListViewController = self.padListViewController; + + navigationController = (UINavigationController *)drawerViewController.leftViewController; + self.padScopeViewController = (HPPadScopeViewController *)navigationController.topViewController; + self.padScopeViewController.padScope = padScope; + self.padScopeViewController.dataSource.managedObjectContext = self.coreDataStack.mainContext; + if (drawerViewController.isLeftDrawerShown) { + [self drawerController:drawerViewController + willShowLeftDrawerAnimated:NO]; + } else { + [self drawerController:drawerViewController + willHideLeftDrawerAnimated:NO]; + } +#endif +} + +- (void)setupAppearanceWhenContainedIn:(Class )containerClass + titleBarFont:(UIFont *)font +{ + BOOL iOS7 = HP_SYSTEM_MAJOR_VERSION() >= 7; + UIImage *image = iOS7 ? nil : [containerClass coloredBackgroundImage]; + UIColor *barTintColor = [containerClass coloredBarTintColor]; + UIColor *tintColor = [containerClass coloredTintColor]; + UIColor *navTitleColor = [containerClass navigationTitleColor]; + + id appearance = [UINavigationBar appearanceWhenContainedIn:containerClass, nil]; + NSDictionary *attributes = @{NSForegroundColorAttributeName:navTitleColor, + NSFontAttributeName:font}; + [appearance setTitleTextAttributes:attributes]; + if (iOS7) { + [appearance setTintColor:tintColor]; + [appearance setBarTintColor:barTintColor]; + } else { + [appearance setBackgroundImage:image + forBarMetrics:UIBarMetricsDefault]; + [appearance setShadowImage:[[UIImage alloc] init]]; + } + appearance = [UINavigationBar appearance]; + [appearance setTitleTextAttributes:attributes]; + + appearance = [UIToolbar appearanceWhenContainedIn:containerClass, nil]; + if (iOS7) { + [appearance setBarTintColor:barTintColor]; + [appearance setTintColor:tintColor]; + } else { + [appearance setBackgroundImage:image + forToolbarPosition:UIToolbarPositionAny + barMetrics:UIBarMetricsDefault]; + } + + appearance = [UIBarButtonItem appearanceWhenContainedIn:containerClass, nil]; + [appearance setTintColor:tintColor]; + + if (iOS7) { + appearance = [UITextField appearanceWhenContainedIn:[UISearchBar class], containerClass, nil]; + [appearance setBackgroundColor:[UIColor hp_mediumGreenGrayColor]]; + return; + } + + [appearance setBackgroundImage:[UIImage new] + forState:UIControlStateNormal + barMetrics:UIBarMetricsDefault]; + UIImage *clearImage = [[UIImage imageNamed:@"clearback"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 1)]; + [appearance setBackButtonBackgroundImage:clearImage + forState:UIControlStateNormal + barMetrics:UIBarMetricsDefault]; +#if 0 + clearImage = [[UIImage imageNamed:@"clearbacklandscape"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 1)]; + [appearance setBackButtonBackgroundImage:clearImage + forState:UIControlStateNormal + barMetrics:UIBarMetricsLandscapePhone]; +#endif + [appearance setTitleTextAttributes:@{UITextAttributeTextColor:tintColor, + UITextAttributeTextShadowColor:[UIColor clearColor]} + forState:UIControlStateNormal]; + [appearance setTitleTextAttributes:@{UITextAttributeTextColor:[UIColor hp_darkGrayColor], + UITextAttributeTextShadowColor:[UIColor clearColor]} + forState:UIControlStateHighlighted]; + + appearance = [UISegmentedControl appearanceWhenContainedIn:containerClass, nil]; + [appearance setBackgroundImage:[UIImage new] + forState:UIControlStateNormal + barMetrics:UIBarMetricsDefault]; + + appearance = [UISearchBar appearanceWhenContainedIn:containerClass, nil]; + [appearance setBackgroundColor:[UIColor colorWithPatternImage:image]]; + + appearance = [NSClassFromString(@"UISearchBarBackground") appearanceWhenContainedIn:containerClass, nil]; + [appearance setAlpha:0]; +} + +- (void)showIPadPadList +{ + NSAssert(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad, @"This should only be called on iPads"); + HPPadSplitViewController *svc = (HPPadSplitViewController *)self.window.rootViewController; + [svc.padListItem.target performSelector:svc.padListItem.action + withObject:self + afterDelay:0]; + +} + +#pragma mark - Core Data stack initialization & delegate + +- (void)initializeCoreDataStack +{ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + self.resetStore = [defaults boolForKey:ResetOnLaunchKey]; + if (self.resetStore) { + NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + for (NSHTTPCookie *cookie in cookieJar.cookies) { + [cookieJar deleteCookie:cookie]; + } + + NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys: + (__bridge id)kSecClassGenericPassword, (__bridge id)kSecClass, + (__bridge id)kSecMatchLimitAll, (__bridge id)kSecMatchLimit, + nil]; + SecItemDelete((__bridge CFDictionaryRef)query); + + NSFileManager *fm = [NSFileManager defaultManager]; + NSDirectoryEnumerator *files; + NSDirectoryEnumerationOptions options = + NSDirectoryEnumerationSkipsSubdirectoryDescendants | + NSDirectoryEnumerationSkipsPackageDescendants | + NSDirectoryEnumerationSkipsHiddenFiles; + files = [fm enumeratorAtURL:[self.storeURL URLByDeletingLastPathComponent] + includingPropertiesForKeys:nil + options:options + errorHandler:^BOOL(NSURL *url, NSError *error) { + TFLog(@"Error enumerating %@: %@", url, error); + return YES; + }]; + NSString *storeFile = self.storeURL.lastPathComponent; + for (NSURL *URL in files) { + if (![URL.lastPathComponent hasPrefix:storeFile]) { + continue; + } + HPLog(@"Deleting file: %@", URL.absoluteString); + [fm removeItemAtURL:URL + error:nil]; + } + [HPStaticCachingURLProtocol removeCacheWithError:nil]; + + for (NSString *key in defaults.dictionaryRepresentation.allKeys) { +#if TARGET_IPHONE_SIMULATOR + if (![key isEqualToString:@"devServer"]) +#endif + { + HPLog(@"Removing key: %@", key); + [defaults removeObjectForKey:key]; + } + } + [defaults synchronize]; + [NSUserDefaults resetStandardUserDefaults]; + } + + self.coreDataStack = [HPCoreDataStack new]; + self.coreDataStack.storeURL = self.storeURL; + + HPAppDelegate * __weak weakSelf = self; + NSManagedObjectID * __block objectID; + [self.coreDataStack saveWithBlock:^(NSManagedObjectContext *localContext) { + NSError * __autoreleasing error; + HPSpace *space = [HPSpace spaceWithURL:[NSURL hp_sharedHackpadURL] + inManagedObjectContext:localContext + error:&error]; + if (error) { + TFLog(@"Error fetching space: %@", error); + } + if (space) { + if ((!space.rootURL || space.domainType != HPToplevelDomainType) && + ![HPSpace migrateRootURLsInManagedObjectContext:localContext + error:&error]) { + TFLog(@"Error migrating spaces: %@", error); + return; + } + objectID = space.objectID; + return; + } + space = [HPSpace insertSpaceWithURL:[NSURL hp_sharedHackpadURL] + name:nil + managedObjectContext:localContext]; + if (![localContext obtainPermanentIDsForObjects:@[space] + error:&error]) { + TFLog(@"Error getting default space permanent ID: %@", error); + return; + } + objectID = space.objectID; + } completion:^(NSError *error) { + if (error) { + TFLog(@"Error saving default space: %@", error); + return; + } + [[HPPadCacheController sharedPadCacheController] setCoreDataStack:weakSelf.coreDataStack]; + if (!objectID) { + return; + } + HPSpace *space = (HPSpace *)[weakSelf.coreDataStack.mainContext existingObjectWithID:objectID + error:&error]; + if (error) { + TFLog(@"Error fetching default space: %@", error); + return; + } + [space.API signInEvenIfSignedIn:NO]; + if (weakSelf.padListViewController.padScope.space) { + return; + } + weakSelf.padListViewController.padScope.space = space; + [weakSelf.padScopeViewController.tableView reloadData]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone || + weakSelf.padListViewController.editorViewController.pad) { + return; + } + [weakSelf showIPadPadList]; + }]; +} + +#pragma mark - Application's Documents directory + +// Returns the URL to the application's Documents directory. +- (NSURL *)applicationDocumentsDirectory +{ + return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory + inDomains:NSUserDomainMask] lastObject]; +} + +- (NSURL *)storeURL +{ + return [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"pads.data"]; +} + +#pragma mark - URL stuffs + +- (void)openPadWithURL:(NSURL *)URL +{ + static NSString * const ShowDetailSegue = @"showDetail"; + + NSManagedObjectID * __block objectID; + NSError * __block padError; + HPAppDelegate * __weak weakSelf = self; + [self.coreDataStack saveWithBlock:^(NSManagedObjectContext *localContext) { + HPPad *pad = [HPPad padWithURL:URL + managedObjectContext:localContext + error:&padError]; + if (!pad) { + return; + } + if (![localContext obtainPermanentIDsForObjects:@[pad] + error:&padError]) { + return; + } + objectID = pad.objectID; + } completion:^(NSError *error) { + if (!error) { + error = padError; + } + HPPad *pad; + if (!error) { + pad = (HPPad *)[weakSelf.coreDataStack.mainContext existingObjectWithID:objectID + error:&error]; + } + if (error) { + TFLog(@"[%@] Could not create pad with path %@: %@", + URL.host, URL.hp_fullPath, error); + [[[UIAlertView alloc] initWithTitle:@"Oops" + message:@"The pad couldn't be found. Please try again later." + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; + return; + } + weakSelf.padScopeViewController.padScope.space = pad.space; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + weakSelf.padListViewController.editorViewController.pad = pad; + } else { + [weakSelf.padListViewController performSegueWithIdentifier:ShowDetailSegue + sender:pad]; + } + }]; +} + +- (void)openSpaceWithURL:(NSURL *)URL +{ + HPAppDelegate * __weak weakSelf = self; + NSManagedObjectID * __block objectID; + // This should be in HPSpace+Impl. + [self.coreDataStack saveWithBlock:^(NSManagedObjectContext *localContext) { + NSError *error = nil; + HPSpace *space = [HPSpace spaceWithURL:URL + inManagedObjectContext:localContext + error:&error]; + if (error) { + return; + } + if (space) { + space.hidden = NO; + } else { + space = [HPSpace insertSpaceWithURL:URL + name:nil + managedObjectContext:localContext]; + if (![localContext obtainPermanentIDsForObjects:@[space] + error:&error]) { + TFLog(@"Error obtaining permanent IDs: %@", error); + return; + } + } + objectID = space.objectID; + } completion:^(NSError *error) { + if (error) { + TFLog(@"[%@] Could not add space: %@", URL.host, error); + return; + } + if (!objectID) { + return; + } + if (!weakSelf) { + return; + } + HPSpace *space = (HPSpace *)[weakSelf.coreDataStack.mainContext existingObjectWithID:objectID + error:&error]; + if (!space) { + TFLog(@"[%@] Could not look up space: %@", URL.host, error); + return; + } + [space.API signInEvenIfSignedIn:NO]; + weakSelf.padScopeViewController.padScope.space = space; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + [self.padListViewController.navigationController popToRootViewControllerAnimated:YES]; + } else { + [self showIPadPadList]; + } + }]; +} + +/* + * If we have a valid session at the time of openURL call, we handle + * Facebook transitions by passing the url argument to handleOpenURL + */ +- (BOOL)application:(UIApplication *)application + openURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication + annotation:(id)annotation +{ + // attempt to extract a token from the url + if ([FBSession.activeSession handleOpenURL:url]) { + return YES; + } + + switch ([HPAPI URLTypeWithURL:url]) { + case HPPadURLType: + [self openPadWithURL:url]; + return YES; + + case HPSpaceURLType: + [self openSpaceWithURL:url]; + return YES; + + // TODO: Allow opening searches, sites, etc. + default: + return NO; + } +} + +#pragma mark - Notifications + +- (void)application:(UIApplication *)application +didReceiveRemoteNotification:(NSDictionary *)userInfo +{ + [self application:application +didReceiveRemoteNotification:userInfo +fetchCompletionHandler:^(UIBackgroundFetchResult result) {}]; +} + +- (void)application:(UIApplication *)application +didReceiveRemoteNotification:(NSDictionary *)userInfo +fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler +{ + static NSString * const HPKey = @"hp"; + static NSString * const PadURLKey = @"u"; + static NSString * const AccountIdKey = @"a"; + static NSString * const EventTypeKey = @"t"; + static NSString * const LastEditedDateKey = @"d"; + + typedef NS_ENUM(unichar, HPNotificationEventType) { + HPCreateEventType = 'c', + HPDeleteEventType = 'd', + HPEditEventType = 'e', + HPFollowEventType = 'f', + HPUnfollowEventType = 'u', + HPInviteEventType = 'i', + HPMentionEventType = 'm', + }; + + HPLog(@"got API notification: %@", userInfo); + NSDictionary *hp = userInfo[HPKey]; + + NSURL *URL = [NSURL URLWithString:hp[PadURLKey]]; + if (!URL) { + TFLog(@"Ignoring notification without pad URL."); + completionHandler(UIBackgroundFetchResultNoData); + return; + } + + NSString *padID = [HPPad padIDWithURL:URL]; + if (!padID) { + TFLog(@"[%@] Could not find pad ID in URL: %@", URL.host, URL.hp_fullPath); + completionHandler(UIBackgroundFetchResultFailed); + return; + } + + HPNotificationEventType eventType = [hp[EventTypeKey] characterAtIndex:0]; + if (!eventType) { + TFLog(@"[%@ %@] Unknown event type in notification: %uh", URL.host, padID, eventType); + completionHandler(UIBackgroundFetchResultFailed); + return; + } + + NSTimeInterval lastEditedDate = [hp[LastEditedDateKey] longLongValue] - NSTimeIntervalSince1970; + + UIApplicationState applicationState = application.applicationState; + switch (applicationState) { + case UIApplicationStateInactive: + [self openPadWithURL:URL]; + completionHandler(UIBackgroundFetchResultNoData); + return; + case UIApplicationStateBackground: { + HPAPI *API = [HPAPI APIWithURL:URL]; + if (!API) { + TFLog(@"[%@ %@] Could not find API for notification URL.", URL.host, padID); + completionHandler(UIBackgroundFetchResultFailed); + return; + } +#if 0 + if (!API.reachability.currentReachabilityStatus) { + // FIXME: reschedule with local notification? + TFLog(@"[%@ %@] Ignoring notification while offline.", URL.host, padID); + completionHandler(UIBackgroundFetchResultFailed); + return; + } +#endif + if (!API.oAuth || ![API loadOAuthFromKeychain]) { + TFLog(@"[%@ %@] No oAuth info for notification.", URL.host, padID); + completionHandler(UIBackgroundFetchResultFailed); + return; + } + break; + } + case UIApplicationStateActive: + break; + } + + NSManagedObjectID * __block objectID; + NSError * __block padError; + [self.coreDataStack saveWithBlock:^(NSManagedObjectContext *localContext) { + HPPad *pad = [HPPad padWithID:padID + title:@"Untitled" + spaceURL:URL + managedObjectContext:localContext + error:&padError]; + if (!pad) { + return; + } + + if (![pad.space.userID isEqualToString:hp[AccountIdKey]]) { + TFLog(@"[%@ %@] Ignoring notification for wrong account: %@ (expecting %@)", + URL.host, padID, hp[AccountIdKey], pad.space.userID); + return; + } + + if (lastEditedDate > pad.lastEditedDate) { + pad.lastEditedDate = lastEditedDate; + } + + switch (eventType) { + case HPEditEventType: + break; + case HPCreateEventType: + case HPFollowEventType: + case HPInviteEventType: + case HPMentionEventType: + pad.followed = YES; + break; + case HPUnfollowEventType: + pad.followed = NO; + break; + case HPDeleteEventType: + [pad.managedObjectContext deleteObject:pad]; + return; + default: + TFLog(@"[%@ %@] Unhandled event type: %uh", URL.host, padID, eventType); + return; + } + + if (applicationState == UIApplicationStateActive) { + // App's running, so let pad cache controller update it. + return; + } + + if (![localContext obtainPermanentIDsForObjects:@[pad] + error:&padError]) { + return; + } + objectID = pad.objectID; + } completion:^(NSError *error) { + if (padError) { + TFLog(@"[%@ %@] Could not update pad from notification: %@", + URL.host, padID, padError); + completionHandler(UIBackgroundFetchResultFailed); + return; + } + if (!objectID) { + completionHandler(UIBackgroundFetchResultNewData); + return; + } + HPPad *pad = (HPPad *)[self.coreDataStack.mainContext existingObjectWithID:objectID + error:&padError]; + if (!pad) { + TFLog(@"[%@ %@] Could not find pad from notification: %@", URL.host, + padID, padError); + completionHandler(UIBackgroundFetchResultFailed); + return; + } + if (pad.hasMissedChanges) { + TFLog(@"[%@ %@] Ignoring notification since we have missed changes.", + URL.host, padID); + completionHandler(UIBackgroundFetchResultNoData); + return; + } + if (pad.lastEditedDate == pad.editor.clientVarsLastEditedDate) { + TFLog(@"[%@ %@] Pad is already up to date.", URL.host, padID); + completionHandler(UIBackgroundFetchResultNoData); + return; + } + [pad requestClientVarsWithRefresh:YES + completion:^(HPPad *pad, NSError *error) { + if (error) { + TFLog(@"[%@ %@] Could not update client vars from notification: %@", URL.host, padID, error); + completionHandler(UIBackgroundFetchResultFailed); + return; + } + [pad requestAuthorsWithCompletion:^(HPPad *pad, NSError *error) { + if (error) { + TFLog(@"[%@ %@] Could not update client vars from notification: %@", URL.host, padID, error); + completionHandler(UIBackgroundFetchResultFailed); + return; + } + completionHandler(UIBackgroundFetchResultNewData); + }]; + }]; + }]; +} + +#pragma mark - Other stuff + +#if DEBUG +- (void)dumpFontsAndExit +{ + for (NSString* family in [UIFont familyNames]) { + HPLog(@"%@", family); + for (NSString* name in [UIFont fontNamesForFamilyName:family]) { + HPLog(@" %@", name); + } + } + exit(0); +} +#endif + +- (void)configureAnalytics +{ + //[Flurry setCrashReportingEnabled:YES]; + [Flurry startSession:HPFlurryAnalyticsKey]; +} + +- (void)initializeTestFlight +{ +#if DEBUG || AD_HOC + if (HP_SYSTEM_MAJOR_VERSION() < 7) { + [TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]]; + } +#endif + HPLog(@"Using App Token: %@", TestFlightAppToken); + [TestFlight takeOff:TestFlightAppToken]; +} + +- (void)initializeProtocols +{ + [HPImageUploadURLProtocol setSharedCoreDataStack:self.coreDataStack]; + [NSURLProtocol registerClass:[HPImageUploadURLProtocol class]]; + [NSURLProtocol registerClass:[HPStaticCachingURLProtocol class]]; +} + ++ (BOOL)isRunningTests +{ + NSDictionary* environment = [[NSProcessInfo processInfo] environment]; + NSString* injectBundle = environment[@"XCInjectBundle"]; + return [[injectBundle pathExtension] isEqualToString:@"octest"]; +} + +- (void)setMobileCookie +{ + NSTimeInterval secondsPerYear = 60 * 60 * 24 * 365; + NSDictionary *cookieProperties = @{ + NSHTTPCookieDomain: [@"." stringByAppendingString:[[NSURL hp_sharedHackpadURL] host]], + NSHTTPCookiePath: @"/", + NSHTTPCookieName: @"HM", + NSHTTPCookieValue: @"T", + NSHTTPCookieExpires: [NSDate dateWithTimeIntervalSinceNow:secondsPerYear], + }; + NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties]; + [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie]; +} + +#pragma mark - Drawer Controller delegate + +- (void)drawerController:(HPDrawerController *)drawerController +willShowLeftDrawerAnimated:(BOOL)animated +{ + self.padScopeViewController.view.userInteractionEnabled = YES; + UINavigationController *mainNav = (UINavigationController *)drawerController.mainViewController; + mainNav.topViewController.view.userInteractionEnabled = NO; +} + +- (void)drawerController:(HPDrawerController *)drawerController +willHideLeftDrawerAnimated:(BOOL)animated +{ + self.padScopeViewController.view.userInteractionEnabled = NO; + UINavigationController *mainNav = (UINavigationController *)drawerController.mainViewController; + mainNav.topViewController.view.userInteractionEnabled = YES; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPBlueNavigationController.h b/client/ios/Hackpad/Hackpad/HPBlueNavigationController.h new file mode 100644 index 0000000..6a89483 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPBlueNavigationController.h @@ -0,0 +1,13 @@ +// +// HPBlueNavigationController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPColoredAppearanceContainer.h" + +@interface HPBlueNavigationController : UINavigationController + +@end diff --git a/client/ios/Hackpad/Hackpad/HPBlueNavigationController.m b/client/ios/Hackpad/Hackpad/HPBlueNavigationController.m new file mode 100644 index 0000000..01e079b --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPBlueNavigationController.m @@ -0,0 +1,45 @@ +// +// HPBlueNavigationController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPBlueNavigationController.h" + +@implementation HPBlueNavigationController ++ (UIImage *)coloredBackgroundImage +{ + return [UIImage imageNamed:@"bluebg.png"]; +} + ++ (UIColor *)coloredBarTintColor +{ + return [UIColor colorWithRed:0x61/255.0 + green:0x88/255.0 + blue:0xcc/255.0 + alpha:1.0]; +} ++ (UIColor *)coloredTintColor +{ + return [UIColor whiteColor]; +} ++ (UIColor *)navigationTitleColor +{ + return [UIColor whiteColor]; +} + +#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleLightContent; +} +- (void)viewDidLoad +{ + [super viewDidLoad]; + self.navigationBar.translucent = NO; +} +#endif + +@end diff --git a/client/ios/Hackpad/Hackpad/HPBrowserViewController.h b/client/ios/Hackpad/Hackpad/HPBrowserViewController.h new file mode 100644 index 0000000..cfb2d05 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPBrowserViewController.h @@ -0,0 +1,29 @@ +// +// HPBrowserViewController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@protocol HPBrowserViewControllerDelegate; + +@interface HPBrowserViewController : UIViewController +@property (weak, nonatomic) IBOutlet UIWebView *webView; +@property (weak, nonatomic) IBOutlet UIBarButtonItem *backButton; +@property (weak, nonatomic) IBOutlet UIBarButtonItem *forwardButton; +@property (copy, nonatomic) NSURLRequest *initialRequest; +@property (weak, nonatomic) id delegate; + +- (IBAction)close:(id)sender; +- (IBAction)share:(id)sender; +@end + +@protocol HPBrowserViewControllerDelegate + +- (BOOL)browserViewController:(HPBrowserViewController *)browserViewController +shouldStartLoadWithHackpadRequest:(NSURLRequest *)request; + +@end \ No newline at end of file diff --git a/client/ios/Hackpad/Hackpad/HPBrowserViewController.m b/client/ios/Hackpad/Hackpad/HPBrowserViewController.m new file mode 100644 index 0000000..049f487 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPBrowserViewController.m @@ -0,0 +1,109 @@ +// +// HPBrowserViewController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPBrowserViewController.h" + +#import "HackpadAdditions/HackpadAdditions.h" + +@interface HPBrowserViewController () + +@property (nonatomic, strong) UIPopoverController *activityPopover; + +@end + +@implementation HPBrowserViewController + +- (void)viewDidLoad +{ + if (self.initialRequest) { + [self.webView loadRequest:self.initialRequest]; + self.initialRequest = nil; + } +} + +- (void)dealloc +{ + self.webView.delegate = nil; +} + +- (void)updateToolbar +{ + self.forwardButton.enabled = self.webView.canGoForward; + self.backButton.enabled = self.webView.canGoBack; + [self.navigationController setToolbarHidden:!(self.webView.canGoBack || self.webView.canGoForward) + animated:YES]; +} + +- (BOOL)webView:(UIWebView *)webView +shouldStartLoadWithRequest:(NSURLRequest *)request + navigationType:(UIWebViewNavigationType)navigationType +{ + HPLog(@"[%@] Loading %@...", request.URL.host, request.URL.absoluteString); + if (request.URL.hp_isHackpadURL && self.delegate) { + return [self.delegate browserViewController:self + shouldStartLoadWithHackpadRequest:request]; + } + return YES; +} + +- (void)webView:(UIWebView *)webView +didFailLoadWithError:(NSError *)error +{ + UIApplication.sharedApplication.networkActivityIndicatorVisible = NO; + [self updateToolbar]; +} + +- (void)webViewDidFinishLoad:(UIWebView *)webView +{ + self.navigationItem.title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"]; + UIApplication.sharedApplication.networkActivityIndicatorVisible = NO; + [self updateToolbar]; +} + +- (void)webViewDidStartLoad:(UIWebView *)webView +{ + UIApplication.sharedApplication.networkActivityIndicatorVisible = YES; +} + +- (IBAction)close:(id)sender +{ + [self dismissViewControllerAnimated:YES + completion:^{}]; +} + +- (IBAction)share:(id)sender +{ + if (self.activityPopover) { + [self.activityPopover dismissPopoverAnimated:YES]; + self.activityPopover = nil; + return; + } + + UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:@[self.webView.request.URL] + applicationActivities:nil]; + if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) { + self.activityPopover = [[UIPopoverController alloc] initWithContentViewController:activity]; + self.activityPopover.delegate = self; + [self.activityPopover presentPopoverFromBarButtonItem:sender + permittedArrowDirections:UIPopoverArrowDirectionAny + animated:YES]; + } else { + [self presentViewController:activity + animated:YES + completion:^{}]; + } +} + +- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController +{ + if (popoverController == self.activityPopover) { + self.activityPopover = nil; + } +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPCancelFreeSearchDisplayController.h b/client/ios/Hackpad/Hackpad/HPCancelFreeSearchDisplayController.h new file mode 100644 index 0000000..da6318b --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPCancelFreeSearchDisplayController.h @@ -0,0 +1,12 @@ +// +// HPCancelFreeSearchDisplayController.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import + +@interface HPCancelFreeSearchDisplayController : UISearchDisplayController +@end diff --git a/client/ios/Hackpad/Hackpad/HPCancelFreeSearchDisplayController.m b/client/ios/Hackpad/Hackpad/HPCancelFreeSearchDisplayController.m new file mode 100644 index 0000000..2fe2c3f --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPCancelFreeSearchDisplayController.m @@ -0,0 +1,21 @@ +// +// HPCancelFreeSearchDisplayController.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPCancelFreeSearchDisplayController.h" + +@implementation HPCancelFreeSearchDisplayController + +- (void)setActive:(BOOL)visible + animated:(BOOL)animated; +{ + [super setActive:visible + animated:animated]; + self.searchBar.showsCancelButton = NO; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPColoredAppearanceContainer.h b/client/ios/Hackpad/Hackpad/HPColoredAppearanceContainer.h new file mode 100644 index 0000000..dfc1747 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPColoredAppearanceContainer.h @@ -0,0 +1,16 @@ +// +// HPColoredAppearanceContainer.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@protocol HPColoredAppearanceContainer ++ (UIImage *)coloredBackgroundImage; ++ (UIColor *)coloredBarTintColor; ++ (UIColor *)coloredTintColor; ++ (UIColor *)navigationTitleColor; +@end diff --git a/client/ios/Hackpad/Hackpad/HPDrawerController.h b/client/ios/Hackpad/Hackpad/HPDrawerController.h new file mode 100644 index 0000000..288d969 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPDrawerController.h @@ -0,0 +1,58 @@ +// +// HPDrawerController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@protocol HPDrawerControllerDelegate; + +@interface HPDrawerController : UIViewController + +@property (strong, nonatomic) UIViewController *mainViewController; +@property (strong, nonatomic) UIViewController *leftViewController; +@property (nonatomic, strong) UIViewController *rightViewController; + +@property (strong, nonatomic) IBOutlet UIView *mainView; +@property (strong, nonatomic) IBOutlet UIView *leftView; +@property (nonatomic, strong) IBOutlet UIView *rightView; + +@property (nonatomic, strong) IBOutlet NSLayoutConstraint *mainLeadingConstraint; +@property (nonatomic, strong) IBOutlet NSLayoutConstraint *mainTrailingConstraint; + +@property (strong, nonatomic) IBOutlet UIPanGestureRecognizer *panGesture; + +@property (assign, nonatomic, getter = isLeftDrawerShown) BOOL leftDrawerShown; +@property (nonatomic, assign, getter = isRightDrawerShown) BOOL rightDrawerShown; + +@property (nonatomic, assign) id delegate; + +- (void)setLeftDrawerShown:(BOOL)leftDrawerShown + animated:(BOOL)animated; + +- (void)setRightDrawerShown:(BOOL)rightDrawerShown + animated:(BOOL)animated; + +- (IBAction)handlePan:(id)sender; + +@end + +@protocol HPDrawerControllerDelegate +@optional + +- (void)drawerController:(HPDrawerController *)drawerController +willShowLeftDrawerAnimated:(BOOL)animated; + +- (void)drawerController:(HPDrawerController *)drawerController +willHideLeftDrawerAnimated:(BOOL)animated; + +- (void)drawerController:(HPDrawerController *)drawerController +willShowRightDrawerAnimated:(BOOL)animated; + +- (void)drawerController:(HPDrawerController *)drawerController +willHideRightDrawerAnimated:(BOOL)animated; + +@end \ No newline at end of file diff --git a/client/ios/Hackpad/Hackpad/HPDrawerController.m b/client/ios/Hackpad/Hackpad/HPDrawerController.m new file mode 100644 index 0000000..28e5fc4 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPDrawerController.m @@ -0,0 +1,309 @@ +// +// HPDrawerController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPDrawerController.h" + +@interface HPDrawerController () +@property (nonatomic, strong) NSArray *leftConstraints; +@property (nonatomic, strong) NSArray *rightConstraints; +@property (nonatomic, strong) NSArray *panConstraints; +@end + +@implementation HPDrawerController + +@synthesize leftViewController = _leftViewController; +@synthesize rightViewController = _rightViewController; + +- (void)viewDidLoad +{ + [super viewDidLoad]; + self.leftView.hidden = YES; + self.rightView.hidden = YES; +} + +- (void)setLeftViewController:(UIViewController *)leftViewController +{ + _leftViewController = leftViewController; + self.leftView.hidden = YES; + NSDictionary *views = @{@"leftView":self.leftView, + @"mainView":self.mainView, + @"view":self.view}; + self.leftConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|[leftView][mainView(==view)]" + options:0 + metrics:nil + views:views]; + +} + +- (void)setRightViewController:(UIViewController *)rightViewController +{ + _rightViewController = rightViewController; + self.rightView.hidden = YES; + NSDictionary *views = @{@"mainView":self.mainView, + @"rightView":self.rightView, + @"view":self.view}; + self.rightConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"[mainView(==view)][rightView]|" + options:0 + metrics:nil + views:views]; +} + +- (void)prepareForSegue:(UIStoryboardSegue *)segue + sender:(id)sender +{ + if ([segue.identifier isEqualToString:@"mainSegue"]) { + self.mainViewController = segue.destinationViewController; + } else if ([segue.identifier isEqualToString:@"leftDrawerSegue"]) { + self.leftViewController = segue.destinationViewController; + } else if ([segue.identifier isEqualToString:@"rightDrawerSegue"]) { + self.rightViewController = segue.destinationViewController; + } +} + +- (UIViewController *)mainViewController +{ + [self view]; + return _mainViewController; +} + +- (UIViewController *)leftViewController +{ + [self view]; + return _leftViewController; +} + +- (UIViewController *)rightViewController +{ + [self view]; + return _rightViewController; +} + +- (UIViewController *)effectiveMainViewController +{ + return [self.mainViewController isKindOfClass:[UINavigationController class]] + ? [(UINavigationController *)self.mainViewController topViewController] + : self.mainViewController; +} + + +- (void)setPanConstraints:(NSArray *)panConstraints +{ + if (_panConstraints) { + [self.view removeConstraints:_panConstraints]; + } + _panConstraints = panConstraints; + if (panConstraints) { + [self.view addConstraints:panConstraints]; + } +} + +- (void)setDrawerShown:(BOOL)shown +{ + self.panGesture.enabled = shown; +} + +- (void)showMainWithAnimated:(BOOL)animated +{ + [self setDrawerShown:NO]; + + self.panConstraints = nil; + if (self.leftConstraints) { + [self.view removeConstraints:self.leftConstraints]; + } + if (self.rightConstraints) { + [self.view removeConstraints:self.rightConstraints]; + } + [self.view addConstraint:self.mainLeadingConstraint]; + [self.view addConstraint:self.mainTrailingConstraint]; + + [UIView animateWithDuration:animated ? 0.25 : 0 + animations:^{ + [self.view layoutIfNeeded]; + } completion:^(BOOL finished) { + self.leftView.hidden = YES; + self.rightView.hidden = YES; + }]; +} + +- (void)showDrawerView:(UIView *)view + constraints:(NSArray *)constraints + animated:(BOOL)animated +{ + [self setDrawerShown:YES]; + self.panConstraints = nil; + view.hidden = NO; + [self.view removeConstraint:self.mainLeadingConstraint]; + [self.view removeConstraint:self.mainTrailingConstraint]; + [self.view addConstraints:constraints]; + [UIView animateWithDuration:animated ? 0.25 : 0 + animations:^{ + [self.view layoutIfNeeded]; + }]; + +} + +- (void)setLeftDrawerShown:(BOOL)leftDrawerShown + animated:(BOOL)animated +{ + if (!leftDrawerShown) { + if ([self.delegate respondsToSelector:@selector(drawerController:willHideLeftDrawerAnimated:)]) { + [self.delegate drawerController:self + willHideLeftDrawerAnimated:animated]; + } + [self showMainWithAnimated:animated]; + return; + } + + NSAssert(!self.isRightDrawerShown, @"Can't show both drawers."); + if ([self.delegate respondsToSelector:@selector(drawerController:willShowLeftDrawerAnimated:)]) { + [self.delegate drawerController:self + willShowLeftDrawerAnimated:animated]; + } + [self showDrawerView:self.leftView + constraints:self.leftConstraints + animated:animated]; +} + +- (void)setLeftDrawerShown:(BOOL)drawerShown +{ + [self setLeftDrawerShown:drawerShown + animated:NO]; +} + +- (BOOL)isLeftDrawerShown +{ + return self.leftView && !self.leftView.hidden; +} + +- (void)setRightDrawerShown:(BOOL)rightDrawerShown + animated:(BOOL)animated +{ + if (!rightDrawerShown) { + if ([self.delegate respondsToSelector:@selector(drawerController:willHideRightDrawerAnimated:)]) { + [self.delegate drawerController:self + willHideRightDrawerAnimated:animated]; + } + [self showMainWithAnimated:animated]; + return; + } + + NSAssert(!self.isLeftDrawerShown, @"Can't show both drawers."); + if ([self.delegate respondsToSelector:@selector(drawerController:willShowRightDrawerAnimated:)]) { + [self.delegate drawerController:self + willShowRightDrawerAnimated:animated]; + } + [self showDrawerView:self.rightView + constraints:self.rightConstraints + animated:animated]; +} + +- (void)setRightDrawerShown:(BOOL)rightDrawerShown +{ + [self setRightDrawerShown:rightDrawerShown + animated:NO]; +} + +- (BOOL)isRightDrawerShown +{ + return self.rightView && !self.rightView.hidden; +} + +- (IBAction)handlePan:(id)sender +{ + UIPanGestureRecognizer *panGesture = sender; + CGPoint point = [panGesture locationInView:self.view]; + + switch (panGesture.state) { + case UIGestureRecognizerStateChanged: { + NSDictionary *views = @{@"mainView":self.mainView, + @"view":self.view}; + + if (self.leftConstraints) { + [self.view removeConstraints:self.leftConstraints]; + } + if (self.rightConstraints) { + [self.view removeConstraints:self.rightConstraints]; + } + + if (self.leftDrawerShown) { + CGFloat offset = MIN(point.x, CGRectGetWidth(self.leftView.bounds)); + self.panConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-offset-[mainView(==view)]" + options:0 + metrics:@{@"offset":@(offset)} + views:views]; + } else if (self.rightDrawerShown) { + //CGFloat offset = MAX(point.x - self.rightView.bounds.size.width - self.rightView.frame.origin.x, -self.rightView.bounds.size.width); + } + [self.view layoutIfNeeded]; + break; + } + case UIGestureRecognizerStateEnded: { + self.panConstraints = nil; + if (self.leftDrawerShown) { + if (point.x < CGRectGetMidX(self.leftView.frame)) { + [self setLeftDrawerShown:NO + animated:YES]; + return; + } else { + [self.view addConstraints:self.leftConstraints]; + } + } else if (self.rightDrawerShown) { + if (point.x > CGRectGetMidX(self.rightView.frame)) { + [self setRightDrawerShown:NO + animated:YES]; + return; + } else { + [self.view addConstraints:self.rightConstraints]; + } + } + [UIView animateWithDuration:0.25 + animations:^{ + [self.view layoutIfNeeded]; + }]; + break; + } + default: + break; + } +} + +- (void)encodeRestorableStateWithCoder:(NSCoder *)coder +{ + [super encodeRestorableStateWithCoder:coder]; + [coder encodeObject:self.mainViewController + forKey:@"MainViewController"]; + [coder encodeObject:self.leftViewController + forKey:@"LeftViewController"]; + [coder encodeObject:self.rightViewController + forKey:@"RightViewController"]; +} + +- (void)decodeRestorableStateWithCoder:(NSCoder *)coder +{ + [super decodeRestorableStateWithCoder:coder]; + // OK this is magic. + [coder decodeObjectForKey:@"MainViewController"]; + if ([coder containsValueForKey:@"LeftViewController"]) { + [coder decodeObjectForKey:@"LeftViewController"]; + } + if ([coder containsValueForKey:@"RightViewController"]) { + [coder decodeObjectForKey:@"RightViewController"]; + } +} + +- (NSUInteger)supportedInterfaceOrientations +{ + return self.effectiveMainViewController.supportedInterfaceOrientations; +} + +- (UIInterfaceOrientation)interfaceOrientation +{ + return self.effectiveMainViewController.interfaceOrientation; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPEmptySearchViewController.h b/client/ios/Hackpad/Hackpad/HPEmptySearchViewController.h new file mode 100644 index 0000000..68203f7 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPEmptySearchViewController.h @@ -0,0 +1,13 @@ +// +// HPEmptySearchViewController.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import + +@interface HPEmptySearchViewController : UIViewController + +@end diff --git a/client/ios/Hackpad/Hackpad/HPEmptySearchViewController.m b/client/ios/Hackpad/Hackpad/HPEmptySearchViewController.m new file mode 100644 index 0000000..3792bb4 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPEmptySearchViewController.m @@ -0,0 +1,22 @@ +// +// HPEmptySearchViewController.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPEmptySearchViewController.h" + +@interface HPEmptySearchViewController () + +@end + +@implementation HPEmptySearchViewController + +- (void)viewDidAppear:(BOOL)animated +{ + [self.searchDisplayController.searchBar becomeFirstResponder]; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPFlurryEventKeys.h b/client/ios/Hackpad/Hackpad/HPFlurryEventKeys.h new file mode 100644 index 0000000..3348129 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPFlurryEventKeys.h @@ -0,0 +1,11 @@ +// +// HPFlurryEventKeys.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +static NSString * const HPPadViewedEventKey = @"Pad_Viewed"; +static NSString * const HPPadEditedEventKey = @"Pad_Edited"; +static NSString * const HPPadEditsCancelledEventKey = @"Pad_EditsCancelled"; \ No newline at end of file diff --git a/client/ios/Hackpad/Hackpad/HPGoogleSignInViewController.h b/client/ios/Hackpad/Hackpad/HPGoogleSignInViewController.h new file mode 100644 index 0000000..131658a --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPGoogleSignInViewController.h @@ -0,0 +1,19 @@ +// +// HPGoogleSignInViewController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface HPGoogleSignInViewController : UIViewController + +@property (weak, nonatomic) IBOutlet UIWebView *webView; +@property (strong, nonatomic, readonly) NSURL *URL; + +- (void)signInToSpaceWithURL:(NSURL *)URL + completion:(void (^)(BOOL, NSError *))handler; + +@end diff --git a/client/ios/Hackpad/Hackpad/HPGoogleSignInViewController.m b/client/ios/Hackpad/Hackpad/HPGoogleSignInViewController.m new file mode 100644 index 0000000..79b570e --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPGoogleSignInViewController.m @@ -0,0 +1,147 @@ +// +// HPGoogleSignInViewController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPGoogleSignInViewController.h" + +#import "HackpadKit/HackpadKit.h" +#import "HackpadAdditions/HackpadUIAdditions.h" + +#import + +static NSString * const HPGoogleSignInPath = @"/ep/account/google-sign-in"; + +static NSString * const HPContParam = @"cont"; + +// From WebKitErrors.h +static NSString *HPWebKitErrorDomain = @"WebKitErrorDomain"; +enum { + HPWebKitErrorCannotShowMIMEType = 100, + HPWebKitErrorCannotShowURL = 101, + HPWebKitErrorFrameLoadInterruptedByPolicyChange = 102, +}; + +static NSString * const SignedInPath = @"/ep/iOS/x-HackpadKit-signed-in"; +static NSString * const UserIdKey = @"userId"; + +@interface HPGoogleSignInViewController () { + void (^_signInHandler)(BOOL, NSError *); +} + +@property (nonatomic, readonly) BOOL hasGoogleCookies; + +- (void)dismissWithError:(NSError *)error + cancelled:(BOOL)cancelled; +- (void)loadRequest; + +@end + +@implementation HPGoogleSignInViewController + +- (void)loadRequest +{ + NSURLRequest *request = [NSURLRequest hp_requestWithURL:[NSURL URLWithString:HPGoogleSignInPath + relativeToURL:self.URL] + HTTPMethod:@"GET" + parameters:@{ + HPContParam:[[NSURL URLWithString:SignedInPath + relativeToURL:self.URL] absoluteString] + }]; + [MBProgressHUD showHUDAddedTo:self.view + animated:YES]; + [self.webView loadRequest:request]; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + if (self.URL) { + [self loadRequest]; + } +} + +- (void)signInToSpaceWithURL:(NSURL *)URL + completion:(void (^)(BOOL, NSError *))handler +{ + NSParameterAssert(handler); + _signInHandler = handler; + _URL = URL; + if (self.isViewLoaded) { + [self loadRequest]; + } +} + +- (void)dismissWithError:(NSError *)error + cancelled:(BOOL)cancelled +{ + // We don't want to get any more notifications. + self.webView.delegate = nil; + void (^handler)(BOOL, NSError *) = _signInHandler; + _signInHandler = nil; + if (handler) { + handler(cancelled, error); + } +} + +#pragma mark - Web view delegate methods + +- (BOOL)webView:(UIWebView *)webView +shouldStartLoadWithRequest:(NSURLRequest *)request + navigationType:(UIWebViewNavigationType)navigationType +{ + static NSString * const OpenIDPath = @"/ep/account/openid"; + HPLog(@"[%@] Should load %@?", self.URL.host, request.URL.absoluteString); + if (![request.URL hp_isOriginEqualToURL:self.URL]) { + return YES; + } + if ([request.URL.path isEqualToString:SignedInPath]) { + [self dismissWithError:nil + cancelled:NO]; + return NO; + } + if ([request.URL.path isEqualToString:OpenIDPath]) { + [MBProgressHUD showHUDAddedTo:self.view + animated:YES]; + } + return YES; +} + +- (void)webViewDidStartLoad:(UIWebView *)webView +{ + HPLog(@"[%@] Loading %@...", self.URL.host, webView.request.URL.absoluteString); +} + +- (void)webViewDidFinishLoad:(UIWebView *)webView +{ + [MBProgressHUD hideAllHUDsForView:self.view + animated:YES]; + HPLog(@"[%@] Loaded %@.", self.URL.host, webView.request.URL.absoluteString); + // Workaround in case of some server bug where we get redrected to /. + if ([webView.request.URL hp_isOriginEqualToURL:self.URL] && + /* [webView.request.URL.path isEqualToString:@"/"] && */ + [webView hp_clientVarValueForKey:UserIdKey].length) { + HPLog(@"[%@] Signed in, but to %@ and not %@.", + self.URL.host, webView.request.URL.absoluteString, + [[NSURL URLWithString:SignedInPath + relativeToURL:self.URL] absoluteString]); + [self dismissWithError:nil + cancelled:NO]; + } +} + +- (void)webView:(UIWebView *)webView +didFailLoadWithError:(NSError *)error +{ + if ([error.domain isEqualToString:HPWebKitErrorDomain] && + error.code == HPWebKitErrorFrameLoadInterruptedByPolicyChange) { + return; + } + [self dismissWithError:error + cancelled:NO]; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPGrayNavigationController.h b/client/ios/Hackpad/Hackpad/HPGrayNavigationController.h new file mode 100644 index 0000000..5edc387 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPGrayNavigationController.h @@ -0,0 +1,13 @@ +// +// HPGrayNavigationController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPColoredAppearanceContainer.h" + +@interface HPGrayNavigationController : UINavigationController + +@end diff --git a/client/ios/Hackpad/Hackpad/HPGrayNavigationController.m b/client/ios/Hackpad/Hackpad/HPGrayNavigationController.m new file mode 100644 index 0000000..4e2bcef --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPGrayNavigationController.m @@ -0,0 +1,62 @@ +// +// HPGrayNavigationController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPGrayNavigationController.h" + +@implementation HPGrayNavigationController ++ (UIImage *)coloredBackgroundImage +{ + return [UIImage imageNamed:@"graybg"]; +} + ++ (UIColor *)coloredBarTintColor +{ + return [UIColor hp_darkGrayColor]; +} ++ (UIColor *)coloredTintColor +{ + return [UIColor hp_lightGreenGrayColor]; +} ++ (UIColor *)navigationTitleColor +{ + return [UIColor hp_mediumGreenGrayColor]; +} + +- (BOOL)disablesAutomaticKeyboardDismissal +{ + if (self.modalPresentationStyle != UIModalPresentationFormSheet) { + return [super disablesAutomaticKeyboardDismissal]; + } + // http://stackoverflow.com/questions/3372333/ipad-keyboard-will-not-dismiss-if-modal-view-controller-presentation-style-is-ui/3386768#3386768 + return NO; +} + +// For sign in view controller +- (NSUInteger)supportedInterfaceOrientations +{ + return self.topViewController.supportedInterfaceOrientations; +} + +- (UIInterfaceOrientation)interfaceOrientation +{ + return self.topViewController.interfaceOrientation; +} + +#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleLightContent; +} +- (void)viewDidLoad +{ + [super viewDidLoad]; + self.navigationBar.translucent = YES; +} +#endif + +@end diff --git a/client/ios/Hackpad/Hackpad/HPGroupedToolbar.h b/client/ios/Hackpad/Hackpad/HPGroupedToolbar.h new file mode 100644 index 0000000..87e1b36 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPGroupedToolbar.h @@ -0,0 +1,20 @@ +// +// HPGroupedToolbar.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +UIKIT_EXTERN NSTimeInterval const HPGroupedToolbarDefaultAnimationDuration; + +@interface HPGroupedToolbar : UIView +@property (nonatomic, weak) UIToolbar *toolbar; +@property (nonatomic, strong) NSArray *groups; +@property (nonatomic, strong) UIColor *selectedGroupTintColor; +@property (nonatomic, strong) UIColor *selectedGroupBackgroundColor; +@property (nonatomic, assign) NSTimeInterval animationDuration; +- (void)showRootToolbarAnimated:(BOOL)animated; +@end diff --git a/client/ios/Hackpad/Hackpad/HPGroupedToolbar.m b/client/ios/Hackpad/Hackpad/HPGroupedToolbar.m new file mode 100644 index 0000000..14e5208 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPGroupedToolbar.m @@ -0,0 +1,177 @@ +// +// HPGroupedToolbar.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPGroupedToolbar.h" + +NSTimeInterval const HPGroupedToolbarDefaultAnimationDuration = 0.4; + +@interface HPGroupedToolbar () +@property (nonatomic, weak) UIBarButtonItem *selectedItem; +@property (nonatomic, weak) UIControl *selectedButton; +@property (nonatomic, weak) UIToolbar *selectedGroup; +@property (nonatomic, strong) UIColor *originalSelectedGroupColor; +@end + +@implementation HPGroupedToolbar + +- (NSTimeInterval)animationDuration +{ + if (!_animationDuration) { + _animationDuration = HPGroupedToolbarDefaultAnimationDuration; + } + return _animationDuration; +} + +- (void)setToolbar:(UIToolbar *)toolbar +{ + toolbar.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); + [self addSubview:toolbar]; + NSUInteger __block nonButtonItems = 0; + [toolbar.items enumerateObjectsUsingBlock:^(UIBarButtonItem *item, NSUInteger idx, BOOL *stop) { + if (item.width <= 0) { + ++nonButtonItems; + return; + } + if (item.action) { + return; + } + item.target = self; + item.action = @selector(toggleGroupWithItem:); + item.tag = idx - nonButtonItems; + }]; + _toolbar = toolbar; +} + +- (NSArray *)buttons +{ + NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { + return [evaluatedObject isKindOfClass:[UIControl class]]; + }]; + NSArray *buttons = [self.toolbar.subviews filteredArrayUsingPredicate:predicate]; + return [buttons sortedArrayUsingComparator:^NSComparisonResult(UIControl *obj1, UIControl *obj2) { + CGFloat x1 = CGRectGetMinX(obj1.frame); + CGFloat x2 = CGRectGetMinX(obj2.frame); + return x1 < x2 ? NSOrderedAscending : x1 > x2 ? NSOrderedDescending : NSOrderedSame; + }]; +} + +- (void)showRootToolbarAnimated:(BOOL)animated +{ + if (!self.selectedGroup) { + return; + } + HPGroupedToolbar * __weak weakSelf = self; + [UIView animateWithDuration:animated ? self.animationDuration / 2 : 0 + animations:^{ + weakSelf.toolbar.frame = weakSelf.toolbar.bounds; + if (self.selectedGroupTintColor) { + weakSelf.selectedItem.tintColor = weakSelf.originalSelectedGroupColor; + } else if (self.selectedGroupBackgroundColor) { + weakSelf.selectedButton.backgroundColor = weakSelf.originalSelectedGroupColor; + } + if (![weakSelf.selectedGroup isKindOfClass:[UIToolbar class]]) { + return; + } + CGRect frame = weakSelf.selectedGroup.bounds; + frame.origin.x = CGRectGetWidth(weakSelf.bounds); + weakSelf.selectedGroup.frame = frame; + } completion:^(BOOL finished) { + weakSelf.selectedGroup.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; + weakSelf.selectedGroup = nil; + weakSelf.selectedItem = nil; + [UIView animateWithDuration:animated ? weakSelf.animationDuration / 2 : 0 + animations:^{ + [[weakSelf buttons] enumerateObjectsUsingBlock:^(UIControl *button, NSUInteger idx, BOOL *stop) { + button.alpha = 1; + }]; + }]; + }]; +} + +- (void)toggleGroupWithItem:(UIBarButtonItem *)sender +{ + if (self.selectedGroup) { + [self showRootToolbarAnimated:YES]; + return; + } + + UIToolbar *selectedGroup = self.groups[sender.tag]; + if (![selectedGroup isKindOfClass:[UIToolbar class]]) { + return; + } + + self.selectedGroup = selectedGroup; + self.selectedItem = sender; + + NSArray *buttons = [self buttons]; + self.selectedButton = buttons[sender.tag]; + self.selectedButton.layer.cornerRadius = 5; + self.selectedButton.layer.masksToBounds = YES; + + CGRect toolbarFrame = self.bounds; + toolbarFrame.origin.x -= CGRectGetMinX(self.selectedButton.frame); + // hack. should be controlled with a property or something. + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + // Don't move 1st button on phone. + toolbarFrame.origin.x += CGRectGetMinX([buttons[0] frame]); + } + + CGFloat offset = CGRectGetWidth(self.selectedButton.frame); + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + // Don't move 1st button on phone. + offset += CGRectGetMinX([buttons[0] frame]); + } + CGRect groupFrame = self.bounds; + groupFrame.size.width -= offset; + + if (!self.selectedGroup.superview) { + self.selectedGroup.center = self.toolbar.center; + groupFrame.origin.x = CGRectGetMaxX(self.bounds); + self.selectedGroup.frame = groupFrame; + self.selectedGroup.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; + [self addSubview:self.selectedGroup]; + } + + groupFrame.origin.x = offset; + + [UIView animateWithDuration:self.animationDuration / 2 + animations:^{ + [buttons enumerateObjectsUsingBlock:^(UIControl *button, NSUInteger idx, BOOL *stop) { + if (idx == sender.tag) { + return; + } + button.alpha = 0; + }]; + } completion:^(BOOL finished) { + [UIView animateWithDuration:self.animationDuration / 2 + animations:^{ + if (self.selectedGroupTintColor) { + self.originalSelectedGroupColor = sender.tintColor; + sender.tintColor = self.selectedGroupTintColor; + } else if (self.selectedGroupBackgroundColor) { + self.originalSelectedGroupColor = self.selectedButton.backgroundColor; + self.selectedButton.backgroundColor = self.selectedGroupBackgroundColor; + } + self.toolbar.frame = toolbarFrame; + self.selectedGroup.frame = groupFrame; + } completion:^(BOOL finished) { + self.selectedGroup.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + }]; + }]; +} + +- (void)setFrame:(CGRect)frame +{ + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + // Hack. + frame.size.width = 320; + } + [super setFrame:frame]; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPInvitationController.h b/client/ios/Hackpad/Hackpad/HPInvitationController.h new file mode 100644 index 0000000..2cc78d1 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPInvitationController.h @@ -0,0 +1,20 @@ +// +// HPInvitationTableDataSource.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPPad; +@class HPInvitationTableViewDataSource; + +@interface HPInvitationController : NSObject + +@property (nonatomic, strong) HPPad *pad; +@property (nonatomic, strong) HPInvitationTableViewDataSource *dataSource; +@property (nonatomic, weak) IBOutlet UIViewController *viewController; +@property (nonatomic, weak) IBOutlet UIBarButtonItem *inviteItem; +@end diff --git a/client/ios/Hackpad/Hackpad/HPInvitationController.m b/client/ios/Hackpad/Hackpad/HPInvitationController.m new file mode 100644 index 0000000..c7f64c6 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPInvitationController.m @@ -0,0 +1,237 @@ +// +// HPInvitationTableDataSource.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPInvitationController.h" + +#import "HackpadKit.h" +#import "HackpadAdditions.h" + +#import "HPInvitationTableViewDataSource.h" + +#import +#import + +@interface HPInvitationController () { + ABPeoplePickerNavigationController *_peoplePicker; + NSDictionary *_selectedResult; +} +@end + +//ABAddressBookCopyPeopleWithName() + +// Sources: +// 1. address book +// 2. + +@implementation HPInvitationController + +- (void)inviteResult:(NSDictionary *)result +{ + _selectedResult = result; + UIView *view = _peoplePicker + ? _peoplePicker.view + : self.viewController.searchDisplayController.isActive + ? self.viewController.searchDisplayController.searchResultsTableView + : self.viewController.view; + [[[UIActionSheet alloc] initWithTitle:nil + delegate:self + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:nil + otherButtonTitles:[NSString stringWithFormat:@"Invite %@", _selectedResult[HPInvitationNameKey]], nil] showInView:view]; +} + +#pragma mark - Table View Delegate + +- (void)tableView:(UITableView *)tableView +didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [tableView deselectRowAtIndexPath:indexPath + animated:YES]; + [self inviteResult:[self.dataSource invitationInfoAtIndexPath:indexPath]]; +} + +#pragma mark - Search Display delegate + +- (BOOL)searchDisplayController:(UISearchDisplayController *)controller +shouldReloadTableForSearchString:(NSString *)searchString +{ + self.dataSource.searchText = searchString; + return NO; +} + +- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller +{ + if (!self.dataSource) { + self.dataSource = [HPInvitationTableViewDataSource new]; + self.dataSource.space = self.pad.space; + self.dataSource.tableView = controller.searchResultsTableView; + + controller.searchResultsDataSource = self.dataSource; + } + if (HP_SYSTEM_MAJOR_VERSION() < 7) { + return; + } + controller.searchBar.searchBarStyle = UISearchBarStyleProminent; + controller.searchBar.barTintColor = [UIColor whiteColor]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + return; + } + // Bug fixes for iOS 7 on iPad: http://petersteinberger.com/blog/2013/fixing-uisearchdisplaycontroller-on-ios-7/ + [controller.searchContentsController hp_setNonSearchViewsHidden:YES + animated:YES]; + [UIView animateWithDuration:0.25f + animations:^{ + controller.searchResultsTableView.alpha = 1; + }]; +} + +- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller +{ + if (HP_SYSTEM_MAJOR_VERSION() < 7) { + return; + } + controller.searchBar.searchBarStyle = UISearchBarStyleMinimal; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + return; + } + [controller.searchContentsController hp_setNonSearchViewsHidden:NO + animated:YES]; + [UIView animateWithDuration:0.25f + animations:^{ + controller.searchResultsTableView.alpha = 0; + }]; +} + +- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller +{ + if (controller.searchBar.superview == self.viewController.view) { + return; + } + [self.viewController.view addSubview:controller.searchBar]; +} + +#pragma Search Bar delegate + +- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar +{ + _peoplePicker = [[ABPeoplePickerNavigationController alloc] init]; + _peoplePicker.displayedProperties = @[@(kABPersonEmailProperty)]; + _peoplePicker.peoplePickerDelegate = self; + + [self.viewController presentViewController:_peoplePicker + animated:YES + completion:NULL]; +} + +#pragma People Picker delegate + +- (void)dismissPeoplePicker:(void (^)(void))handler +{ + _peoplePicker.delegate = nil; + _peoplePicker = nil; + [self.viewController dismissViewControllerAnimated:YES + completion:handler]; +} + +- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker + shouldContinueAfterSelectingPerson:(ABRecordRef)person +{ + NSString *email; + CFArrayRef people = ABPersonCopyArrayOfAllLinkedPeople(person); + for (NSUInteger i = 0; i < CFArrayGetCount(people); i++) { + person = CFArrayGetValueAtIndex(people, i); + ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty); + CFIndex count = ABMultiValueGetCount(multi); + if (count == 1 && !email) { + email = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(multi, 0); + } else if (count) { + email = nil; + // break loop. + i = CFArrayGetCount(people); + } + CFRelease(multi); + } + CFRelease(people); + if (!email) { + return YES; + } + + NSString *name = (__bridge_transfer NSString *)ABRecordCopyCompositeName(person); + if (!name.length) { + name = email; + } + [self inviteResult:@{HPInvitationNameKey:name, + HPInvitationEmailKey:email}]; + return NO; +} + +- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker + shouldContinueAfterSelectingPerson:(ABRecordRef)person + property:(ABPropertyID)property + identifier:(ABMultiValueIdentifier)identifier +{ + ABMultiValueRef multi = ABRecordCopyValue(person, property); + CFIndex index = ABMultiValueGetIndexForIdentifier(multi, identifier); + NSString *email = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(multi, index); + CFRelease(multi); + NSString *name = (__bridge_transfer NSString *)ABRecordCopyCompositeName(person); + if (!name.length) { + name = email; + } + [self inviteResult:@{HPInvitationNameKey:name, + HPInvitationEmailKey:email}]; + return NO; +} + +- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker +{ + [self dismissPeoplePicker:NULL]; +} + +#pragma mark Alert delegate + +- (void)actionSheet:(UIActionSheet *)actionSheet +didDismissWithButtonIndex:(NSInteger)buttonIndex +{ + if (buttonIndex == actionSheet.cancelButtonIndex) { + return; + } + void (^handler)(HPPad *, NSError *) = ^(HPPad *pad, NSError *error) { + if (error) { + [[[UIAlertView alloc] initWithTitle:@"Invitation Error" + message:error.localizedDescription + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; + } else { + void (^handler2)(void) = ^{ + self.viewController.searchDisplayController.searchBar.text = nil; + [self.viewController.searchDisplayController setActive:NO + animated:YES]; + }; + if (_peoplePicker) { + [self dismissPeoplePicker:handler2]; + } else { + handler2(); + } + } + }; + if (_selectedResult[HPInvitationUserIDKey]) { + [self.pad sendInvitationWithUserId:_selectedResult[HPInvitationUserIDKey] + completion:handler]; + } else if (_selectedResult[HPInvitationEmailKey]) { + [self.pad sendInvitationWithEmail:_selectedResult[HPInvitationEmailKey] + completion:handler]; + } else if (_selectedResult[HPInvitationFacebookIDKey]) { + [self.pad sendInvitationWithFacebookID:_selectedResult[HPInvitationFacebookIDKey] + name:_selectedResult[HPInvitationNameKey] + completion:handler]; + } +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPInvitationTableViewDataSource.h b/client/ios/Hackpad/Hackpad/HPInvitationTableViewDataSource.h new file mode 100644 index 0000000..7dbeeed --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPInvitationTableViewDataSource.h @@ -0,0 +1,24 @@ +// +// HPInvitationTableViewDataSource.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPSpace; + +UIKIT_EXTERN NSString * const HPInvitationEmailKey; +UIKIT_EXTERN NSString * const HPInvitationFacebookIDKey; +UIKIT_EXTERN NSString * const HPInvitationLabelKey; +UIKIT_EXTERN NSString * const HPInvitationNameKey; +UIKIT_EXTERN NSString * const HPInvitationUserIDKey; + +@interface HPInvitationTableViewDataSource : NSObject +@property (nonatomic, strong) HPSpace *space; +@property (nonatomic, strong) UITableView *tableView; +@property (nonatomic, strong) NSString *searchText; +- (NSDictionary *)invitationInfoAtIndexPath:(NSIndexPath *)indexPath; +@end diff --git a/client/ios/Hackpad/Hackpad/HPInvitationTableViewDataSource.m b/client/ios/Hackpad/Hackpad/HPInvitationTableViewDataSource.m new file mode 100644 index 0000000..4a7d260 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPInvitationTableViewDataSource.m @@ -0,0 +1,237 @@ +// +// HPInvitationTableViewDataSource.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPInvitationTableViewDataSource.h" + +#import +#import + +NSString * const HPInvitationEmailKey = @"email"; +NSString * const HPInvitationFacebookIDKey = @"fbid"; +NSString * const HPInvitationLabelKey = @"label"; +NSString * const HPInvitationNameKey = @"name"; +NSString * const HPInvitationUserIDKey = @"userId"; + +@interface HPInvitationTableViewDataSource () +@property (nonatomic, assign) ABAddressBookRef addressBook; +@property (nonatomic, strong) ABPeoplePickerNavigationController *peoplePicker; +@property (nonatomic, strong) NSMutableArray *results; +@property (nonatomic, assign) NSUInteger requestID; +@property (nonatomic, strong) NSMutableDictionary *seenEmail; +@end + +@implementation HPInvitationTableViewDataSource + +#pragma mark - NSObject + +- (id)init +{ + self = [super init]; + if (!self) { + return nil; + } + CFErrorRef errorRef = NULL; + _addressBook = ABAddressBookCreateWithOptions(NULL, &errorRef); + NSError *error = (__bridge_transfer NSError *)errorRef; + if (error) { + TFLog(@"[%@] Could not create address book: %@", self.space.URL.host, error); + } + if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { + ABAddressBookRequestAccessWithCompletion(self.addressBook, NULL); + } + self.results = [NSMutableArray array]; + self.seenEmail = [NSMutableDictionary dictionary]; + return self; +} + +- (void)dealloc +{ + if (_addressBook) { + CFRelease(_addressBook); + _addressBook = NULL; + } +} + +#pragma mark - Implementation + +static CFComparisonResult +HPInvitationTableViewDataSourcePersonComparator(const void *val1, + const void *val2, + void *context) +{ + return ABPersonComparePeopleByName(val1, val2, ABPersonGetSortOrdering()); +} + +- (void)addAddressBookResultsForSearchText:(NSString *)searchText +{ + CFArrayRef unsorted = ABAddressBookCopyPeopleWithName(self.addressBook, (__bridge CFStringRef)searchText); + CFIndex count = CFArrayGetCount(unsorted); + + CFMutableArrayRef sorted = CFArrayCreateMutableCopy(kCFAllocatorDefault, count, unsorted); + CFRelease(unsorted); + + CFArraySortValues(sorted, CFRangeMake(0, count), + HPInvitationTableViewDataSourcePersonComparator, NULL); + + for (CFIndex i = 0; i < count; i++) { + ABRecordRef person = CFArrayGetValueAtIndex(sorted, i); + ABMultiValueRef emailValue = ABRecordCopyValue(person, kABPersonEmailProperty); + if (!ABMultiValueGetCount(emailValue)) { + CFRelease(emailValue); + continue; + } + NSString *name = (__bridge_transfer NSString *)ABRecordCopyCompositeName(person); + name = [name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + for (CFIndex j = 0; j < ABMultiValueGetCount(emailValue); j++) { + NSString *label = (__bridge_transfer NSString *)ABMultiValueCopyLabelAtIndex(emailValue, j); + label = (__bridge_transfer NSString *)ABAddressBookCopyLocalizedLabel((__bridge CFStringRef)label); + NSString *email = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(emailValue, j); + NSDictionary *info = @{HPInvitationNameKey:name.length ? name : email, + HPInvitationEmailKey:email, + HPInvitationLabelKey:label}; + if (!self.seenEmail[email]) { + [self.results addObject:info]; + self.seenEmail[email] = info; + } + } + CFRelease(emailValue); + } + CFRelease(sorted); +} + +- (void)addServerResultsForSearchText:(NSString *)searchText +{ + HPInvitationTableViewDataSource * __weak weakSelf = self; + NSUInteger requestID = ++self.requestID; + [self.space requestContactsMatchingText:searchText + completion:^(HPSpace *space, + NSArray *contacts, + NSError *error) + { + if (!weakSelf || weakSelf.requestID != requestID) { + return; + } + if (error) { + TFLog(@"[%@] Could not find contacts for search string %@: %@", + space.URL.host, searchText, error); + return; + } + + NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:contacts.count]; + [contacts enumerateObjectsUsingBlock:^(NSDictionary *contact, NSUInteger idx, BOOL *stop) { + if (![contact isKindOfClass:[NSDictionary class]]) { + return; + } + NSString *email = contact[HPInvitationEmailKey]; + NSString *facebookID = contact[HPInvitationFacebookIDKey]; + NSString *userID = contact[HPInvitationUserIDKey]; + if (!([email isKindOfClass:[NSString class]] && email.length) && + !([facebookID isKindOfClass:[NSString class]] && facebookID.length) && + !([userID isKindOfClass:[NSString class]] && userID.length)) { + return; + } + + [indexPaths addObject:[NSIndexPath indexPathForRow:weakSelf.results.count + inSection:0]]; + [weakSelf.results addObject:contact]; + if ([email isKindOfClass:[NSString class]] && email.length) { + _seenEmail[email] = contact; + } + }]; + if (!indexPaths.count) { + return; + } + [weakSelf.tableView beginUpdates]; + [weakSelf.tableView insertRowsAtIndexPaths:indexPaths + withRowAnimation:UITableViewRowAnimationAutomatic]; + [weakSelf.tableView endUpdates]; + }]; +} + +- (void)setSearchText:(NSString *)searchText +{ + [self.results removeAllObjects]; + [self.seenEmail removeAllObjects]; + + NSUInteger requestID = ++self.requestID; + + if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) { + [self addAddressBookResultsForSearchText:searchText]; + } + if (!searchText.length) { + [self.tableView reloadData]; + return; + } + + HPInvitationTableViewDataSource * __weak weakSelf = self; + double delayInSeconds = .4; + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); + dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ + if (!weakSelf || weakSelf.requestID != requestID) { + return; + } + [weakSelf addServerResultsForSearchText:searchText]; + }); + + if ([searchText rangeOfString:@"@"].location == NSNotFound) { + [self.tableView reloadData]; + return; + } + NSDictionary *info = @{HPInvitationEmailKey:searchText, + HPInvitationNameKey:searchText}; + [self.results addObject:info]; + + self.seenEmail[searchText] = info; + + [self.tableView reloadData]; +} + +- (NSDictionary *)invitationInfoAtIndexPath:(NSIndexPath *)indexPath +{ + return self.results[indexPath.row]; +} + +#pragma mark - Table view data source + +- (NSInteger)tableView:(UITableView *)tableView + numberOfRowsInSection:(NSInteger)section +{ + return [self.results count]; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView + cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString * const CellIdentifier = @"Cell"; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; + if (!cell) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle + reuseIdentifier:CellIdentifier]; + cell.backgroundColor = tableView.backgroundColor; + } + cell.accessoryView = nil; + cell.textLabel.font = [UIFont hp_padTitleFontOfSize:cell.textLabel.font.pointSize]; + cell.detailTextLabel.font = [UIFont hp_padTitleFontOfSize:cell.detailTextLabel.font.pointSize]; + + NSDictionary *result = _results[indexPath.row]; + NSString *name = result[HPInvitationNameKey]; + NSString *email = result[HPInvitationEmailKey]; + cell.textLabel.text = name; + if ([name isEqualToString:email]) { + cell.detailTextLabel.text = nil; + return cell; + } + + NSString *label = result[HPInvitationEmailKey]; + [NSString stringWithFormat:@"%@ %@", label ? label : @"", email ? email : @""]; + NSCharacterSet *ws = [NSCharacterSet whitespaceAndNewlineCharacterSet]; + cell.detailTextLabel.text = [label stringByTrimmingCharactersInSet:ws]; + return cell; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadAutocompleteTableViewDataSource.h b/client/ios/Hackpad/Hackpad/HPPadAutocompleteTableViewDataSource.h new file mode 100644 index 0000000..9cc0fee --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadAutocompleteTableViewDataSource.h @@ -0,0 +1,15 @@ +// +// HPPadAutocompleteTableViewDataSource.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import + +@interface HPPadAutocompleteTableViewDataSource : NSObject +@property (nonatomic, strong) NSArray *autocompleteData; +@property (nonatomic, strong) NSURL *baseURL; +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadAutocompleteTableViewDataSource.m b/client/ios/Hackpad/Hackpad/HPPadAutocompleteTableViewDataSource.m new file mode 100644 index 0000000..00948de --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadAutocompleteTableViewDataSource.m @@ -0,0 +1,85 @@ +// +// HPPadAutocompleteTableViewDataSource.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadAutocompleteTableViewDataSource.h" + +#import + +@interface HPPadAutocompleteTableViewDataSource () +@property (nonatomic, strong) NSCache *iconsCache; +@end + +@implementation HPPadAutocompleteTableViewDataSource + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView + numberOfRowsInSection:(NSInteger)section +{ + return self.autocompleteData.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView + cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString * const identifier = @"AutocompleteCell"; + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; + + if (!cell) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault + reuseIdentifier:identifier]; + cell.textLabel.font = [UIFont hp_UITextFontOfSize:14]; + } + NSDictionary *contact = self.autocompleteData[indexPath.row]; + cell.textLabel.text = contact[@"title"]; + NSString *imageString = contact[@"image"]; + if (!imageString) { + cell.imageView.image = nil; + return cell; + } + if (self.iconsCache) { + cell.imageView.image = [self.iconsCache objectForKey:imageString]; + if (cell.imageView.image) { + return cell; + } + } else { + self.iconsCache = [[NSCache alloc] init]; + } + cell.imageView.image = nil; + + NSURL *URL = [imageString hasPrefix:@"/"] + ? [NSURL URLWithString:imageString + relativeToURL:self.baseURL] + : [NSURL URLWithString:imageString]; + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0ul); + HPPadAutocompleteTableViewDataSource * __weak weakSelf = self; + dispatch_async(queue, ^{ + UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:URL]]; + if (!image) { + return; + } + [weakSelf.iconsCache setObject:image + forKey:imageString]; + dispatch_async(dispatch_get_main_queue(), ^{ + if (indexPath.row >= _autocompleteData.count || + weakSelf.autocompleteData[indexPath.row] != contact) { + return; + } + UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; + cell.imageView.image = image; + [cell setNeedsLayout]; + }); + }); + return cell; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadCell.h b/client/ios/Hackpad/Hackpad/HPPadCell.h new file mode 100644 index 0000000..80a7aa7 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadCell.h @@ -0,0 +1,27 @@ +// +// HPPadCell.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPPad; +@class HPUserInfoImageView; + +@interface HPPadCell : UITableViewCell + +@property (nonatomic, strong) HPPad *pad; + +@property (nonatomic, weak) IBOutlet UIView *snippetBackgroundView; +@property (nonatomic, weak) IBOutlet UILabel *titleLabel; +@property (nonatomic, weak) IBOutlet UILabel *summaryLabel; +@property (nonatomic, strong) IBOutlet UIWebView *snippetView; +@property (nonatomic, strong) IBOutletCollection(HPUserInfoImageView) NSArray *userInfoImageViews; +@property (nonatomic, weak) IBOutlet UIButton *moreButton; +- (IBAction)showMore:(id)sender; +- (void)setPad:(HPPad *)pad + animated:(BOOL (^)(void))animated; +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadCell.m b/client/ios/Hackpad/Hackpad/HPPadCell.m new file mode 100644 index 0000000..d1f7d91 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadCell.m @@ -0,0 +1,227 @@ +// +// HPPadCell.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadCell.h" + +#import "HackpadKit.h" +#import "HackpadAdditions.h" + +#import "HPUserInfoImageView.h" +#import "HPPadCellBackgroundView.h" + +@interface HPPadCell () { + UILongPressGestureRecognizer *_longPressGesture; + NSString *loadedHTML; + BOOL sortedUserImages; +} +@end + +@implementation HPPadCell + +- (void)awakeFromNib +{ + [super awakeFromNib]; + self.summaryLabel.font = [UIFont hp_UITextFontOfSize:self.summaryLabel.font.pointSize]; + self.titleLabel.font = [UIFont hp_padTitleFontOfSize:self.titleLabel.font.pointSize]; +} + +- (void)prepareForReuse +{ + [super prepareForReuse]; + loadedHTML = nil; + [self.snippetView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; +} + +- (void)setPad:(HPPad *)pad +{ + [self setPad:pad + animated:^{ return NO; }]; +} + +- (void)setPad:(HPPad *)pad + animated:(BOOL (^)(void))animated +{ + _pad = pad; +#if 0 + self.backgroundColor = [UIColor colorWithWhite:0.95 + alpha:1]; + self.snippetView.scrollView.scrollsToTop = NO; + if ((self.snippetView.autoresizingMask & UIViewAutoresizingFlexibleWidth) && + [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) { + // Otherwise it zooms when resizing larger?! + self.snippetView.autoresizingMask &= ~UIViewAutoresizingFlexibleWidth; + } + + if (![loadedHTML isEqualToString:pad.snippetHTML]) { + loadedHTML = pad.snippetHTML; + [self.snippetView loadHTMLString:pad.fullSnippetHTML + baseURL:nil]; + } + + if (!_longPressGesture) { + _longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self + action:@selector(longPress:)]; + _longPressGesture.delegate = self; + [self.contentView addGestureRecognizer:_longPressGesture]; + } + + CGRect __block frame = self.titleLabel.frame; + frame.size.width = CGRectGetWidth(self.snippetView.frame); +#endif + if (!sortedUserImages) { + sortedUserImages = YES; + self.userInfoImageViews = [self.userInfoImageViews sortedArrayUsingComparator:^(HPUserInfoImageView *view1, + HPUserInfoImageView *view2) + { + return view1.frame.origin.x < view2.frame.origin.x + ? NSOrderedAscending + : view1.frame.origin.x > view2.frame.origin.x + ? NSOrderedDescending + : NSOrderedSame; + }]; + } + + if (!self.backgroundView) { + self.backgroundView = [[HPPadCellBackgroundView alloc] initWithFrame:self.bounds]; + } + + NSURL *URL; + if (pad.authorPic) { + URL = [NSURL URLWithString:pad.authorPic + relativeToURL:[pad.authorPic hasPrefix:@"/"] ? pad.URL : nil]; + } else { + URL = [pad.snippetUserPics firstObject]; + } + if ([URL isKindOfClass:[NSURL class]]) { + [self.userInfoImageViews[0] setURL:URL + connected:NO + animatedBlock:animated]; + } else { + [[self.userInfoImageViews[0] imageView] setImage:nil]; + } + + //self.titleLabel.frame = frame; + self.titleLabel.text = pad.title.length ? pad.title : @"Untitled"; + if (self.pad.hasMissedChanges) { + self.summaryLabel.text = @"YOU have offline changes:"; + return; + } + if (!pad.authorName && ![pad.authorNames count]) { + self.summaryLabel.text = nil; + return; + } + NSString *authorName = pad.authorName; + if (!authorName) { + pad.authorName = [pad.authorNames firstObject]; + } + self.summaryLabel.text = [NSString stringWithFormat:@"%@ edited:", + [authorName uppercaseStringWithLocale:[NSLocale currentLocale]]]; +#if 0 + NSString *editedBy; + switch ([pad.authorNames count]) { + case 0: + self.summaryLabel.text = nil; + return; + case 1: + editedBy = pad.authorNames[0]; + break; + case 2: + editedBy = [pad.authorNames componentsJoinedByString:@" and "]; + break; + default: + editedBy = [[pad.authorNames subarrayWithRange:NSMakeRange(0, [pad.authorNames count] - 1)] componentsJoinedByString:@", "]; + editedBy = [editedBy stringByAppendingFormat:@", and %@", [pad.authorNames lastObject]]; + break; + } + [UIView transitionWithView:self.summaryLabel + duration:animated() ? 0.25 : 0 + options:UIViewAnimationOptionTransitionCrossDissolve + animations:^{ + self.summaryLabel.text = [NSString stringWithFormat:@"%@ edited:", pad.authorNames[0]]; + } + completion:nil]; +#endif +} + +#if 0 +- (void)setSelected:(BOOL)selected + animated:(BOOL)animated +{ + [super setSelected:selected + animated:animated]; + if (!selected && animated) { + // Otherwise the background fades to gray (table background color) + [UIView animateWithDuration:.25 + animations:^ + { + self.snippetBackgroundView.backgroundColor = [UIColor whiteColor]; + }]; + } +} + +- (void)setHighlighted:(BOOL)highlighted + animated:(BOOL)animated +{ + BOOL changing = highlighted != self.isHighlighted; + [super setHighlighted:highlighted + animated:animated]; + // When scrolling, we want UIWebView to be opaque, but need it transparent + // when highlighted. + if (changing) { + self.snippetView.opaque = !highlighted; + // Doesn't automaticaly redraw without this... + [self.snippetView loadHTMLString:self.pad.fullSnippetHTML + baseURL:nil]; + } +} + +- (void)setEditing:(BOOL)editing + animated:(BOOL)animated +{ + CGRect oldFrame = self.contentView.frame; + [super setEditing:editing + animated:animated]; + if (!editing && animated) { + // Otherwise the cell doesn't animate resizing? + // FIXME: Still doesn't animate hiding the confirmation button... + CGRect newFrame = self.contentView.frame; + self.contentView.frame = oldFrame; + [UIView animateWithDuration:0.25 + animations:^ + { + self.contentView.frame = newFrame; + }]; + } +} + +- (void)longPress:(UILongPressGestureRecognizer *)longPressGesture +{ + if (longPressGesture.state != UIGestureRecognizerStateBegan) { + return; + } + [self showMore:longPressGesture]; +} +#endif + +- (IBAction)showMore:(id)sender +{ +#if 0 + for (UIView *view = self.superview; view; view = view.superview) { + if ([view isKindOfClass:[UITableView class]]) { + UITableView *tableView = (UITableView *)view; + if ([tableView.delegate respondsToSelector:@selector(tableView:accessoryButtonTappedForRowWithIndexPath:)]) { + [tableView.delegate tableView:tableView + accessoryButtonTappedForRowWithIndexPath:[tableView indexPathForCell:self]]; + } + break; + } + } +#endif +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadCellBackgroundView.h b/client/ios/Hackpad/Hackpad/HPPadCellBackgroundView.h new file mode 100644 index 0000000..4e7cee4 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadCellBackgroundView.h @@ -0,0 +1,13 @@ +// +// HPPadCellBackgroundView.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface HPPadCellBackgroundView : UIView + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadCellBackgroundView.m b/client/ios/Hackpad/Hackpad/HPPadCellBackgroundView.m new file mode 100644 index 0000000..eaa66f8 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadCellBackgroundView.m @@ -0,0 +1,29 @@ +// +// HPPadCellBackgroundView.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadCellBackgroundView.h" + +@implementation HPPadCellBackgroundView + +- (void)drawRect:(CGRect)rect +{ + static NSUInteger const HPadding = 8; + static NSUInteger const VPadding = 6; + + CGContextRef ctx = UIGraphicsGetCurrentContext(); + + [[UIColor hp_lightGreenGrayColor] setFill]; + CGContextFillRect(ctx, self.bounds); + + [[UIColor whiteColor] setFill]; + CGContextFillRect(ctx, CGRectMake(HPadding, 0, + self.bounds.size.width - 2 * HPadding, + self.bounds.size.height - VPadding)); +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadCollectionCell.h b/client/ios/Hackpad/Hackpad/HPPadCollectionCell.h new file mode 100644 index 0000000..43027ea --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadCollectionCell.h @@ -0,0 +1,22 @@ +// +// HPPadCollectionCell.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +typedef enum { + HPUncheckedPadCollectionCell = 0, + HPCheckedPadCollectionCell, + HPSpinningPadCollectionCell +} HPPadCollectionCellState; + +@interface HPPadCollectionCell : UITableViewCell +@property(weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicationView; +@property(weak, nonatomic) IBOutlet UILabel *collectionTextLabel; +@property(weak, nonatomic) IBOutlet UIImageView *collectionImageView; +@property(assign, nonatomic) HPPadCollectionCellState state; +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadCollectionCell.m b/client/ios/Hackpad/Hackpad/HPPadCollectionCell.m new file mode 100644 index 0000000..36b0243 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadCollectionCell.m @@ -0,0 +1,32 @@ +// +// HPPadCollectionCell.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadCollectionCell.h" + +@implementation HPPadCollectionCell + +- (id)initWithStyle:(UITableViewCellStyle)style + reuseIdentifier:(NSString *)reuseIdentifier +{ + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; + return self; +} + +- (void)setState:(HPPadCollectionCellState)state +{ + _state = state; + self.collectionImageView.hidden = state == HPSpinningPadCollectionCell; + self.collectionImageView.image = [UIImage imageNamed:state == HPCheckedPadCollectionCell + ? @"checked.png" : @"unchecked.png" ]; + if (state == HPSpinningPadCollectionCell) { + [self.activityIndicationView startAnimating]; + } else { + [self.activityIndicationView stopAnimating]; + } +} +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadCollectionViewController.h b/client/ios/Hackpad/Hackpad/HPPadCollectionViewController.h new file mode 100644 index 0000000..e1f852f --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadCollectionViewController.h @@ -0,0 +1,23 @@ +// +// HPPadCollectionViewController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPPad; + +@interface HPPadCollectionViewController : UITableViewController + +@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController; + +@property (strong, nonatomic) HPPad *pad; + +- (IBAction)refreshCollections:(id)sender; +- (IBAction)onDone:(id)sender; +- (IBAction)addCollection:(id)sender; + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadCollectionViewController.m b/client/ios/Hackpad/Hackpad/HPPadCollectionViewController.m new file mode 100644 index 0000000..97d8318 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadCollectionViewController.m @@ -0,0 +1,356 @@ +// +// HPPadCollectionViewController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadCollectionViewController.h" + +#import "HackpadKit/HackpadKit.h" +#import "HackpadAdditions/HackpadAdditions.h" + +#import "HPPadCollectionCell.h" +#import "HPPadSharingViewController.h" +#import + +@interface HPPadCollectionViewController () { + BOOL _isRefreshing; + UIAlertView *_createAlert; +} + +@end + +@implementation HPPadCollectionViewController + +- (void)setPad:(HPPad *)pad +{ + _pad = pad; + if (!_pad) { + return; + } + + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPCollectionEntity]; + fetch.predicate = [NSPredicate predicateWithFormat:@"space == %@", self.pad.space]; + NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"title" + ascending:YES]; + fetch.sortDescriptors = [NSArray arrayWithObject:sort]; + + self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetch + managedObjectContext:self.pad.managedObjectContext + sectionNameKeyPath:nil + cacheName:nil]; + self.fetchedResultsController.delegate = self; + + NSError * __autoreleasing error; + if (![self.fetchedResultsController performFetch:&error]) { + TFLog(@"Could not request collections: %@", error); + } + + [self.tableView reloadData]; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + // This is hooked up in the storyboard but doesn't work? + [self.refreshControl addTarget:self + action:@selector(refreshCollections:) + forControlEvents:UIControlEventValueChanged]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return self.fetchedResultsController.sections.count; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + id sectionInfo = [self.fetchedResultsController.sections objectAtIndex:section]; + return [sectionInfo numberOfObjects]; +} + +- (void)configureCell:(HPPadCollectionCell *)cell + atIndexPath:(NSIndexPath *)indexPath +{ + HPCollection *collection = [self.fetchedResultsController objectAtIndexPath:indexPath]; + + HPLog(@"[%@] Loading %@ => %@", collection.space.URL.host, indexPath, collection.collectionID); + + cell.collectionTextLabel.text = collection.title; + + cell.state = [_pad.collections member:collection] + ? HPCheckedPadCollectionCell + : HPUncheckedPadCollectionCell; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView + cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString *CellIdentifier = @"PadCollectionCell"; + HPPadCollectionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier + forIndexPath:indexPath]; + [self configureCell:cell + atIndexPath:indexPath]; + return cell; +} + + +// Override to support conditional editing of the table view. +- (BOOL)tableView:(UITableView *)tableView +canEditRowAtIndexPath:(NSIndexPath *)indexPath +{ + return YES; +} + +// Override to support editing the table view. +- (void)tableView:(UITableView *)tableView +commitEditingStyle:(UITableViewCellEditingStyle)editingStyle +forRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (editingStyle == UITableViewCellEditingStyleDelete) { + HPCollection *collection = [self.fetchedResultsController objectAtIndexPath:indexPath]; + [collection deleteWithCompletion:^(HPCollection *collection, NSError *error) { + if (error) { + TFLog(@"[%@] Could not delete collection: %@", + collection.space.URL.host, error); + } + }]; + } + else if (editingStyle == UITableViewCellEditingStyleInsert) { + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view + } +} + +/* +// Override to support rearranging the table view. +- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath +{ +} +*/ + +/* +// Override to support conditional rearranging of the table view. +- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath +{ + // Return NO if you do not want the item to be re-orderable. + return YES; +} +*/ + +- (void)prepareForSegue:(UIStoryboardSegue *)segue + sender:(id)sender +{ + if ([segue.identifier isEqualToString:@"EditSharing"]) { + HPPadSharingViewController *sharing = segue.destinationViewController; + NSIndexPath *indexPath = [self.tableView indexPathForCell:sender]; + HPCollection *collection = [self.fetchedResultsController objectAtIndexPath:indexPath]; + if (!collection.sharingOptions) { + [collection hp_performBlock:^(HPCollection *collection, + NSError *__autoreleasing *error) + { + if (collection.sharingOptions) { + return; + } + collection.sharingOptions = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([HPSharingOptions class]) + inManagedObjectContext:collection.managedObjectContext]; + } + completion:^(HPCollection *collection, NSError *error) + { + if (error) { + TFLog(@"[%@] Could not create sharing options: %@", + collection.space.URL.host, error); + return; + } + sharing.sharingOptions = collection.sharingOptions; + }]; + } else { + sharing.sharingOptions = collection.sharingOptions; + } + } +} + +#pragma mark - Table view delegate + +- (void)tableView:(UITableView *)tableView +didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + HPCollection *collection = [self.fetchedResultsController objectAtIndexPath:indexPath]; + if ([collection.pads member:self.pad]) { + [collection removePadsObject:self.pad + completion:nil]; + } else { + [collection addPadsObject:self.pad + completion:nil]; + } + [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] + withRowAnimation:UITableViewRowAnimationAutomatic]; +} + +#pragma mark - Fetched results delegate + +/* + Assume self has a property 'tableView' -- as is the case for an instance of a UITableViewController + subclass -- and a method configureCell:atIndexPath: which updates the contents of a given cell + with information from a managed object at the given index path in the fetched results controller. + */ + +- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller +{ + HPLog(@"[%@] %s", self.pad.URL.host, __PRETTY_FUNCTION__); + [self.tableView beginUpdates]; +} + + +- (void)controller:(NSFetchedResultsController *)controller + didChangeSection:(id )sectionInfo + atIndex:(NSUInteger)sectionIndex + forChangeType:(NSFetchedResultsChangeType)type +{ + HPLog(@"[%@] %s", self.pad.URL.host, __PRETTY_FUNCTION__); + + switch(type) { + case NSFetchedResultsChangeInsert: + [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] + withRowAnimation:UITableViewRowAnimationFade]; + break; + + case NSFetchedResultsChangeDelete: + [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] + withRowAnimation:UITableViewRowAnimationFade]; + break; + } +} + + +- (void)controller:(NSFetchedResultsController *)controller + didChangeObject:(id)anObject + atIndexPath:(NSIndexPath *)indexPath + forChangeType:(NSFetchedResultsChangeType)type + newIndexPath:(NSIndexPath *)newIndexPath +{ + HPLog(@"[%@] %s", self.pad.URL.host, __PRETTY_FUNCTION__); + + switch(type) { + + case NSFetchedResultsChangeInsert: + [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] + withRowAnimation:UITableViewRowAnimationFade]; + break; + + case NSFetchedResultsChangeDelete: + [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] + withRowAnimation:UITableViewRowAnimationFade]; + break; + + case NSFetchedResultsChangeMove: + [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] + withRowAnimation:UITableViewRowAnimationFade]; + [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] + withRowAnimation:UITableViewRowAnimationFade]; + break; + case NSFetchedResultsChangeUpdate: + [self configureCell:(HPPadCollectionCell *)[self.tableView cellForRowAtIndexPath:indexPath] + atIndexPath:indexPath]; + break; + + } +} + +- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller +{ + HPLog(@"[%@] %s", self.pad.URL.host, __PRETTY_FUNCTION__); + [self.tableView endUpdates]; +} + +#pragma mark - Object methods + +- (IBAction)refreshCollections:(id)sender +{ + if (_isRefreshing) { + return; + } + [self.pad.space requestFollowedPadsWithRefresh:YES + completion:^(HPSpace *space, + NSError *error) + { + _isRefreshing = NO; + [self.refreshControl endRefreshing]; + if (error) { + TFLog(@"[%@] Could not request collections: %@", + space.URL.host, error); + } + }]; +} + +- (IBAction)onDone:(id)sender +{ +#if DEBUG + for (NSManagedObject *obj in self.fetchedResultsController.managedObjectContext.updatedObjects) { + HPLog(@"[%@] changes: %@", self.pad.URL.host, obj.changedValues); + } +#endif + [self dismissViewControllerAnimated:YES + completion:^{}]; +} + +- (void)alertView:(UIAlertView *)alertView +didDismissWithButtonIndex:(NSInteger)buttonIndex +{ + if (alertView == _createAlert) { + alertView.delegate = nil; + _createAlert = nil; + if (buttonIndex == alertView.cancelButtonIndex) { + return; + } + NSString *name = [alertView textFieldAtIndex:0].text; + if (!name.length) { + return; + } + + [self.pad.space createCollectionWithName:name + pad:self.pad + completion:^(HPSpace *space, + HPCollection *collection, + NSError *error) + { + if (error) { + TFLog(@"[%@] Error creating collection: %@", + space.URL.host, error); + } + }]; + } +} + +- (IBAction)addCollection:(id)sender +{ + _createAlert = [[UIAlertView alloc] initWithTitle:@"Create Collection" + message:@"Enter the name for your new collection." + delegate:self + cancelButtonTitle:@"Cancel" + otherButtonTitles:@"Create", + nil]; + _createAlert.alertViewStyle = UIAlertViewStylePlainTextInput; + UITextField *text = [_createAlert textFieldAtIndex:0]; + text.returnKeyType = UIReturnKeyDone; + text.placeholder = @"Collection Name"; + text.delegate = self; + [_createAlert show]; +} + +#pragma mark - Text field delegate + +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + if (textField == [_createAlert textFieldAtIndex:0]) { + [_createAlert dismissWithClickedButtonIndex:_createAlert.firstOtherButtonIndex + animated:YES]; + } + return YES; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadEditorViewController.h b/client/ios/Hackpad/Hackpad/HPPadEditorViewController.h new file mode 100644 index 0000000..42e17c8 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadEditorViewController.h @@ -0,0 +1,86 @@ +// +// HPPadEditorViewController.h +// Hackpad +// +// +// Copyright (c) 2012 Hackpad. All rights reserved. +// + +#import "HPPadWebController.h" + +@class HPPad; +@class HPUserInfoImageView; + +typedef NS_ENUM(NSUInteger, PadEditorAction) { + BoldEditorAction = 10, + ItalicsEditorAction, + UnderlineEditorAction, + StrikethroughEditorAction, + + BulletedListEditorAction = 20, + NumberedListEditorAction, + TaskListEditorAction, + CommentEditorAction, + + IndentEditorAction = 30, + OutdentEditorAction, + + LinkEditorAction = 40, + InsertTableAction, + InsertPhotoAction, + InsertLinkAction, + InsertDropboxAction, + TagEditorAction, + + Heading1EditorAction = 50, + Heading2EditorAction, + Heading3EditorAction +}; + + +@interface HPPadEditorViewController : UIViewController +@property (nonatomic, strong) HPPadWebController *padWebController; +@property (strong, nonatomic) HPPad *pad; +@property (nonatomic, strong) HPSpace *defaultSpace; + +// Left navbar items +@property (nonatomic, weak) IBOutlet UIBarButtonItem *backItem; +@property (nonatomic, weak) IBOutlet UIBarButtonItem *searchItem; + +// Right navbar items +@property (nonatomic, strong) IBOutlet UIBarButtonItem *followedItem; +@property (nonatomic, strong) IBOutlet UIBarButtonItem *photoItem; + +// Toolbars +@property (weak, nonatomic) IBOutlet UIToolbar *toolbar; +@property (weak, nonatomic) IBOutlet UIToolbar *editorAccessoryToolbar; +@property (weak, nonatomic) IBOutlet UIToolbar *formattingToolbar; +@property (weak, nonatomic) IBOutlet UIToolbar *listsToolbar; +@property (weak, nonatomic) IBOutlet UIToolbar *insertToolbar; + +@property (nonatomic, weak) IBOutlet UIBarButtonItem *leftPaddingItem; +@property (nonatomic, weak) IBOutlet UIBarButtonItem *rightPaddingItem; + +@property (nonatomic, weak) IBOutlet HPUserInfoImageView *userInfoImageView; + +@property (nonatomic, weak) IBOutlet UITextField *focusWorkaroundTextField; +@property (weak, nonatomic) IBOutlet UITableView *autocompleteTableView; + +@property (nonatomic, weak) IBOutlet NSLayoutConstraint *searchBarConstraint; +@property (nonatomic, weak) IBOutlet NSLayoutConstraint *autocompleteTableHeightConstraint; +@property (nonatomic, weak) IBOutlet NSLayoutConstraint *autocompleteTableTopConstraint; + +// Regular toolbar. +- (IBAction)createPad:(id)sender; +- (IBAction)signIn:(id)sender; +- (IBAction)togglePadFollowed:(id)sender; +- (IBAction)searchPads:(id)sender; +- (IBAction)goBack:(id)sender; + +// Keyboard toolbar. +- (IBAction)toolbarEditorAction:(id)sender; +- (IBAction)keyboardDone:(id)sender; + +- (IBAction)toggleUserInfos:(id)sender; + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadEditorViewController.m b/client/ios/Hackpad/Hackpad/HPPadEditorViewController.m new file mode 100644 index 0000000..91bda7e --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadEditorViewController.m @@ -0,0 +1,1616 @@ +// +// HPPadEditorViewController.m +// Hackpad +// +// +// Copyright (c) 2012 Hackpad. All rights reserved. +// + +#import "HPPadEditorViewController.h" + +#import "HackpadKit/HackpadKit.h" +#import "HackpadAdditions/HackpadUIAdditions.h" + +#import "HPActionSheetBlockDelegate.h" +#import "HPAlertViewBlockDelegate.h" +#import "HPBrowserViewController.h" +#import "HPDrawerController.h" +#import "HPGroupedToolbar.h" +#import "HPInvitationController.h" +#import "HPPadAutocompleteTableViewDataSource.h" +#import "HPPadCollectionViewController.h" +#import "HPPadSearchTableViewDataSource.h" +#import "HPPadSharingViewController.h" +#import "HPUserInfoCollection.h" +#import "HPUserInfoImageView.h" +#import "HPUserInfosViewController.h" + +#import + +#import +#import +#import +#import +#import "Flurry.h" + +static NSString * const AboutBlank = @"about:blank"; +static NSString * const BrowserSegue = @"BrowserSegue"; +static NSString * const OpenPadSegue = @"OpenPad"; + +static NSString * const DataKey = @"data"; + +@interface HPPadEditorViewController () +@property (nonatomic, strong) NSDate *creationDate; +@property (nonatomic, strong) NSURLRequest *photoRequest; +@property (nonatomic, readonly) UISearchDisplayController *currentSearchDisplayController; +@property (nonatomic, strong) UIPopoverController *autocompleteDataPopover; +@property (nonatomic, strong) UIActionSheet *imageSheet; +@property (nonatomic, strong) UIStoryboardPopoverSegue *popoverSegue; +@property (nonatomic, strong) HPPadSearchTableViewDataSource *searchDataSource; +@property (nonatomic, strong) HPGroupedToolbar *groupedToolbar; +@property (nonatomic, strong) id signInObserver; +@property (nonatomic, strong) id signOutObserver; +@property (nonatomic, assign) CGFloat keyboardOrigin; +@property (nonatomic, assign) BOOL restoringFocus; +@property (nonatomic, assign, getter = isFreakingOut) BOOL freakingOut; +@end + +@implementation HPPadEditorViewController + +#pragma mark - Managing the detail item + +- (void)setPad:(HPPad *)pad +{ + if (self.padWebController.delegate == self) { + self.padWebController.delegate = nil; + } + [self.padWebController saveClientVarsAndTextWithCompletion:nil]; + + _pad = pad; + + if (self.isViewLoaded && self.padWebController.webView.superview == self.view) { + [self.padWebController.webView removeFromSuperview]; + } + + if (!pad) { + self.padWebController = nil; + return; + } + + self.padWebController = [HPPadWebController sharedPadWebControllerWithPad:pad]; + + if (!self.isViewLoaded) { + return; + } + [self configureView]; + [self addWebView]; + [self loadWebView]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + [self showEditingToolbar:NO + animated:YES]; + } +} + +- (void)addWebView +{ + if (self.padWebController.webView.superview == self.view) { + return; + } + self.padWebController.delegate = self; + + self.padWebController.webView.translatesAutoresizingMaskIntoConstraints = NO; + self.padWebController.webView.keyboardDisplayRequiresUserAction = NO; + + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + [self.view addSubview:self.padWebController.webView]; + } else { + [self.view insertSubview:self.padWebController.webView + belowSubview:self.autocompleteTableView]; + } + + NSDictionary *views; + NSArray *cn; + if (HP_SYSTEM_MAJOR_VERSION() >= 7) { + views = @{@"webView":self.padWebController.webView, + @"topGuide":self.topLayoutGuide}; + cn = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[topGuide][webView]|" + options:0 + metrics:nil + views:views]; + [self.view addConstraints:cn]; + } else { + views = @{@"webView":self.padWebController.webView}; + cn = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[webView]|" + options:0 + metrics:nil + views:views]; + [self.view addConstraints:cn]; + } + cn = [NSLayoutConstraint constraintsWithVisualFormat:@"|[webView]|" + options:0 + metrics:nil + views:views]; + [self.view addConstraints:cn]; + [self.view layoutIfNeeded]; +} + +- (void)goBack +{ + self.pad = nil; + if (self.navigationController.viewControllers.firstObject == self || + self.navigationController.topViewController != self) { + return; + } + [self.navigationController popViewControllerAnimated:YES]; +} + +- (void)openSupportMail +{ + static NSString * const IOSSupportAtHackpad = @"support+ios@example.com"; + static NSString * const MessageBodyFormat = @"" + "\n" + "-- Please leave the following information --\n" + "Pad URL: %@\n"; + + MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; + [mailer setToRecipients:@[IOSSupportAtHackpad]]; + [mailer setSubject:[NSString stringWithFormat:@"Error loading pad %@", self.pad.padID]]; + [mailer setMessageBody:[NSString stringWithFormat:MessageBodyFormat, self.pad.URL.absoluteString] + isHTML:NO]; + mailer.mailComposeDelegate = self; + [self presentViewController:mailer + animated:YES + completion:nil]; +} + +- (void)discardChanges +{ + HPPadEditorViewController * __weak weakSelf = self; + HPActionSheetBlockDelegate *delegate = [[HPActionSheetBlockDelegate alloc] initWithBlock:^(UIActionSheet *actionSheet, NSInteger button) { + if (button == actionSheet.cancelButtonIndex) { + return; + } + [weakSelf.pad discardMissedChangesWithCompletion:^(HPPad *pad, NSError *error) { + [weakSelf loadWebView]; + }]; + }]; + [[[UIActionSheet alloc] initWithTitle:@"Your unsaved changes will be lost. This cannot be undone." + delegate:delegate + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Discard Changes" + otherButtonTitles:nil] showInView:self.view]; +} + +- (void)reloadAfterSignedIn +{ + BOOL goBack = NO; + BOOL reloadWebView = NO; + HPPadEditorViewController * __weak weakSelf = self; + HPAPI *API = self.pad.space.API; + @synchronized (API) { + switch (self.pad.space.API.authenticationState) { + case HPRequiresSignInAuthenticationState: + goBack = YES; + break; + case HPSignedInAuthenticationState: + reloadWebView = YES; + break; + default: { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + self.signInObserver = [nc addObserverForName:HPAPIDidSignInNotification + object:API + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + [weakSelf removeReloadObservers]; + [weakSelf reloadWebView]; + }]; + self.signOutObserver = [nc addObserverForName:HPAPIDidSignOutNotification + object:API + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + [weakSelf removeReloadObservers]; + [weakSelf goBack]; + }]; + } + } + } + // Don't need to do these while @synchronized + if (goBack) { + [self goBack]; + } + if (reloadWebView) { + [self reloadWebView]; + } +} + +- (void)handleWebViewLoadError:(NSError *)error +{ + TFLog(@"[%@ %@] Could not load pad web view: %@", + self.pad.space.URL.host, self.pad.padID, error); + BOOL padNotFound = NO; + if ([error.domain isEqualToString:HPHackpadErrorDomain]) { + switch (error.code) { + case HPSignInRequired: + [self reloadAfterSignedIn]; + return; + case HPFailedRequestError: { + NSURL *failingURL = error.userInfo[NSURLErrorFailingURLErrorKey]; + NSNumber *statusCode = error.userInfo[HPURLErrorFailingHTTPStatusCode]; + padNotFound = [failingURL.path isEqualToString:HPPadClientVarsPath] && statusCode.integerValue == 404; + break; + } + default: + break; + } + } + NSString *message = padNotFound + ? @"The pad does not exist, or you don't have access to it." + : @"The pad could not be loaded. If this continues," + " please contact support."; + UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops" + message:message + delegate:nil + cancelButtonTitle:@"Cancel" + otherButtonTitles:nil]; + NSInteger mailButton = -1; + NSInteger discardButton = -1; + NSInteger requestAccessButton = -1; + if (padNotFound) { + requestAccessButton = [alertView addButtonWithTitle:@"Request Access"]; + } else { + if ([MFMailComposeViewController canSendMail]) { + mailButton = [alertView addButtonWithTitle:@"Contact Support"]; + } + if (self.pad.hasMissedChanges) { + discardButton = [alertView addButtonWithTitle:@"Discard Changes"]; + } + } + HPPadEditorViewController * __weak weakSelf = self; + HPAlertViewBlockDelegate *delegate = [[HPAlertViewBlockDelegate alloc] initWithBlock:^(UIAlertView *alertView, NSInteger button) { + if (button == alertView.cancelButtonIndex) { + [weakSelf goBack]; + } else if (button == mailButton) { + [weakSelf openSupportMail]; + } else if (button == discardButton) { + [weakSelf discardChanges]; + } else if (button == requestAccessButton) { + MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:weakSelf.view + animated:YES]; + [weakSelf.pad requestAccessWithCompletion:^(HPPad *pad, NSError *error) { + // This request always sends an error, so ignore it for now. + [HUD hide:YES]; + [weakSelf goBack]; + [[[UIAlertView alloc] initWithTitle:@"Cool" + message:@"We've sent the owner of the pad an email requesting access for you." + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; + }]; + } + }]; + alertView.delegate = delegate; + [alertView show]; +} + +- (void (^)(NSError *))webViewLoadCompletion +{ + HPPadEditorViewController * __weak weakSelf = self; + return ^(NSError *error) { + if (!weakSelf || weakSelf.padWebController.delegate != weakSelf) { + return; + } + if (error) { + [weakSelf handleWebViewLoadError:error]; + return; + } + [weakSelf updatePeoplePhoto]; + }; +} + +- (void)loadWebView +{ + [self.padWebController loadWithCompletion:self.webViewLoadCompletion]; +} + +- (void)reloadWebView +{ + [self.padWebController reloadDiscardingChanges:NO + cachePolicy:NSURLRequestReloadRevalidatingCacheData + completion:self.webViewLoadCompletion]; +} + +- (void)setFollowedButtonIsFollowed:(BOOL)followed + animated:(BOOL)animated +{ + if (!self.pad.space) { + [self.navigationItem setRightBarButtonItem:nil + animated:YES]; + return; + } + if (followed) { + [self.navigationItem setRightBarButtonItem:self.photoItem + animated:animated]; + return; + } + UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace + target:nil + action:nil]; + spacer.width = HP_SYSTEM_MAJOR_VERSION() >= 7 ? 16 : 0; + [self.navigationItem setRightBarButtonItems:@[self.photoItem, spacer, self.followedItem] + animated:animated]; +} + +- (void)configureView +{ + if (!self.pad) { + return; + } + BOOL enabled = !!self.pad.space.API.reachability.currentReachabilityStatus; + self.followedItem.enabled = enabled; + self.photoItem.enabled = enabled; + [self setFollowedButtonIsFollowed:self.pad.followed + animated:YES]; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + [Flurry logEvent:HPPadViewedEventKey timed:YES]; + + self.followedItem.possibleTitles = [NSSet setWithObjects:@"Follow", @"Unfollow", nil]; + + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + + [center addObserver:self + selector:@selector(contextDidSave:) + name:NSManagedObjectContextDidSaveNotification + object:nil]; + [center addObserver:self + selector:@selector(reachabilityDidChangeWithNotification:) + name:kReachabilityChangedNotification + object:nil]; + + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + self.navigationItem.leftItemsSupplementBackButton = YES; + self.groupedToolbar = (HPGroupedToolbar *)self.navigationItem.titleView; + self.groupedToolbar.selectedGroupBackgroundColor = [UIColor hp_lightGreenGrayColor]; + self.editorAccessoryToolbar.frame = self.groupedToolbar.bounds; + [self initializeGroupedToolbarWithBackgroundImage:nil + groupBackgroundImage:nil]; + [self showEditingToolbar:NO + animated:NO]; + [center addObserver:self + selector:@selector(keyboardWillChangeFrameWithNotification:) + name:UIKeyboardWillChangeFrameNotification + object:nil]; + } else { + if (HP_SYSTEM_MAJOR_VERSION() >= 7) { + self.view.backgroundColor = self.navigationController.navigationBar.barTintColor; + } else { + self.searchBarConstraint.constant = 0; + } + + [center addObserver:self + selector:@selector(keyboardWillHideWithNotification:) + name:UIKeyboardWillHideNotification + object:nil]; + [center addObserver:self + selector:@selector(keyboardWillShowWithNotification:) + name:UIKeyboardWillShowNotification + object:nil]; + [center addObserver:self + selector:@selector(keyboardDidShowWithNotification:) + name:UIKeyboardDidShowNotification + object:nil]; + self.navigationItem.leftBarButtonItems = @[self.backItem, self.searchItem]; + } + + [self configureView]; + if (self.pad) { + [self addWebView]; + [self loadWebView]; + } +} + +- (IBAction)goBack:(id)sender +{ + [self.navigationController popViewControllerAnimated:YES]; +} + +- (void)removeObservers +{ + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [center removeObserver:self + name:NSManagedObjectContextDidSaveNotification + object:nil]; + [center removeObserver:self + name:kReachabilityChangedNotification + object:nil]; + if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { + [center removeObserver:self + name:UIKeyboardWillShowNotification + object:nil]; + [center removeObserver:self + name:UIKeyboardDidShowNotification + object:nil]; + [center removeObserver:self + name:UIKeyboardWillHideNotification + object:nil]; + } else { + [center removeObserver:self + name:UIKeyboardWillChangeFrameNotification + object:nil]; + } + [self removeReloadObservers]; +} + +- (void)removeReloadObservers +{ + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + if (self.signInObserver) { + [center removeObserver:self.signInObserver]; + self.signInObserver = nil; + } + if (self.signOutObserver) { + [center removeObserver:self.signOutObserver]; + self.signOutObserver = nil; + } +} + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + if (!self.padWebController.webView) { + return; + } + // In case the user has opened this pad linked from another pad, and is now + // going back through the navigation stack + [self addWebView]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + return; + } + [self showEditingToolbar:NO + animated:NO]; +} + +- (void)viewWillDisappear:(BOOL)animated +{ + [super viewWillDisappear:animated]; + if ([self.navigationController.viewControllers indexOfObject:self] != NSNotFound) { + return; + } + // This means we're going back. + self.pad = nil; + [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; + [Flurry endTimedEvent:HPPadViewedEventKey withParameters:nil]; +} + +- (void)dealloc +{ + [self hideDialogs]; + [self removeObservers]; + self.padWebController.delegate = nil; +} + +- (void)contextDidSave:(NSNotification *)note +{ + NSManagedObjectContext *managedObjectContext = note.object; + if (managedObjectContext.concurrencyType == NSMainQueueConcurrencyType) { + if (self.pad.managedObjectContext != managedObjectContext || + ![[note.userInfo objectForKey:NSUpdatedObjectsKey] member:self.pad]) { + return; + } + [self configureView]; + } +} + +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation +{ + [self.padWebController updateViewportWidth]; +} + +- (IBAction)toggleUserInfos:(id)sender +{ + if (![self shouldPerformSegueWithIdentifier:@"EditSharing" + sender:sender]) { + return; + } + UIStoryboardPopoverSegue *segue = [[UIStoryboardPopoverSegue alloc] initWithIdentifier:@"EditSharing" + source:self + destination:[self.storyboard instantiateViewControllerWithIdentifier:@"EditSharingNavigationController"]]; + [self prepareForSegue:segue + sender:sender]; + [segue.popoverController presentPopoverFromBarButtonItem:self.photoItem + permittedArrowDirections:UIPopoverArrowDirectionAny + animated:YES]; +} + +- (void)hideDialogs +{ + // Delegate is called for action sheets, so no need to unset. + [_imageSheet dismissWithClickedButtonIndex:_imageSheet.cancelButtonIndex + animated:YES]; + + // Delegate *isn't* called for popovers, so unset; +#if 0 + [_searchPopover dismissPopoverAnimated:YES]; + _searchPopover.delegate = nil; + _searchPopover = nil; +#endif + + [_popoverSegue.popoverController dismissPopoverAnimated:YES]; + _popoverSegue.popoverController.delegate = nil; + _popoverSegue = nil; + + [self.autocompleteDataPopover dismissPopoverAnimated:YES]; + self.autocompleteDataPopover.delegate = nil; + self.autocompleteDataPopover = nil; + + [self.autocompleteTableView hp_setHidden:YES + animated:YES]; +} + +- (IBAction)createPad:(id)sender +{ + HPPadEditorViewController * __weak weakSelf = self; + [(self.pad.space ?: self.defaultSpace) blankPadWithTitle:@"Untitled" + followed:YES + completion:^(HPPad *pad, NSError *error) + { + if (!pad) { + if (error) { + TFLog(@"[%@] Could not create pad: %@", + weakSelf.pad.URL.host, error); + } + return; + } + if (weakSelf.pad) { + [weakSelf performSegueWithIdentifier:OpenPadSegue + sender:pad]; + } else { + self.pad = pad; + } + }]; +} + + +#pragma mark - Notifications + +- (void)reachabilityDidChangeWithNotification:(NSNotification *)note +{ + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + if (note.object == self.pad.space.API.reachability) { + [self configureView]; + } + }]; +} + +- (void)keyboardWillHideWithNotification:(NSNotification *)note +{ + UIView *firstResponder = [self.padWebController.webView hp_firstResponderSubview]; + if (!firstResponder) { + return; + } + if (self.restoringFocus) { + HPLog(@"[%@] (ignoring hide triggered by restoring focus)", + self.pad.space.URL.host); + self.restoringFocus = NO; + return; + } + [self.autocompleteTableView hp_setHidden:YES + animated:YES]; + self.padWebController.visibleEditorHeight = 0; + [self.navigationController setNavigationBarHidden:NO + animated:YES]; +} + +- (UIToolbar *)findToolbarInAccessoryView:(UIView *)accessoryView +{ + UIToolbar * __block toolbar; + [accessoryView.subviews enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) { + [subview.subviews enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) { + if ([subview isKindOfClass:[UIToolbar class]]) { + toolbar = (UIToolbar *)subview; + *stop = YES; + } + }]; + if (toolbar) { + *stop = YES; + } + }]; + return toolbar; +} + +- (void)initializeGroupedToolbarWithBackgroundImage:(UIImage *)backgroundImage + groupBackgroundImage:(UIImage *)groupBackgroundImage +{ + self.groupedToolbar.toolbar = self.editorAccessoryToolbar; + if (backgroundImage) { + [self.groupedToolbar.toolbar setBackgroundImage:backgroundImage + forToolbarPosition:UIBarPositionAny + barMetrics:UIBarMetricsDefault]; + [self.groupedToolbar.toolbar setShadowImage:[UIImage new] + forToolbarPosition:UIBarPositionAny]; + } + self.groupedToolbar.groups = @[self.formattingToolbar, self.listsToolbar, + self.insertToolbar, [NSNull null], [NSNull null], + [NSNull null]]; + if (!groupBackgroundImage) { + return; + } + [self.groupedToolbar.groups enumerateObjectsUsingBlock:^(UIToolbar *toolbar, NSUInteger idx, BOOL *stop) { + if (![toolbar isKindOfClass:[UIToolbar class]]) { + return; + } + [toolbar setBackgroundImage:groupBackgroundImage + forToolbarPosition:UIBarPositionAny + barMetrics:UIBarMetricsDefault]; + [toolbar setShadowImage:[UIImage new] + forToolbarPosition:UIBarPositionAny]; + }]; +} + +- (void)keyboardWillShowWithNotification:(NSNotification *)note +{ + static NSString * const EditorBackgroundName = @"editorbg"; + static NSString * const GroupBackgroundName = @"groupbg"; + static NSInteger const ToolbarPadding6 = 12; + static NSInteger const ToolbarPadding7 = 16; + + [Flurry logEvent:HPPadEditedEventKey]; + + UIView *firstResponder = [self.padWebController.webView hp_firstResponderSubview]; + if (!firstResponder) { + return; + } + if (self.creationDate) { + TFLog(@"[%@] ^^^ Took %.3fs to create pad.\n\n", self.pad.space.URL.host, + -self.creationDate.timeIntervalSinceNow); + self.creationDate = nil; + } + + // Swap in our toolbar. + if (firstResponder.superview != self.padWebController.webView.scrollView) { + return; + } + + if (self.groupedToolbar) { + [self.groupedToolbar showRootToolbarAnimated:NO]; + return; + } + + // Clear padding + self.leftPaddingItem.width = self.rightPaddingItem.width = -(HP_SYSTEM_MAJOR_VERSION() >= 7 + ? ToolbarPadding7 + : ToolbarPadding6); + + UIToolbar *toolbar = [self findToolbarInAccessoryView:firstResponder.inputAccessoryView]; + toolbar.items = nil; + toolbar.opaque = YES; + toolbar.translucent = NO; + + self.groupedToolbar = [[HPGroupedToolbar alloc] initWithFrame:toolbar.bounds]; + self.groupedToolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + self.groupedToolbar.selectedGroupTintColor = [UIColor whiteColor]; + self.editorAccessoryToolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; + self.editorAccessoryToolbar.bounds = self.groupedToolbar.bounds; + [self initializeGroupedToolbarWithBackgroundImage:[UIImage imageNamed:EditorBackgroundName] + groupBackgroundImage:[UIImage imageNamed:GroupBackgroundName]]; + + [toolbar addSubview:self.groupedToolbar]; + + self.focusWorkaroundTextField.inputAccessoryView = firstResponder.inputAccessoryView; +} + +- (void)keyboardDidShowWithNotification:(NSNotification *)note +{ + UIView *firstResponder = [self.padWebController.webView hp_firstResponderSubview]; + if (!firstResponder) { + return; + } + [self.navigationController setNavigationBarHidden:YES + animated:YES]; + CGRect frame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + frame = [self.navigationController.view convertRect:frame + fromView:nil]; + self.keyboardOrigin = frame.origin.y - self.padWebController.webView.frame.origin.y; + self.padWebController.visibleEditorHeight = self.keyboardOrigin; +} + +- (void)keyboardWillChangeFrameWithNotification:(NSNotification *)note +{ + UIView *firstResponder = [self.padWebController.webView hp_firstResponderSubview]; + if (!firstResponder) { + if (self.navigationItem.rightBarButtonItems.count == self.editorAccessoryToolbar.items.count) { + [self showEditingToolbar:NO + animated:YES]; + } + return; + } + + CGRect kframe = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + [self showEditingToolbar:CGRectIntersectsRect(kframe, self.view.frame) + animated:YES]; +} + +#pragma mark - Main Toolbar actions + +- (void)showEditingToolbar:(BOOL)editing + animated:(BOOL)animated +{ + BOOL showBar = self.pad && editing; + if (showBar && self.navigationItem.titleView.isHidden) { + self.navigationItem.titleView.alpha = 0; + self.navigationItem.titleView.hidden = NO; + } + [UIView animateWithDuration:animated ? 0.25 : 0 + animations:^{ + self.navigationItem.titleView.alpha = showBar; + } completion:^(BOOL finished) { + self.navigationItem.titleView.hidden = !showBar; + }]; +} + +- (IBAction)togglePadFollowed:(id)sender +{ + HPPadEditorViewController * __weak weakSelf = self; + [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; + BOOL followed = !self.pad.followed; + [self setFollowedButtonIsFollowed:followed + animated:YES]; + [self.pad setFollowed:followed + completion:^(HPPad *pad, NSError *error) + { + [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; + if (error) { + TFLog(@"[%@ %@] Error toggling pad: %@", pad.URL.host, pad.padID, + error); + } + [weakSelf setFollowedButtonIsFollowed:weakSelf.pad.followed + animated:YES]; + }]; +} + +- (IBAction)signIn:(id)sender +{ + [self.pad.space.API signInEvenIfSignedIn:NO]; +} + +- (void)updatePeoplePhoto +{ + HPUserInfoCollection *userInfos = self.padWebController.userInfos; + HPUserInfo *userInfo = userInfos.userInfos.firstObject; + _userInfoImageView.stack = userInfos.userInfos.count > 1; + if (userInfo) { + [_userInfoImageView setURL:userInfo.userPicURL + connected:userInfo.status == HPConnectedUserInfoStatus + animated:YES]; + } else { + [_userInfoImageView setURL:nil + connected:NO + animated:YES]; + } +} + +- (void)searchPads:(id)sender +{ + self.searchDisplayController.searchBar.hidden = NO; + [self.searchDisplayController.searchBar becomeFirstResponder]; +} + +#pragma mark - Keyboard toolbar actions + +- (void)clickToolbarAction:(PadEditorAction)action + barButtonItem:(UIBarButtonItem *)barButtonItem +{ + BOOL showRootToolbar = YES; + [self hideDialogs]; + + NSString *command; + + switch (action) { + case BoldEditorAction: + command = @"bold"; + break; + case ItalicsEditorAction: + command = @"italic"; + break; + case UnderlineEditorAction: + command = @"underline"; + break; + case StrikethroughEditorAction: + command = @"strikethrough"; + break; + + case Heading1EditorAction: + command = @"heading1"; + break; + case Heading2EditorAction: + command = @"heading2"; + break; + case Heading3EditorAction: + command = @"heading3"; + break; + + case BulletedListEditorAction: + command = @"insertunorderedlist"; + showRootToolbar = NO; + break; + case NumberedListEditorAction: + command = @"insertorderedlist"; + showRootToolbar = NO; + break; + case TaskListEditorAction: + command = @"inserttasklist"; + showRootToolbar = NO; + break; + case CommentEditorAction: + command = @"insertcomment"; + break; + + case IndentEditorAction: + command = @"indent"; + showRootToolbar = NO; + break; + case OutdentEditorAction: + command = @"outdent"; + showRootToolbar = NO; + break; + + case LinkEditorAction: + command = @"linkinsert"; + break; + case InsertTableAction: + command = @"tableinsert"; + break; + case TagEditorAction: + [self.padWebController insertString:@"#"]; + [self.groupedToolbar showRootToolbarAnimated:YES]; + return; + case InsertPhotoAction: + [[self.padWebController.webView hp_firstResponderSubview] resignFirstResponder]; + if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { + _imageSheet = [[UIActionSheet alloc] initWithTitle:@"Insert Image" + delegate:self + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:nil + otherButtonTitles:@"Take Photo", @"Choose Existing", nil]; + if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) { + [_imageSheet showInView:self.view]; + } else { + [_imageSheet showFromBarButtonItem:barButtonItem + animated:YES]; + } + } else { + [self showImagePickerForSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; + } + [self.groupedToolbar showRootToolbarAnimated:YES]; + return; + + default: + TFLog(@"[%@ %@] Unhandled toolbar action: %lu", self.pad.space.URL.host, + self.pad.padID, (unsigned long)action); + return; + } + + [self.padWebController clickToolbarWithCommand:command]; + if (showRootToolbar) { + [self.groupedToolbar showRootToolbarAnimated:YES]; + } +} + +- (IBAction)toolbarEditorAction:(id)sender +{ + [self clickToolbarAction:[sender tag] + barButtonItem:sender]; +} + +- (IBAction)keyboardDone:(id)sender +{ + [self.focusWorkaroundTextField resignFirstResponder]; + [[self.padWebController.webView hp_firstResponderSubview] resignFirstResponder]; +} + +#pragma mark - Action Sheet delegate + +- (void)imageSheetDidDismissWithButtonIndex:(NSInteger)buttonIndex +{ + UIActionSheet *actionSheet = _imageSheet; + _imageSheet.delegate = nil; + _imageSheet = nil; + + if (buttonIndex == actionSheet.cancelButtonIndex) { + return; + } + + UIImagePickerControllerSourceType sourceType; + sourceType = buttonIndex == actionSheet.firstOtherButtonIndex + ? UIImagePickerControllerSourceTypeCamera + : UIImagePickerControllerSourceTypePhotoLibrary; + + [self showImagePickerForSourceType:sourceType]; +} + +- (void)actionSheet:(UIActionSheet *)actionSheet +didDismissWithButtonIndex:(NSInteger)buttonIndex +{ + if (actionSheet == _imageSheet) { + [self imageSheetDidDismissWithButtonIndex:buttonIndex]; + } +} + +#pragma mark - Popover controller delegate + +- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController +{ + if (popoverController == _popoverSegue.popoverController) { + _popoverSegue.popoverController.delegate = nil; + _popoverSegue = nil; +#if 0 + } + if (popoverController == _searchPopover) { + _searchPopover.delegate = nil; + _searchPopover = nil; +#endif + } else if(popoverController == self.autocompleteDataPopover) { + self.autocompleteDataPopover.delegate = nil; + self.autocompleteDataPopover = nil; + } +} + +#pragma Segues + +- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier + sender:(id)sender +{ + if ([identifier isEqualToString:_popoverSegue.identifier] && + _popoverSegue.popoverController.isPopoverVisible) { + [self hideDialogs]; + return NO; + } + if ([identifier isEqualToString:OpenPadSegue]) { + [self hideDialogs]; + return sender != self.pad; + } + return YES; +} + +- (void)openPadWithURL:(NSURL *)URL +{ + HPPadEditorViewController * __weak weakSelf = self; + NSManagedObjectID * __block objectID; + [self.pad.managedObjectContext.hp_stack saveWithBlock:^(NSManagedObjectContext *localContext) { + NSError * __autoreleasing error; + HPPad *pad = [HPPad padWithURL:URL + managedObjectContext:localContext + error:&error]; + if (!pad) { + TFLog(@"[%@] Could not create pad object for URL: %@", URL.host, + URL.hp_fullPath); + return; + } + if (![pad.managedObjectContext obtainPermanentIDsForObjects:@[pad] + error:&error]) { + TFLog(@"[%@] Could not obtain permanent object ID for URL: %@", + URL.host, URL.hp_fullPath); + return; + } + objectID = pad.objectID; + } completion:^(NSError *error) { + // avoid double-tap, see -padWebController:didOpenURL: + weakSelf.view.userInteractionEnabled = YES; + if (!objectID) { + return; + } + HPPad *pad = (HPPad *)[weakSelf.pad.managedObjectContext existingObjectWithID:objectID + error:&error]; + if (!pad) { + TFLog(@"[%@] Could not find pad with ID %@: %@", URL.host, objectID, error); + return; + } + [weakSelf performSegueWithIdentifier:OpenPadSegue + sender:pad]; + }]; +} + +// iPhone -> show detail +- (void)prepareForSegue:(UIStoryboardSegue *)segue + sender:(id)sender +{ + HPLog(@"[%@] Make way for segue: %@ -> %@", self.pad.space.URL.host, + segue.identifier, segue.destinationViewController); + if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]]) { + [self hideDialogs]; + _popoverSegue = (UIStoryboardPopoverSegue *)segue; + _popoverSegue.popoverController.delegate = self; + } + if ([segue.identifier isEqualToString:@"EditCollections"]) { + UIViewController *vc = [segue.destinationViewController topViewController]; + HPPadCollectionViewController *collections = (HPPadCollectionViewController *)vc; + collections.pad = self.pad; + } else if ([segue.identifier isEqualToString:@"EditSharing"]) { + HPPadSharingViewController *sharing; + sharing = (HPPadSharingViewController *)[segue.destinationViewController topViewController]; + sharing.delegate = self; + sharing.userInfos = self.padWebController.userInfos; + if (self.pad.sharingOptions) { + sharing.sharingOptions = self.pad.sharingOptions; + return; + } + [self.pad hp_performBlock:^(HPPad *pad, NSError *__autoreleasing *error) { + if (pad.sharingOptions) { + return; + } + pad.sharingOptions = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([HPSharingOptions class]) + inManagedObjectContext:pad.managedObjectContext]; + } completion:^(HPPad *pad, NSError *error) { + if (!pad.sharingOptions) { + TFLog(@"[%@ %@] Could not create sharing options: %@", + pad.space.URL.host, pad.padID, error); + return; + } + sharing.sharingOptions = pad.sharingOptions; + }]; + } else if ([segue.identifier isEqualToString:BrowserSegue]) { + UIViewController *vc = [segue.destinationViewController topViewController]; + HPBrowserViewController *browser = (HPBrowserViewController *)vc; + browser.delegate = self; + browser.initialRequest = sender; + // avoid double-tap, see -padWebController:didOpenURL: + self.view.userInteractionEnabled = YES; + } else if ([segue.identifier isEqualToString:@"UserInfosList"]) { + HPUserInfosViewController *userInfos = (HPUserInfosViewController *)[segue.destinationViewController topViewController]; + userInfos.pad = self.pad; + userInfos.userInfos = self.padWebController.userInfos; + } else if ([segue.identifier isEqualToString:OpenPadSegue]) { + HPPadEditorViewController *editor = segue.destinationViewController; + editor.pad = sender; + } else if ([segue.identifier isEqualToString:@"Search"]) { + UIViewController *vc = segue.destinationViewController; + vc.searchDisplayController.delegate = self; + vc.searchDisplayController.searchResultsDelegate = self; + vc.searchDisplayController.searchBar.placeholder = [NSString stringWithFormat:@"Search %@", [(self.pad.space ?: self.defaultSpace) name]]; + if ([sender isKindOfClass:[NSString class]]) { + vc.searchDisplayController.searchBar.text = sender; + } + } +} + +#pragma mark - Pad web controller delegate + +- (void)updateScrollViewContentInsetForAutocomplete +{ + CGFloat webHeight = CGRectGetHeight(self.padWebController.webView.bounds); + UIEdgeInsets insets = self.padWebController.webView.scrollView.contentInset; + insets.bottom = webHeight - self.padWebController.visibleEditorHeight; + self.padWebController.webView.scrollView.contentInset = insets; + self.padWebController.webView.scrollView.scrollIndicatorInsets = insets; +} + +- (void)positionAutocompleteTableView +{ + NSUInteger rows = UIInterfaceOrientationIsLandscape(self.interfaceOrientation) ? 2 : 4; + CGFloat tableHeight = self.autocompleteTableView.rowHeight * rows; + self.padWebController.visibleEditorHeight = self.keyboardOrigin - tableHeight; + self.autocompleteTableHeightConstraint.constant = tableHeight; + self.autocompleteTableTopConstraint.constant = self.keyboardOrigin - tableHeight; + [self updateScrollViewContentInsetForAutocomplete]; +} + +- (void)padWebControllerDidBeginAutocomplete:(HPPadWebController *)padWebController +{ + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + [self positionAutocompleteTableView]; + self.autocompleteTableView.dataSource = padWebController.autocompleteDataSource; + [self.autocompleteTableView reloadData]; + [self.autocompleteTableView hp_setHidden:NO + animated:YES]; + [self updateScrollViewContentInsetForAutocomplete]; + return; + } + + UITableViewController *controller = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain]; + self.autocompleteTableView = controller.tableView; + self.autocompleteTableView.delegate = self; + self.autocompleteTableView.dataSource = padWebController.autocompleteDataSource; + self.autocompleteDataPopover = [[UIPopoverController alloc] initWithContentViewController:controller]; + self.autocompleteDataPopover.delegate = self; + CGRect popRect = self.padWebController.webView.frame; + popRect.size.height /= 3; + [self.autocompleteDataPopover presentPopoverFromRect:popRect + inView:self.padWebController.webView + permittedArrowDirections:UIPopoverArrowDirectionAny + animated:YES]; +} + +- (void)padWebControllerDidUpdateAutocomplete:(HPPadWebController *)padWebController +{ + [self.autocompleteTableView hp_setHidden:NO + animated:YES]; + [self.autocompleteTableView reloadData]; +} + +- (void)padWebControllerDidFinishAutocomplete:(HPPadWebController *)padWebController +{ + self.autocompleteTableView.dataSource = nil; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + [self.autocompleteTableView hp_setHidden:YES + animated:YES]; + [self.autocompleteTableView reloadData]; + self.padWebController.visibleEditorHeight = self.keyboardOrigin; + [self updateScrollViewContentInsetForAutocomplete]; + return; + } + + self.autocompleteTableView.delegate = nil; + self.autocompleteTableView = nil; + [self.autocompleteDataPopover dismissPopoverAnimated:NO]; +} + +- (void)padWebController:(HPPadWebController *)padWebController + didOpenURL:(NSURL *)URL +{ + if (self.navigationController.topViewController != self) { + return; + } + // Prevent accidental double-tap + if (!self.view.userInteractionEnabled) { + return; + } + self.view.userInteractionEnabled = NO; + switch ([HPAPI URLTypeWithURL:URL]) { + case HPUserProfileURLType: + // FIXME: Fetch profile, search on username + case HPExternalURLType: + HPLog(@"[%@ %@] Opening browser segue for %@", + self.pad.space.URL.host, self.pad.padID, URL); + [self performSegueWithIdentifier:BrowserSegue + sender:[NSURLRequest requestWithURL:URL]]; + break; + case HPPadURLType: + [self openPadWithURL:URL]; + break; + case HPSearchURLType: { + [self.padWebController.webView.hp_firstResponderSubview resignFirstResponder]; + NSString *searchText = URL.query.hp_dictionaryByParsingURLParameters[HPQueryParam]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + [self performSegueWithIdentifier:@"Search" + sender:searchText]; + } else { + [self.searchDisplayController setActive:YES + animated:YES]; + self.searchDisplayController.searchBar.text = searchText; + } + self.view.userInteractionEnabled = YES; + break; + } + default: + TFLog(@"[%@ %@] Unhandled URL: %@", + self.padWebController.webView.request.URL.host, + self.pad.padID, URL); + self.view.userInteractionEnabled = YES; +#if 0 + [[[UIAlertView alloc] initWithTitle:@"Sorry" + message:@"Unfortunately, that URL cannot be opened." + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; +#endif + break; + } +} + +- (void)padWebControllerDidUpdateUserInfo:(HPPadWebController *)padWebController +{ + [self updatePeoplePhoto]; +} + +- (void)setReloadToolbarHidden:(BOOL)hidden +{ + if (hidden) { + [self.navigationController setToolbarHidden:YES + animated:YES]; + self.toolbarItems = nil; + return; + } + UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace + target:nil + action:nil]; + UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"Reload" + style:UIBarButtonItemStylePlain + target:self + action:@selector(reloadClientVars:)]; + self.toolbarItems = @[spacer, item, spacer]; + [self.navigationController setToolbarHidden:NO + animated:YES]; +} + +- (void)padWebControllerDidDeletePad:(HPPadWebController *)padWebController +{ + if (self.navigationController.topViewController != self || + self.navigationController.viewControllers.firstObject == self) { + [self configureView]; + self.pad = nil; + return; + } + [self.navigationController popViewControllerAnimated:YES]; +} + +- (void)reloadClientVars:(id)sender +{ + HPPadEditorViewController * __weak weakSelf = self; + HPActionSheetBlockDelegate *delegate = [[HPActionSheetBlockDelegate alloc] initWithBlock:^(UIActionSheet *actionSheet, NSInteger button) { + if (button == actionSheet.cancelButtonIndex) { + [weakSelf setReloadToolbarHidden:NO]; + return; + } + [weakSelf setReloadToolbarHidden:YES]; + [weakSelf.pad hp_performBlock:^(HPPad *pad, NSError *__autoreleasing *error) { + pad.hasMissedChanges = NO; + } completion:^(HPPad *pad, NSError *error) { + [pad requestClientVarsWithRefresh:YES + completion:^(HPPad *pad, NSError *error) { + weakSelf.freakingOut = NO; + [weakSelf.padWebController reloadDiscardingChanges:YES + cachePolicy:NSURLRequestReturnCacheDataElseLoad + completion:NULL]; + }]; + }]; + }]; + [[[UIActionSheet alloc] initWithTitle:@"Your unsaved changes will be lost. This cannot be undone." + delegate:delegate + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Discard Changes" + otherButtonTitles:nil] showInView:self.view]; +} + +- (void)padWebControllerDidFreakOut:(HPPadWebController *)padWebController +{ + if (self.isFreakingOut) { + return; + } + self.freakingOut = YES; + NSString *message = @"An error is preventing the pad from synchronizing. " + "If you'd like to copy your changes before reloading, tap Reload Later."; + UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"How embarrassing..." + message:message + delegate:nil + cancelButtonTitle:@"Reload Later" + otherButtonTitles:@"Reload Now", nil]; + NSInteger mailButton = -1; + if ([MFMailComposeViewController canSendMail]) { + mailButton = [alertView addButtonWithTitle:@"Contact Support"]; + } + + HPPadEditorViewController * __weak weakSelf = self; + HPAlertViewBlockDelegate *delegate = [[HPAlertViewBlockDelegate alloc] initWithBlock:^(UIAlertView *alertView, NSInteger button) { + if (button == alertView.firstOtherButtonIndex) { + [weakSelf reloadClientVars:weakSelf]; + return; + } else if (button == mailButton) { + [weakSelf openSupportMail]; + } + [weakSelf setReloadToolbarHidden:NO]; + }]; + alertView.delegate = delegate; + [alertView show]; +} + +#pragma mark - Web view delegate + +- (BOOL)webView:(UIWebView *)webView +shouldStartLoadWithRequest:(NSURLRequest *)request + navigationType:(UIWebViewNavigationType)navigationType +{ + NSParameterAssert(request); + HPLog(@"[%@] %s %@", self.pad.space.URL.host, __PRETTY_FUNCTION__, request.URL); + /* + * Unlike Safari, UIWebView blurs when loading a new iframe, causing the + * keyboard to hide. This often happens for the comet iframe, for example. + * Work around that by capturing the currently focused element, and restoring + * it in -webViewDidStartLoad:. + */ + if ([webView hp_firstResponderSubview].isFirstResponder) { + [self saveFocus]; + } + return YES; +} + +- (void)webViewDidFinishLoad:(UIWebView *)webView +{ + // Sometimes -webViewDidStartLoad: doesn't get called, so check this here, too. + [self restoreFocus]; +} + +- (void)saveFocus +{ + // Call directly as it needs to be synchronous so keyboard doesn't go away. + if ([self.padWebController saveFocus]) { + HPLog(@"[%@] Enabling focus workaround.", self.pad.space.URL.host); + // Make non-empty so that backspace works. + self.focusWorkaroundTextField.text = @"A"; + [self.focusWorkaroundTextField becomeFirstResponder]; + } +} + +- (void)restoreFocus +{ + if (self.focusWorkaroundTextField.isFirstResponder) { + HPLog(@"[%@] Restoring focus.", self.pad.space.URL.host); + self.restoringFocus = YES; + [self.padWebController saveFocus]; + } +} + +- (void)webViewDidStartLoad:(UIWebView *)webView +{ + // iframe is loading now, so restore focus if we saved it. + [self restoreFocus]; +} + +#pragma mark - Browser view delegate + +- (BOOL)browserViewController:(HPBrowserViewController *)browserViewController +shouldStartLoadWithHackpadRequest:(NSURLRequest *)request +{ + // FIXME: Sanitize this to prevent redirections? + NSString *padID = [HPPad padIDWithURL:request.URL]; + if (!padID) { + TFLog(@"[%@ %@] Browser wanted to open internal link that was not a pad: %@", + self.pad.space.URL.host, self.pad.padID, request.URL); + return YES; + } + [browserViewController close:self]; + [self openPadWithURL:request.URL]; + return NO; +} + +#pragma mark - State preservation +// UIWebView restoration doesn't work with HTML as a string, only requests. +static NSString * const PadKey = @"padKey"; + +- (void)encodeRestorableStateWithCoder:(NSCoder *)coder +{ + [super encodeRestorableStateWithCoder:coder]; + + if (self.pad) { + [coder encodeObject:self.pad.objectID.URIRepresentation + forKey:PadKey]; + } +} + +- (void)decodeRestorableStateWithCoder:(NSCoder *)coder +{ + [super decodeRestorableStateWithCoder:coder]; + + NSURL *URL = [coder decodeObjectOfClass:NSURL.class + forKey:PadKey]; + if (!URL) { + return; + } + + HPCoreDataStack *coreDataStack = [HPCoreDataStack sharedStateRestorationCoreDataStack]; + NSManagedObjectID *objectID = [coreDataStack.persistentStoreCoordinator managedObjectIDForURIRepresentation:URL]; + NSError * __autoreleasing error; + self.pad = (HPPad *)[coreDataStack.mainContext existingObjectWithID:objectID + error:&error]; + if (error) { + TFLog(@"Could not load pad %@: %@", objectID, error); + } +} + +#pragma mark - Image picker delegate + +- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType +{ + UIImagePickerController *picker = [[UIImagePickerController alloc] init]; + picker.delegate = self; + picker.sourceType = sourceType; + if (sourceType == UIImagePickerControllerSourceTypePhotoLibrary) { + picker.modalPresentationStyle = UIModalPresentationFormSheet; + } + [self presentViewController:picker + animated:YES + completion:NULL]; +} + +- (void)imagePickerController:(UIImagePickerController *)picker +didFinishPickingMediaWithInfo:(NSDictionary *)info +{ + [self.padWebController insertImage:info[UIImagePickerControllerOriginalImage]]; + [self dismissViewControllerAnimated:YES + completion:NULL]; +} + +- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker +{ + [self dismissViewControllerAnimated:YES + completion:NULL]; +} + +#pragma mark - Undo / Redo + +- (void)motionEnded:(UIEventSubtype)motion + withEvent:(UIEvent *)event +{ + if (!motion != UIEventSubtypeMotionShake) { + [super motionEnded:motion + withEvent:event]; + return; + } + HPPadEditorViewController * __weak weakSelf = self; + [self.padWebController canUndoOrRedoWithCompletion:^(BOOL canUndo, BOOL canRedo) { + if (!canUndo && !canRedo) { + return; + } + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil + message:nil + delegate:nil + cancelButtonTitle:@"Cancel" + otherButtonTitles:nil]; + NSInteger undoButtonIndex = -1; + if (canUndo) { + undoButtonIndex = [alert addButtonWithTitle:@"Undo"]; + } + NSInteger redoButtonIndex = -1; + if (canRedo) { + redoButtonIndex = [alert addButtonWithTitle:@"Redo"]; + } + HPAlertViewBlockDelegate *delegate = [[HPAlertViewBlockDelegate alloc] initWithBlock:^(UIAlertView *alertView, + NSInteger buttonIndex) + { + if (buttonIndex == undoButtonIndex) { + [weakSelf.padWebController undo]; + } else if (buttonIndex == redoButtonIndex) { + [weakSelf.padWebController redo]; + } + }]; + alert.delegate = delegate; + [alert show]; + }]; +} + +#pragma mark - Pad sharing view controller delegate + +- (void)padSharingViewControllerDidFinish:(HPPadSharingViewController *)padSharingViewController +{ + padSharingViewController.delegate = nil; + if ([_popoverSegue.identifier isEqualToString:@"EditSharing"]) { + [self hideDialogs]; + } else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) { + [self dismissViewControllerAnimated:YES + completion:NULL]; + } +} + +#pragma mark - Text field delegate + +- (BOOL)textField:(UITextField *)textField +shouldChangeCharactersInRange:(NSRange)range +replacementString:(NSString *)string +{ + [self restoreFocus]; + if (string.length) { + [self.padWebController insertString:string]; + } else { + [self.padWebController deleteText]; + } + return NO; +} + +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + [self.padWebController insertNewLine]; + return NO; +} + +#pragma mark - TableView delegate methods + +- (void)tableView:(UITableView *)tableView +didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (tableView == self.autocompleteTableView) { + [self.padWebController selectAutocompleteData:self.padWebController.autocompleteDataSource.autocompleteData[indexPath.row][DataKey] + atIndex:indexPath.row]; + } else if (tableView.dataSource == self.searchDataSource) { + HPPad *pad = [self.searchDataSource padAtIndexPath:indexPath]; + [self.currentSearchDisplayController setActive:NO + animated:YES]; + [self performSegueWithIdentifier:OpenPadSegue + sender:pad]; + } +} + +#pragma mark - UISearchDisplay delegate + +- (UISearchDisplayController *)currentSearchDisplayController +{ + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + return self.searchDisplayController; + } + return self.popoverSegue.popoverController.contentViewController.searchDisplayController; +} + +- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller +{ + HPSpace *searchSpace = self.pad.space ?: self.defaultSpace; + self.searchDataSource = [[HPPadSearchTableViewDataSource alloc] init]; + self.searchDataSource.managedObjectContext = searchSpace.managedObjectContext; + self.searchDataSource.padScope = [[HPPadScope alloc] initWithCoreDataStack:searchSpace.managedObjectContext.hp_stack]; + self.searchDataSource.padScope.space = searchSpace; + controller.searchResultsDataSource = self.searchDataSource; + controller.searchResultsDelegate = self; + self.searchDataSource.tableView = controller.searchResultsTableView; + controller.searchResultsTableView.rowHeight = 60; + self.searchDataSource.searchText = controller.searchBar.text; + [controller.searchBar.superview bringSubviewToFront:controller.searchBar]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + return; + } + // FIXME: figure out how to slide webview down on iOS 7 instead + controller.searchBar.alpha = 0; + [UIView animateWithDuration:0.25 + animations:^{ + controller.searchBar.alpha = 1; + if (HP_SYSTEM_MAJOR_VERSION() < 7) { + return; + } + self.padWebController.webView.alpha = 0; + }]; +} + +- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller +{ + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + [self hideDialogs]; + return; + } + [UIView animateWithDuration:0.25 + animations:^{ + self.searchDisplayController.searchBar.alpha = 0; + if (HP_SYSTEM_MAJOR_VERSION() < 7) { + return; + } + self.padWebController.webView.alpha = 1; + }]; +} + +- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller +{ + controller.searchResultsTableView.dataSource = nil; + self.searchDataSource.tableView = nil; + self.searchDataSource = nil; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + [controller.searchBar.superview sendSubviewToBack:controller.searchBar]; + } +} + +- (BOOL)searchDisplayController:(UISearchDisplayController *)controller +shouldReloadTableForSearchString:(NSString *)searchString +{ + self.searchDataSource.searchText = (searchString.length > 2) ? searchString : nil; + return NO; +} + +#pragma mark - MFMailComposeViewControllerDelegate + +- (void)mailComposeController:(MFMailComposeViewController *)controller + didFinishWithResult:(MFMailComposeResult)result + error:(NSError *)error +{ + controller.mailComposeDelegate = nil; + [self dismissViewControllerAnimated:YES + completion:nil]; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadListViewController.h b/client/ios/Hackpad/Hackpad/HPPadListViewController.h new file mode 100644 index 0000000..6acc5eb --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadListViewController.h @@ -0,0 +1,32 @@ +// +// HPPadListViewController.h +// Hackpad +// +// +// Copyright (c) 2012 Hackpad. All rights reserved. +// + +#import +#import + +@class HPPadScope; +@class HPPadEditorViewController; +@class HPPadTableViewDataSource; + +@interface HPPadListViewController : UITableViewController + +@property(strong, nonatomic) IBOutlet HPPadTableViewDataSource *dataSource; + +@property (strong, nonatomic) HPPadScope *padScope; +@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext; + +@property (strong, nonatomic) IBOutlet HPPadEditorViewController *editorViewController; +@property (strong, nonatomic) IBOutlet UIBarButtonItem *signInButtonItem; +@property (strong, nonatomic) IBOutlet UIBarButtonItem *composeButtonItem; +@property (nonatomic, strong) UIPopoverController *masterPopoverController; + +- (IBAction)createPad:(id)sender; +- (IBAction)signIn:(id)sender; +- (IBAction)toggleDrawer:(id)sender; + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadListViewController.m b/client/ios/Hackpad/Hackpad/HPPadListViewController.m new file mode 100644 index 0000000..b298636 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadListViewController.m @@ -0,0 +1,639 @@ +// +// HPPadListViewController.m +// Hackpad +// +// +// Copyright (c) 2012 Hackpad. All rights reserved. +// + +#import "HPPadListViewController.h" + +#import "HPDrawerController.h" +#import "HPPadEditorViewController.h" +#import "HPPadCacheController.h" +#import "HPPadTableViewDataSource.h" +#import "HPPadSearchTableViewDataSource.h" +#import "HPSignInController.h" + +#import +#import + +#import +#import +#import + +static NSString * const OfflineTitle = @"Offline"; +static NSString * const SignInTitle = @"Sign In"; +static NSString * const SignOutTitle = @"Sign Out"; + +static NSString * const ShowDetailSegue = @"showDetail"; +static NSString * const SelectSourceSegue = @"selectSource"; +static NSString * const CreatePadSegue = @"createPad"; + +static BOOL AuthenticationStateContext; + +@interface HPPadListViewController () { + id scopeObserver; + id signInObserver; + HPPadSearchTableViewDataSource *searchDataSource; + NSMutableSet *expandedIndexPaths; +} +@property (nonatomic, strong) HPPadWebController *padWebController; +@property (nonatomic, strong) HPSpace *observingSpace; +@property (nonatomic, strong) MBProgressHUD *signInHUD; +@property (nonatomic, assign, getter = isSigningIn) BOOL signingIn; +@property (nonatomic, assign, getter = isRequestingPads) BOOL requestingPads; +- (void)configureView; +- (void)scopeDidChange; +@end + +@implementation HPPadListViewController + +- (void)dealloc +{ + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + if (scopeObserver) { + [center removeObserver:scopeObserver]; + scopeObserver = nil; + } + if (signInObserver) { + [center removeObserver:signInObserver]; + signInObserver = nil; + } + [center removeObserver:self]; + [self.observingSpace removeObserver:self + forKeyPath:@"authenticationState"]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context +{ + if (context != &AuthenticationStateContext) { + [super observeValueForKeyPath:keyPath + ofObject:object + change:change + context:context]; + return; + } + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + [self updateSigningIn]; + }]; +} + +- (void)configureProgressHUD +{ + if (self.isRequestingPads || self.isSigningIn) { + if (self.signInHUD) { + return; + } + self.signInHUD = [MBProgressHUD showHUDAddedTo:self.view + animated:YES]; + } else if (self.signInHUD) { + [self.signInHUD hide:YES]; + self.signInHUD = nil; + } +} + +- (void)setSigningIn:(BOOL)signingIn +{ + _signingIn = signingIn; + [self configureProgressHUD]; +} + +- (void)setRequestingPads:(BOOL)requestingPads +{ + _requestingPads = requestingPads; + [self configureProgressHUD]; +} + +- (void)updateSigningIn +{ + UIBarButtonItem *item; + switch (self.padScope.space.API.authenticationState) { + case HPRequiresSignInAuthenticationState: + item = self.signInButtonItem; + break; + case HPReconnectAuthenticationState: + case HPSignedInAuthenticationState: + item = self.composeButtonItem; + break; + default: + break; + } + [self.navigationItem setRightBarButtonItem:item + animated:YES]; + self.signingIn = !item; +} + +- (void)signInControllerWillRequestPadsWithNotification:(NSNotification *)note +{ + if (note.userInfo[HPSignInControllerSpaceKey] != self.padScope.space) { + return; + } + if ([self.dataSource tableView:self.tableView + numberOfRowsInSection:0]) { + return; + } + self.requestingPads = YES; +} + +- (void)signInControllerDidRequestPadsWithNotification:(NSNotification *)note +{ + if (note.userInfo[HPSignInControllerSpaceKey] != self.padScope.space) { + return; + } + self.requestingPads = NO; +} + +- (void)configureView +{ + HPLog(@"[%@] %s", self.padScope.space.URL.host, __PRETTY_FUNCTION__); + if (!self.padScope.space) { + return; + } + self.title = self.padScope.collection + ? self.padScope.collection.title + : self.padScope.space.name; + // Avoid animating the title change along with the buttons below. + [self.navigationController.navigationBar layoutIfNeeded]; + [self updateSigningIn]; +} + +- (void)viewDidLoad +{ + HPLog(@"[%@] %s", self.padScope.space.URL.host, __PRETTY_FUNCTION__); + [super viewDidLoad]; + + // XXX: The color being saved in the storyboard isn't quite right? + self.tableView.backgroundColor = [UIColor hp_lightGreenGrayColor]; + self.refreshControl.backgroundColor = [UIColor hp_lightGreenGrayColor]; + + [self.refreshControl addTarget:self + action:@selector(refresh:) + forControlEvents:UIControlEventValueChanged]; + + self.signInButtonItem.possibleTitles = [NSSet setWithObjects:SignInTitle, + SignOutTitle, OfflineTitle, nil]; + + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + HPPadListViewController * __weak weakSelf = self; + scopeObserver = [center addObserverForName:HPPadScopeDidChangeNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + if (note.object == weakSelf.padScope) { + [weakSelf configureView]; + [weakSelf scopeDidChange]; + } + }]; + signInObserver = [center addObserverForName:HPAPIDidSignInNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + if (note.object == weakSelf.padScope.space.API) { + [weakSelf configureView]; + [weakSelf reloadPadWebControllerForSignIn]; + } + }]; + [center addObserver:self + selector:@selector(signInControllerWillRequestPadsWithNotification:) + name:HPSignInControllerWillRequestPadsNotification + object:nil]; + [center addObserver:self + selector:@selector(signInControllerDidRequestPadsWithNotification:) + name:HPSignInControllerWillRequestPadsNotification + object:nil]; + [self configureView]; +} + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + [self.navigationController setToolbarHidden:YES + animated:animated]; + if (!self.padWebController && self.observingSpace) { + [self loadPadWebController]; + } + } +} + +- (void)viewDidDisappear:(BOOL)animated +{ + [super viewDidDisappear:animated]; + self.padWebController = nil; +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + self.padWebController = nil; +} + +- (void)loadEditorWithPad:(HPPad *)pad +{ + self.padWebController = [HPPadWebController sharedPadWebControllerWithPad:pad + padWebController:self.padWebController]; + self.editorViewController.pad = pad; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + [self loadPadWebController]; + } else { + self.padWebController = nil; + self.editorViewController = nil; + } +} + +// iPhone -> show detail +- (void)prepareForSegue:(UIStoryboardSegue *)segue + sender:(id)sender +{ + if ([segue.identifier isEqualToString:ShowDetailSegue]) { + self.editorViewController = segue.destinationViewController; + if ([sender isKindOfClass:[HPPad class]]) { + [self loadEditorWithPad:sender]; + } + // otherwise pad is set above in didSelectRowAtIndexPath: + } else if ([segue.identifier isEqualToString:CreatePadSegue]) { + NSParameterAssert([sender isKindOfClass:[HPPad class]]); + self.editorViewController = segue.destinationViewController; + [self loadEditorWithPad:sender]; + } +} + +- (NSUInteger)supportedInterfaceOrientations +{ + return [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad + ? UIInterfaceOrientationMaskAll + : UIInterfaceOrientationMaskPortrait; +} + +#pragma mark - PadListViewController implementation + +- (void)loadPadWebController +{ + [self loadPadWebControllerWithCachePolicy:NSURLRequestReturnCacheDataElseLoad]; +} + +- (void)loadPadWebControllerWithCachePolicy:(NSURLRequestCachePolicy)cachePolicy +{ + /* + * If we don't stop loading first, we'll get an "operation cancelled" error + * from the *new* WebView - even though we only killed the old one? + */ + [self.padWebController.webView stopLoading]; + self.padWebController = [[HPPadWebController alloc] initWithSpace:self.observingSpace + frame:CGRectMake(0, 0, 320, 480)]; + HPPadListViewController * __weak weakSelf = self; + HPPadWebController * __weak padWebController = self.padWebController; + [self.padWebController loadWithCachePolicy:cachePolicy + completion:^(NSError *error) + { + if (!error) { + return; + } + TFLog(@"[%@] Could not preload web controller: %@", + weakSelf.observingSpace.URL.host, error); + if (padWebController && weakSelf.padWebController != padWebController) { + return; + } + weakSelf.padWebController = nil; + }]; +} + +- (void)reloadPadWebControllerForSignIn +{ + if (!self.padWebController) { + return; + } + [self loadPadWebControllerWithCachePolicy:NSURLRequestReloadRevalidatingCacheData]; +} + +- (void)scopeDidChange +{ + [self.observingSpace removeObserver:self + forKeyPath:@"authenticationState"]; + self.observingSpace = self.padScope.space; + [self.observingSpace addObserver:self + forKeyPath:@"authenticationState" + options:0 + context:&AuthenticationStateContext]; + if (self.observingSpace != self.padWebController.space && + self.navigationController.topViewController == self) { + [self loadPadWebController]; + } + self.editorViewController.defaultSpace = self.padScope.space; +} + +- (void)setPadScope:(HPPadScope *)padScope +{ + HPLog(@"[%@] %s", padScope.space.URL.host, __PRETTY_FUNCTION__); + + self.managedObjectContext = padScope.coreDataStack.mainContext; + _padScope = padScope; + + self.dataSource.managedObjectContext = self.managedObjectContext; + self.dataSource.padScope = padScope; + + searchDataSource.managedObjectContext = self.managedObjectContext; + searchDataSource.padScope = padScope; + + if (!self.isViewLoaded) { + return; + } + + [self configureView]; + [self scopeDidChange]; + [self.tableView reloadData]; +} + +- (IBAction)signIn:(id)sender +{ + [self.padScope.space.API signInEvenIfSignedIn:NO]; + [self configureView]; +} + +- (IBAction)toggleDrawer:(id)sender +{ + HPDrawerController *drawer = (HPDrawerController *)self.navigationController.parentViewController; + [drawer setLeftDrawerShown:!drawer.isLeftDrawerShown + animated:YES]; +} + +- (IBAction)refresh:(id)sender +{ + if (!self.padScope.space.API.isSignedIn || + !self.padScope.space.API.reachability.currentReachabilityStatus) { + [self.refreshControl endRefreshing]; + return; + } + NSString *host = self.padScope.space.URL.host; + // http://blog.wednesdaynight.org/2014/2/2/endRefreshing-while-decelerating + UIRefreshControl * __weak refreshControl = self.refreshControl; + [self.padScope.space requestFollowedPadsWithRefresh:YES + completion:^(id obj, NSError *error) + { + if (error) { + TFLog(@"[%@] Could not fetch pads: %@", host, error); + } + dispatch_async(dispatch_get_main_queue(), ^{ + [refreshControl performSelector:@selector(endRefreshing) + withObject:nil + afterDelay:0]; + }); + }]; +} + +- (IBAction)createPad:(id)sender +{ + HPPadListViewController * __weak weakSelf = self; + UIBarButtonItem *item = sender; + if ([item isKindOfClass:[UIBarButtonItem class]]) { + item.enabled = NO; + } + [self.padScope.space blankPadWithTitle:@"Untitled" + followed:YES + completion:^(HPPad *pad, NSError *error) + { + if ([item isKindOfClass:[UIBarButtonItem class]]) { + item.enabled = YES; + } + if (!pad) { + if (error) { + TFLog(@"[%@] Could not create blank pad: %@", + weakSelf.padScope.space.URL.host, error); + } + return; + } + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + [weakSelf performSegueWithIdentifier:CreatePadSegue + sender:pad]; + } else { + [self.masterPopoverController dismissPopoverAnimated:YES]; + [self.editorViewController.navigationController popToRootViewControllerAnimated:YES]; + [self loadEditorWithPad:pad]; + } + }]; +} + +#pragma mark - Table view delegate + +- (NSString *)tableView:(UITableView *)tableView +titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath +{ + HPPad *pad = [self.dataSource padAtIndexPath:indexPath]; + return pad.hasMissedChanges ? @"Discard Changes" : @"Remove"; +} + +- (void)tableView:(UITableView *)tableView +didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + HPPad *pad; + if (tableView == self.tableView) { + pad = [self.dataSource padAtIndexPath:indexPath]; + } else if (tableView == self.searchDisplayController.searchResultsTableView) { + pad = [searchDataSource padAtIndexPath:indexPath]; + } else { + return; + } + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + [self performSegueWithIdentifier:ShowDetailSegue + sender:[tableView cellForRowAtIndexPath:indexPath]]; + [self loadEditorWithPad:pad]; + } else { + [self.masterPopoverController dismissPopoverAnimated:YES]; + [self loadEditorWithPad:pad]; + } +} + +#if 0 +- (CGFloat)tableView:(UITableView *)tableView +heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (tableView == self.tableView) { + HPPad *pad = [self.dataSource padAtIndexPath:indexPath]; + CGFloat snippetHeight = [expandedIndexPaths member:indexPath] ? pad.expandedSnippetHeight : pad.snippetHeight; + return MAX(77 - 44 + MAX(snippetHeight, 21), 44); + } + return 60; +} +#endif + +- (void)tableView:(UITableView *)tableView +accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath +{ + HPPad *pad = [self.dataSource padAtIndexPath:indexPath]; + if (pad.snippetHeight <= 164) { + return; + } + BOOL shrink = !![expandedIndexPaths member:indexPath]; + if (shrink) { + [expandedIndexPaths removeObject:indexPath]; + } else { + [expandedIndexPaths addObject:indexPath]; + } + [tableView reloadRowsAtIndexPaths:@[indexPath] + withRowAnimation:UITableViewRowAnimationAutomatic]; + [tableView scrollToRowAtIndexPath:indexPath + atScrollPosition:shrink ? UITableViewScrollPositionMiddle : UITableViewScrollPositionTop + animated:YES]; +} + +#pragma mark - Scroll view delegate + +- (void)enablePadCacheController +{ + [[HPPadCacheController sharedPadCacheController] setDisabled:NO]; +} + +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView +{ + [[HPPadCacheController sharedPadCacheController] setDisabled:YES]; + [self performSelector:@selector(enablePadCacheController) + withObject:nil + afterDelay:0]; +} + +#pragma mark - UISearchDisplay delegate + +- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller +{ + searchDataSource = [[HPPadSearchTableViewDataSource alloc] init]; + searchDataSource.managedObjectContext = self.managedObjectContext; + searchDataSource.padScope = self.padScope; + searchDataSource.prototypeTableView = self.tableView; + searchDataSource.tableView = controller.searchResultsTableView; + controller.searchResultsTableView.dataSource = searchDataSource; + controller.searchResultsTableView.rowHeight = 60; + if (HP_SYSTEM_MAJOR_VERSION() < 7) { + return; + } + [UIView transitionWithView:controller.searchBar + duration:0.25 + options:UIViewAnimationOptionTransitionCrossDissolve + animations:^{ + controller.searchBar.searchBarStyle = UISearchBarStyleProminent; + controller.searchBar.barTintColor = [UIColor whiteColor]; + } completion:nil]; +} + +- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller +{ + if (HP_SYSTEM_MAJOR_VERSION() < 7) { + return; + } + [UIView transitionWithView:controller.searchBar + duration:0.25 + options:UIViewAnimationOptionTransitionCrossDissolve + animations:^{ + controller.searchBar.searchBarStyle = UISearchBarStyleMinimal; + } completion:nil]; +} + +- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller +{ + controller.searchResultsTableView.dataSource = nil; + searchDataSource.tableView = nil; + searchDataSource = nil; + if (controller.searchBar.superview == self.tableView) { + return; + } + [self.tableView addSubview:controller.searchBar]; +} + +- (BOOL)searchDisplayController:(UISearchDisplayController *)controller +shouldReloadTableForSearchString:(NSString *)searchString +{ + if (!self.padScope.space.userID) { + return NO; + } + searchDataSource.searchText = (searchString.length > 2) ? searchString : nil; + return NO; +} + +#pragma mark - State preservation + +static NSString * const HPPadListScope = @"HPPadListScope"; + +- (void)encodeRestorableStateWithCoder:(NSCoder *)coder +{ + // Don't persist editing, as we have no UI to undo it. + self.editing = NO; + [super encodeRestorableStateWithCoder:coder]; + NSManagedObject *managedObject = self.padScope.collection + ? self.padScope.collection + : self.padScope.space; + if (managedObject) { + [coder encodeObject:managedObject.objectID.URIRepresentation + forKey:HPPadListScope]; + } +} + +- (void)decodeRestorableStateWithCoder:(NSCoder *)coder +{ + [super decodeRestorableStateWithCoder:coder]; + + NSURL *URL = [coder decodeObjectOfClass:[NSURL class] + forKey:HPPadListScope]; + + if (!URL) { + return; + } + + NSManagedObjectID *objectID = [self.padScope.coreDataStack.persistentStoreCoordinator managedObjectIDForURIRepresentation:URL]; + if (!objectID) { + TFLog(@"Could not find objectID for restored URL: %@", URL); + return; + } + + NSError * __autoreleasing error; + NSManagedObject *managedObject = [self.managedObjectContext existingObjectWithID:objectID + error:&error]; + if (error) { + TFLog(@"Could not find restoring object: %@", error); + return; + } + + if ([managedObject isKindOfClass:[HPCollection class]]) { + self.padScope.collection = (HPCollection *)managedObject; + } else if ([managedObject isKindOfClass:[HPSpace class]]) { + self.padScope.space = (HPSpace *)managedObject; + } else { + TFLog(@"Unexpected saved scope: %@", managedObject); + } +} + +#pragma mark - UIDataSourceModelAssociation implementation + +- (NSString *)modelIdentifierForElementAtIndexPath:(NSIndexPath *)idx + inView:(UIView *)view +{ + HPPad *pad = [self.dataSource padAtIndexPath:idx]; + return pad.objectID.URIRepresentation.absoluteString; +} + +- (NSIndexPath *)indexPathForElementWithModelIdentifier:(NSString *)identifier + inView:(UIView *)view +{ + NSURL *URL = [NSURL URLWithString:identifier]; + if (!URL) { + return nil; + } + NSManagedObjectID *objectID = [self.managedObjectContext.persistentStoreCoordinator managedObjectIDForURIRepresentation:URL]; + NSError * __autoreleasing error; + NSManagedObject *obj = [self.managedObjectContext existingObjectWithID:objectID + error:&error]; + if (!obj) { + if (error) { + TFLog(@"Error reloading pad: %@", error); + } + return nil; + } + return [self.dataSource indexPathForPad:(HPPad *)obj]; + +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadScopeTableViewDataSource.h b/client/ios/Hackpad/Hackpad/HPPadScopeTableViewDataSource.h new file mode 100644 index 0000000..e7f5512 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadScopeTableViewDataSource.h @@ -0,0 +1,16 @@ +// +// HPPadScopeTableVIewDataSource.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import + +@interface HPPadScopeTableViewDataSource : NSObject +@property (nonatomic, weak) IBOutlet UITableView *tableView; +@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext; +- (id)objectAtIndexPath:(NSIndexPath *)indexPath; +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadScopeTableViewDataSource.m b/client/ios/Hackpad/Hackpad/HPPadScopeTableViewDataSource.m new file mode 100644 index 0000000..5b95ce0 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadScopeTableViewDataSource.m @@ -0,0 +1,495 @@ +// +// HPPadScopeTableViewDataSource.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadScopeTableViewDataSource.h" + +#import "HPActionSheetBlockDelegate.h" + +#import + +#import +#import + +static NSString * const CollectionImageName = @"up-chevron"; +static NSString * const SwitchUserImageName = @"user"; + +@interface HPPadScopeTableViewDataSource () +@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController; +@property (nonatomic, strong) NSMutableDictionary *collectionFetchedResultsControllers; +@property (nonatomic, strong) NSMutableDictionary *collectionCounts; +@property (nonatomic, strong) NSMutableArray *deferredBlocks; +@property (nonatomic, strong) NSMutableSet *shownCollections; +@end + +@implementation HPPadScopeTableViewDataSource + +- (void)dealloc +{ + self.fetchedResultsController.delegate = nil; + [self.collectionFetchedResultsControllers enumerateKeysAndObjectsUsingBlock:^(id key, NSFetchedResultsController *frc, BOOL *stop) { + frc.delegate = nil; + }]; +} + +#pragma mark - Implementation + +- (NSFetchedResultsController *)fetchedResultsController +{ + if (_fetchedResultsController) { + return _fetchedResultsController; + } + if (!self.managedObjectContext) { + return nil; + } + NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:HPSpaceEntity]; + fetchRequest.predicate = [NSPredicate predicateWithFormat:@"hidden == NO"]; + fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"domainType" + ascending:YES], + [NSSortDescriptor sortDescriptorWithKey:@"name" + ascending:YES]]; + fetchRequest.shouldRefreshRefetchedObjects = YES; + _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest + managedObjectContext:self.managedObjectContext + sectionNameKeyPath:nil + cacheName:nil]; + _fetchedResultsController.delegate = self; + NSError * __autoreleasing error; + if (![_fetchedResultsController performFetch:&error]) { + TFLog(@"Couldn't perform fetch: %@", error); + } + [_fetchedResultsController.fetchedObjects enumerateObjectsUsingBlock:^(HPSpace *space, NSUInteger idx, BOOL *stop) { + [self fetchedResultsControllerForSpace:space]; + }]; + return _fetchedResultsController; +} + +- (HPSpace *)spaceForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return self.fetchedResultsController.fetchedObjects[indexPath.section]; +} + +- (NSMutableDictionary *)collectionFetchedResultsControllers +{ + if (!_collectionFetchedResultsControllers) { + _collectionFetchedResultsControllers = [NSMutableDictionary dictionary]; + } + return _collectionFetchedResultsControllers; +} + +- (NSMutableDictionary *)collectionCounts +{ + if (!_collectionCounts) { + _collectionCounts = [NSMutableDictionary dictionary]; + } + return _collectionCounts; +} + +- (NSMutableSet *)shownCollections +{ + if (!_shownCollections) { + _shownCollections = [NSMutableSet set]; + } + return _shownCollections; +} + +- (NSFetchedResultsController *)fetchedResultsControllerForSpace:(HPSpace *)space +{ + NSFetchedResultsController *collectionFetchedResultsController; + collectionFetchedResultsController = [self.collectionFetchedResultsControllers objectForKey:space.objectID]; + if (collectionFetchedResultsController) { + return collectionFetchedResultsController; + } + + NSError * __autoreleasing error; + if (![space.managedObjectContext obtainPermanentIDsForObjects:@[space] + error:&error]) { + TFLog(@"[%@] Could not get permanent object id: %@", space.URL.host, error); + return nil; + } + + NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:HPCollectionEntity]; + fetchRequest.predicate = [NSPredicate predicateWithFormat:@"space == %@ AND followed == YES", space]; + fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"title" + ascending:YES]]; + fetchRequest.shouldRefreshRefetchedObjects = YES; + collectionFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest + managedObjectContext:self.fetchedResultsController.managedObjectContext + sectionNameKeyPath:nil + cacheName:nil]; + collectionFetchedResultsController.delegate = self; + self.collectionFetchedResultsControllers[space.objectID] = collectionFetchedResultsController; + if (![collectionFetchedResultsController performFetch:&error]) { + TFLog(@"[%@] Couldn't perform fetch: %@", space.URL.host, error); + } + self.collectionCounts[space.objectID] = [NSNumber numberWithInteger:collectionFetchedResultsController.fetchedObjects.count]; + return collectionFetchedResultsController; +} + +- (id)objectAtIndexPath:(NSIndexPath *)indexPath +{ + HPSpace *space = [self spaceForRowAtIndexPath:indexPath]; + if (!indexPath.row) { + return space; + } + + NSFetchedResultsController *collectionFetchedResultsController; + collectionFetchedResultsController = [self fetchedResultsControllerForSpace:space]; + return collectionFetchedResultsController.fetchedObjects[indexPath.row - 1]; +} + +- (void)configureCell:(UITableViewCell *)cell + atIndexPath:(NSIndexPath *)indexPath +{ + id object = [self objectAtIndexPath:indexPath]; + NSAssert([object isKindOfClass:[HPSpace class]] || [object isKindOfClass:[HPCollection class]], + @"Don't know how to handle %@ object.", [object class]); + + cell.textLabel.font = [UIFont hp_UITextFontOfSize:cell.textLabel.font.pointSize]; + cell.detailTextLabel.font = [UIFont hp_UITextFontOfSize:cell.detailTextLabel.font.pointSize]; + + if ([object isKindOfClass:[HPCollection class]]) { + HPCollection *collection = object; + cell.textLabel.text = collection.title; + cell.detailTextLabel.text = nil; + return; + } + + UIImage *image; + UIButton *button; + HPSpace *space = object; + + cell.textLabel.text = space.name; + cell.detailTextLabel.text = space.URL.host; + + CGFloat buttonWidth = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 64 : 58; + if (space.collections.count) { + image = [UIImage imageNamed:CollectionImageName]; + button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonWidth, 40)]; + [button setImage:image + forState:UIControlStateNormal]; + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(collectionButtonTapped:)]; + [button addGestureRecognizer:tap]; + if (![self.shownCollections member:space.objectID]) { + button.transform = CGAffineTransformMakeRotation(M_PI); + } + button.tag = indexPath.section; + } + cell.accessoryView = button; + + image = [UIImage imageNamed:SwitchUserImageName]; + button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonWidth, 40)]; + button.tag = indexPath.section; + + [button setImage:image + forState:UIControlStateNormal]; + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(switchUser:)]; + [button addGestureRecognizer:tap]; + + cell.editingAccessoryView = button; +} + +- (void)collectionButtonTapped:(UITapGestureRecognizer *)sender +{ + if (sender.state != UIGestureRecognizerStateEnded) { + return; + } + UIButton *button = (UIButton *)sender.view; + NSParameterAssert([button isKindOfClass:[UIButton class]]); + NSInteger section = button.tag; + HPSpace *space = [self spaceForRowAtIndexPath:[NSIndexPath indexPathForRow:0 + inSection:section]]; + NSUInteger rowsCount = [self.collectionCounts[space.objectID] integerValue]; + NSMutableArray *rows = [NSMutableArray arrayWithCapacity:rowsCount]; + for (NSUInteger row = 1; row <= rowsCount; row++) { + [rows addObject:[NSIndexPath indexPathForRow:row + inSection:section]]; + } + CGAffineTransform transform = CGAffineTransformIdentity; + [self.tableView beginUpdates]; + if ([self.shownCollections member:space.objectID]) { + [self.shownCollections removeObject:space.objectID]; + [self.tableView deleteRowsAtIndexPaths:rows + withRowAnimation:UITableViewRowAnimationAutomatic]; + transform = CGAffineTransformMakeRotation(M_PI); + } else { + [self.shownCollections addObject:space.objectID]; + [self.tableView insertRowsAtIndexPaths:rows + withRowAnimation:UITableViewRowAnimationAutomatic]; + } + [self.tableView endUpdates]; + [UIView animateWithDuration:0.25 + animations:^{ + button.transform = transform; + }]; +} + +- (void)switchUser:(UITapGestureRecognizer *)sender +{ + if (sender.state != UIGestureRecognizerStateEnded) { + return; + } + UIButton *button = (UIButton *)sender.view; + NSParameterAssert([button isKindOfClass:[UIButton class]]); + NSInteger section = button.tag; + HPSpace *space = [self spaceForRowAtIndexPath:[NSIndexPath indexPathForRow:0 + inSection:section]]; + HPAPI *API = space.API; + HPPadScopeTableViewDataSource * __weak weakSelf = self; + HPActionSheetBlockDelegate *delegate = [[HPActionSheetBlockDelegate alloc] initWithBlock:^(UIActionSheet *sheet, NSInteger button) { + if (button == sheet.cancelButtonIndex) { + return; + } + [weakSelf.tableView setEditing:NO + animated:YES]; + @synchronized (API) { + API.authenticationState = HPRequiresSignInAuthenticationState; + API.userID = space.userID; + API.authenticationState = HPSignInPromptAuthenticationState; + } + }]; + // Showing from the clipped view displays wrong in iOS 7. + UIView *view = self.tableView; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && HP_SYSTEM_MAJOR_VERSION() >= 7) { + view = view.window; + } + + [[[UIActionSheet alloc] initWithTitle:space.name + delegate:delegate + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Switch Accounts" + otherButtonTitles:nil] showInView:view]; +} + +#pragma mark - Table view data source implementation + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return self.fetchedResultsController.fetchedObjects.count; +} + +- (NSInteger)tableView:(UITableView *)tableView + numberOfRowsInSection:(NSInteger)section +{ + /* + We can't just use the fetchedResultController's count because we get + updates from the space controller and collection controllers separately. + For example, we'll see the updated count here after getting the space's + changed callback, but before getting the collection's, so we don't return + the value UITableView expects. + */ + HPSpace *space = self.fetchedResultsController.fetchedObjects[section]; + + return [self.shownCollections member:space.objectID] + ? [self.collectionCounts[space.objectID] integerValue] + 1 + : 1; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView + cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString * const SpaceCellIdentifier = @"SpaceCell"; + static NSString * const CollectionCellIdentifier = @"CollectionCell"; + UITableViewCell *cell; + // Search results doesn't have a table view, so just use main view w/o indexPath. + cell = [tableView dequeueReusableCellWithIdentifier:indexPath.row ? CollectionCellIdentifier : SpaceCellIdentifier + forIndexPath:indexPath]; + [self configureCell:cell + atIndexPath:indexPath]; + + return cell; +} + +- (void)tableView:(UITableView *)tableView +commitEditingStyle:(UITableViewCellEditingStyle)editingStyle +forRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (editingStyle != UITableViewCellEditingStyleDelete) { + return; + } + NSManagedObject *object = [self objectAtIndexPath:indexPath]; + if ([object isKindOfClass:[HPCollection class]]) { + [(HPCollection *)object setFollowed:NO + completion:^(HPCollection *collection, NSError *error) + { + if (error) { + TFLog(@"[%@] Error unfollowing collection: %@", + collection.space.URL.host, error); + } + }]; + return; + } + HPSpace *space = (HPSpace *)object; + @synchronized ([space API]) { + if (space.API.authenticationState != HPRequiresSignInAuthenticationState) { + MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:tableView + animated:YES]; + [space signOutWithCompletion:^(HPSpace *space, NSError *error) { + [HUD hide:YES]; + if (error) { + TFLog(@"[%@] Error signing out of space: %@", + space.URL.host, error); + } + }]; + return; + } + NSAssert(indexPath.section, @"Shouldn't remove root space"); + [space hp_performBlock:^(HPSpace *space, NSError *__autoreleasing *error) { + space.hidden = YES; + } completion:^(HPSpace *space, NSError *error) { + if (error) { + TFLog(@"[%@] Could not hide space: %@", space.URL.host, error); + } + }]; + } +} + +#pragma mark - Fetched results controller delegate + +/* + Assume self has a property 'tableView' -- as is the case for an instance of a UITableViewController + subclass -- and a method configureCell:atIndexPath: which updates the contents of a given cell + with information from a managed object at the given index path in the fetched results controller. + */ + +- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller +{ + HPLog(@"%s", __PRETTY_FUNCTION__); + NSAssert(!self.deferredBlocks, @"Recursively changing content"); + self.deferredBlocks = [NSMutableArray array]; + [self.tableView beginUpdates]; +} + +- (void)controller:(NSFetchedResultsController *)controller + didChangeObject:(id)anObject + atIndexPath:(NSIndexPath *)indexPath + forChangeType:(NSFetchedResultsChangeType)type + newIndexPath:(NSIndexPath *)newIndexPath +{ + HPLog(@"%s %@ (%lu) %@ => %@", __PRETTY_FUNCTION__, [anObject class], (unsigned long)type, indexPath, newIndexPath); + if ([anObject isKindOfClass:[HPSpace class]]) { + if (indexPath) { + indexPath = [NSIndexPath indexPathForRow:0 + inSection:indexPath.row]; + } + if (newIndexPath) { + newIndexPath = [NSIndexPath indexPathForRow:0 + inSection:newIndexPath.row]; + } + switch (type) { + case NSFetchedResultsChangeInsert: { + HPPadScopeTableViewDataSource * __weak weakSelf = self; + [self.deferredBlocks addObject:^{ + [weakSelf fetchedResultsControllerForSpace:anObject]; + }]; + [self.tableView insertSections:[NSIndexSet indexSetWithIndex:newIndexPath.section] + withRowAnimation:UITableViewRowAnimationFade]; + return; + } + case NSFetchedResultsChangeDelete: + [self.collectionCounts removeObjectForKey:[anObject objectID]]; + [self.collectionFetchedResultsControllers removeObjectForKey:[anObject objectID]]; + [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] + withRowAnimation:UITableViewRowAnimationFade]; + return; + default: + break; + } + } else { + HPSpace *space = [(HPCollection *)anObject space]; + if (!space) { + space = [anObject changedValuesForCurrentEvent][@"space"]; + if (space.isDeleted) { + HPLog(@"[%@] Ignoring collection change for deleted space.", + space.URL.host); + return; + } + } + NSIndexPath *spaceIndexPath = [self.fetchedResultsController indexPathForObject:space]; + NSAssert(spaceIndexPath, @"[%@] Could not find space index path for collection: %@", + space.URL.host, [anObject title]); + if (indexPath) { + indexPath = [NSIndexPath indexPathForRow:indexPath.row + 1 + inSection:spaceIndexPath.row]; + } + if (newIndexPath) { + newIndexPath = [NSIndexPath indexPathForRow:newIndexPath.row + 1 + inSection:spaceIndexPath.row]; + } + BOOL shown = !![self.shownCollections member:space.objectID]; + switch(type) { + case NSFetchedResultsChangeInsert: + if (!newIndexPath) { + return; + } + self.collectionCounts[space.objectID] = [NSNumber numberWithInteger:[self.collectionCounts[space.objectID] integerValue] + 1]; + if (!shown) { + return; + } + [self.tableView insertRowsAtIndexPaths:@[newIndexPath] + withRowAnimation:UITableViewRowAnimationFade]; + return; + + case NSFetchedResultsChangeDelete: { + if (!indexPath) { + return; + } + self.collectionCounts[space.objectID] = [NSNumber numberWithInteger:[self.collectionCounts[space.objectID] integerValue] - 1]; + if (!shown) { + return; + } + [self.tableView deleteRowsAtIndexPaths:@[indexPath] + withRowAnimation:UITableViewRowAnimationFade]; + return; + } + default: + if (!shown) { + return; + } + break; + } + } + + HPLog(@" => %@ => %@", indexPath, newIndexPath); + + UITableViewCell *cell; + switch (type) { + case NSFetchedResultsChangeMove: + if (indexPath && newIndexPath) { + [self.tableView deleteRowsAtIndexPaths:@[indexPath] + withRowAnimation:UITableViewRowAnimationFade]; + [self.tableView insertRowsAtIndexPaths:@[newIndexPath] + withRowAnimation:UITableViewRowAnimationFade]; + } + break; + case NSFetchedResultsChangeUpdate: + cell = [self.tableView cellForRowAtIndexPath:indexPath]; + if (cell) { + [self configureCell:[self.tableView cellForRowAtIndexPath:indexPath] + atIndexPath:indexPath]; + } + break; + default: + break; + } +} + +- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller +{ + HPLog(@"%s", __PRETTY_FUNCTION__); + [self.tableView endUpdates]; + NSAssert(self.deferredBlocks, @"Not changing content"); + NSArray *blocks = self.deferredBlocks; + self.deferredBlocks = nil; + [blocks enumerateObjectsUsingBlock:^(void (^deferredBlock)(void), NSUInteger idx, BOOL *stop) { + deferredBlock(); + }]; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadScopeViewController.h b/client/ios/Hackpad/Hackpad/HPPadScopeViewController.h new file mode 100644 index 0000000..92ce81a --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadScopeViewController.h @@ -0,0 +1,24 @@ +// +// HPPadSourceViewController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPPadScope; +@class HPPadScopeTableViewDataSource; + +@interface HPPadScopeViewController : UITableViewController + +@property (strong, nonatomic) HPPadScope *padScope; +@property (nonatomic, strong) IBOutlet HPPadScopeTableViewDataSource *dataSource; +@property (nonatomic, strong) IBOutlet UIBarButtonItem *accountsItem; + +- (IBAction)addSpace:(id)sender; +- (IBAction)showHiddenSpaces:(id)sender; +- (IBAction)editAccounts:(id)sender; + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadScopeViewController.m b/client/ios/Hackpad/Hackpad/HPPadScopeViewController.m new file mode 100644 index 0000000..ea04710 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadScopeViewController.m @@ -0,0 +1,264 @@ +// +// HPPadSourceViewController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadScopeViewController.h" + +#import "HPDrawerController.h" +#import "HPPadScopeTableViewDataSource.h" +#import "HPAddSpaceViewController.h" +#import "HPWhiteNavigationController.h" + +#import "HackpadKit/HackpadKit.h" +#import "HackpadAdditions/HackpadAdditions.h" + +#import "Reachability.h" +#import + +@interface HPPadScopeViewController () +@end + +@implementation HPPadScopeViewController + +#pragma mark - UIViewController + +- (void)viewDidLoad +{ + self.tableView.backgroundColor = [UIColor hp_darkGrayColor]; + [super viewDidLoad]; + [self.refreshControl addTarget:self + action:@selector(refresh:) + forControlEvents:UIControlEventValueChanged]; +} + +#pragma mark - Implementation + +- (IBAction)cancel:(id)sender +{ + [self dismissViewControllerAnimated:YES + completion:NULL]; +} + +- (IBAction)refresh:(id)sender +{ + NSUInteger spaces = [self.dataSource numberOfSectionsInTableView:self.tableView]; + NSUInteger __block requests = spaces; + HPPadScopeViewController * __weak weakSelf = self; + for (NSUInteger i = 0; i < spaces; i++) { + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 + inSection:i]; + HPSpace *space = [self.dataSource objectAtIndexPath:indexPath]; + NSAssert([space isKindOfClass:[HPSpace class]], @"Row 0 should always be a space"); + if (!space.API.isSignedIn || !space.API.reachability.currentReachabilityStatus) { + --requests; + continue; + } + [space requestFollowedPadsWithRefresh:YES + completion:^(HPSpace *space, + NSError *error) + { + if (!--requests) { + [weakSelf.refreshControl endRefreshing]; + } + }]; + } + if (!requests) { + [self.refreshControl endRefreshing]; + } +} + +- (IBAction)addSpace:(id)sender +{ + HPAddSpaceViewController *viewController = [[HPAddSpaceViewController alloc] init]; + viewController.delegate = self; + HPWhiteNavigationController *navigationController = [[HPWhiteNavigationController alloc] initWithRootViewController:viewController]; + navigationController.modalPresentationStyle = UIModalPresentationFormSheet; + [self presentViewController:navigationController + animated:YES + completion:nil]; +} + +- (void)setEditing:(BOOL)editing + animated:(BOOL)animated +{ + [super setEditing:editing + animated:animated]; + [self.navigationItem setRightBarButtonItem:editing ? self.editButtonItem : self.accountsItem + animated:animated]; +} + +- (void)editAccounts:(id)sender +{ + [self setEditing:YES + animated:YES]; +} + +- (void)showHiddenSpaces:(id)sender +{ + [self setEditing:YES + animated:YES]; + return; + [self.padScope.coreDataStack saveWithBlock:^(NSManagedObjectContext *localContext) { + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass([HPSpace class])]; + fetch.predicate = [NSPredicate predicateWithFormat:@"hidden == YES"]; + NSError *error = nil; + NSArray *spaces = [localContext executeFetchRequest:fetch error:&error]; + if (!spaces) { + TFLog(@"Error fetching spaces: %@", error); + } + [spaces enumerateObjectsUsingBlock:^(HPSpace *space, NSUInteger idx, BOOL *stop) { + space.hidden = NO; + }]; + } completion:^(NSError *error) { + if (error) { + TFLog(@"Could not show hidden spaces: %@", error); + } + }]; +} + +#pragma mark - Table view delegate + +- (void)tableView:(UITableView *)tableView +didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [tableView deselectRowAtIndexPath:indexPath + animated:YES]; + HPDrawerController *drawer = (HPDrawerController *)self.navigationController.parentViewController; + // Works around sliding label w/ autolayout? + if ([drawer isKindOfClass:[HPDrawerController class]]) { + [drawer.view layoutIfNeeded]; + [drawer setLeftDrawerShown:NO + animated:YES]; + } + id object = [self.dataSource objectAtIndexPath:indexPath]; + if ([object isKindOfClass:[HPSpace class]]) { + if (self.padScope.collection || self.padScope.space != object) { + self.padScope.space = object; + } + } else { + if (self.padScope.collection != object) { + self.padScope.collection = object; + } + } + [self.padScope.space.API signInEvenIfSignedIn:NO]; +} + +- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView + editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (indexPath.row) { + return UITableViewCellEditingStyleDelete; + } + HPSpace *space = [self.dataSource objectAtIndexPath:indexPath]; + return space.userID ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleNone; +} + +- (NSString *)tableView:(UITableView *)tableView +titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return indexPath.row + ? NSLocalizedString(@"Unfollow", nil) + : NSLocalizedString(@"Sign Out", nil); +} + +- (CGFloat)tableView:(UITableView *)tableView +heightForHeaderInSection:(NSInteger)section +{ + return 0; +} + +- (void)tableView:(UITableView *)tableView + willDisplayCell:(UITableViewCell *)cell +forRowAtIndexPath:(NSIndexPath *)indexPath +{ + cell.backgroundColor = indexPath.row ? [UIColor hp_reallyDarkGrayColor] : tableView.backgroundColor; +} + +#pragma mark - HPAddSpaceViewControllerDelegate + +- (void)addSpaceViewController:(HPAddSpaceViewController *)viewController + didFinishWithSpaceName:(NSString *)name +{ + [self dismissViewControllerAnimated:YES + completion:nil]; + if (!name.length) { + return; + } + NSURL *spaceURL; + if ([name hasPrefix:[[NSURL hp_sharedHackpadURL] scheme]]) { + spaceURL = [NSURL URLWithString:name]; + } else if ([name rangeOfString:@"."].location != NSNotFound) { + spaceURL = [[NSURL alloc] initWithScheme:[[NSURL hp_sharedHackpadURL] scheme] + host:name + path:@"/"]; + } else { + spaceURL = [NSURL hp_URLForSubdomain:name + relativeToURL:[NSURL hp_sharedHackpadURL]]; + } + NSManagedObjectID * __block objectID; + HPPadScopeViewController * __weak weakSelf = self; + + [self.padScope.coreDataStack saveWithBlock:^(NSManagedObjectContext *localContext) { + NSError *error = nil; + HPSpace *space = [HPSpace spaceWithURL:spaceURL + inManagedObjectContext:localContext + error:&error]; + if (error) { + return; + } + if (space) { + space.hidden = NO; + } else { + space = [HPSpace insertSpaceWithURL:spaceURL + name:nil + managedObjectContext:localContext]; + if (![localContext obtainPermanentIDsForObjects:@[space] + error:&error]) { + TFLog(@"Error obtaining permanent IDs: %@", error); + return; + } + } + objectID = space.objectID; + } completion:^(NSError *error) { + if (error) { + TFLog(@"[%@] Could not add space: %@", spaceURL.host, error); + return; + } + if (!objectID) { + return; + } + if (!weakSelf) { + return; + } + HPSpace *space = (HPSpace *)[self.padScope.coreDataStack.mainContext existingObjectWithID:objectID + error:&error]; + if (!space) { + TFLog(@"[%@] Could not look up space: %@", spaceURL.host, error); + return; + } + [NSURL hp_addHackpadURL:space.URL]; + [space.API signInEvenIfSignedIn:NO]; + weakSelf.padScope.space = space; + }]; +} + +- (void)addSpaceViewControllerDidCancel:(HPAddSpaceViewController *)viewController +{ + [self dismissViewControllerAnimated:YES + completion:nil]; +} + +- (BOOL)addSpaceViewControllerCanCancel:(HPAddSpaceViewController *)viewController +{ + NSManagedObjectContext *context = self.padScope.coreDataStack.mainContext; + NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:HPSpaceEntity]; + NSError *error = nil; + NSUInteger count = [context countForFetchRequest:fetchRequest error:&error]; + return count > 0 || error != nil; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadSearchTableViewDataSource.h b/client/ios/Hackpad/Hackpad/HPPadSearchTableViewDataSource.h new file mode 100644 index 0000000..a4c78e9 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadSearchTableViewDataSource.h @@ -0,0 +1,21 @@ +// +// HPPadSearchTableViewDataSource.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPPad; +@class HPPadScope; + +@interface HPPadSearchTableViewDataSource : NSObject +@property (nonatomic, weak) IBOutlet UITableView *tableView; +@property (nonatomic, weak) IBOutlet UITableView *prototypeTableView; +@property (nonatomic, strong) HPPadScope *padScope; +@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext; +@property (nonatomic, copy) NSString *searchText; +- (HPPad *)padAtIndexPath:(NSIndexPath *)indexPath; +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadSearchTableViewDataSource.m b/client/ios/Hackpad/Hackpad/HPPadSearchTableViewDataSource.m new file mode 100644 index 0000000..46b1869 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadSearchTableViewDataSource.m @@ -0,0 +1,319 @@ +// +// HPPadSearchTableViewDataSource.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadSearchTableViewDataSource.h" + +#import "HPSearchResultsController.h" + +#import +#import +#import +#import + +static NSString *PadIDKey = @"padID"; + +static NSUInteger const MaxLengthOfKeywordRange = 40; + +@interface HPPadSearchTableViewDataSource () { + id _padScopeObserver; + id _signInObserver; + NSMutableDictionary *_snippets; + HPSpace *_space; + NSUInteger _generation; +} +@property (nonatomic, strong) HPSearchResultsController *searchResultsController; +@end + +@implementation HPPadSearchTableViewDataSource + +- (id)init +{ + self = [super init]; + if (self) { + _snippets = [NSMutableDictionary dictionary]; + HPPadSearchTableViewDataSource * __weak weakSelf = self; + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + _padScopeObserver = [center addObserverForName:HPPadScopeDidChangeNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + if (note.object == weakSelf.padScope) { + [weakSelf reloadTable]; + } + }]; + _signInObserver = [center addObserverForName:HPAPIDidSignInNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + if (note.object == weakSelf.padScope.space.API) { + [weakSelf reloadTable]; + } + }]; + } + return self; +} + +- (void)dealloc +{ + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + if (_padScopeObserver) { + [center removeObserver:_padScopeObserver]; + } + if (_signInObserver) { + [center removeObserver:_signInObserver]; + } + _searchResultsController.delegate = nil; +} + +#pragma mark - Implementation + +- (void)reloadTable +{ + self.searchResultsController.delegate = nil; + self.searchResultsController = nil; + if (self.searchText) { + self.searchText = self.searchText; + } +} + +- (HPSearchResultsController *)searchResultsController +{ + if (!self.padScope.space || !self.searchText.length) { + return nil; + } + if (_searchResultsController) { + return _searchResultsController; + } + + NSError * __autoreleasing error; + _space = (HPSpace *)[self.managedObjectContext existingObjectWithID:self.padScope.space.objectID + error:&error]; + if (!_space) { + TFLog(@"[%@] Could not fetch space: %@", self.padScope.space.URL.host, error); + } + + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPPadEntity]; + fetch.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"lastEditedDate" + ascending:NO]]; + _searchResultsController = [[HPSearchResultsController alloc] initWithFetchRequest:fetch + managedObjectContext:self.managedObjectContext + sectionNameKeyPath:nil + cacheName:nil]; + _searchResultsController.baseSearchPredicate = self.padScope.collection + ? [NSPredicate predicateWithFormat:@"ANY collections == %@", self.padScope.collection.objectID] + : [NSPredicate predicateWithFormat:@"space == %@", self.padScope.space.objectID]; + + _searchResultsController.delegate = self; + return _searchResultsController; +} + +- (HPPad *)padAtIndexPath:(NSIndexPath *)indexPath +{ + return [_searchResultsController objectAtIndexPath:indexPath]; +} + +- (void)configureCell:(UITableViewCell *)cell + atIndexPath:(NSIndexPath *)indexPath +{ + HPPad *pad = [self padAtIndexPath:indexPath]; + cell.textLabel.font = [UIFont hp_padTitleFontOfSize:cell.textLabel.font.pointSize]; + cell.textLabel.text = pad.title; + id snippet = _snippets[pad.padID]; + if (!snippet && (!self.searchText.length || !pad.search.content)) { + cell.detailTextLabel.text = nil; + return; + } + if ([snippet isKindOfClass:[NSAttributedString class]]) { + cell.detailTextLabel.attributedText = snippet; + return; + } + const CGFloat fontSize = 13; + UIFont *regularFont = [UIFont hp_padTextFontOfSize:fontSize]; + UIFont *highlightingFont = [UIFont hp_UITextFontOfSize:fontSize]; + if (snippet) { + snippet = [NSAttributedString attributedStringFromHTML:snippet + boldFont:highlightingFont + regularFont:regularFont]; + } else { + snippet = [NSAttributedString hp_initWithString:pad.search.content + attributes:@{NSFontAttributeName:regularFont} + highlightingKeywords:self.searchText + highlightingAttributes:@{NSFontAttributeName:highlightingFont} + maxLengthOfKeywordRange:MaxLengthOfKeywordRange]; + } + if (snippet ) { + _snippets[pad.padID] = snippet; + } + cell.detailTextLabel.attributedText = snippet; +} + +- (void)setSearchText:(NSString *)searchText +{ + _searchText = [searchText copy]; + [_snippets removeAllObjects]; + if (!searchText.length) { + self.searchResultsController.delegate = nil; + self.searchResultsController = nil; + [self.tableView reloadData]; + return; + } + [self.searchResultsController setSearchText:searchText + variable:@"search.content"]; + + NSInteger myGeneration = ++_generation; + + if (!_space.API.reachability.currentReachabilityStatus) { + self.searchResultsController.searchResultsPredicate = nil; + return; + } + + [_space requestPadsMatchingText:searchText + refresh:NO + completion:^(HPSpace *space, + NSArray *pads, + NSDictionary *serverSnippets, + NSError *error) + { + if (_generation != myGeneration) { + return; + } + if (error) { + TFLog(@"[%@] Could not search: %@", space.URL.host, error); + } + [serverSnippets enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + if (!_snippets[key]) { + _snippets[key] = obj; + } + }]; + HPLog(@"[%@] Found %lu search results; updating predicate", + space.URL.host, (unsigned long)pads.count); + self.searchResultsController.searchResultsPredicate = pads.count + ? [NSPredicate predicateWithFormat:@"SELF IN %@", pads] + : nil; + }]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return self.searchResultsController.sections.count; +} + +- (NSInteger)tableView:(UITableView *)tableView + numberOfRowsInSection:(NSInteger)section +{ + id sectionInfo; + sectionInfo = self.searchResultsController.sections[section]; + return [sectionInfo numberOfObjects]; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView + cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString * const SearchCellIdentifier = @"SearchCell"; + UITableViewCell *cell; + cell = [tableView dequeueReusableCellWithIdentifier:SearchCellIdentifier]; + if (!cell) { + if (self.prototypeTableView) { + cell = [self.prototypeTableView dequeueReusableCellWithIdentifier:SearchCellIdentifier]; + } else { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle + reuseIdentifier:SearchCellIdentifier]; + } + } + [self configureCell:cell + atIndexPath:indexPath]; + return cell; +} + +#pragma mark - Fetched results delegate + +- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller +{ + //HPLog(@"%s", __PRETTY_FUNCTION__); + [self.tableView beginUpdates]; +} + + +- (void)controller:(NSFetchedResultsController *)controller + didChangeSection:(id )sectionInfo + atIndex:(NSUInteger)sectionIndex + forChangeType:(NSFetchedResultsChangeType)type +{ + //HPLog(@"%s", __PRETTY_FUNCTION__); + switch(type) { + case NSFetchedResultsChangeInsert: + [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] + withRowAnimation:UITableViewRowAnimationFade]; + break; + + case NSFetchedResultsChangeDelete: + [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] + withRowAnimation:UITableViewRowAnimationFade]; + break; + } +} + + +- (void)controller:(NSFetchedResultsController *)controller + didChangeObject:(id)anObject + atIndexPath:(NSIndexPath *)indexPath + forChangeType:(NSFetchedResultsChangeType)type + newIndexPath:(NSIndexPath *)newIndexPath +{ + //HPLog(@"%s %@ (%lu) %@ => %@", __PRETTY_FUNCTION__, [anObject class], (unsigned long)type, indexPath, newIndexPath); + UITableViewCell *cell; + switch(type) { + case NSFetchedResultsChangeInsert: + [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] + withRowAnimation:UITableViewRowAnimationFade]; + break; + + case NSFetchedResultsChangeDelete: + [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] + withRowAnimation:UITableViewRowAnimationFade]; + break; + + case NSFetchedResultsChangeMove: + [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] + withRowAnimation:UITableViewRowAnimationFade]; + [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] + withRowAnimation:UITableViewRowAnimationFade]; + break; + case NSFetchedResultsChangeUpdate: + cell = [self.tableView cellForRowAtIndexPath:indexPath]; + if (cell) { + [self configureCell:cell + atIndexPath:indexPath]; + } + break; + } +} + +- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller +{ + //HPLog(@"%s", __PRETTY_FUNCTION__); + [self.tableView endUpdates]; +} + +#pragma mark - Search results controller delegte + +- (void)controllerDidChangePredicate:(HPSearchResultsController *)controller +{ + //HPLog(@"Search predicate: %@", self.searchResultsController.fetchRequest.predicate); + NSError * __autoreleasing error; + if (![self.searchResultsController performFetch:&error]) { + TFLog(@"Could not perform search: %@", error); + } + [self.tableView reloadData]; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadSharingViewController.h b/client/ios/Hackpad/Hackpad/HPPadSharingViewController.h new file mode 100644 index 0000000..cdbd822 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadSharingViewController.h @@ -0,0 +1,44 @@ +// +// HPPadSharingViewController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPSharingOptions; +@class HPUserInfoCollection; + +@protocol HPPadSharingViewControllerDelegate; + +@interface HPPadSharingViewController : UITableViewController + +@property (nonatomic, strong) HPSharingOptions *sharingOptions; + +@property (nonatomic, strong) IBOutlet UITableViewCell *linkCell; +@property (nonatomic, strong) IBOutlet UITableViewCell *denyCell; +@property (nonatomic, strong) IBOutlet UITableViewCell *allowCell; +@property (nonatomic, strong) IBOutlet UITableViewCell *domainCell; +@property (nonatomic, strong) IBOutlet UITableViewCell *anonymousCell; +@property (nonatomic, strong) IBOutlet UITableViewCell *friendsCell; +@property (nonatomic, strong) IBOutlet UITableViewCell *askCell; + +@property (nonatomic, weak) IBOutlet UITableViewCell *moderateCell; +@property (nonatomic, weak) IBOutlet UISwitch *moderateSwitch; + +@property (nonatomic, strong) IBOutlet UIBarButtonItem *doneItem; +@property (nonatomic, strong) HPUserInfoCollection *userInfos; + +@property (nonatomic, assign) id delegate; + +- (IBAction)toggleModerated:(id)sender; +- (IBAction)share:(id)sender; +- (IBAction)done:(id)sender; +@end + +@protocol HPPadSharingViewControllerDelegate +@optional +- (void)padSharingViewControllerDidFinish:(HPPadSharingViewController *)padSharingViewController; +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadSharingViewController.m b/client/ios/Hackpad/Hackpad/HPPadSharingViewController.m new file mode 100644 index 0000000..849fb54 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadSharingViewController.m @@ -0,0 +1,410 @@ +// +// HPPadSharingViewController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadSharingViewController.h" + +#import "HackpadKit/HackpadKit.h" +#import "HackpadAdditions/HackpadAdditions.h" + +#import "HPInvitationController.h" +#import "HPUserInfoImageView.h" +#import "HPUserInfoCell.h" + +#import +#import + +enum { + PeopleSection, + SharingTypeSection, + SwitchSection, + + SectionCount +}; + +enum { + LabelTag = 1, + DetailLabelTag, + ImageTag +}; + +@interface HPPadSharingViewController () +@property (nonatomic, strong) HPInvitationController *invitationController; +@property (nonatomic, strong) HPUserInfo *actionInfo; +@property (nonatomic, strong) NSMutableArray *cells; +@property (nonatomic, strong) id changeObserver; +@property (nonatomic, strong) id addObserver; +@property (nonatomic, strong) id removeObserver; +@property (nonatomic, assign) BOOL refreshing; +@property (nonatomic, assign) BOOL enabled; +@property (nonatomic, assign) BOOL configuredSharingOptions; +@end + +@implementation HPPadSharingViewController + +#pragma mark - Object + +- (void)dealloc +{ + if (_changeObserver) { + [[NSNotificationCenter defaultCenter] removeObserver:_changeObserver]; + } + if (_addObserver) { + [[NSNotificationCenter defaultCenter] removeObserver:_addObserver]; + } + if (_removeObserver) { + [[NSNotificationCenter defaultCenter] removeObserver:_removeObserver]; + } + [[NSNotificationCenter defaultCenter] removeObserver:self + name:kReachabilityChangedNotification + object:nil]; +} + +#pragma mark - View controller + +- (void)viewDidLoad +{ + [super viewDidLoad]; + HPPadSharingViewController * __weak weakSelf = self; + _changeObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSManagedObjectContextDidSaveNotification + object:nil + queue:nil + usingBlock:^(NSNotification *note) + { + if ([note.object concurrencyType] != NSMainQueueConcurrencyType) { + return; + } + if (!weakSelf.sharingOptions) { + return; + } + if (note.object != weakSelf.sharingOptions.managedObjectContext) { + return; + } + if (![note.userInfo[NSUpdatedObjectsKey] member:weakSelf.sharingOptions]) { + return; + } + [weakSelf configureView]; + }]; + _addObserver = [[NSNotificationCenter defaultCenter] addObserverForName:HPUserInfoCollectionDidAddUserInfoNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + if (note.object != weakSelf.userInfos) { + return; + } + NSUInteger row = [note.userInfo[HPUserInfoCollectionUserInfoIndexKey] unsignedIntegerValue]; + [weakSelf.tableView beginUpdates]; + [weakSelf.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row + inSection:PeopleSection]] + withRowAnimation:UITableViewRowAnimationAutomatic]; + [weakSelf.tableView endUpdates]; + }]; + _removeObserver = [[NSNotificationCenter defaultCenter] addObserverForName:HPUserInfoCollectionDidRemoveUserInfoNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + if (note.object != weakSelf.userInfos) { + return; + } + NSUInteger row = [note.userInfo[HPUserInfoCollectionUserInfoIndexKey] unsignedIntegerValue]; + [weakSelf.tableView beginUpdates]; + [weakSelf.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row + inSection:PeopleSection]] + withRowAnimation:UITableViewRowAnimationAutomatic]; + [weakSelf.tableView endUpdates]; + }]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(reachabilityDidChangeWithNotification:) + name:kReachabilityChangedNotification + object:nil]; + [@[self.linkCell, self.denyCell, self.allowCell, self.domainCell, self.anonymousCell, self.friendsCell, self.askCell, self.moderateCell] enumerateObjectsUsingBlock:^(UITableViewCell *cell, NSUInteger idx, BOOL *stop) { + cell.textLabel.font = [UIFont hp_UITextFontOfSize:cell.textLabel.font.pointSize]; + }]; + [self configureView]; + [self refresh:self]; +} + +- (UITableViewCell *)cellWithSharingType:(HPSharingType)sharingType +{ + NSUInteger i = [self rowWithSharingType:sharingType]; + return i == NSNotFound ? nil : _cells[i]; +} + +- (NSUInteger)rowWithSharingType:(HPSharingType)sharingType +{ + return [_cells indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) { + return [obj tag] == sharingType; + }]; +} + +- (void)maybeAddCell:(UITableViewCell *)cell + sharingType:(HPSharingType)sharingType +{ + if (self.sharingOptions.allowedSharingTypes & sharingType) { + [_cells addObject:cell]; + cell.tag = sharingType; + cell.accessoryType = sharingType == self.sharingOptions.sharingType + ? UITableViewCellAccessoryCheckmark + : UITableViewCellAccessoryNone; + } +} + +- (void)setEnabled:(BOOL)enabled +{ + _enabled = enabled; + self.moderateSwitch.enabled = enabled; + self.editButtonItem.enabled = enabled; + self.searchDisplayController.searchBar.userInteractionEnabled = enabled; + self.searchDisplayController.searchBar.alpha = enabled ? 1 : .7; + if (enabled) { + return; + } + [self setEditing:NO + animated:YES]; +} + +- (void)configureView +{ + HPPad *pad = self.sharingOptions.pad; + self.enabled = pad.padID && pad.space.API.reachability.currentReachabilityStatus; + + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + self.navigationItem.title = self.sharingOptions.pad.title; + } + + [self.moderateSwitch setOn:self.sharingOptions.moderated + animated:YES]; + + if (!self.sharingOptions.space.URL.hp_isToplevelHackpadURL) { + self.linkCell.textLabel.text = [NSString stringWithFormat:@"Anyone at %@", self.sharingOptions.space.name]; + self.domainCell.textLabel.text = [NSString stringWithFormat:@"Everyone at %@", self.sharingOptions.space.name]; + if (self.sharingOptions.space.public) { + self.allowCell.textLabel.text = @"Everyone (public)"; + } else if (self.sharingOptions.collection) { + self.allowCell.textLabel.text = [NSString stringWithFormat:@"Everyone at %@", self.sharingOptions.space.name]; + } else { + self.allowCell.textLabel.text = @"Everyone (readonly)"; + } + } + + _cells = [NSMutableArray arrayWithCapacity:7]; + + [self maybeAddCell:self.denyCell + sharingType:HPDenySharingType]; + [self maybeAddCell:self.linkCell + sharingType:HPLinkSharingType]; + [self maybeAddCell:self.domainCell + sharingType:HPDomainSharingType]; + [self maybeAddCell:self.allowCell + sharingType:HPAllowSharingType]; + [self maybeAddCell:self.anonymousCell + sharingType:HPAnonymousSharingType]; + [self maybeAddCell:self.friendsCell + sharingType:HPFriendsSharingType]; + [self maybeAddCell:self.askCell + sharingType:HPAskSharingType]; + + BOOL reload = !self.configuredSharingOptions; + self.configuredSharingOptions = !!self.sharingOptions; + if (reload) { + [self.tableView reloadData]; + } else if (self.sharingOptions.pad.isCreator) { + [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:SharingTypeSection] + withRowAnimation:UITableViewRowAnimationNone]; + } +} + +- (void)reachabilityDidChangeWithNotification:(NSNotification *)note +{ + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + if (note.object != self.sharingOptions.pad.space.API.reachability) { + return; + } + [self configureView]; + }]; +} + +- (void)setSharingOptions:(HPSharingOptions *)sharingOptions +{ + _sharingOptions = sharingOptions; + [(HPInvitationController *)self.searchDisplayController.delegate setPad:sharingOptions.pad]; + if (self.isViewLoaded) { + [self configureView]; + [self refresh:self]; + } +} + +- (void)refresh:(id)sender +{ + if (_refreshing) { + return; + } + if (!self.sharingOptions) { + return; + } + _refreshing = YES; + [self.sharingOptions refreshWithCompletion:^(HPSharingOptions *sharingOptions, + NSError *error) + { + _refreshing = NO; + }]; +} + +- (void)setEditing:(BOOL)editing + animated:(BOOL)animated +{ + [super setEditing:editing + animated:animated]; + [self.navigationItem setRightBarButtonItem:editing ? nil : self.doneItem + animated:animated]; +} + +- (void)done:(id)sender +{ + if ([self.delegate respondsToSelector:@selector(padSharingViewControllerDidFinish:)]) { + [self.delegate padSharingViewControllerDidFinish:self]; + } +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return self.sharingOptions.pad.isCreator ? SectionCount : 1; +} + +- (NSInteger)tableView:(UITableView *)tableView + numberOfRowsInSection:(NSInteger)section +{ + switch (section) { + case SharingTypeSection: + return _cells.count; + + case SwitchSection: + return 1; + + case PeopleSection: + return self.userInfos.userInfos.count; + + } + return 0; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView + cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + switch (indexPath.section) { + case SharingTypeSection: + return _cells[indexPath.row]; + + case SwitchSection: + return self.moderateCell; + } + + static NSString *CellIdentifier = @"PeopleCell"; + HPUserInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier + forIndexPath:indexPath]; + if (cell.userInfo) { + cell.userInfo = nil; + } + HPUserInfo *userInfo = self.userInfos.userInfos[indexPath.row]; + [cell setUserInfo:userInfo + animated:!userInfo.userPicURL]; + + return cell; +} + +- (void)tableView:(UITableView *)tableView +commitEditingStyle:(UITableViewCellEditingStyle)editingStyle +forRowAtIndexPath:(NSIndexPath *)indexPath +{ + NSParameterAssert(editingStyle == UITableViewCellEditingStyleDelete); + HPPadSharingViewController * __weak weakSelf = self; + + HPUserInfo *userInfo = self.userInfos.userInfos[indexPath.row]; + [self.sharingOptions.pad removeUserWithId:userInfo.userID + completion:^(HPPad *pad, NSError *error) + { + if (error) { + [[[UIAlertView alloc] initWithTitle:@"Request Failed" + message:error.localizedDescription + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; + return; + } + [weakSelf.userInfos removeUserInfo:userInfo]; + }]; +} + +- (NSString *)tableView:(UITableView *)tableView +titleForHeaderInSection:(NSInteger)section +{ + switch (section) { + case PeopleSection: + return @"Shared With"; + + case SharingTypeSection: + return @"Open To"; + + default: + return nil; + } +} + +#pragma mark - Table view delegate + +- (BOOL)tableView:(UITableView *)tableView +shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath +{ + return self.enabled && indexPath.section == SharingTypeSection; +} + +- (BOOL)tableView:(UITableView *)tableView +canEditRowAtIndexPath:(NSIndexPath *)indexPath +{ + return self.enabled && indexPath.section == PeopleSection; +} + +- (void)tableView:(UITableView *)tableView +didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [tableView deselectRowAtIndexPath:indexPath + animated:YES]; + if (!self.enabled || indexPath.section != SharingTypeSection) { + return; + } + [self.sharingOptions setSharingType:(HPSharingType)[_cells[indexPath.row] tag] + completion:nil]; +} + +- (NSString *)tableView:(UITableView *)tableView +titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return @"Remove"; +} + +#pragma mark - UI actions + +- (IBAction)toggleModerated:(id)sender +{ + [self.sharingOptions setModerated:[(UISwitch *)sender isOn] + completion:nil]; +} + +- (IBAction)share:(id)sender +{ + UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[self.sharingOptions.pad.URL] + applicationActivities:nil]; + [self presentViewController:controller + animated:YES + completion:nil]; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadSplitViewController.h b/client/ios/Hackpad/Hackpad/HPPadSplitViewController.h new file mode 100644 index 0000000..7e457bb --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadSplitViewController.h @@ -0,0 +1,16 @@ +// +// HPPadViewController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPPadListViewController; + +@interface HPPadSplitViewController : UISplitViewController +@property (nonatomic, strong) UIBarButtonItem *padListItem; +@property (nonatomic, weak) IBOutlet HPPadListViewController *padListViewController; +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadSplitViewController.m b/client/ios/Hackpad/Hackpad/HPPadSplitViewController.m new file mode 100644 index 0000000..c71a3c6 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadSplitViewController.m @@ -0,0 +1,132 @@ +// +// HPPadViewController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadSplitViewController.h" + +#import + +#import "HPDrawerController.h" +#import "HPPadListViewController.h" + +static NSInteger const PadListItemTag = 0x3000; + +@implementation HPPadSplitViewController + +#pragma mark - private methods + +- (UINavigationController *)editorsController +{ + return (UINavigationController *)self.viewControllers[1]; +} + +- (void)updateLeftBarButtonItemsWithViewController:(UIViewController *)viewController + animated:(BOOL)animated +{ + UINavigationItem *navigationItem = viewController.navigationItem; + NSUInteger i = navigationItem.leftBarButtonItems + ? [navigationItem.leftBarButtonItems indexOfObjectPassingTest:^BOOL(UIBarButtonItem *item, + NSUInteger idx, + BOOL *stop) + { + return item.tag == PadListItemTag ? (*stop = YES) : NO; + }] + : NSNotFound; + + NSMutableArray *items; + if (i == NSNotFound && self.padListItem) { + items = [NSMutableArray arrayWithObject:self.padListItem]; + if (navigationItem.leftBarButtonItems) { + [items addObjectsFromArray:navigationItem.leftBarButtonItems]; + } + } else if (i != NSNotFound && !self.padListItem) { + items = [navigationItem.leftBarButtonItems mutableCopy]; + [items removeObjectAtIndex:i]; + } else { + return; + } + [navigationItem setLeftBarButtonItems:items + animated:animated]; +} + +- (void)updateLeftBarButtonItems +{ + [self updateLeftBarButtonItemsWithViewController:self.editorsController.topViewController + animated:YES]; +} + +#pragma mark - UIViewController implementation + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + if (self.padListItem) { + [self updateLeftBarButtonItems]; + } +} + +#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleDefault; +} +#endif + +#pragma mark - Split view delegate + +- (void)splitViewController:(UISplitViewController *)splitController + willHideViewController:(UIViewController *)viewController + withBarButtonItem:(UIBarButtonItem *)barButtonItem + forPopoverController:(UIPopoverController *)popoverController +{ + static NSString * const MenuImageName = @"menu"; + barButtonItem.tag = PadListItemTag; + self.padListItem = barButtonItem; + barButtonItem.image = [UIImage imageNamed:MenuImageName]; + [self updateLeftBarButtonItems]; + self.padListViewController.masterPopoverController = popoverController; +} + +- (void)splitViewController:(UISplitViewController *)splitController + willShowViewController:(UIViewController *)viewController + invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem +{ + if (barButtonItem == self.padListItem) { + self.padListItem = nil; + [self updateLeftBarButtonItems]; + self.padListViewController.masterPopoverController = nil; + } +} + +#if 0 +- (BOOL)splitViewController:(UISplitViewController *)svc + shouldHideViewController:(UIViewController *)vc + inOrientation:(UIInterfaceOrientation)orientation +{ + return YES; +} +#endif + +- (void)splitViewController:(UISplitViewController *)svc + popoverController:(UIPopoverController *)pc + willPresentViewController:(UIViewController *)aViewController +{ + [(HPDrawerController *)aViewController setLeftDrawerShown:NO]; +} + +#pragma mark - Navigation controller delegate + +- (void)navigationController:(UINavigationController *)navigationController + willShowViewController:(UIViewController *)viewController + animated:(BOOL)animated +{ + [self updateLeftBarButtonItemsWithViewController:viewController + animated:animated]; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadTableViewDataSource.h b/client/ios/Hackpad/Hackpad/HPPadTableViewDataSource.h new file mode 100644 index 0000000..ad4366d --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadTableViewDataSource.h @@ -0,0 +1,21 @@ +// +// HPPadTableViewDataSource.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import + +@class HPPad; +@class HPPadScope; + +@interface HPPadTableViewDataSource : NSObject +@property (nonatomic, weak) IBOutlet UITableView *tableView; +@property (nonatomic, strong) HPPadScope *padScope; +@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext; +- (HPPad *)padAtIndexPath:(NSIndexPath *)indexPath; +- (NSIndexPath *)indexPathForPad:(HPPad *)pad; +@end diff --git a/client/ios/Hackpad/Hackpad/HPPadTableViewDataSource.m b/client/ios/Hackpad/Hackpad/HPPadTableViewDataSource.m new file mode 100644 index 0000000..d2ce9eb --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPadTableViewDataSource.m @@ -0,0 +1,358 @@ +// +// HPPadTableViewDataSource.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadTableViewDataSource.h" + +#import "HPActionSheetBlockDelegate.h" +#import "HPPadCell.h" + +#import +#import +#import + +static NSString * const CellID = @"PadCell"; + +@interface HPPadTableViewDataSource () { + id selectedObject; + id padScopeObserver; +} +@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController; +@property (nonatomic, strong) id fetchedObject; +@property (nonatomic, assign, getter = isUpdating) BOOL updating; +@end + +@implementation HPPadTableViewDataSource + +- (id)init +{ + self = [super init]; + if (!self) { + return self; + } + HPPadTableViewDataSource * __weak weakSelf = self; + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + padScopeObserver = [center addObserverForName:HPPadScopeDidChangeNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + if (note.object != weakSelf.padScope) { + return; + } + [weakSelf performSelector:@selector(reloadTable) + withObject:nil + afterDelay:0]; + }]; + return self; +} + +- (void)dealloc +{ + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + if (padScopeObserver) { + [center removeObserver:padScopeObserver]; + } + _fetchedResultsController.delegate = nil; +} + +- (void)setTableView:(UITableView *)tableView +{ + _tableView = tableView; + UINib *nib = [UINib nibWithNibName:CellID + bundle:nil]; + [tableView registerNib:nib + forCellReuseIdentifier:CellID]; +} + +- (void)reloadTable +{ + if ((self.padScope.collection && [self.padScope.collection isEqual:self.fetchedObject]) || + (!self.padScope.collection && [self.padScope.space isEqual:self.fetchedObject])) { + return; + } + + // reloadData abandons editing, but tries to reset the editing cell first, + // calling tableView:canEditRowAtIndexPath: with an indexPath that no longer + // exists. so do that before resetting the FRC. + self.tableView.editing = NO; + _fetchedResultsController.delegate = nil; + self.fetchedResultsController = nil; + [self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) + animated:NO]; + [self.tableView reloadData]; +} + +- (NSFetchedResultsController *)fetchedResultsController +{ + if (_fetchedResultsController) { + return _fetchedResultsController; + } + if (!self.padScope.space) { + return nil; + } + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPPadEntity]; + fetch.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"lastEditedDate" + ascending:NO]]; + fetch.shouldRefreshRefetchedObjects = YES; + if (self.padScope.collection) { + self.fetchedObject = self.padScope.collection; + fetch.predicate = [NSPredicate predicateWithFormat:@"ANY collections == %@", self.padScope.collection]; + } else { + self.fetchedObject = self.padScope.space; + fetch.predicate = [NSPredicate predicateWithFormat:@"space == %@ && followed == YES", self.padScope.space]; + } + fetch.fetchBatchSize = 12; + _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetch + managedObjectContext:self.managedObjectContext + sectionNameKeyPath:nil + cacheName:nil]; + _fetchedResultsController.delegate = self; + NSError * __autoreleasing error; + if (![_fetchedResultsController performFetch:&error]) { + TFLog(@"[%@] Couldn't perform fetch: %@", self.padScope.space.URL.host, error); + } + return _fetchedResultsController; +} + +- (HPPad *)padAtIndexPath:(NSIndexPath *)indexPath +{ + return [self.fetchedResultsController objectAtIndexPath:indexPath]; +} + +- (NSIndexPath *)indexPathForPad:(HPPad *)pad +{ + return [self.fetchedResultsController indexPathForObject:pad]; +} + +- (void)configureCell:(UITableViewCell *)cell + atIndexPath:(NSIndexPath *)indexPath +{ + NSParameterAssert([cell isKindOfClass:[HPPadCell class]]); + HPPadCell *padCell = (HPPadCell *)cell; + HPPad *pad = [self padAtIndexPath:indexPath]; + UITableView * __weak tableView = self.tableView; + [padCell setPad:pad + animated:^BOOL{ + return !tableView.decelerating; + }]; + padCell.moreButton.hidden = pad.snippetHeight >= pad.expandedSnippetHeight; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return self.fetchedResultsController.sections.count; +} + +- (NSInteger)tableView:(UITableView *)tableView + numberOfRowsInSection:(NSInteger)section +{ + id sectionInfo; + sectionInfo = self.fetchedResultsController.sections[section]; + return [sectionInfo numberOfObjects]; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView + cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell; + cell = [self.tableView dequeueReusableCellWithIdentifier:CellID + forIndexPath:indexPath]; + [self configureCell:cell + atIndexPath:indexPath]; + return cell; +} + +- (BOOL)tableView:(UITableView *)tableView +canEditRowAtIndexPath:(NSIndexPath *)indexPath +{ + return YES; +} + +- (void)tableView:(UITableView *)tableView +commitEditingStyle:(UITableViewCellEditingStyle)editingStyle +forRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (editingStyle != UITableViewCellEditingStyleDelete) { + return; + } + HPPad *pad = [self padAtIndexPath:indexPath]; + if (pad.hasMissedChanges) { + [self confirmAndAbandonMissedChangesWithPad:pad]; + } else { + [self confirmAndDeleteOrUnfollowPad:pad]; + } +} + +- (void)confirmAndAbandonMissedChangesWithPad:(HPPad *)pad +{ + HPPadTableViewDataSource * __weak weakSelf = self; + HPActionSheetBlockDelegate *delegate = [[HPActionSheetBlockDelegate alloc] initWithBlock:^(UIActionSheet *actionSheet, NSInteger button) { + if (button == actionSheet.cancelButtonIndex) { + return; + } + [pad discardMissedChangesWithCompletion:^(HPPad *pad, NSError *error) { + NSIndexPath *indexPath = [weakSelf.fetchedResultsController indexPathForObject:pad]; + if (!indexPath) { + return; + } + [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] + withRowAnimation:UITableViewRowAnimationAutomatic]; + }]; + }]; + [[[UIActionSheet alloc] initWithTitle:@"Your unsaved changes will be lost. This cannot be undone." + delegate:delegate + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Discard Changes" + otherButtonTitles:nil] showInView:self.tableView]; +} + +- (void)confirmAndDeleteOrUnfollowPad:(HPPad *)pad +{ + void (^delegateBlock)(UIActionSheet *, NSInteger) = ^(UIActionSheet *actionSheet, + NSInteger buttonIndex) { + if (buttonIndex == actionSheet.firstOtherButtonIndex) { + [pad setFollowed:NO + completion:^(HPPad *pad, NSError *error) + { + if (error) { + [[[UIAlertView alloc] initWithTitle:@"Unfollowing Error" + message:[NSString stringWithFormat:@"The pad could not be unfollowed: %@", error.localizedDescription] + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; + } + }]; + } else if (buttonIndex != actionSheet.cancelButtonIndex) { + [pad deleteWithCompletion:^(HPPad *pad, NSError *error) { + if (error) { + [[[UIAlertView alloc] initWithTitle:@"Oops" + message:[NSString stringWithFormat:@"The pad could not be deleted: %@", error.localizedDescription] + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; + } + }]; + } + }; + [[[UIActionSheet alloc] initWithTitle:nil + delegate:[[HPActionSheetBlockDelegate alloc] initWithBlock:delegateBlock] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Delete" + otherButtonTitles:@"Unfollow", nil] showInView:self.tableView.superview]; +} + +#pragma mark - Fetched results delegate + +- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller +{ + //HPLog(@"%s", __PRETTY_FUNCTION__); + NSIndexPath *indexPath = self.tableView.indexPathForSelectedRow; + if (indexPath) { + selectedObject = [controller objectAtIndexPath:indexPath]; + } +// [self.tableView beginUpdates]; +} + +- (void)setUpdating:(BOOL)updating +{ + if (_updating == updating) { + return; + } + _updating = updating; + if (updating) { + [self.tableView beginUpdates]; + } else { + [self.tableView endUpdates]; + } +} + +- (void)controller:(NSFetchedResultsController *)controller + didChangeSection:(id )sectionInfo + atIndex:(NSUInteger)sectionIndex + forChangeType:(NSFetchedResultsChangeType)type +{ + //HPLog(@"%s", __PRETTY_FUNCTION__); + switch(type) { + case NSFetchedResultsChangeInsert: + self.updating = YES; + [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] + withRowAnimation:UITableViewRowAnimationFade]; + break; + + case NSFetchedResultsChangeDelete: + self.updating = YES; + [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] + withRowAnimation:UITableViewRowAnimationFade]; + break; + } +} + + +- (void)controller:(NSFetchedResultsController *)controller + didChangeObject:(id)anObject + atIndexPath:(NSIndexPath *)indexPath + forChangeType:(NSFetchedResultsChangeType)type + newIndexPath:(NSIndexPath *)newIndexPath +{ + //HPLog(@"%s %@ (%lu) %@ => %@", __PRETTY_FUNCTION__, [anObject class], (unsigned long)type, indexPath, newIndexPath); + UITableViewCell *cell; + switch(type) { + case NSFetchedResultsChangeInsert: + self.updating = YES; + [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] + withRowAnimation:UITableViewRowAnimationFade]; + break; + + case NSFetchedResultsChangeDelete: + self.updating = YES; + [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] + withRowAnimation:UITableViewRowAnimationFade]; + break; + + case NSFetchedResultsChangeMove: + self.updating = YES; + [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] + withRowAnimation:UITableViewRowAnimationFade]; + [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] + withRowAnimation:UITableViewRowAnimationFade]; + break; + case NSFetchedResultsChangeUpdate: + cell = [self.tableView cellForRowAtIndexPath:indexPath]; + if (cell) { + self.updating = YES; + [self configureCell:cell + atIndexPath:indexPath]; + } + break; + } +} + +- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller +{ + //HPLog(@"%s", __PRETTY_FUNCTION__); + NSDate *date = [NSDate new]; + self.updating = NO; + //[self.tableView endUpdates]; + NSTimeInterval delta = -date.timeIntervalSinceNow; + if (delta > .1) { + HPLog(@"Ending updates took %.3fs", delta); + } + if (selectedObject) { + NSIndexPath *indexPath = [controller indexPathForObject:selectedObject]; + selectedObject = nil; + if (indexPath) { + [self.tableView selectRowAtIndexPath:indexPath + animated:NO + scrollPosition:UITableViewScrollPositionNone]; + } + } +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPopoverLayoutFixTableView.h b/client/ios/Hackpad/Hackpad/HPPopoverLayoutFixTableView.h new file mode 100644 index 0000000..2cf9166 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPopoverLayoutFixTableView.h @@ -0,0 +1,13 @@ +// +// HPPopoverLayoutFixTableView.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import + +@interface HPPopoverLayoutFixTableView : UITableView + +@end diff --git a/client/ios/Hackpad/Hackpad/HPPopoverLayoutFixTableView.m b/client/ios/Hackpad/Hackpad/HPPopoverLayoutFixTableView.m new file mode 100644 index 0000000..fc4e28d --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPPopoverLayoutFixTableView.m @@ -0,0 +1,22 @@ +// +// HPPopoverLayoutFixTableView.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPPopoverLayoutFixTableView.h" + +@implementation HPPopoverLayoutFixTableView + +- (void)setFrame:(CGRect)frame +{ + if (HP_SYSTEM_MAJOR_VERSION() >= 7 && frame.origin.y == 44) { + frame.origin.y += 20; + frame.size.height -= 20; + } + [super setFrame:frame]; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPSearchResultsController.h b/client/ios/Hackpad/Hackpad/HPSearchResultsController.h new file mode 100644 index 0000000..d68d9f4 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPSearchResultsController.h @@ -0,0 +1,28 @@ +// +// HPSearchResultsController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface HPSearchResultsController : NSFetchedResultsController + +@property (strong, nonatomic, readonly) NSPredicate *resultsPredicate; +@property (strong, nonatomic) NSPredicate *baseSearchPredicate; +@property (strong, nonatomic) NSPredicate *searchResultsPredicate; +@property (strong, nonatomic) NSPredicate *searchTextPredicate; +@property (strong, nonatomic) NSPredicate *searchTextResultsPredicate; + +- (void)setSearchText:(NSString *)searchText + variable:(NSString *)variable; + +@end + +@protocol HPSearchResultsControllerDelegate + +- (void)controllerDidChangePredicate:(HPSearchResultsController *)controller; + +@end diff --git a/client/ios/Hackpad/Hackpad/HPSearchResultsController.m b/client/ios/Hackpad/Hackpad/HPSearchResultsController.m new file mode 100644 index 0000000..5624cc2 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPSearchResultsController.m @@ -0,0 +1,127 @@ +// +// HPSearchResultsController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPSearchResultsController.h" + +#import + +@implementation HPSearchResultsController + +- (void)setBaseSearchPredicate:(NSPredicate *)baseSearchPredicate +{ + _baseSearchPredicate = baseSearchPredicate; + [self fetchSearchTextResults]; +} + +- (void)setSearchResultsPredicate:(NSPredicate *)searchResultsPredicate +{ + _searchResultsPredicate = searchResultsPredicate; + [self updatePredicate]; +} + +- (void)setSearchTextResultsPredicate:(NSPredicate *)searchTextResultsPredicate +{ + _searchTextResultsPredicate = searchTextResultsPredicate; + [self updatePredicate]; +} + +- (void)setSearchTextPredicate:(NSPredicate *)searchTextPredicate +{ + _searchTextPredicate = searchTextPredicate; + [self fetchSearchTextResults]; +} + +- (void)setSearchText:(NSString *)searchText + variable:(NSString *)variable +{ + NSMutableArray *predicates = [NSMutableArray array]; + [searchText enumerateSubstringsInRange:NSMakeRange(0, searchText.length) + options:NSStringEnumerationByWords + usingBlock:^(NSString *word, NSRange substringRange, NSRange enclosingRange, BOOL *stop) + { + NSAssert(word.length, @"Word should not be empty."); + [predicates addObject:[NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", variable, word]]; + }]; + [self setSearchTextPredicate:[NSCompoundPredicate andPredicateWithSubpredicates:predicates]]; +} + +- (NSPredicate *)resultsPredicate +{ + if (_searchResultsPredicate && _searchTextResultsPredicate) { + NSArray *subpredicates = @[_searchResultsPredicate, + _searchTextResultsPredicate]; + return [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates]; + } else if (_searchResultsPredicate) { + return _searchResultsPredicate; + } else if (_searchTextResultsPredicate) { + return _searchTextResultsPredicate; + } else { + return [NSPredicate predicateWithValue:NO]; + } +} + +- (void)updatePredicate +{ + self.fetchRequest.predicate = self.resultsPredicate; + if ([(id)self.delegate respondsToSelector:@selector(controllerDidChangePredicate:)]) { + id delegate = (id )self.delegate; + [delegate controllerDidChangePredicate:self]; + } +} + +- (void)fetchSearchTextResults +{ + if (!self.baseSearchPredicate || !self.searchTextPredicate) { + return; + } + + NSManagedObjectContext *managedObjectContext = self.managedObjectContext; + NSPredicate *basePredicate = self.baseSearchPredicate; + NSPredicate *textPredicate = self.searchTextPredicate; + NSString *entityName = self.fetchRequest.entityName; + + double delayInSeconds = 0.400; + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); + dispatch_after(popTime, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ + BOOL __block changed; + [managedObjectContext performBlockAndWait:^{ + changed = self.baseSearchPredicate != basePredicate || self.searchTextPredicate != textPredicate; + }]; + if (changed) { + return; + } + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:entityName]; + NSArray *subpredicates = @[basePredicate, textPredicate]; + fetch.predicate = [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates]; + fetch.resultType = NSManagedObjectIDResultType; + + NSManagedObjectContext *worker = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; + worker.persistentStoreCoordinator = self.managedObjectContext.persistentStoreCoordinator; + [worker performBlock:^{ + NSError * __autoreleasing error; + NSDate *date = [NSDate date]; + NSArray *results = [worker executeFetchRequest:fetch + error:&error]; + TFLog(@"Search took %.3f seconds.", -date.timeIntervalSinceNow); + NSPredicate *searchTextResultsPredicate; + if (results.count) { + searchTextResultsPredicate = [NSPredicate predicateWithFormat:@"SELF IN %@", results]; + } else if (error) { + TFLog(@"Could not perform text search: %@", error); + } + [managedObjectContext performBlock:^{ + if (self.baseSearchPredicate == basePredicate && + self.searchTextPredicate == textPredicate) { + self.searchTextResultsPredicate = searchTextResultsPredicate; + } + }]; + }]; + }); +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPSignInController.h b/client/ios/Hackpad/Hackpad/HPSignInController.h new file mode 100644 index 0000000..91c4263 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPSignInController.h @@ -0,0 +1,25 @@ +// +// HPSignInController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPCoreDataStack; + +UIKIT_EXTERN NSString * const HPSignInControllerWillRequestPadsNotification; +UIKIT_EXTERN NSString * const HPSignInControllerDidRequestPadsNotification; + +UIKIT_EXTERN NSString * const HPSignInControllerSpaceKey; + +@interface HPSignInController : NSObject + ++ (id)defaultController; + +- (void)addObserversWithCoreDataStack:(HPCoreDataStack *)coreDataStack + rootViewController:(UIViewController *)rootViewController; + +@end diff --git a/client/ios/Hackpad/Hackpad/HPSignInController.m b/client/ios/Hackpad/Hackpad/HPSignInController.m new file mode 100644 index 0000000..5c975c6 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPSignInController.m @@ -0,0 +1,331 @@ +// +// HPSignInController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPSignInController.h" + +#import "HackpadKit/HackpadKit.h" +#import + +#import "HPSignInViewController.h" + +#import +#import + +NSString * const HPSignInControllerWillRequestPadsNotification = @"HPSignInControllerWillRequestPadsNotification"; +NSString * const HPSignInControllerDidRequestPadsNotification = @"HPSignInControllerDidRequestPadsNotification"; + +NSString * const HPSignInControllerSpaceKey = @"HPSignInControllerSpace"; + +@interface HPSignInController () +@property (nonatomic, strong) NSMutableSet *todo; ++ (UIStoryboard *)signInStoryboard; +@end + +@implementation HPSignInController + ++ (id)defaultController +{ + static HPSignInController *defaultController; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + defaultController = [self new]; + }); + return defaultController; +} + +- (id)init +{ + if (!(self = [super init])) { + return nil; + } + self.todo = [NSMutableSet set]; + return self; +} + ++ (UIStoryboard *)signInStoryboard +{ + return [UIStoryboard storyboardWithName:UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? @"SignIn_iPad" : @"SignIn_iPhone" + bundle:nil]; +} + +- (BOOL)resetSpace:(HPSpace *)space + withNewUserID:(NSString *)userID + error:(NSError * __autoreleasing *)error +{ + [HPStaticCachingURLProtocol removeCacheWithHost:space.API.URL.host + error:NULL]; + HPSpace *newSpace = [NSEntityDescription insertNewObjectForEntityForName:HPSpaceEntity + inManagedObjectContext:space.managedObjectContext]; + newSpace.name = space.name; + newSpace.public = space.public; + newSpace.signInMethods = space.signInMethods; + newSpace.rootURL = space.rootURL; + newSpace.userID = userID; + newSpace.hidden = space.hidden; + newSpace.domainType = space.domainType; + + [space.managedObjectContext deleteObject:space]; + + if (space.URL.hp_isToplevelHackpadURL) { + HPPad *pad = [HPPad welcomePadInManagedObjectContext:newSpace.managedObjectContext + error:nil]; + pad.followed = YES; + } + + return YES; +} + +- (void)addObserversWithCoreDataStack:(HPCoreDataStack *)coreDataStack + rootViewController:(UIViewController *)rootViewController +{ + NSManagedObjectContext *managedObjectContext = coreDataStack.mainContext; + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + HPSignInController * __weak weakSelf = self; + [center addObserverForName:HPAPIDidRequireUserActionNotification + object:nil + queue:nil + usingBlock:^(NSNotification *note) + { + HPAPI *API = note.object; + NSUInteger sessionID = API.sessionID; + switch (API.authenticationState) { + case HPSignInPromptAuthenticationState: { + [managedObjectContext performBlock:^{ + HPSignInController *strongSelf = weakSelf; + if (!strongSelf) { + return; + } + NSError *error; + HPSpace *space = [HPSpace spaceWithAPI:API + inManagedObjectContext:managedObjectContext + error:&error]; + if (error) { + TFLog(@"[%@] Could not find space: %@", API.URL.host, error); + return; + } + + [strongSelf.todo addObject:space]; + if (strongSelf.todo.count == 1) { + [strongSelf signInToSpace:space + rootViewController:rootViewController]; + } + }]; + break; + } + case HPChangedUserAuthenticationState: { + HPLog(@"[%@] Space changed users: %@ -> %@", API.URL.host, API.userID, + [note.userInfo objectForKey:HPAPINewUserIDKey]); + MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:rootViewController.view + animated:YES]; + [coreDataStack saveWithBlock:^(NSManagedObjectContext *localContext) { + NSError *error = nil; + HPSignInController *strongSelf = weakSelf; + if (!strongSelf) { + return; + } + HPSpace *space = [HPSpace spaceWithAPI:API + inManagedObjectContext:localContext + error:&error]; + if (!space) { + return; + } + [strongSelf resetSpace:space + withNewUserID:note.userInfo[HPAPINewUserIDKey] + error:&error]; + } completion:^(NSError *error) { + [HUD hide:YES]; + if (error) { + TFLog(@"[%@] Could not reset space: %@", API.URL.host, error); + return; + } + if (API.sessionID != sessionID) { + return; + } + API.authenticationState = HPSignedInAuthenticationState; + }]; + break; + } + default: + TFLog(@"[%@] Unexpected authentication state: %lu", + API.URL.host, (unsigned long)API.authenticationState); + break; + } + }]; + [center addObserverForName:HPAPIDidSignInNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + if (!weakSelf) { + return; + } + HPAPI *API = note.object; + NSUInteger sessionID = API.sessionID; + NSError * __autoreleasing error; + HPSpace *space = [HPSpace spaceWithAPI:API + inManagedObjectContext:managedObjectContext + error:&error]; + if (!space) { + return; + } + if (space.userID.length) { + if (![space.userID isEqualToString:API.userID]) { + TFLog(@"[%@] userID mismatch: expected %@ but found %@", + API.URL.host, API.userID, space.userID); + return; + } + } else { + [space hp_performBlock:^(HPSpace *space, NSError *__autoreleasing *error) + { + @synchronized ([space API]) { + if (!space.API.isSignedIn || space.API.sessionID != sessionID) { + return; + } + space.userID = API.userID; + } + } completion:^(HPSpace *space, NSError *error) { + if (error) { + TFLog(@"[%@] Could not update space userID: %@", API.URL.host, error); + } + }]; + } + [[NSNotificationCenter defaultCenter] postNotificationName:HPSignInControllerWillRequestPadsNotification + object:self + userInfo:@{HPSignInControllerSpaceKey:space}]; + [space requestFollowedPadsWithRefresh:YES + completion:^(HPSpace *space, NSError *error) + { + if (error) { + TFLog(@"[%@] Could not import pads: %@", + API.URL.host, error); + } + }]; + [space refreshSpacesWithCompletion:^(HPSpace *sites, + NSError *error) { + if (error) { + TFLog(@"[%@] Could not update sites: %@", + space.URL.host, error); + } + }]; + }]; + [center addObserverForName:HPAPIDidSignOutNotification + object:nil + queue:nil + usingBlock:^(NSNotification *note) + { + HPAPI *API = note.object; + if (API.authenticationState != HPRequiresSignInAuthenticationState) { + return; + } + MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:rootViewController.view + animated:YES]; + [coreDataStack saveWithBlock:^(NSManagedObjectContext *localContext) { + NSError *error = nil; + HPSignInController *strongSelf = weakSelf; + if (!strongSelf) { + return; + } + HPSpace *space = [HPSpace spaceWithAPI:API + inManagedObjectContext:localContext + error:&error]; + if (!space) { + + } + [strongSelf resetSpace:space + withNewUserID:nil + error:nil]; + + } completion:^(NSError *error) { + [HUD hide:YES]; + if (error) { + TFLog(@"[%@] Could not handle sign out: %@", API.URL.host, error); + } + }]; + }]; + [center addObserverForName:HPAPIDidFailToSignInNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + [SignInAlertHelper showAlertWithSignInError:[note.userInfo objectForKey:HPAPISignInErrorKey]]; + }]; +} + +- (void)signInToSpace:(HPSpace *)space + rootViewController:(UIViewController *)rootViewController +{ + UINavigationController *navCon = [[self.class signInStoryboard] instantiateInitialViewController]; + if (HP_SYSTEM_MAJOR_VERSION() < 7) { + [navCon view]; + navCon.navigationBar.translucent = NO; + } + HPSignInViewController *signIn = (HPSignInViewController *)navCon.topViewController; + + UIViewController *viewController = rootViewController; + while (viewController.presentedViewController) { + viewController = viewController.presentedViewController; + } +// MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:viewController.view +// animated:YES]; + BOOL oldUserInteractionEnabled = rootViewController.view.userInteractionEnabled; + rootViewController.view.userInteractionEnabled = NO; + [space refreshOptionsWithCompletion:^(id unused, NSError *error) + { + rootViewController.view.userInteractionEnabled = oldUserInteractionEnabled; +// [HUD hide:YES]; + if (error) { + [_todo removeObject:space]; + [space signOutWithCompletion:nil]; + [SignInAlertHelper showAlertWithSignInError:error]; + return; + } + + UIViewController *viewController = rootViewController; + while (viewController.presentedViewController) { + viewController = viewController.presentedViewController; + } + [signIn signInToSpace:space + completion:^(BOOL canceled, + NSError *signInError) + { + [viewController dismissViewControllerAnimated:YES + completion:^ + { + NSError *error = signInError; + [_todo removeObject:space]; + if (error || canceled) { + if (error) { + [SignInAlertHelper showAlertWithSignInError:error]; + error = nil; + } else { + HPLog(@"[%@] Canceled sign in.", space.API.URL.host); + } + [space signOutWithCompletion:nil]; + } else { + HPLog(@"[%@] Signed in.", space.API.URL.host); + space.API.authenticationState = HPRequestAPISecretAuthenticationState; + } + HPSpace *todo; + while ((todo = [_todo anyObject])) { + if (todo.API.authenticationState != HPSignInPromptAuthenticationState) { + [_todo removeObject:todo]; + continue; + } + [self signInToSpace:todo + rootViewController:rootViewController]; + break; + } + }]; + }]; + [viewController presentViewController:navCon + animated:YES + completion:nil]; + }]; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPSignInViewController.h b/client/ios/Hackpad/Hackpad/HPSignInViewController.h new file mode 100644 index 0000000..2cbb91d --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPSignInViewController.h @@ -0,0 +1,66 @@ +// +// HPSignInViewController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPSpace; + +@interface HPSignInViewController : UIViewController + +@property (strong, nonatomic, readonly) HPSpace *space; +@property (strong, nonatomic, readonly) NSURL *URL; + +@property (weak, nonatomic) IBOutlet UIButton *googleButton; +@property (weak, nonatomic) IBOutlet UIButton *facebookButton; +@property (weak, nonatomic) IBOutlet UIView *orView; +@property (weak, nonatomic) IBOutlet UILabel *orLabel; +@property (weak, nonatomic) IBOutlet UIView *leftDots; +@property (weak, nonatomic) IBOutlet UIView *rightDots; +@property (weak, nonatomic) IBOutlet UIButton *emailButton; +@property (weak, nonatomic) IBOutlet UIButton *forgotPasswordButton; +@property (weak, nonatomic) IBOutlet UIButton *showSignUpButton; + +@property (weak, nonatomic) IBOutlet UITextField *nameField; +@property (weak, nonatomic) IBOutlet UITextField *emailField; +@property (weak, nonatomic) IBOutlet UITextField *passwordField; +@property (weak, nonatomic) IBOutlet UITextField *verifyField; + +@property (nonatomic, strong) IBOutlet UIBarButtonItem *cancelItem; +@property (nonatomic, strong) IBOutlet UIBarButtonItem *backItem; +@property (nonatomic, strong) IBOutlet UIBarButtonItem *signInItem; +@property (nonatomic, strong) IBOutlet UIBarButtonItem *signUpItem; + +- (IBAction)showButtons:(id)sender; +- (IBAction)cancelSignIn:(id)sender; + +- (IBAction)signInToFacebook:(id)sender; + +- (IBAction)showSignIn:(id)sender; +- (IBAction)signIn:(id)sender; +- (IBAction)showForgottenPassword:(id)sender; + +- (IBAction)showSignUp:(id)sender; +- (IBAction)signUp:(id)sender; +- (IBAction)resendVerification:(id)sender; + +- (IBAction)updateCheckbox:(UITextField *)sender; +- (IBAction)updateSignInItem:(id)sender; +- (IBAction)updateSignUpItem:(id)sender; + +- (void)signInToSpace:(HPSpace *)space + completion:(void (^)(BOOL, NSError *))handler; + +@end + +@interface SignInAlertHelper : NSObject +@property (strong, nonatomic) UIAlertView *alertView; +@property (strong, nonatomic) NSError *error; +@property (strong, nonatomic) SignInAlertHelper *cycle; + ++ (void)showAlertWithSignInError:(NSError *)error; +@end diff --git a/client/ios/Hackpad/Hackpad/HPSignInViewController.m b/client/ios/Hackpad/Hackpad/HPSignInViewController.m new file mode 100644 index 0000000..789c8fb --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPSignInViewController.m @@ -0,0 +1,916 @@ +// +// HPSignInViewController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPSignInViewController.h" + +#import "HackpadKit/HackpadKit.h" +#import "HackpadAdditions/HackpadUIAdditions.h" + +#import "HPGoogleSignInViewController.h" + +#import +#import +#import +#import + +static NSString * const HPConnectFBSessionPath = @"/ep/account/connect-fb-session"; +static NSString * const HPForgotPasswordPath = @"/ep/account/forgot-password"; +static NSString * const HPPostSigninPath = @"/ep/account/signin"; +static NSString * const HPResendEmailVerificationPath = @"/ep/account/resend-email-verification"; +static NSString * const HPSignUpPath = @"/ep/account/signup"; + +static NSString * const SignedInPath = @"/ep/iOS/x-HackpadKit-signed-in"; + +static NSString * const HPAccessTokenParam = @"access_token"; +static NSString * const HPEmailParam = @"email"; +static NSString * const HPNameParam = @"name"; +static NSString * const HPPasswordParam = @"password"; + +static NSString * const UserIdKey = @"userId"; + +static const NSUInteger BigFontSize = 30; +static const NSUInteger NormalFontSize = 17; +static const NSUInteger SmallFontSize = 14; +#define PADDING (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? @60 : @20) +#define SPACING (@24) + +#define ALWAYS_SIGN_OUT 1 + +typedef NS_ENUM(NSUInteger, ActionType) { + NoAction, + VerifyEmailAction, + RecoverPasswordAction +}; + +@interface HPSignInViewController () { + void (^_signInHandler)(BOOL, NSError *); + ActionType _action; + UIAlertView *_alert; + BOOL _triedRenewing; +} + +@property (nonatomic, readonly) BOOL hasGoogleCookies; +@property (nonatomic, assign, getter = isPasswordVerified) BOOL passwordVerified; +@property (nonatomic, strong) NSArray *topConstraints; +@property (nonatomic, strong) UILabel *titleLabel; + +- (void)signInWithFacebook; +- (void)signOutOfGoogle; +- (void)dismissWithError:(NSError *)error + cancelled:(BOOL)cancelled; +- (void)requestPasswordResetForEmail:(NSString *)email; +- (void)resendVerificationForEmail:(NSString *)email; +@end + +@implementation HPSignInViewController + +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (void)setPromptHidden:(BOOL)hidden +{ + // FIXME: figure out why color here is wrong on iOS 6 + if (hidden || self.space.URL.hp_isToplevelHackpadURL || HP_SYSTEM_MAJOR_VERSION() < 7) { + self.navigationItem.prompt = nil; + return; + } + self.navigationItem.prompt = @"WELCOME TO"; +} + +- (void)configureView +{ + self.googleButton.enabled = self.space.signInMethods & HPGoogleSignInMask; + [self.facebookButton hp_setAlphaWithUserInteractionEnabled:self.space.signInMethods & HPFaceboookSignInMask]; + self.emailButton.enabled = self.space.signInMethods & HPPasswordSignInMask; + + [self updateSignUpItem:self]; + [self updateSignInItem:self]; +} + +- (NSUInteger)supportedInterfaceOrientations +{ + return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone + ? UIInterfaceOrientationMaskPortrait + : UIInterfaceOrientationMaskAll; +} + +- (void)viewDidLoad +{ + static const CGFloat ButtonHeight = 44; + + [super viewDidLoad]; + + NSDictionary *views = NSDictionaryOfVariableBindings(_googleButton, _facebookButton, _orView, + _emailButton, _forgotPasswordButton, _showSignUpButton, + _nameField, _emailField, _passwordField, _verifyField); + // Reset IB constraints + for (UIView *view in views.allValues) { + [view removeFromSuperview]; + view.translatesAutoresizingMaskIntoConstraints = NO; + [self.view addSubview:view]; + } + NSDictionary *metrics = @{@"height":@(ButtonHeight), + @"spacing":SPACING, + @"padding":PADDING}; + NSArray *formats = @[@"V:[_googleButton(height)]-spacing-[_facebookButton(height)]-spacing-[_orView(height)]-spacing-[_emailButton(height)]", + @"V:[_orView]-spacing-[_emailField(height)][_passwordField(height)][_forgotPasswordButton(height)]", + @"V:[_passwordField][_showSignUpButton(height)]", + @"V:[_nameField(height)][_emailField][_passwordField][_verifyField(height)]", + @"|-padding-[_showSignUpButton(==_forgotPasswordButton)]-[_forgotPasswordButton]-padding-|"]; + for (NSString *format in formats) { + NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:format + options:0 + metrics:metrics + views:views]; + [self.view addConstraints:constraints]; + } + + for (UIView *view in @[self.googleButton, self.facebookButton, self.orView, self.emailButton, + self.nameField, self.emailField, self.passwordField, self.verifyField]) { + views = NSDictionaryOfVariableBindings(view); + NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-padding-[view]-padding-|" + options:0 + metrics:metrics + views:views]; + [self.view addConstraints:constraints]; + } + + [self signOutOfFacebook]; + [self signOutOfGoogle]; + + NSAttributedString *(^buttonLabel)(NSString *) = ^(NSString *type) { + UIFont *font = [UIFont hp_UITextFontOfSize:NormalFontSize]; + NSMutableAttributedString *label; + label = [[NSMutableAttributedString alloc] initWithString:@"Sign in with " + attributes:@{NSFontAttributeName:font}]; + font = [UIFont hp_prioritizedUITextFontOfSize:NormalFontSize]; + [label appendAttributedString:[[NSAttributedString alloc] initWithString:type + attributes:@{NSFontAttributeName:font}]]; + return label; + }; + + self.googleButton.titleLabel.attributedText = buttonLabel(@"Google"); + self.facebookButton.titleLabel.attributedText = buttonLabel(@"Facebook"); + self.emailButton.titleLabel.attributedText = buttonLabel(@"email"); + + UIFont *font = [UIFont hp_UITextFontOfSize:SmallFontSize]; + self.forgotPasswordButton.titleLabel.font = font; + self.showSignUpButton.titleLabel.font = font; + + self.titleLabel = [UILabel new]; + self.titleLabel.font = [UIFont hp_prioritizedUITextFontOfSize:BigFontSize]; + self.titleLabel.adjustsFontSizeToFitWidth = YES; + self.titleLabel.textColor = [UIColor whiteColor]; + self.titleLabel.backgroundColor = [UIColor clearColor]; + self.titleLabel.textAlignment = NSTextAlignmentCenter; + self.navigationItem.titleView = self.titleLabel; + + UIImage *image = [UIImage imageNamed:@"google44"]; + UIEdgeInsets insets = UIEdgeInsetsMake(image.size.height / 2, image.size.width, + image.size.height / 2, 0); + [self.googleButton setBackgroundImage:[image resizableImageWithCapInsets:insets] + forState:UIControlStateNormal]; + + image = [[UIImage imageNamed:@"facebook44"] resizableImageWithCapInsets:insets]; + [self.facebookButton setBackgroundImage:image + forState:UIControlStateNormal]; + + image = [[UIImage imageNamed:@"email-button-white"] resizableImageWithCapInsets:insets]; + [self.emailButton setBackgroundImage:image + forState:UIControlStateNormal]; + + UIImageView *(^imageViewNamed)(NSString * const) = ^(NSString * const imageName) { + UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]]; + imageView.frame = CGRectMake(0, 0, ButtonHeight, ButtonHeight); + imageView.contentMode = UIViewContentModeCenter; + return imageView; + }; + + void (^setImages)(UITextField *, NSString *, NSString *) = ^(UITextField *textField, + NSString *leftImageName, + NSString *rightImageName) { + textField.leftView = imageViewNamed(leftImageName); + textField.leftViewMode = UITextFieldViewModeAlways; + textField.rightView = imageViewNamed(rightImageName); + textField.rightView.hidden = YES; + textField.rightViewMode = UITextFieldViewModeAlways; + }; + + setImages(self.nameField, @"user-green", @"check-green"); + setImages(self.emailField, @"email-green", @"check-green"); + setImages(self.passwordField, @"password-green", @"check-green"); + setImages(self.verifyField, @"password-green", @"x-red"); + + self.signInItem.enabled = NO; + self.signUpItem.enabled = NO; + + [self setPromptHidden:NO]; + [self showButtonsAnimated:NO]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(reachabilityDidChangeWithNotification:) + name:kReachabilityChangedNotification + object:nil]; +} + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + [self configureView]; + self.orLabel.font = [UIFont hp_prioritizedUITextFontOfSize:14]; + UIColor *dots = [UIColor colorWithPatternImage:[UIImage imageNamed:@"dot44"]]; + self.leftDots.backgroundColor = dots; + self.rightDots.backgroundColor = dots; +} + +- (void)viewDidDisappear:(BOOL)animated +{ + [super viewDidDisappear:animated]; + [self setPromptHidden:YES]; +} + +- (void)viewDidAppear:(BOOL)animated +{ + [super viewDidAppear:animated]; + [self setPromptHidden:NO]; + [self configureView]; +} + +- (void)reachabilityDidChangeWithNotification:(NSNotification *)note +{ + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + if (note.object != self.space.API.reachability || + !self.space.API.reachability.currentReachabilityStatus) { + return; + } + [self.space refreshOptionsWithCompletion:^(HPSpace *space, NSError *error) { + if (error) { + [SignInAlertHelper showAlertWithSignInError:error]; + } + [self configureView]; + }]; + }]; +} + +- (IBAction)showButtons:(id)sender +{ + [self showButtonsAnimated:YES]; +} + +- (void)showViews:(NSArray *)toShow + hidingViews:(NSArray *)toHide + animated:(BOOL)animated + animations:(void (^)(void))animations + completion:(void (^)(BOOL))completion +{ + for (UIView *view in toShow) { + view.alpha = 0; + view.hidden = NO; + } + [UIView animateWithDuration:animated ? 0.25 : 0 + animations:^{ + for (UIView *view in toShow) { + view.alpha = 1; + } + for (UIView *view in toHide) { + view.alpha = 0; + } + if (animations) { + animations(); + } + [self.view layoutIfNeeded]; + } completion:^(BOOL finished) { + for (UIView *view in toHide) { + view.hidden = YES; + } + if (!completion) { + return; + } + completion(finished); + }]; +} + +- (void)setTopView:(UIView *)view +{ + if (self.topConstraints) { + [self.view removeConstraints:self.topConstraints]; + } + NSDictionary *views; + NSString *format; + NSDictionary *metrics = @{@"padding":PADDING}; + if (HP_SYSTEM_MAJOR_VERSION() >= 7) { + id top = self.topLayoutGuide; + views = NSDictionaryOfVariableBindings(view, top); + format = @"V:[top]-padding-[view]"; + } else { + views = NSDictionaryOfVariableBindings(view); + format = @"V:|-padding-[view]"; + } + self.topConstraints = [NSLayoutConstraint constraintsWithVisualFormat:format + options:0 + metrics:metrics + views:views]; + [self.view addConstraints:self.topConstraints]; +} + +- (void)showButtonsAnimated:(BOOL)animated +{ + self.topView = self.googleButton; + [self.view.hp_firstResponderSubview resignFirstResponder]; + [self.navigationItem setLeftBarButtonItem:self.space.URL.hp_isToplevelHackpadURL ? nil: self.cancelItem + animated:animated]; + [self.navigationItem setRightBarButtonItem:nil + animated:animated]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + [self setPromptHidden:NO]; + } + [self showViews:@[self.googleButton, self.facebookButton, self.orView, self.emailButton] + hidingViews:@[self.nameField, self.emailField, self.passwordField, self.verifyField, + self.forgotPasswordButton, self.showSignUpButton] + animated:animated + animations:^{ + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + return; + } + self.titleLabel.font = [UIFont hp_prioritizedUITextFontOfSize:BigFontSize]; + self.titleLabel.textColor = [UIColor whiteColor]; + } completion:^(BOOL finished) { + self.signInItem.enabled = NO; + self.signUpItem.enabled = NO; + }]; +} + +- (IBAction)showSignIn:(id)sender +{ + self.topView = self.emailField; + + [self.navigationItem setLeftBarButtonItem:self.backItem + animated:YES]; + [self.navigationItem setRightBarButtonItem:self.signInItem + animated:YES]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + [self setPromptHidden:YES]; + } + self.passwordField.returnKeyType = UIReturnKeySend; + [self showViews:@[self.emailField, self.passwordField, self.forgotPasswordButton, self.showSignUpButton] + hidingViews:@[self.googleButton, self.facebookButton, self.orView, self.emailButton] + animated:YES + animations:^{ + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + return; + } + self.titleLabel.font = [UIFont hp_UITextFontOfSize:20]; + self.titleLabel.textColor = [UIColor hp_lightGreenGrayColor]; + } completion:^(BOOL finished) { + [self updateSignInItem:self]; + if (!self.emailField.text.length) { + [self.emailField becomeFirstResponder]; + } else { + [self.passwordField becomeFirstResponder]; + } + }]; +} + +- (void)showSignUp:(id)sender +{ + self.topView = self.nameField; + + [self.navigationItem setRightBarButtonItem:self.signUpItem + animated:YES]; + self.passwordField.returnKeyType = UIReturnKeyNext; + [self showViews:@[self.nameField, self.verifyField] + hidingViews:@[self.forgotPasswordButton, self.showSignUpButton] + animated:YES + animations:NULL + completion:^(BOOL finished) { + [self updateSignUpItem:self]; + if (!self.nameField.text.length) { + [self.nameField becomeFirstResponder]; + } else if (!self.emailField.text.length) { + [self.emailField becomeFirstResponder]; + } else if (!self.passwordField.text.length) { + [self.passwordField becomeFirstResponder]; + } else { + [self.verifyField becomeFirstResponder]; + } + }]; +} + +- (void)signInToSpace:(HPSpace *)space + completion:(void (^)(BOOL, NSError *))handler +{ + NSParameterAssert(handler); + _signInHandler = handler; + _space = space; + _URL = space.URL; + [_URL hp_dumpCookies]; + if (!self.isViewLoaded) { + [self view]; + } + [self setPromptHidden:NO]; + self.titleLabel.attributedText = [[NSAttributedString alloc] initWithString:self.space.name.uppercaseString + attributes:@{NSKernAttributeName:@(4)}]; + [self.titleLabel sizeToFit]; + if (self.isViewLoaded) { + [self configureView]; + } +} + +- (void)dismissWithError:(NSError *)error + cancelled:(BOOL)cancelled +{ + // We don't want to get any more notifications. + void (^handler)(BOOL, NSError *) = _signInHandler; + _signInHandler = nil; + if (handler) { + handler(cancelled, error); + } +} + +- (IBAction)cancelSignIn:(id)sender +{ + [self dismissWithError:nil + cancelled:YES]; +} + +- (BOOL)hasGoogleCookies +{ + NSHTTPCookieStorage *jar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + HPLog(@"---- Cookies for google.com ----"); + for (NSHTTPCookie *cookie in jar.cookies) { + if ([cookie.domain isEqualToString:@"google.com"] || + [cookie.domain hasSuffix:@".google.com"]) { + HPLog(@"%@[%@]: %@", cookie.domain, cookie.name, cookie.value); + HPLog(@"---------------- google.com ----"); + return YES; + } + } + HPLog(@"---------------- google.com ----"); + return NO; +} + +- (void)signOutOfGoogle +{ + NSHTTPCookieStorage *jar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + HPLog(@"---- Cookies for google.com ----"); + for (NSHTTPCookie *cookie in jar.cookies) { + if ([cookie.domain isEqualToString:@"google.com"] || + [cookie.domain hasSuffix:@".google.com"]) { + HPLog(@"XXX %@[%@]: %@", cookie.domain, cookie.name, cookie.value); + [jar deleteCookie:cookie]; + } + } + HPLog(@"---------------- google.com ----"); +// self.googleCell.accessoryType = UITableViewCellAccessoryNone; +} + +- (IBAction)updateSignInItem:(id)sender +{ + self.signInItem.enabled = self.space.signInMethods & HPPasswordSignInMask && + self.emailField.text.length && self.passwordField.text.length; +} + +- (IBAction)updateSignUpItem:(id)sender +{ + self.signUpItem.enabled = self.space.signInMethods & HPPasswordSignInMask && + self.nameField.text.length && + self.emailField.text.length && + self.passwordField.text.length && + [self.passwordField.text isEqualToString:self.verifyField.text]; +} + +- (IBAction)updateCheckbox:(UITextField *)textField +{ + if (textField.isSecureTextEntry) { + self.passwordVerified = [self.passwordField.text isEqualToString:self.verifyField.text]; + } + textField.rightView.hidden = !textField.text.length; +} + +- (void)prepareForSegue:(UIStoryboardSegue *)segue + sender:(id)sender +{ + if ([segue.identifier isEqualToString:@"GoogleSignIn"]) { + HPGoogleSignInViewController *googleSignIn = segue.destinationViewController; + //googleSignIn.navigationItem.title = self.titleLabel.text; + googleSignIn.title = self.titleLabel.text; + [self setPromptHidden:YES]; + [googleSignIn signInToSpaceWithURL:self.URL + completion:_signInHandler]; + } +} + +#pragma mark - Text field delegate + +- (void)textFieldDidBeginEditing:(UITextField *)textField +{ + textField.backgroundColor = [UIColor whiteColor]; +} + +- (void)textFieldDidEndEditing:(UITextField *)textField +{ + textField.backgroundColor = textField.text.length ? [UIColor hp_mediumGreenGrayColor] : [UIColor whiteColor]; +} + +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + if (textField == [_alert textFieldAtIndex:0]) { + [_alert dismissWithClickedButtonIndex:_alert.firstOtherButtonIndex + animated:YES]; + } else if (!self.nameField.isHidden && self.signUpItem.enabled) { + [textField resignFirstResponder]; + [self signUp:textField]; + } else if (self.nameField.isHidden && self.signInItem.enabled) { + [textField resignFirstResponder]; + [self signIn:textField]; + } else if (textField == self.nameField && self.nameField.text.length) { + [self.emailField becomeFirstResponder]; + } else if (textField == self.emailField && self.emailField.text.length) { + [self.passwordField becomeFirstResponder]; + } else if (textField == self.passwordField && self.passwordField.text.length) { + if (self.verifyField.isHidden) { + [self.emailField becomeFirstResponder]; + } else { + [self.verifyField becomeFirstResponder]; + } + } else if (textField == self.verifyField && self.verifyField.text.length) { + [self.nameField becomeFirstResponder]; + } + return YES; +} + +- (void)setPasswordVerified:(BOOL)passwordVerified +{ + if (passwordVerified == _passwordVerified) { + return; + } + _passwordVerified = passwordVerified; + UIImageView *imageView = (UIImageView *)self.verifyField.rightView; + imageView.image = [UIImage imageNamed:passwordVerified ? @"check-green" : @"x-red"]; +} + +- (IBAction)signIn:(id)sender +{ + NSURL *URL = [NSURL URLWithString:HPPostSigninPath + relativeToURL:self.URL]; + NSDictionary *params = @{HPEmailParam:self.emailField.text, + HPPasswordParam:self.passwordField.text, + HPAPIXSRFTokenParam:[HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view + animated:YES]; + [NSURLConnection sendAsynchronousRequest:request + queue:[NSOperationQueue mainQueue] + completionHandler:^(NSURLResponse *response, + NSData *data, + NSError *error) + { + [HUD hide:YES]; + if (!error && [HPAPI JSONObjectWithResponse:response + data:data + JSONOptions:0 + request:request + error:&error]) { + [self dismissWithError:nil + cancelled:NO]; + } else if (error) { + [SignInAlertHelper showAlertWithSignInError:error]; + } + }]; +} + +- (IBAction)showForgottenPassword:(id)sender +{ + _action = RecoverPasswordAction; + _alert = [[UIAlertView alloc] initWithTitle:@"Recover Password" + message:@"You will receive a link to reset your password." + delegate:self + cancelButtonTitle:@"Cancel" + otherButtonTitles:@"Send Email", nil]; + _alert.alertViewStyle = UIAlertViewStylePlainTextInput; + UITextField *text = [_alert textFieldAtIndex:0]; + text.keyboardType = UIKeyboardTypeEmailAddress; + text.returnKeyType = UIReturnKeySend; + text.placeholder = @"user@example.com"; + text.delegate = self; + [_alert show]; +} + +- (void)requestPasswordResetForEmail:(NSString *)email +{ + NSURL *URL = [NSURL URLWithString:HPForgotPasswordPath + relativeToURL:self.URL]; + NSDictionary *params = @{HPEmailParam:email, + HPAPIXSRFTokenParam:[HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + // FIXME: This returns 200 w/ HTML whether or not the email was invalid. + [NSURLConnection sendAsynchronousRequest:request + queue:nil + completionHandler:NULL]; +} + +- (IBAction)signUp:(id)sender +{ + NSURL *URL = [NSURL URLWithString:HPSignUpPath + relativeToURL:self.URL]; + NSDictionary *params = @{HPNameParam:self.nameField.text, + HPEmailParam:self.emailField.text, + HPPasswordParam:self.passwordField.text, + HPAPIXSRFTokenParam:[HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:[NSURL URLWithString:HPSignUpPath + relativeToURL:self.URL] + HTTPMethod:@"POST" + parameters:params]; + [NSURLConnection sendAsynchronousRequest:request + queue:[NSOperationQueue mainQueue] + completionHandler:^(NSURLResponse *response, + NSData *data, + NSError *error) + { + if (!error && [HPAPI JSONObjectWithResponse:response + data:data + JSONOptions:0 + request:request + error:&error]) { + [self.navigationController popViewControllerAnimated:YES]; + } else if (error) { + [SignInAlertHelper showAlertWithSignInError:error]; + } + }]; +} + +- (IBAction)resendVerification:(id)sender +{ + if (self.emailField.text.length) { + [self resendVerificationForEmail:self.emailField.text]; + return; + } + + _action = VerifyEmailAction; + _alert = [[UIAlertView alloc] initWithTitle:@"Verify Email" + message:@"You will receive a link to verify your address." + delegate:self + cancelButtonTitle:@"Cancel" + otherButtonTitles:@"Send Email", nil]; + _alert.alertViewStyle = UIAlertViewStylePlainTextInput; + UITextField *text = [_alert textFieldAtIndex:0]; + text.keyboardType = UIKeyboardTypeEmailAddress; + text.returnKeyType = UIReturnKeySend; + text.placeholder = @"user@example.com"; + text.delegate = self; + [_alert show]; +} + +- (void)resendVerificationForEmail:(NSString *)email +{ + NSURL *URL = [NSURL URLWithString:HPResendEmailVerificationPath + relativeToURL:self.URL]; + NSDictionary *params = @{HPEmailParam:email, + HPAPIXSRFTokenParam:[HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + [NSURLConnection sendAsynchronousRequest:request + queue:[NSOperationQueue mainQueue] + completionHandler:^(NSURLResponse *response, + NSData *data, + NSError *error) + { + if (!error && [HPAPI JSONObjectWithResponse:response + data:data + JSONOptions:0 + request:request + error:&error]) { + [self.navigationController popViewControllerAnimated:YES]; + } else if (error) { + [SignInAlertHelper showAlertWithSignInError:error]; + } + }]; +} + +#pragma mark - Facebook stuffs + +- (void)loginView:(FBLoginView *)loginView + handleError:(NSError *)error +{ + [self dismissWithError:error + cancelled:NO]; +} + +- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView +{ + [self signInWithFacebook]; +} + +- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView +{ + [self signOutOfFacebook]; +} + +/* + * Opens a Facebook session and optionally shows the login UX. + */ + +- (IBAction)signInToFacebook:(id)sender +{ + HPSignInViewController * __weak weakSelf = self; + MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view + animated:YES]; + [FBSession openActiveSessionWithReadPermissions:nil + allowLoginUI:YES + completionHandler:^(FBSession *session, + FBSessionState state, + NSError *error) + { + [HUD hide:YES]; +#if !ALWAYS_SIGN_OUT + self.facebookCell.accessoryType = [FBSession activeSession].isOpen + ? UITableViewCellAccessoryDetailDisclosureButton + : UITableViewCellAccessoryNone; +#endif + switch (state) { + case FBSessionStateOpen: + [weakSelf signInWithFacebook]; + break; + case FBSessionStateClosed: + case FBSessionStateClosedLoginFailed: + [self signOutOfFacebook]; + break; + default: + break; + } + if (error) { + [weakSelf dismissWithError:error + cancelled:NO]; + } + }]; +} + +- (void)signInWithFacebook +{ + NSParameterAssert([FBSession activeSession].isOpen); + + HPSignInViewController * __weak weakSelf = self; + MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view + animated:YES]; + NSURL *URL = [NSURL URLWithString:HPConnectFBSessionPath + relativeToURL:self.URL]; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"GET" + parameters:@{ + HPAccessTokenParam:[FBSession activeSession].accessTokenData.accessToken}]; + [NSURLConnection sendAsynchronousRequest:request + queue:[NSOperationQueue mainQueue] + completionHandler:^(NSURLResponse *response, + NSData *data, + NSError *error) + { + [HUD hide:YES]; + if (weakSelf && (error || ![HPAPI JSONObjectWithResponse:response + data:data + JSONOptions:0 + request:request + error:&error])) { + TFLog(@"[%@] Facebook sign in failed.", URL.host); + /* + * The cached FB token can get out of sync with ACAccountStore if + * we never call -closeAndClearTokenInformation:. In that case, we + * will send an invalid token to the server, but since we're not + * requesting something withFBSession, it won't realize it's out of + * sync. So clear the token, try to renew it, and try to sign in + * again. If that fails, give up. + * + * This can be reproduced by signing out of hackpad, deleting your + * Facebook account in Settings, adding your account again, and + * trying to sign in to hackpad using Facebook. + */ +#if 0 + HPLog(@"[%@] Token from FB: %@", URL.host, + [FBSession activeSession].accessTokenData.accessToken); + ACAccountStore *store = [[ACAccountStore alloc] init]; + ACAccountType *accountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]; + for (ACAccount *account in [store accountsWithAccountType:accountType]) { + HPLog(@"[%@] Token from system: %@", URL.host, + account.credential.oauthToken); + } +#endif + [self signOutOfFacebook]; + HPSignInViewController *blockSelf = weakSelf; + if (!blockSelf->_triedRenewing) { + blockSelf->_triedRenewing = YES; + HPLog(@"[%@] Renewing credentials...", URL.host); + [FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result, + NSError *renewError) + { + if (result == ACAccountCredentialRenewResultRenewed) { + HPLog(@"[%@] Trying to sign in with renewed credentials.", + URL.host); + [weakSelf signInToFacebook:nil]; + } else { + [weakSelf dismissWithError:renewError ? renewError : error + cancelled:NO]; + } + }]; + return; + } + } + [weakSelf dismissWithError:error + cancelled:NO]; + }]; +} + +- (void)signOutOfFacebook +{ + [[FBSession activeSession] closeAndClearTokenInformation]; +} + +#pragma mark - Alert view delegate + +- (void)alertView:(UIAlertView *)alertView +didDismissWithButtonIndex:(NSInteger)buttonIndex +{ + if (alertView == _alert) { + _alert = nil; + } else { + return; + } + if (buttonIndex == alertView.cancelButtonIndex) { + return; + } + if (_action == RecoverPasswordAction) { + [self requestPasswordResetForEmail:[alertView textFieldAtIndex:0].text]; + } else { + [self resendVerificationForEmail:[alertView textFieldAtIndex:0].text]; + } +} + +@end + +@implementation SignInAlertHelper + +- (void)alertView:(UIAlertView *)alertView +clickedButtonAtIndex:(NSInteger)buttonIndex +{ + NSParameterAssert(alertView == self.alertView); + if (buttonIndex == 0) { + NSString *message = self.error.localizedDescription; + if (self.error.fberrorUserMessage) { + message = self.error.fberrorUserMessage; + } + if (self.error.localizedFailureReason) { + message = [message stringByAppendingFormat:@" %@", self.error.localizedFailureReason]; + } + if (self.error.localizedRecoverySuggestion) { + message = [message stringByAppendingFormat:@" %@", self.error.localizedRecoverySuggestion]; + } + [alertView dismissWithClickedButtonIndex:buttonIndex + animated:NO]; + [[[UIAlertView alloc] initWithTitle:@"Error Details" + message:message + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; + } + alertView.delegate = nil; + self.cycle = nil; +} + +- (void)showAlertWithSignInError:(NSError *)error +{ + self.cycle = self; + self.error = error.userInfo[NSUnderlyingErrorKey]; + + self.alertView = [[UIAlertView alloc] initWithTitle:@"Try Signing In Again" + message:error.localizedDescription + delegate:self + cancelButtonTitle:nil + otherButtonTitles:@"Details", @"OK", nil]; + [self.alertView show]; +} + ++ (void)showAlertWithSignInError:(NSError *)error +{ + TFLog(@"Sign in error: %@", error); + if (error.userInfo[NSUnderlyingErrorKey]) { + [[[self alloc] init] showAlertWithSignInError:error]; + } else if ([error.domain isEqualToString:HPHackpadErrorDomain]) { + [[[UIAlertView alloc] initWithTitle:@"Try Signing In Again" + message:error.localizedDescription + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; + } +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPSpaceCell.h b/client/ios/Hackpad/Hackpad/HPSpaceCell.h new file mode 100644 index 0000000..0c25dfb --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPSpaceCell.h @@ -0,0 +1,13 @@ +// +// HPSpaceCell.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import + +@interface HPSpaceCell : UITableViewCell + +@end diff --git a/client/ios/Hackpad/Hackpad/HPSpaceCell.m b/client/ios/Hackpad/Hackpad/HPSpaceCell.m new file mode 100644 index 0000000..c69028e --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPSpaceCell.m @@ -0,0 +1,25 @@ +// +// HPSpaceCell.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPSpaceCell.h" + +@implementation HPSpaceCell + +- (void)layoutSubviews +{ + [super layoutSubviews]; + if (HP_SYSTEM_MAJOR_VERSION() < 7) { + return; + } + // Hack to center chevrons under gear + CGRect frame = self.accessoryView.frame; + frame.origin.x = CGRectGetWidth(self.bounds) - CGRectGetWidth(frame); + self.accessoryView.frame = frame; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPTextFieldCell.h b/client/ios/Hackpad/Hackpad/HPTextFieldCell.h new file mode 100644 index 0000000..989c42e --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPTextFieldCell.h @@ -0,0 +1,15 @@ +// +// HPTextFieldCell.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface HPTextFieldCell : UITableViewCell + +@property (weak, nonatomic) IBOutlet UITextField *textField; + +@end diff --git a/client/ios/Hackpad/Hackpad/HPTextFieldCell.m b/client/ios/Hackpad/Hackpad/HPTextFieldCell.m new file mode 100644 index 0000000..4dd78c4 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPTextFieldCell.m @@ -0,0 +1,20 @@ +// +// HPTextFieldCell.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPTextFieldCell.h" + +@implementation HPTextFieldCell + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated +{ + [super setSelected:selected animated:animated]; + + // Configure the view for the selected state +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPTextFieldCell.xib b/client/ios/Hackpad/Hackpad/HPTextFieldCell.xib new file mode 100644 index 0000000..e099a7c --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPTextFieldCell.xib @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/Hackpad/HPUserInfoCell.h b/client/ios/Hackpad/Hackpad/HPUserInfoCell.h new file mode 100644 index 0000000..8b80633 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPUserInfoCell.h @@ -0,0 +1,22 @@ +// +// HPUserInfoCell.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPUserInfoImageView; +@class HPUserInfo; + +@interface HPUserInfoCell : UITableViewCell +@property (nonatomic, weak) IBOutlet HPUserInfoImageView *userInfoImageView; +@property (nonatomic, weak) IBOutlet UILabel *nameLabel; +@property (nonatomic, weak) IBOutlet UILabel *statusLabel; +@property (nonatomic, strong) HPUserInfo *userInfo; + +- (void)setUserInfo:(HPUserInfo *)userInfo + animated:(BOOL)animated; +@end diff --git a/client/ios/Hackpad/Hackpad/HPUserInfoCell.m b/client/ios/Hackpad/Hackpad/HPUserInfoCell.m new file mode 100644 index 0000000..ad9d09a --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPUserInfoCell.m @@ -0,0 +1,43 @@ +// +// HPUserInfoCell.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPUserInfoCell.h" + +#import "HPUserInfoImageView.h" +#import "HPUserInfo.h" + +@implementation HPUserInfoCell + +@synthesize userInfoImageView = _userInfoImageView; + +- (void)setUserInfo:(HPUserInfo *)userInfo +{ + [self setUserInfo:userInfo + animated:NO]; +} + +- (void)setUserInfo:(HPUserInfo *)userInfo + animated:(BOOL)animated +{ + _userInfo = userInfo; + self.nameLabel.text = userInfo.name; + self.nameLabel.font = [UIFont hp_UITextFontOfSize:self.nameLabel.font.pointSize]; + self.statusLabel.text = userInfo.statusText; + self.statusLabel.font = [UIFont hp_UITextFontOfSize:self.statusLabel.font.pointSize]; + if (userInfo) { + [self.userInfoImageView setURL:userInfo.userPicURL + connected:userInfo.status == HPConnectedUserInfoStatus + animated:animated]; + } else { + [self.userInfoImageView setURL:nil + connected:NO + animated:animated]; + } +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPUserInfoImageView.h b/client/ios/Hackpad/Hackpad/HPUserInfoImageView.h new file mode 100644 index 0000000..4470510 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPUserInfoImageView.h @@ -0,0 +1,26 @@ +// +// HPUserInfoImageView.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPUserInfo; + +@interface HPUserInfoImageView : UIView + +@property (nonatomic, strong, readonly) UIImageView *imageView; +@property (nonatomic, assign, getter = isStack) BOOL stack; + +- (void)setURL:(NSURL *)URL + connected:(BOOL)connected + animated:(BOOL)animated; + +- (void)setURL:(NSURL *)URL + connected:(BOOL)connected + animatedBlock:(BOOL (^)(void))animated; + +@end diff --git a/client/ios/Hackpad/Hackpad/HPUserInfoImageView.m b/client/ios/Hackpad/Hackpad/HPUserInfoImageView.m new file mode 100644 index 0000000..6d7de8d --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPUserInfoImageView.m @@ -0,0 +1,316 @@ +// +// HPUserInfoImageView.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPUserInfoImageView.h" + +#import + +#import "HPUserInfo.h" +#import "HPStaticCachingURLProtocol.h" +#import "NSURL+HackpadAdditions.h" + +#import "UIImage+Resize.h" +#import + +static NSString * const AboutUnknown = @"about:unknown"; +static CGFloat const ImageOffset = 4; +static CGFloat const CircleOffset = 1; +static CGFloat const ShadowOffset = 5; + +@interface HPUserInfoImageView () { + UIImageView *_connectedView; + NSURL *_URL; +} +@property (nonatomic, strong, readwrite) UIImageView *imageView; +@property (nonatomic, readonly) UIImageView *connectedView; +@end + +@implementation HPUserInfoImageView + ++ (UIImage *)connectedImage +{ + return [UIImage imageNamed:@"online.png"]; +} + ++ (UIImage *)unknownImage +{ + return [UIImage imageNamed:@"nophoto.png"]; +} + ++ (NSCache *)imageCache +{ + static NSCache *cache; + if (!cache) { + cache = [[NSCache alloc] init]; + cache.countLimit = 32; + } + return cache; +} + ++ (NSCache *)imageCacheAtSize:(CGFloat)size +{ + NSCache *cache = [self imageCache]; + NSNumber *key = [NSNumber numberWithFloat:size]; + NSCache *sizeCache = [cache objectForKey:key]; + if (!sizeCache) { + sizeCache = [[NSCache alloc] init]; + sizeCache.countLimit = 32; + [cache setObject:sizeCache + forKey:key]; + } + return sizeCache; +} + ++ (NSData *)cachedDataForURL:(NSURL *)URL +{ + return [HPStaticCachingURLProtocol cachedDataWithRequest:[NSURLRequest requestWithURL:URL] + returningResponse:NULL + error:NULL]; +} + ++ (UIImage *)nonIndexedImageWithImage:(UIImage *)image +{ + // Thumbnailing doesn't work on indexed images. + return CGColorSpaceGetModel(CGImageGetColorSpace(image.CGImage)) == kCGColorSpaceModelIndexed + ? [UIImage imageWithData:UIImageJPEGRepresentation(image, 1)] + : image; +} + ++ (UIImage *)cachedImageForURL:(NSURL *)URL +{ + NSCache *cache = [self imageCache]; + UIImage *image = [cache objectForKey:URL.absoluteString]; + if (!image) { + if ([URL.absoluteString isEqualToString:AboutUnknown]) { + image = [self unknownImage]; + } else { + NSData *data = [self cachedDataForURL:URL]; + if (data) { + image = [UIImage imageWithData:data]; + } + } + if (image) { + image = [self nonIndexedImageWithImage:image]; + [self setCachedImage:image + forURL:URL]; + } + } + return image; +} + ++ (void)setCachedImage:(UIImage *)image + forURL:(NSURL *)URL +{ + [[self imageCache] setObject:image + forKey:URL.absoluteString]; +} + ++ (UIImage *)thumbnailImageForURL:(NSURL *)URL + size:(CGFloat)size +{ + NSCache *sizeCache = [self imageCacheAtSize:size]; + UIImage *image = [sizeCache objectForKey:URL.absoluteString]; + if (!image) { + image = [self cachedImageForURL:URL]; + if (image) { + CGFloat scale = [UIScreen mainScreen].scale; + image = [image thumbnailImage:size * scale + transparentBorder:0 + cornerRadius:size * scale / 2 + interpolationQuality:kCGInterpolationHigh]; + if (image) { + [sizeCache setObject:image + forKey:URL.absoluteString]; + } else { + TFLog(@"[%@] Could not create thumbnail image %@", URL.host, + URL.hp_fullPath); + } + } + } + return image; +} + +- (BOOL)isOpaque +{ + return NO; +} + +- (void)setStack:(BOOL)stack +{ + if (stack == _stack) { + return; + } + _stack = stack; + self.imageView.frame = self.imageFrame; + [self setNeedsDisplay]; +} + +- (CGRect)imageFrame +{ + CGFloat scale = [UIScreen mainScreen].scale; + CGFloat sizeOffset = 2 * ImageOffset; + if (self.isStack) { + sizeOffset += ShadowOffset; + } + return CGRectMake(ImageOffset / scale, ImageOffset / scale, + CGRectGetWidth(self.frame) - sizeOffset / scale, + CGRectGetHeight(self.frame) - sizeOffset / scale); +} + +- (UIImageView *)imageView +{ + if (_imageView) { + return _imageView; + } + + _imageView = [[UIImageView alloc] initWithFrame:self.imageFrame]; + [self addSubview:_imageView]; + + return _imageView; +} + +- (UIImageView *)connectedView +{ + if (!_connectedView) { + _connectedView = [[UIImageView alloc] initWithImage:[self.class connectedImage]]; + _connectedView.autoresizingMask = + UIViewAutoresizingFlexibleLeftMargin | + UIViewAutoresizingFlexibleTopMargin; + _connectedView.hidden = YES; + CGRect frame = _connectedView.frame; + frame.origin.x = self.frame.size.width - frame.size.width; + frame.origin.y = self.frame.size.height - frame.size.height; + _connectedView.frame = frame; + [self addSubview:_connectedView]; + } + return _connectedView; +} + +- (void)requestImageWithAnimated:(BOOL (^)(void))animated +{ + NSURL *URL = _URL; + NSURLRequest *request = [NSURLRequest requestWithURL:URL + cachePolicy:NSURLRequestReturnCacheDataElseLoad + timeoutInterval:60]; + [NSURLConnection sendAsynchronousRequest:request + queue:[NSOperationQueue mainQueue] + completionHandler:^(NSURLResponse *response, + NSData *data, + NSError *error) + { + if (error) { + TFLog(@"[%@] Could not load image %@: %@", URL.host, + URL.hp_fullPath, error); + return; + } + UIImage *image; + if ([response isKindOfClass:[NSHTTPURLResponse class]] && + [(NSHTTPURLResponse *)response statusCode] == 200) { + image = [UIImage imageWithData:data]; + } + if (image) { + image = [self.class nonIndexedImageWithImage:image]; + [self.class setCachedImage:image + forURL:URL]; + } + if (!image || ![URL isEqual:_URL]) { + return; + } + image = [self.class thumbnailImageForURL:URL + size:self.frame.size.height]; + if (animated()) { + [UIView transitionWithView:self + duration:0.25 + options:UIViewAnimationOptionTransitionCrossDissolve + animations:^{ + self.imageView.image = image; + } + completion:NULL]; + } else { + self.imageView.image = image; + } + }]; +} + +- (void)setURL:(NSURL *)URL + connected:(BOOL)connected + animated:(BOOL)animated +{ + [self setURL:URL + connected:connected + animatedBlock:^{ return animated; }]; +} + +- (void)setURL:(NSURL *)URL + connected:(BOOL)connected + animatedBlock:(BOOL (^)(void))animated +{ + UIImage *image; + BOOL setImage = ![_URL isEqual:URL] || !URL != !self.imageView.image; + if (setImage) { + _URL = URL; + if (URL) { + image = [self.class thumbnailImageForURL:URL + size:self.frame.size.height]; + } + if (!image) { + image = [self.class thumbnailImageForURL:[NSURL URLWithString:AboutUnknown] + size:self.frame.size.height]; + if (URL) { + HPLog(@"[%@] Need to download %@", URL.host, URL.hp_fullPath); + [self requestImageWithAnimated:animated]; + } + } + } + void (^animations)(void) = ^{ + if (setImage) { + self.imageView.image = image; + } + self.connectedView.hidden = !connected; + }; + if (animated()) { + [UIView transitionWithView:self + duration:0.25 + options:UIViewAnimationOptionTransitionCrossDissolve + animations:animations + completion:NULL]; + } else { + animations(); + } +} + +- (void)drawRect:(CGRect)rect +{ + CGFloat scale = [UIScreen mainScreen].scale; + CGContextRef ctx = UIGraphicsGetCurrentContext(); + + [[UIColor hp_darkGreenColor] setStroke]; + [[UIColor whiteColor] setFill]; + CGContextSetLineWidth(ctx, 1 / scale); + + CGFloat size = 2 * CircleOffset; + if (self.isStack) { + size += ShadowOffset; +#if 1 + CGContextAddEllipseInRect(ctx, CGRectMake(rect.origin.x + (CircleOffset + 3) / scale, + rect.origin.y + (CircleOffset + 4) / scale, + rect.size.width - size / scale, + rect.size.height - size / scale)); + CGContextDrawPath(ctx, kCGPathFillStroke); +#endif + CGContextSetShadow(ctx, CGSizeMake(0, 1), 1); + } + + CGContextAddEllipseInRect(ctx, CGRectMake(rect.origin.x + CircleOffset / scale, + rect.origin.y + CircleOffset / scale, + rect.size.width - size / scale, + rect.size.height - size / scale)); + CGContextDrawPath(ctx, kCGPathFillStroke); +} + +@end diff --git a/client/ios/Hackpad/Hackpad/HPUserInfosViewController.h b/client/ios/Hackpad/Hackpad/HPUserInfosViewController.h new file mode 100644 index 0000000..616c4d6 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPUserInfosViewController.h @@ -0,0 +1,22 @@ +// +// HPUserInfosViewController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPUserInfoCollection; +@class HPPad; + +@interface HPUserInfosViewController : UITableViewController + +@property (nonatomic, strong) IBOutlet UIBarButtonItem *doneItem; +@property (nonatomic, strong) HPPad *pad; +@property (nonatomic, strong) HPUserInfoCollection *userInfos; + +- (IBAction)done:(id)sender; + +@end diff --git a/client/ios/Hackpad/Hackpad/HPUserInfosViewController.m b/client/ios/Hackpad/Hackpad/HPUserInfosViewController.m new file mode 100644 index 0000000..ea477a2 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/HPUserInfosViewController.m @@ -0,0 +1,173 @@ +// +// HPUserInfosViewController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPUserInfosViewController.h" + +#import + +#import "HPUserInfoImageView.h" +#import "HPUserInfoCell.h" + +enum { + LabelTag = 1, + DetailLabelTag, + ImageTag +}; + +@interface HPUserInfosViewController () { + HPUserInfo *_actionInfo; + id _addObserver; + id _removeObserver; +} +@end + +@implementation HPUserInfosViewController + +#pragma mark - User infos + +- (IBAction)done:(id)sender +{ + [self dismissViewControllerAnimated:YES + completion:NULL]; +} + +#pragma mark - Object + +- (void)dealloc +{ + if (_addObserver) { + [[NSNotificationCenter defaultCenter] removeObserver:_addObserver]; + } + if (_removeObserver) { + [[NSNotificationCenter defaultCenter] removeObserver:_removeObserver]; + } +} + +#pragma mark - View controller + +- (void)viewDidLoad +{ + [super viewDidLoad]; + [self.navigationItem setRightBarButtonItem:self.editButtonItem + animated:YES]; + _addObserver = [[NSNotificationCenter defaultCenter] addObserverForName:HPUserInfoCollectionDidAddUserInfoNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + if (note.object != self.userInfos) { + return; + } + NSUInteger row = [note.userInfo[HPUserInfoCollectionUserInfoIndexKey] unsignedIntegerValue]; + [self.tableView beginUpdates]; + [self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row + inSection:0]] + withRowAnimation:UITableViewRowAnimationAutomatic]; + [self.tableView endUpdates]; + }]; + _removeObserver = [[NSNotificationCenter defaultCenter] addObserverForName:HPUserInfoCollectionDidRemoveUserInfoNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + if (note.object != self.userInfos) { + return; + } + NSUInteger row = [note.userInfo[HPUserInfoCollectionUserInfoIndexKey] unsignedIntegerValue]; + [self.tableView beginUpdates]; + [self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row + inSection:0]] + withRowAnimation:UITableViewRowAnimationAutomatic]; + [self.tableView endUpdates]; + }]; +} + +- (void)setEditing:(BOOL)editing + animated:(BOOL)animated +{ + [super setEditing:editing + animated:animated]; + [self.navigationItem setLeftBarButtonItem:editing ? nil : self.doneItem + animated:animated]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return self.userInfos.userInfos.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView + cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString *CellIdentifier = @"Cell"; + HPUserInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier + forIndexPath:indexPath]; + if (cell.userInfo) { + cell.userInfo = nil; + } + HPUserInfo *userInfo = self.userInfos.userInfos[indexPath.row]; + [cell setUserInfo:userInfo + animated:!userInfo.userPicURL]; + + return cell; +} + +- (void)tableView:(UITableView *)tableView +commitEditingStyle:(UITableViewCellEditingStyle)editingStyle +forRowAtIndexPath:(NSIndexPath *)indexPath +{ + NSParameterAssert(editingStyle == UITableViewCellEditingStyleDelete); + HPUserInfo *userInfo = self.userInfos.userInfos[indexPath.row]; + [self.pad removeUserWithId:userInfo.userID + completion:^(HPPad *pad, NSError *error) + { + if (error) { + [[[UIAlertView alloc] initWithTitle:@"Request Failed" + message:error.localizedDescription + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; + } else { + [self.userInfos removeUserInfo:userInfo]; + } + }]; +} + +#pragma mark - Table view delegate + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + // Navigation logic may go here. Create and push another view controller. + /* + <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; + // ... + // Pass the selected object to the new view controller. + [self.navigationController pushViewController:detailViewController animated:YES]; + */ +} + +- (BOOL)tableView:(UITableView *)tableView +shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath +{ + return NO; +} + +- (NSString *)tableView:(UITableView *)tableView +titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return @"Remove"; +} + +@end diff --git a/client/ios/Hackpad/Hackpad/Hackpad-Info.plist b/client/ios/Hackpad/Hackpad/Hackpad-Info.plist new file mode 100644 index 0000000..219fbc6 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/Hackpad-Info.plist @@ -0,0 +1,85 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME}${BUNDLE_DISPLAY_NAME_SUFFIX} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIcons + + CFBundleIcons~ipad + + CFBundleIdentifier + com.hackpad.${PRODUCT_NAME:rfc1034identifier}${BUILD_IDENTIFIER_SUFFIX} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.2 + CFBundleSignature + ???? + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLIconFile + Icon + CFBundleURLName + com.hackpad.Hackpad${BUILD_IDENTIFIER_SUFFIX} + CFBundleURLSchemes + + https + hackpad${BUILD_IDENTIFIER_SUFFIX} + + + + CFBundleURLSchemes + + fb145393915506961 + + + + CFBundleVersion + 0 + FacebookAppID + 145393915506961 + LSRequiresIPhoneOS + + UIBackgroundModes + + remote-notification + + UIMainStoryboardFile + MainStoryboard_iPhone + UIMainStoryboardFile~ipad + MainStoryboard_iPad + UIPrerenderedIcon + + UIRequiredDeviceCapabilities + + armv7 + + UIStatusBarStyle + UIStatusBarStyleDefault + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/client/ios/Hackpad/Hackpad/Hackpad-Prefix.pch b/client/ios/Hackpad/Hackpad/Hackpad-Prefix.pch new file mode 100644 index 0000000..cab0719 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/Hackpad-Prefix.pch @@ -0,0 +1,19 @@ +// +// Prefix header for all source files of the 'Hackpad' target in the 'Hackpad' project +// + +#import + +#ifndef __IPHONE_5_0 +#warning "This project uses features only available in iOS SDK 5.0 and later." +#endif + +#ifdef __OBJC__ + #import + #import + #import + #import + #import + #import "HPFlurryEventKeys.h" + #import "HPLog.h" +#endif diff --git a/client/ios/Hackpad/Hackpad/Hackpad.js b/client/ios/Hackpad/Hackpad/Hackpad.js new file mode 100644 index 0000000..016728e --- /dev/null +++ b/client/ios/Hackpad/Hackpad/Hackpad.js @@ -0,0 +1,563 @@ +(function () { + function Hackpad() { var bridge; try { + console.log('Hackpad()'); + // Check that this seems like a pad page. + var failedURLs = []; + if (typeof $ != 'undefined') { + failedURLs = $('link').filter(function (idx) { + return this.loadError; + }).map(function (idx, link) { + return link.href; + }).toArray(); + } + if (typeof $ == 'undefined' || typeof clientVars == 'undefined' || failedURLs.length) { + // console.log('$:', window.$, 'clientVars:', window.clientVars, 'failedURLs:', failedURLs); + return JSON.stringify({ loaded: false, + typeofJQuery: typeof $, + typeofClientVars: typeof clientVars, + failedURLs: failedURLs }); + } + delete failedURLs; + + function getNewPadClientVars() { + return { + newPad: true, + userColor: 0, + isProPad: true, + isCreator: true, + isPublicPad: false, + invitedUserInfos: [pad.myUserInfo], + invitedGroupInfos: [], + initialTitle: '', + padTitle: 'Untitled', + collab_client_vars: { + apool: { + nextNum: 0, + numToAttrib: {} + }, + historicalAuthorData: {}, + initialAttributedText: { + attribs: '|4+4', + text: '%0A%0A%0A%0A' + }, + rev: 1 + } + }; + } + + // Set up the Obj-C bridge. + function buildBridge (event) { + console.log('WebViewJavascriptBridgeReady'); + bridge = (event || {}).bridge || window.WebViewJavascriptBridge; + function bridgeLog (oldFunc) { + var prefix = $.makeArray(arguments).slice(1); + return function() { + oldFunc && oldFunc.apply(this, arguments); + var isError = arguments.callee == console.error; + arguments = $.map($.makeArray(arguments), function (v) { + try { + JSON.stringify(v); + return $.isArray(v) ? [v] : v; + } catch (exception) { + return v.toString(); + } + }); + bridge.callHandler('log', { + arguments: $.merge($.merge([], prefix), arguments), + error: isError + }); + } + } + console.log = bridgeLog(console.log); + console.error = bridgeLog(console.error, '[error]'); + console.warn = bridgeLog(console.warn, '[warn]'); + console.info = bridgeLog(console.info, '[info]'); + console.log('WebViewJavascriptBridgeReady'); + + bridge.init(function (data, responseCallback) { + console.log("Unhandle bridge callback:", data, responseCallback); + }); + + bridge.registerHandler('autocomplete', function (data, responseCallback) { + padautolink.finish(data.selected, data.selectedIndex); + }); + + bridge.registerHandler('quickCam', function () { + padeditor.ace.callWithAce(function (ace) { + ace.ace_beginAppending(); + }); + }); + + bridge.registerHandler('insertImage', function (data, responseCallback) { + /*var jpegData = atob(data); + var ab = new ArrayBuffer(jpegData.length); + var ia = new Uint8Array(ab); + for (var i = 0; i < jpegData.length; i++) { + ia[i] = jpegData.charCodeAt(i); + }*/ + padeditor.ace.callWithAce(function(ace) { + ace.ace_doInsertImageBlob(data /*new Blob([ab], {type: 'image/jpeg'})*/); + }); + }); + + bridge.registerHandler('canUndoRedo', function (data, responseCallback) { + padeditor.ace.callWithAce(function (ace) { + responseCallback({ undo: ace.ace_canUndoRedo('undo'), + redo: ace.ace_canUndoRedo('redo') }); + }); + }); + + bridge.registerHandler('doUndoRedo', function (data, responseCallback) { + padeditor.ace.callWithAce(function (ace) { + ace.ace_doUndoRedo(data); + }, data, true); + }); + + bridge.registerHandler('insertText', function (data, responseCallback) { + padeditor.ace.callWithAce(function (ace) { + ace.ace_performDocumentReplaceSelection(data); + }, 'insertText', true); + }); + + bridge.registerHandler('doDeleteKey', function (data, responseCallback) { + padeditor.ace.callWithAce(function (ace) { + ace.ace_doDeleteKey(); + }, 'deleteKey', true); + }); + + bridge.registerHandler('doReturnKey', function (data, responseCallback) { + padeditor.ace.callWithAce(function (ace) { + ace.ace_doReturnKey(); + }, 'returnKey', true); + }); + + bridge.registerHandler('doToolbarClick', function (data, responseCallback) { + var heading = data.match(/^heading(\d)$/); + if (heading) { + padeditor.ace.callWithAce(function (ace) { + ace.ace_doSetHeadingLevel(heading[1]); + }); + } else { + padeditbar.toolbarClick(data); + } + }); + + function updateViewportWidth(width) { + $('meta[name=viewport]').attr('content', $('meta[name=viewport]').attr('content').split(',').map(function(keyval) { + var kv = keyval.split('=').map(function(kv) { + return kv.trim(); + }); + if (kv[0] == 'width') { + kv[1] = width; + } + return kv.join('='); + }).join(',')); + } + bridge.registerHandler('updateViewportWidth', function (data, responseCallback) { + updateViewportWidth(data); + }); + setTimeout(function () { + bridge.callHandler('getViewportWidth', null, function (data) { + if (data) { + updateViewportWidth(data); + } + }); + }); + + bridge.registerHandler('addClientVars', function (data, responseCallback) { + $(function () { + var thrown; + try { + pad.addClientVars(data || getNewPadClientVars()); + } catch (e) { + thrown = e; + throw e; + } finally { + responseCallback({ + success: !thrown, + error: thrown + }); + } + }); + }); + + bridge.registerHandler('getClientVarsAndText', function (clientVars, responseCallback) { + var response; + try { + if (typeof pad === 'undefined' || !pad.collabClient) { + return; + } + padeditor.ace.callWithAce(function (ace) { + if (!ace.ace_getBaseAttributedText) { + return; + } + var baseAText = ace.ace_getBaseAttributedText(); + var rep = ace.ace_getRep(); + baseAText.text = escape(baseAText.text); + var retClientVars = $.extend(/* deep */ true, {}, clientVars || getNewPadClientVars(), { + collab_client_vars: { + apool: rep.apool.toJsonable(), + initialAttributedText: baseAText, + rev: pad.collabClient.getCurrentRevisionNumber() + }, + newPad: false, + padTitle: rep.lines.atIndex(0).text + }); + // Overwrite this instead of extending, as getMissedChanges() + // doesn't provide values if there weren't changes. + retClientVars.collab_client_vars.missedChanges = pad.collabClient.getMissedChanges(); + response = { + clientVars: retClientVars, + text: ace.ace_exportText() + }; + }, 'getClientVarsAndText', true); + } catch (e) { + response = { + error: e + }; + } finally { + responseCallback(response); + } + }); + + bridge.registerHandler('setVisibleEditorHeight', function (height, responseCallback) { + if (!padeditor.setVisibleHeight) { + return; + } + padeditor.setVisibleHeight(height); + padeditor.ace.callWithAce(function (ace) { + if (ace.ace_scrollSelectionIntoView) { + ace.ace_scrollSelectionIntoView(); + } + }); + }); + + bridge.registerHandler('reconnectCollabClient', function (data, responseCallback) { + if (!pad || !pad.collabClient) { + return; + } + // reconnect() checks that it's in DISCONNECTED for us. + pad.collabClient.reconnect(); + }); + + bridge.registerHandler('setAttachmentURL', function (data, responseCallback) { + padeditor.ace.callWithAce(function (ace) { + ace.ace_setAttachmentUrl && ace.ace_setAttachmentUrl(data.attachmentId, + data.url, data.key); + responseCallback(); + }); + }); + + // Stuff that requires both the bridge and pad. + $(function () { + var ProximaNovaLightTextFace = '"ProximaNova-Light"'; + console.log('$(WebViewJavascriptBridgeReady)'); + if (typeof pad == 'undefined') { + bridge.callHandler('documentDidFailLoad'); + return; + } + + function delayedCall(callback, timeout) { + var timer = 0; + return function () { + if (timer) { + clearTimeout(timer); + } + timer = setTimeout(function () { + timer = 0; + callback(); + }, timeout); + }; + } + + var oldTitleHandler = pad.handleNewTitle; + // The first time this is called is in pad.init(), after initializing + // padeditor.ace and pad.collabClient, so this is a good time to add + // our hooks to those. + pad.handleNewTitle = function(title) { + console.log('handleNewTitle()'); + // No need to update on every keypress. + var setTitleDelayed = delayedCall(function () { + bridge.callHandler('setTitle', pad.title); + }, 250); + pad.handleNewTitle = function (title) { + if (pad.getPadId()) { + oldTitleHandler.apply(this, arguments); + setTitleDelayed(); + } + } + pad.handleNewTitle(title); + + var oldUserJoin = pad.handleUserJoin; + pad.handleUserJoin = function (userInfo) { + oldUserJoin(userInfo); + bridge.callHandler('userInfo', { userInfo: userInfo, addUser: true }); + }; + var oldUserUpdate = pad.handleUserUpdate; + pad.handleUserUpdate = function (userInfo) { + oldUserUpdate(userInfo); + bridge.callHandler('userInfo', { userInfo: userInfo, addUser: true }); + }; + var oldUserLeave = pad.handleUserLeave; + pad.handleUserLeave = function (userInfo) { + oldUserLeave(userInfo); + bridge.callHandler('userInfo', { userInfo: userInfo, addUser: false }); + }; + var oldUserKill = pad.handleUserKill; + pad.handleUserKill = function (userInfo) { + oldUserKill(userInfo); + bridge.callHandler('userInfo', { userInfo: userInfo, addUser: false }); + }; + + var handleNetworkActivity = delayedCall(function () { + var channelState = pad.collabClient.getChannelState + ? pad.collabClient.getChannelState() + : pad.collabClient.getDiagnosticInfo().channelState; + bridge.callHandler('setHasNetworkActivity', + channelState != 'DISCONNECTED' && + (channelState.indexOf('CONNECTING') >= 0 || + pad.collabClient.hasUncommittedChanges())); + }, 1000); + + // collabClient initializes itself as CONNECTING. + // var oldChannelStateChange = pad.handleChannelStateChange; + pad.handleChannelStateChange = function (channelState, moreInfo) { + //console.log('state change:', arguments); + // I think we handle anything needed here natively? + // oldChannelStateChange.apply(this, arguments); + switch (channelState) { + case 'CONNECTED': + bridge.callHandler('collabClientDidConnect'); + break; + case 'DISCONNECTED': + bridge.callHandler('collabClientDidDisconnect', + pad.collabClient.hasUncommittedChanges()); + break; + } + handleNetworkActivity(); + }; + + var handleSynchronize = delayedCall(function () { + if (!pad.collabClient.hasUncommittedChanges) { + return; + } + bridge.callHandler('collabClientDidSynchronize'); + }, 1000); + var oldCollabAction = pad.handleCollabAction; + pad.handleCollabAction = function (action) { + // console.log('collab action:', arguments); + oldCollabAction.apply(this, arguments); + handleNetworkActivity(); + if (action != 'commitAcceptedByServer') { + return; + } + handleSynchronize(); + } + + if (pad.collabClient) { + pad.collabClient.setOnUserJoin(pad.handleUserJoin); + pad.collabClient.setOnUpdateUserInfo(pad.handleUserUpdate); + pad.collabClient.setOnUserLeave(pad.handleUserLeave); + pad.collabClient.setOnUserKill(pad.handleUserKill); + pad.collabClient.setOnChannelStateChange(pad.handleChannelStateChange); + pad.collabClient.setOnInternalAction(pad.handleCollabAction); + pad.collabClient.setOnConnectionTrouble(function (msg) { + if (msg != 'OK') { + //console.log('connection trouble:', msg, pad.collabClient.getDiagnosticInfo().debugMessages); + bridge.callHandler('connectionTrouble', { + message: msg, + debugMessages: $.makeArray(pad.collabClient.getDiagnosticInfo().debugMessages) + }); + } + }); + } + + padeditor.ace.callWithAce(function (ace) { + console.log('Hackpad.callWithAce()'); + if (!pad.monospace) { + ace.ace_setProperty('textface', ProximaNovaLightTextFace); + } + ace.ace_setOnOpenLink && ace.ace_setOnOpenLink(function (href, internal) { + bridge.callHandler('openLink', { href: href, internal: internal }); + }); + ace.ace_setOnAttach(function (imageBlob, attachmentId) { + var s3bucket = clientVars.attachmentsBucket || 'hackpad-attachments'; + var s3BucketRoot = clientVars.s3BucketRoot || 's3.amazonaws.com'; + var rootURL = "https://" + s3bucket + "." + s3BucketRoot + "/"; + bridge.callHandler('uploadImage', { + imageBlob: imageBlob, + attachmentId: attachmentId, + rootURL: rootURL, + }); + }); + + // This happens in debug builds. + if (pad.initTime && clientVars.newPad) { + padeditor.ace.focus(); + } + }, true, 'Hackpad.callWithAce()'); + }; // handleNewTitle() + // If pad.init has already been called. + if (pad.collabClient || pad.newPad) { + pad.handleNewTitle(pad.getTitle() || ''); + } + + var oldOptionsHandler = pad.handleOptionsChange; + pad.handleOptionsChange = function (opts) { + oldOptionsHandler.apply(this, arguments); + bridge.callHandler('setSharingOptions', opts); + }; + + var oldViewOptionsFunc = padeditor.setViewOptions; + padeditor.setViewOptions = function (opts) { + oldViewOptionsFunc(opts); + var monospaceUnset = String(opts['useMonospaceFont']) == 'false'; + if (!monospaceUnset) { + return; + } + padeditor.ace.callWithAce(function (ace) { + ace.ace_setProperty('textface', ProximaNovaLightTextFace); + }); + }; + + var oldShowModal = modals.showModal; + modals.showModal = function (modalId) { + switch (modalId) { + case '#page-login-box': + bridge.callHandler('signIn'); + break; + case'#freakout-dialog': + bridge.callHandler('freakOut'); + break; + case '#connectionbox': + // we already detect status == DISCONNECTED natively + break; + default: + oldShowModal.apply(this, arguments); + break; + } + }; + if (!window.onfreakout) { + window.onfreakout = function(msg) { + modals.showModal("#freakout-dialog", 0, true /* not cancellable */); + }; + } + + if (padautolink.setAutocompleteHandler) { + padautolink.setAutocompleteHandler(function (method, data) { + if (data) { + data = $.map(data, function (contact) { + var item = $('
').html(contact.data[0]); + var img = item.find('img'); + return { + title: item.text(), + image: img && img.attr('src'), + data: contact + }; + }); + } + bridge.callHandler('autocomplete', {method:method, data:data}); + }); + } + + pad.handleDelete = function () { + bridge.callHandler('deletePad'); + }; + }); // $(WebViewJavascriptBridgeReady) + } + if (window.WebViewJavascriptBridge) { + setTimeout(buildBridge); + } else { + document.addEventListener('WebViewJavascriptBridgeReady', buildBridge, false); + } + + // And finally our UIWebView iframe focus hack. + // These need to be synchronous so we can't use the bridge. + var restoreFocus; + window.hackpadKit.saveFocus = function() { + var elem = document.activeElement; + if (elem == document.body) { + return !!restoreFocus; + } + while ('contentDocument' in elem) { + elem = elem.contentDocument.activeElement; + } + var selection = elem.ownerDocument.getSelection(); + var ranges = []; + for (var i = 0; i < selection.rangeCount; i++) { + ranges[i] = selection.getRangeAt(i); + } + if (!ranges.length) { + console.log('no ranges in selection:', selection); + return false; + } + var savedAt = new Date; + restoreFocus = function() { + console.log('restoring focus after', (new Date - savedAt) / 1000, 'seconds.'); + elem.focus(); + // Without focusing the window, events fire but text isn't added to DOM. + elem.ownerDocument.defaultView.focus(); + if (ranges.length) { + var selection = elem.ownerDocument.getSelection(); + selection.removeAllRanges(); + for (var i = 0; i < ranges.length; i++) { + selection.addRange(ranges[i]); + } + } + selection.focusNode.parentNode.scrollIntoView(true); + restoreFocus = null; + }; + return true; + }; + + window.hackpadKit.restoreFocus = function () { + restoreFocus && restoreFocus(); + }; +/* + $('head').append( + '' + ); +*/ + // Preload a table iframe to make sure it's cached. + $('body').append(''); + + return JSON.stringify({ + loaded: true, + padID: clientVars.padId, + userID: clientVars.userId, + invitedUserInfos: clientVars.invitedUserInfos + }); + } catch (e) { + if (!bridge) { + window.hackpadException = e; + console.log('exception loading:', e); + return; + } + bridge.callHandler('documentDidFailLoad', e); + } + } // Hackpad + if (window.hackpadKit) { + return JSON.stringify({ loaded: false }); + } + window.hackpadKit = {}; + if (document.readyState === 'complete' || document.readyState === 'interactive') { + setTimeout(Hackpad); + } else { + document.addEventListener('DOMContentLoaded', Hackpad, false ); + document.addEventListener('load', Hackpad, false); + } + return JSON.stringify({ loaded: true }); +})(); diff --git a/client/ios/Hackpad/Hackpad/PadCell.xib b/client/ios/Hackpad/Hackpad/PadCell.xib new file mode 100644 index 0000000..24da38d --- /dev/null +++ b/client/ios/Hackpad/Hackpad/PadCell.xib @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/Hackpad/Settings.bundle/Root.plist b/client/ios/Hackpad/Hackpad/Settings.bundle/Root.plist new file mode 100644 index 0000000..6d234fb --- /dev/null +++ b/client/ios/Hackpad/Hackpad/Settings.bundle/Root.plist @@ -0,0 +1,45 @@ + + + + + PreferenceSpecifiers + + + Type + PSToggleSwitchSpecifier + Title + Reset on Next Launch + Key + resetOnLaunch + DefaultValue + + + + DefaultValue + + Key + devServer + Title + Use Local Server + Type + PSToggleSwitchSpecifier + + + Type + PSGroupSpecifier + Title + + + + Type + PSChildPaneSpecifier + Title + Acknowledgements + File + Acknowledgements + + + StringsTable + Root + + diff --git a/client/ios/Hackpad/Hackpad/Settings.bundle/en.lproj/Root.strings b/client/ios/Hackpad/Hackpad/Settings.bundle/en.lproj/Root.strings new file mode 100644 index 0000000..8cd87b9 Binary files /dev/null and b/client/ios/Hackpad/Hackpad/Settings.bundle/en.lproj/Root.strings differ diff --git a/client/ios/Hackpad/Hackpad/en.lproj/InfoPlist.strings b/client/ios/Hackpad/Hackpad/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..477b28f --- /dev/null +++ b/client/ios/Hackpad/Hackpad/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/client/ios/Hackpad/Hackpad/en.lproj/MainStoryboard_iPad.storyboard b/client/ios/Hackpad/Hackpad/en.lproj/MainStoryboard_iPad.storyboard new file mode 100644 index 0000000..b1718f6 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/en.lproj/MainStoryboard_iPad.storyboard @@ -0,0 +1,943 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/Hackpad/en.lproj/MainStoryboard_iPhone.storyboard b/client/ios/Hackpad/Hackpad/en.lproj/MainStoryboard_iPhone.storyboard new file mode 100644 index 0000000..032c306 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/en.lproj/MainStoryboard_iPhone.storyboard @@ -0,0 +1,986 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/Hackpad/en.lproj/SignIn_iPad.storyboard b/client/ios/Hackpad/Hackpad/en.lproj/SignIn_iPad.storyboard new file mode 100644 index 0000000..4f041b9 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/en.lproj/SignIn_iPad.storyboard @@ -0,0 +1,293 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/Hackpad/en.lproj/SignIn_iPhone.storyboard b/client/ios/Hackpad/Hackpad/en.lproj/SignIn_iPhone.storyboard new file mode 100644 index 0000000..2c18885 --- /dev/null +++ b/client/ios/Hackpad/Hackpad/en.lproj/SignIn_iPhone.storyboard @@ -0,0 +1,292 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/Hackpad/main.m b/client/ios/Hackpad/Hackpad/main.m new file mode 100644 index 0000000..64215fa --- /dev/null +++ b/client/ios/Hackpad/Hackpad/main.m @@ -0,0 +1,18 @@ +// +// main.m +// Hackpad +// +// +// Copyright (c) 2012 Hackpad. All rights reserved. +// + +#import + +#import "HPAppDelegate.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([HPAppDelegate class])); + } +} diff --git a/client/ios/Hackpad/HackpadAdditions/HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/HackpadAdditions.h new file mode 100644 index 0000000..6792ef9 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/HackpadAdditions.h @@ -0,0 +1,18 @@ +// +// HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import diff --git a/client/ios/Hackpad/HackpadAdditions/HackpadUIAdditions.h b/client/ios/Hackpad/HackpadAdditions/HackpadUIAdditions.h new file mode 100644 index 0000000..aa9c21f --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/HackpadUIAdditions.h @@ -0,0 +1,15 @@ +// +// HackpadUIAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import +#import +#import +#import +#import +#import diff --git a/client/ios/Hackpad/HackpadAdditions/NSAttributedString+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/NSAttributedString+HackpadAdditions.h new file mode 100644 index 0000000..1257f9d --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSAttributedString+HackpadAdditions.h @@ -0,0 +1,19 @@ +// +// NSAttributedString+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface NSAttributedString (HackpadAdditions) + ++ (NSAttributedString *)hp_initWithString:(NSString *)string + attributes:(NSDictionary *)attributes + highlightingKeywords:(NSString *)highlightingKeywords + highlightingAttributes:(NSDictionary *)highlightingAttributes + maxLengthOfKeywordRange:(NSUInteger)maxLengthOfKeywordRange; + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSAttributedString+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/NSAttributedString+HackpadAdditions.m new file mode 100644 index 0000000..ab8c060 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSAttributedString+HackpadAdditions.m @@ -0,0 +1,94 @@ +// +// NSAttributedString+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "NSAttributedString+HackpadAdditions.h" + +@implementation NSAttributedString (HackpadAdditions) + ++ (NSAttributedString *)hp_initWithString:(NSString *)string + attributes:(NSDictionary *)attributes + highlightingKeywords:(NSString *)highlightingKeywords + highlightingAttributes:(NSDictionary *)highlightingAttributes + maxLengthOfKeywordRange:(NSUInteger)maxLengthOfKeywordRange; +{ + maxLengthOfKeywordRange /= 2; + NSParameterAssert(string.length); + + string = [string stringByReplacingOccurrencesOfString:@"\\s+" + withString:@" " + options:NSRegularExpressionSearch + range:NSMakeRange(0, string.length)]; + /** + * Find all keywords' occurrences. + */ + NSMutableIndexSet *snippetRanges = [NSMutableIndexSet indexSet]; + NSMutableIndexSet *highlightedRanges = [NSMutableIndexSet indexSet]; + [highlightingKeywords enumerateSubstringsInRange:NSMakeRange(0, highlightingKeywords.length) + options:NSStringEnumerationByWords + usingBlock:^(NSString *keywordSubstring, + NSRange keywordSubstringRange, + NSRange keywordEnclosingRange, + BOOL *stop) + { + NSRange searchRange = NSMakeRange(0, string.length); + NSRange highlightedRange; + NSRange snippetRange; + while (searchRange.location < string.length) { + searchRange.length = string.length - searchRange.location; + highlightedRange = [string rangeOfString:keywordSubstring + options:NSCaseInsensitiveSearch + range:searchRange]; + if (highlightedRange.location == NSNotFound) { + break; + } + [highlightedRanges addIndexesInRange:highlightedRange]; + searchRange.location = highlightedRange.location + highlightedRange.length; + + snippetRange.location = highlightedRange.location + highlightedRange.length / 2; + if (snippetRange.location < maxLengthOfKeywordRange) { + snippetRange.location = 0; + } else { + snippetRange.location -= maxLengthOfKeywordRange; + } + snippetRange.length = 2 * maxLengthOfKeywordRange; + snippetRange = NSIntersectionRange(snippetRange, NSMakeRange(0, string.length)); + [snippetRanges addIndexesInRange:snippetRange]; + } + }]; + + if (!highlightedRanges.count) { + return nil; + } + + NSMutableAttributedString * __block searchSnippets; + [snippetRanges enumerateRangesUsingBlock:^(NSRange range, BOOL *stop) { + if (searchSnippets) { + [searchSnippets appendAttributedString:[[NSAttributedString alloc] initWithString:@"..." + attributes:attributes]]; + } + NSMutableAttributedString *snippet = [[NSMutableAttributedString alloc] initWithString:[string substringWithRange:range] + attributes:attributes]; + [highlightedRanges enumerateRangesInRange:range + options:0 + usingBlock:^(NSRange highlightRange, BOOL *stop) + { + highlightRange.location -= range.location; + [snippet addAttributes:highlightingAttributes + range:highlightRange]; + }]; + if (searchSnippets) { + [searchSnippets appendAttributedString:snippet]; + } else { + searchSnippets = snippet; + } + }]; + + return searchSnippets.length ? searchSnippets : nil; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSData+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/NSData+HackpadAdditions.h new file mode 100644 index 0000000..0d13acc --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSData+HackpadAdditions.h @@ -0,0 +1,15 @@ +// +// NSData+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface NSData (HackpadAdditions) + +- (NSString *)hp_hexEncodedString; + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSData+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/NSData+HackpadAdditions.m new file mode 100644 index 0000000..0ac0c48 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSData+HackpadAdditions.m @@ -0,0 +1,24 @@ +// +// NSData+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "NSData+HackpadAdditions.h" + +@implementation NSData (HackpadAdditions) + +- (NSString *)hp_hexEncodedString +{ + NSUInteger length = self.length; + const unsigned char *bytes = (const unsigned char *)self.bytes; + NSMutableString *s = [NSMutableString stringWithCapacity:length * 2]; + for (NSUInteger i = 0; i < length; i++) { + [s appendFormat:@"%.2hhx", bytes[i]]; + } + return s; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSError+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/NSError+HackpadAdditions.h new file mode 100644 index 0000000..5bf2bd2 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSError+HackpadAdditions.h @@ -0,0 +1,13 @@ +// +// NSError+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface NSError (HackpadAdditions) +- (NSError *)hp_errorWithOriginalValidationError:(NSError *)error; +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSError+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/NSError+HackpadAdditions.m new file mode 100644 index 0000000..3a7c5cb --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSError+HackpadAdditions.m @@ -0,0 +1,37 @@ +// +// NSError+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "NSError+HackpadAdditions.h" + +#import + +@implementation NSError (HackpadAdditions) + +- (NSError *)hp_errorWithOriginalValidationError:(NSError *)error +{ + if (!error) { + return self; + } + NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; + NSMutableArray *errors = [NSMutableArray arrayWithObject:self]; + + if (error.code == NSValidationMultipleErrorsError) { + [userInfo addEntriesFromDictionary:error.userInfo]; + [errors addObjectsFromArray:userInfo[NSDetailedErrorsKey]]; + } else { + [errors addObject:error]; + } + + userInfo[NSDetailedErrorsKey] = errors; + + return [NSError errorWithDomain:NSCocoaErrorDomain + code:NSValidationMultipleErrorsError + userInfo:userInfo]; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSManagedObject+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/NSManagedObject+HackpadAdditions.h new file mode 100644 index 0000000..d562622 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSManagedObject+HackpadAdditions.h @@ -0,0 +1,23 @@ +// +// NSManagedObject+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface NSManagedObject (HackpadAdditions) + +- (void)hp_performBlock:(void (^)(id, NSError * __autoreleasing *))block + completion:(void (^)(id, NSError *))handler; + +- (void)hp_updateProperties:(NSArray *)properties + values:(NSDictionary *)values; + +- (void)hp_sendAsynchronousRequest:(NSURLRequest *)request + block:(void (^)(id, NSURLResponse *, NSData *, NSError * __autoreleasing *))block + completion:(void (^)(id, NSError *))handler; + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSManagedObject+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/NSManagedObject+HackpadAdditions.m new file mode 100644 index 0000000..6aad42e --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSManagedObject+HackpadAdditions.m @@ -0,0 +1,113 @@ +// +// NSManagedObject+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "NSManagedObject+HackpadAdditions.h" +#import "HackpadAdditions.h" + +#import "HPError.h" + +//#define DEBUG_COOKIES 1 + +@implementation NSManagedObject (HackpadAdditions) + +- (void)hp_updateProperties:(NSArray *)properties + values:(NSDictionary *)values +{ + for (NSString *property in properties) { + id value = [values objectForKey:property]; + if (value && ![[self valueForKey:property] isEqual:value]) { + [self setValue:value + forKey:property]; + } + } +} + +- (void)hp_performBlock:(void (^)(id, NSError *__autoreleasing *))block + completion:(void (^)(id, NSError *))handler +{ + NSParameterAssert(!self.objectID.isTemporaryID); + + NSManagedObject * __weak weakSelf = self; + NSManagedObjectID *objectID = self.objectID; + NSManagedObjectContext *managedObjectContext = self.managedObjectContext; + NSError * __block error; + [managedObjectContext.hp_stack saveWithBlock:^(NSManagedObjectContext *localContext) { + NSManagedObject *obj = [localContext existingObjectWithID:objectID + error:&error]; + if (obj) { + block(obj, &error); + } + } completion:^(NSError *saveError) { + if (!handler) { + return; + } + [managedObjectContext performBlockAndWait:^{ + handler(weakSelf.managedObjectContext ? weakSelf : nil, + error ? error : saveError); + }]; + }]; +} + +- (void)hp_sendAsynchronousRequest:(NSURLRequest *)request + block:(void (^)(id, NSURLResponse *, NSData *, NSError * __autoreleasing *))block + completion:(void (^)(id, NSError *))handler; + +{ + static NSOperationQueue *operationQueue; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + operationQueue = [[NSOperationQueue alloc] init]; + operationQueue.name = @"NSManagedObject+HackpadAdditions Asynchronous Request Queue"; + }); + +#if DEBUG_COOKIES + [request.URL hp_dumpCookies]; +#endif + + // If this object is deleted, self.managedObjectContext will be nil. Keep + // this around so we can make the callbacks. + NSManagedObjectContext *managedObjectContext = self.managedObjectContext; + NSManagedObject * __weak weakSelf = self; +#if DEBUG + NSDate *date = [NSDate date]; +#endif + [NSURLConnection sendAsynchronousRequest:request + queue:operationQueue + completionHandler:^(NSURLResponse *response, + NSData *data, + NSError *connectionError) + + { + HPLog(@"[%@] Request %@ took %.3f seconds", request.URL.host, + request.URL.hp_fullPath, -date.timeIntervalSinceNow); +#if DEBUG_COOKIES + HPLog(@"[%@] Headers for %@: %@", request.URL.host, + request.URL.hp_fullPath, + [(NSHTTPURLResponse *)response allHeaderFields]); + [request.URL hp_dumpCookies]; +#endif + [managedObjectContext performBlock:^{ + if (!weakSelf.managedObjectContext) { + // Object was deleted. + if (handler) { + handler(nil, nil); + } + return; + } + [weakSelf hp_performBlock:^(NSManagedObject *obj, NSError *__autoreleasing *error) { + if (connectionError && error) { + *error = connectionError; + } + block(obj, response, data, error); + } + completion:handler]; + }]; + }]; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSManagedObjectContext+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/NSManagedObjectContext+HackpadAdditions.h new file mode 100644 index 0000000..30fe6b8 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSManagedObjectContext+HackpadAdditions.h @@ -0,0 +1,20 @@ +// +// NSManagedObjectContext+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPCoreDataStack; + +@interface NSManagedObjectContext (HackpadAdditions) + +@property (nonatomic, strong, setter=hp_setStack:) HPCoreDataStack *hp_stack; +@property (nonatomic, strong, setter=hp_setName:) NSString *hp_name; + +- (BOOL)hp_saveToStore:(NSError * __autoreleasing *)error; + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSManagedObjectContext+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/NSManagedObjectContext+HackpadAdditions.m new file mode 100644 index 0000000..0629cbf --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSManagedObjectContext+HackpadAdditions.m @@ -0,0 +1,100 @@ +// +// NSManagedObjectContext+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "NSManagedObjectContext+HackpadAdditions.h" + +#import + +static NSString *const HPManagedObjectContextNameKey = @"HPManagedObjectContextName"; +static NSString * const HPCoreDataStackKey = @"HPCoreDataStackKey"; + +@implementation NSManagedObjectContext (HackpadAdditions) + +- (HPCoreDataStack *)hp_stack +{ + return self.userInfo[HPCoreDataStackKey]; +} + +- (void)hp_setStack:(HPCoreDataStack *)stack +{ + self.userInfo[HPCoreDataStackKey] = stack; +} + +- (NSString *)hp_name +{ + return self.userInfo[HPManagedObjectContextNameKey]; +} + +- (void)hp_setName:(NSString *)name +{ + self.userInfo[HPManagedObjectContextNameKey] = [name copy]; +} + +- (BOOL)hp_saveToStore:(NSError * __autoreleasing *)error +{ + UIApplication *app = [UIApplication sharedApplication]; + UIBackgroundTaskIdentifier taskID = [app beginBackgroundTaskWithExpirationHandler:^{ + TFLog(@"Warning: %s failed to complete in time.", __PRETTY_FUNCTION__); + }]; + if (taskID == UIBackgroundTaskInvalid) { + TFLog(@"Warning: Background tasks not supported for save."); + } + return [self hp_saveToStoreWithTaskID:taskID + error:error]; +} + +- (BOOL)hp_saveToStoreWithTaskID:(UIBackgroundTaskIdentifier)taskID + error:(NSError * __autoreleasing *)error +{ + NSUInteger deletes = self.deletedObjects.count; + NSSet *insertedObjects = self.insertedObjects; + NSUInteger inserts = insertedObjects.count; + NSUInteger updates = self.updatedObjects.count; + + NSError *saveError; + if (inserts && ![self obtainPermanentIDsForObjects:insertedObjects.allObjects + error:&saveError]) { + TFLog(@"[%@] Could not obtain permanent IDs: %@", self.hp_name, saveError); + if (error) { + *error = saveError; + } + if (taskID != UIBackgroundTaskInvalid) { + [[UIApplication sharedApplication] endBackgroundTask:taskID]; + } + return NO; + } + + NSDate *date = [NSDate new]; + BOOL ret = [self save:&saveError]; + NSTimeInterval delta = -date.timeIntervalSinceNow; + if (!ret) { + TFLog(@"[%@] Could not save: %@", self.hp_name, saveError); + if (error) { + *error = saveError; + } + } + if (delta > .1) { + NSUInteger registered = self.registeredObjects.count; + TFLog(@"[%@] save took %.3fs; %lu inserts, %lu updates, " + "%lu deletes, %lu registered.", self.hp_name, delta, + (unsigned long)inserts, (unsigned long)updates, + (unsigned long)deletes, (unsigned long)registered); + } + if (ret && self.parentContext) { + NSManagedObjectContext *parentContext = self.parentContext; + [parentContext performBlock:^{ + [parentContext hp_saveToStoreWithTaskID:taskID + error:nil]; + }]; + } else if (taskID != UIBackgroundTaskInvalid) { + [[UIApplication sharedApplication] endBackgroundTask:taskID]; + } + return ret; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSString+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/NSString+HackpadAdditions.h new file mode 100644 index 0000000..fbda503 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSString+HackpadAdditions.h @@ -0,0 +1,22 @@ +// +// NSString+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface NSString (HackpadAdditions) + ++ (NSString *)hp_stringWithURLParameters:(NSDictionary *)parameters; + +- (NSString *)hp_stringByAddingPercentEscapes; +- (NSString *)hp_stringByReplacingPercentEscapes; +- (NSDictionary *)hp_dictionaryByParsingURLParameters; +- (NSString *)hp_stringByAppendingPathComponents:(NSArray *)components; +- (BOOL)hp_isValidEmailAddress; +- (NSString *)hp_SHA1Digest; ++ (NSString *)hp_stringNamed:(NSString *)name; +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSString+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/NSString+HackpadAdditions.m new file mode 100644 index 0000000..ba85152 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSString+HackpadAdditions.m @@ -0,0 +1,126 @@ +// +// NSString+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "NSString+HackpadAdditions.h" + +#import + +@implementation NSString (HackpadAdditions) + +- (NSString *)hp_stringByAddingPercentEscapes +{ + CFStringRef str; + str = CFURLCreateStringByAddingPercentEscapes(NULL, + (CFStringRef)self, + NULL, + CFSTR("!*'\"();:@&=+$,/?%#[]% "), + kCFStringEncodingUTF8); + return CFBridgingRelease(str); +} + +- (NSString *)hp_stringByReplacingPercentEscapes +{ + CFStringRef str; + str = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, + (CFStringRef)[self stringByReplacingOccurrencesOfString:@"+" + withString:@" "], + CFSTR(""), + kCFStringEncodingUTF8); + return CFBridgingRelease(str); +} + ++ (NSString *)hp_stringWithURLParameters:(NSDictionary *)parameters +{ + if (!parameters.count) { + return @""; + } + NSMutableArray *a = [NSMutableArray arrayWithCapacity:parameters.count]; + for (NSString *key in [parameters keysSortedByValueUsingComparator:^NSComparisonResult(id obj1, id obj2) { + return [(NSString *)obj1 compare:obj2]; + }]) { + [a addObject:[@[[key hp_stringByAddingPercentEscapes], + [(NSString *)[parameters valueForKey:key] hp_stringByAddingPercentEscapes]]componentsJoinedByString:@"="]]; + } + return [a componentsJoinedByString:@"&"]; +} + +- (NSDictionary *)hp_dictionaryByParsingURLParameters +{ + NSArray *keyvals = [self componentsSeparatedByString:@"&"]; + NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:keyvals.count]; + for (NSString *keyvalStr in keyvals) { + NSArray *keyval = [keyvalStr componentsSeparatedByString:@"="]; + if (keyval.count > 1) { + params[[keyval[0] hp_stringByReplacingPercentEscapes]] = [keyval[1] hp_stringByReplacingPercentEscapes]; + } + } + return params; +} + +- (NSString *)hp_stringByAppendingPathComponents:(NSArray *)components +{ + NSString *ret = self; + for (NSString *component in components) { + ret = [ret stringByAppendingPathComponent:component]; + } + return ret; +} + +- (BOOL)hp_isValidEmailAddress +{ + static NSRegularExpression *regexp; + if (!regexp) { + regexp = [NSRegularExpression regularExpressionWithPattern:@"^[\\w\\_\\.\\+\\-]+\\@[\\w\\_\\-]+\\.[\\w\\_\\=\\/]+$" + options:0 + error:nil]; + } + return [regexp numberOfMatchesInString:self + options:0 + range:NSMakeRange(0, self.length)] > 0; + +} + +- (NSString *)hp_SHA1Digest +{ + if ([self lengthOfBytesUsingEncoding:NSUTF8StringEncoding] > UINT32_MAX) { + return nil; + } + NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding]; + unsigned char digest[CC_SHA1_DIGEST_LENGTH]; + CC_SHA1(data.bytes, (CC_LONG)data.length, digest); + NSMutableString *ret = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; + for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) { + [ret appendFormat:@"%02x", (unsigned int)digest[i]]; + } + return ret; +} + ++ (NSString *)hp_stringNamed:(NSString *)name +{ + static NSCache *cache; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + cache = [[NSCache alloc] init]; + cache.name = @"hp_stringNamed:"; + }); + NSString *ret = [cache objectForKey:name]; + if (!ret) { + ret = [[NSBundle mainBundle] pathForResource:name + ofType:nil]; + ret = [NSString stringWithContentsOfFile:ret + encoding:NSUTF8StringEncoding + error:nil]; + if (ret) { + [cache setObject:ret + forKey:name]; + } + } + return ret; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSURL+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/NSURL+HackpadAdditions.h new file mode 100644 index 0000000..2a5a8de --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSURL+HackpadAdditions.h @@ -0,0 +1,36 @@ +// +// NSURL+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface NSURL (HackpadAdditions) + ++ (void)hp_addHackpadURL:(NSURL *)URL; ++ (void)hp_removeHackpadURL:(NSURL *)URL; ++ (void)hp_clearHackpadURLs; + ++ (instancetype)hp_sharedHackpadURL; + ++ (instancetype)hp_URLForSubdomain:(NSString *)subdomain + relativeToURL:(NSURL *)URL; + +- (void)hp_dumpCookies; +- (void)hp_deleteCookies; + +@property (nonatomic, readonly) NSString *hp_fullPath; +@property (nonatomic, readonly) BOOL hp_isHackpadURL; +@property (nonatomic, readonly) BOOL hp_isToplevelHackpadURL; +@property (nonatomic, readonly) BOOL hp_isHackpadSubdomain; + +- (BOOL)hp_isOriginEqualToURL:(NSURL *)URL; + +@end + +@interface NSURL (HackpadDeprecatedAdditions) +@property (nonatomic, readonly) NSString *hp_hackpadSubdomain; +@end \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadAdditions/NSURL+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/NSURL+HackpadAdditions.m new file mode 100644 index 0000000..2d2ecdb --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSURL+HackpadAdditions.m @@ -0,0 +1,183 @@ +// +// NSURL+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "NSURL+HackpadAdditions.h" + +static NSString * const BaseURL = @"https://hackpad.com/"; +#if TARGET_IPHONE_SIMULATOR +static NSString * const DevServerKey = @"devServer"; +static NSString * const DevBaseURL = @"http://bar.hackpad.com:9000/"; +#endif +static NSString * const URLsKey = @"com.hackpad.hackpadURLs"; + +@implementation NSURL (HackpadAdditions) + ++ (void)hp_syncHackpadURLs +{ + NSMutableArray *URLs = [NSMutableArray arrayWithCapacity:[[self hp_sharedHackpadURLs] count]]; + [[self hp_sharedHackpadURLs] enumerateObjectsUsingBlock:^(NSURL *URL, BOOL *stop) { + [URLs addObject:URL.absoluteString]; + }]; + [[NSUserDefaults standardUserDefaults] setObject:URLs + forKey:URLsKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + ++ (NSMutableSet *)hp_sharedHackpadURLs +{ + static NSMutableSet *URLs; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSArray *saved = [[NSUserDefaults standardUserDefaults] arrayForKey:URLsKey]; + if (!saved) { + saved = @[[[self hp_sharedHackpadURL] absoluteString]]; + } + URLs = [NSMutableSet setWithCapacity:saved.count]; + [saved enumerateObjectsUsingBlock:^(NSString *URL, NSUInteger idx, BOOL *stop) { + [URLs addObject:[NSURL URLWithString:URL]]; + }]; + }); + return URLs; +} + ++ (void)hp_addHackpadURL:(NSURL *)URL +{ + NSParameterAssert([URL isKindOfClass:[NSURL class]]); + [[self hp_sharedHackpadURLs] addObject:[NSURL URLWithString:@"/" + relativeToURL:URL]]; + [self hp_syncHackpadURLs]; +} + ++ (void)hp_removeHackpadURL:(NSURL *)URL +{ + NSParameterAssert([URL isKindOfClass:[NSURL class]]); + [[self hp_sharedHackpadURLs] removeObject:[NSURL URLWithString:@"/" + relativeToURL:URL]]; + [self hp_syncHackpadURLs]; +} + ++ (void)hp_clearHackpadURLs +{ + [[self hp_sharedHackpadURLs] removeAllObjects]; + [self hp_addHackpadURL:[self hp_sharedHackpadURL]]; +} + ++ (id)hp_sharedHackpadURL +{ + static NSURL *sharedURL; + if (!sharedURL) { + NSString *baseURL = BaseURL; +#if TARGET_IPHONE_SIMULATOR + if ([[NSUserDefaults standardUserDefaults] boolForKey:DevServerKey]) { + baseURL = DevBaseURL; + } +#endif + sharedURL = [NSURL URLWithString:baseURL]; + } + return sharedURL; +} + +- (void)hp_dumpCookies +{ +#if DEBUG + NSHTTPCookieStorage *jar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + @synchronized (jar) { + HPLog(@"[%@] ---- Cookies for %@ ----", self.host, self.hp_fullPath); + for (NSHTTPCookie *cookie in [jar cookiesForURL:self]) { + HPLog(@"[%@] %@[%@]: %@", self.host, cookie.domain, cookie.name, cookie.value); + } + HPLog(@"[%@] ---------------- %@ ----", self.host, self.hp_fullPath); + } +#endif +} + +- (void)hp_deleteCookies +{ + NSHTTPCookieStorage *jar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + @synchronized (jar) { + HPLog(@"[%@] ---- Deleting Cookies for %@ ----", self.host, self.hp_fullPath); + for (NSHTTPCookie *cookie in [jar cookiesForURL:self]) { + HPLog(@"[%@] %@[%@]: %@", self.host, cookie.domain, cookie.name, cookie.value); + [jar deleteCookie:cookie]; + } + HPLog(@"[%@] ---------------- %@ ----", self.host, self.hp_fullPath); + [self hp_dumpCookies]; + } +} + ++ (id)hp_URLForSubdomain:(NSString *)subdomain + relativeToURL:(NSURL *)URL +{ + if (!subdomain.length) { + return [URL copy]; + } + NSString *str; + // This is dumb. + if (URL.port) { + str = [NSString stringWithFormat:@"%@://%@.%@:%@%@", + URL.scheme, subdomain, URL.host, URL.port, URL.path]; + } else { + str = [NSString stringWithFormat:@"%@://%@.%@%@", + URL.scheme, subdomain, URL.host, URL.path]; + } + return [NSURL URLWithString:str]; +} + +- (BOOL)hp_isOriginEqualToURL:(NSURL *)URL +{ + return [self.scheme isEqualToString:URL.scheme] && + [self.host isEqualToString:URL.host] && + (self.port == URL.port || [self.port isEqualToNumber:URL.port]); +} + +- (BOOL)hp_isHackpadURL +{ + return [[self.class hp_sharedHackpadURLs] member:[[NSURL URLWithString:@"/" + relativeToURL:self] absoluteURL]] || + self.hp_isHackpadSubdomain; +} + +- (BOOL)hp_isHackpadSubdomain +{ + return [self.host hasSuffix:[@"." stringByAppendingString:[[self.class hp_sharedHackpadURL] host]]]; +} + +- (BOOL)hp_isToplevelHackpadURL +{ + return [self.host isEqualToString:[[self.class hp_sharedHackpadURL] host]]; +} + +- (NSString *)hp_fullPath +{ + NSMutableString *fullPath = self.path.mutableCopy; + if (self.query.length) { + [fullPath appendString:@"?"]; + [fullPath appendString:self.query]; + } + if (self.fragment.length) { + [fullPath appendString:@"#"]; + [fullPath appendString:self.fragment]; + } + return fullPath; +} + +@end + +@implementation NSURL (HackpadDeprecatedAdditions) +- (NSString *)hp_hackpadSubdomain +{ + NSString *domain = [[self.class hp_sharedHackpadURL] host]; + if ([self.host isEqualToString:domain]) { + return @""; + } + if ([self.host hasSuffix:domain]) { + return [self.host substringToIndex:self.host.length - domain.length - 1]; + } + return nil; +} +@end \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadAdditions/NSURLRequest+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/NSURLRequest+HackpadAdditions.h new file mode 100644 index 0000000..8e3c1fc --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSURLRequest+HackpadAdditions.h @@ -0,0 +1,17 @@ +// +// NSURLRequest+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface NSURLRequest (HackpadAdditions) + ++ (id)hp_requestWithURL:(NSURL *)URL + HTTPMethod:(NSString *)HTTPMethod + parameters:(NSDictionary *)parameters; + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSURLRequest+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/NSURLRequest+HackpadAdditions.m new file mode 100644 index 0000000..2e3b8fd --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSURLRequest+HackpadAdditions.m @@ -0,0 +1,36 @@ +// +// NSURLRequest+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "NSURLRequest+HackpadAdditions.h" + +#import "HackpadAdditions.h" + +@implementation NSURLRequest (HackpadAdditions) + ++ (id)hp_requestWithURL:(NSURL *)URL + HTTPMethod:(NSString *)HTTPMethod + parameters:(NSDictionary *)parameters +{ + NSMutableURLRequest *request; + BOOL isPost = [HTTPMethod isEqualToString:@"POST"]; + NSString *params = [NSString hp_stringWithURLParameters:parameters]; + if (!isPost && params.length) { + URL = [NSURL URLWithString:[@"?" stringByAppendingString:params] + relativeToURL:URL]; + } + request = [NSMutableURLRequest requestWithURL:URL]; + request.HTTPMethod = HTTPMethod; + if (isPost && params.length) { + [request setValue:@"application/x-www-form-urlencoded" + forHTTPHeaderField:@"Content-Type"]; + request.HTTPBody = [params dataUsingEncoding:NSASCIIStringEncoding]; + } + return request; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSURLResponse+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/NSURLResponse+HackpadAdditions.h new file mode 100644 index 0000000..611b72a --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSURLResponse+HackpadAdditions.h @@ -0,0 +1,13 @@ +// +// NSURLResponse+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface NSURLResponse (HackpadAdditions) +@property (nonatomic, readonly) NSStringEncoding hp_textEncoding; +@end diff --git a/client/ios/Hackpad/HackpadAdditions/NSURLResponse+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/NSURLResponse+HackpadAdditions.m new file mode 100644 index 0000000..92e1582 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/NSURLResponse+HackpadAdditions.m @@ -0,0 +1,20 @@ +// +// NSURLResponse+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "NSURLResponse+HackpadAdditions.h" + +@implementation NSURLResponse (HackpadAdditions) + +- (NSStringEncoding)hp_textEncoding +{ + CFStringRef textEncodingName = (__bridge CFStringRef)self.textEncodingName; + CFStringEncoding encoding = CFStringConvertIANACharSetNameToEncoding(textEncodingName); + return CFStringConvertEncodingToNSStringEncoding(encoding); +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIColor+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/UIColor+HackpadAdditions.h new file mode 100644 index 0000000..942b442 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIColor+HackpadAdditions.h @@ -0,0 +1,21 @@ +// +// UIColor+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface UIColor (HackpadAdditions) + ++ (UIColor *)hp_darkGreenColor; ++ (UIColor *)hp_mediumGreenGrayColor; ++ (UIColor *)hp_lightGreenGrayColor; ++ (UIColor *)hp_yellowColor; ++ (UIColor *)hp_redColor; ++ (UIColor *)hp_darkGrayColor; ++ (UIColor *)hp_reallyDarkGrayColor; + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIColor+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/UIColor+HackpadAdditions.m new file mode 100644 index 0000000..e066b06 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIColor+HackpadAdditions.m @@ -0,0 +1,69 @@ +// +// UIColor+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "UIColor+HackpadAdditions.h" + +@implementation UIColor (HackpadAdditions) + ++ (UIColor *)hp_darkGreenColor +{ + return [UIColor colorWithRed:0x4B / 256.0 + green:0x89 / 256.0 + blue:0x71 / 256.0 + alpha:1.0]; +} + ++ (UIColor *)hp_mediumGreenGrayColor +{ + return [UIColor colorWithRed:0xc3 / 256.0 + green:0xcc / 256.0 + blue:0xc9 / 256.0 + alpha:1.0]; +} + ++ (UIColor *)hp_lightGreenGrayColor +{ + return [UIColor colorWithRed:0xe2 / 256.0 + green:0xe6 / 256.0 + blue:0xe4 / 256.0 + alpha:1.0]; +} + ++ (UIColor *)hp_yellowColor +{ + return [UIColor colorWithRed:0xff / 256.0 + green:0xf7 / 256.0 + blue:0x9d / 256.0 + alpha:1.0]; +} + ++ (UIColor *)hp_redColor +{ + return [UIColor colorWithRed:0xbe / 256.0 + green:0x1e / 256.0 + blue:0x2d / 256.0 + alpha:1.0]; +} + ++ (UIColor *)hp_darkGrayColor +{ + return [UIColor colorWithRed:0x33 / 256.0 + green:0x33 / 256.0 + blue:0x35 / 256.0 + alpha:1.0]; +} + ++ (UIColor *)hp_reallyDarkGrayColor +{ + return [UIColor colorWithRed:0x27 / 256.0 + green:0x27 / 256.0 + blue:0x29 / 256.0 + alpha:1.0]; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIDevice+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/UIDevice+HackpadAdditions.h new file mode 100644 index 0000000..b0cbe8f --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIDevice+HackpadAdditions.h @@ -0,0 +1,17 @@ +// +// UIDevice+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +#define HP_SYSTEM_MAJOR_VERSION() ([[UIDevice currentDevice] hp_systemMajorVersion]) + +@interface UIDevice (HackpadAdditions) + +- (NSInteger)hp_systemMajorVersion; + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIDevice+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/UIDevice+HackpadAdditions.m new file mode 100644 index 0000000..a638a15 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIDevice+HackpadAdditions.m @@ -0,0 +1,23 @@ +// +// UIDevice+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "UIDevice+HackpadAdditions.h" + +@implementation UIDevice (HackpadAdditions) + +- (NSInteger)hp_systemMajorVersion +{ + static NSInteger version = 0; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + version = [[[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."][0] integerValue]; + }); + return version; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIFont+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/UIFont+HackpadAdditions.h new file mode 100644 index 0000000..d953213 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIFont+HackpadAdditions.h @@ -0,0 +1,18 @@ +// +// UIFont+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface UIFont (HackpadAdditions) + ++ (UIFont *)hp_padTextFontOfSize:(CGFloat)size; ++ (UIFont *)hp_UITextFontOfSize:(CGFloat)size; ++ (UIFont *)hp_prioritizedUITextFontOfSize:(CGFloat)size; ++ (UIFont *)hp_padTitleFontOfSize:(CGFloat)size; + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIFont+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/UIFont+HackpadAdditions.m new file mode 100644 index 0000000..ffa9422 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIFont+HackpadAdditions.m @@ -0,0 +1,37 @@ +// +// UIFont+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "UIFont+HackpadAdditions.h" + +@implementation UIFont (HackpadAdditions) + ++ (UIFont *)hp_padTextFontOfSize:(CGFloat)size +{ + return [UIFont fontWithName:@"ProximaNova-Light" + size:size]; +} + ++ (UIFont *)hp_UITextFontOfSize:(CGFloat)size +{ + return [UIFont fontWithName:@"ProximaNova-Semibold" + size:size]; +} + ++ (UIFont *)hp_prioritizedUITextFontOfSize:(CGFloat)size +{ + return [UIFont fontWithName:@"ProximaNova-Extrabld" + size:size]; +} + ++ (UIFont *)hp_padTitleFontOfSize:(CGFloat)size +{ + return [UIFont fontWithName:@"ProximaNova-Bold" + size:size]; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIView+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/UIView+HackpadAdditions.h new file mode 100644 index 0000000..7af0e78 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIView+HackpadAdditions.h @@ -0,0 +1,18 @@ +// +// UIView+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface UIView (HackpadAdditions) + +- (UIView *)hp_firstResponderSubview; +- (UIView *)hp_subviewThatCanBecomeFirstResponder; +- (void)hp_setAlphaWithUserInteractionEnabled:(BOOL)userInteractionEnabled; +- (void)hp_setHidden:(BOOL)hidden + animated:(BOOL)animated; +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIView+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/UIView+HackpadAdditions.m new file mode 100644 index 0000000..dd9128e --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIView+HackpadAdditions.m @@ -0,0 +1,68 @@ +// +// UIView+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "UIView+HackpadAdditions.h" + +@implementation UIView (HackpadAdditions) + +- (UIView *)hp_firstResponderSubview +{ + if (self.isFirstResponder) { + return self; + } + for (UIView *subview in self.subviews) { + UIView *view = [subview hp_firstResponderSubview]; + if (view) { + return view; + } + } + return nil; +} + +- (UIView *)hp_subviewThatCanBecomeFirstResponder +{ + if (self.canBecomeFirstResponder) { + return self; + } + for (UIView *subview in self.subviews) { + UIView *view = [subview hp_subviewThatCanBecomeFirstResponder]; + if (view) { + return view; + } + } + return nil; +} + +- (void)hp_setAlphaWithUserInteractionEnabled:(BOOL)userInteractionEnabled +{ + self.userInteractionEnabled = userInteractionEnabled; + self.alpha = userInteractionEnabled ? 1 : 0.33; +} + +- (void)hp_setHidden:(BOOL)hidden + animated:(BOOL)animated +{ + if (hidden == self.hidden) { + return; + } + if (!hidden) { + self.alpha = 0; + self.hidden = hidden; + } + [UIView animateWithDuration:animated ? 0.25 : 0 + animations:^{ + self.alpha = !hidden; + } completion:^(BOOL finished) { + if (!finished) { + return; + } + self.hidden = hidden; + }]; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIViewController+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/UIViewController+HackpadAdditions.h new file mode 100644 index 0000000..9188545 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIViewController+HackpadAdditions.h @@ -0,0 +1,15 @@ +// +// UIViewController+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import + +@interface UIViewController (HackpadAdditions) + +- (void)hp_setNonSearchViewsHidden:(BOOL)hidden + animated:(BOOL)animated; +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIViewController+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/UIViewController+HackpadAdditions.m new file mode 100644 index 0000000..f21af3d --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIViewController+HackpadAdditions.m @@ -0,0 +1,27 @@ +// +// UIViewController+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "UIViewController+HackpadAdditions.h" + +@implementation UIViewController (HackpadAdditions) + +- (void)hp_setNonSearchViewsHidden:(BOOL)hidden + animated:(BOOL)animated +{ + [UIView animateWithDuration:animated ? 0.25 : 0 + animations:^{ + [self.view.subviews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) { + if (view == self.searchDisplayController.searchBar || view == self.searchDisplayController.searchResultsTableView) { + return; + } + view.alpha = !hidden; + }]; + }]; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIWebView+HackpadAdditions.h b/client/ios/Hackpad/HackpadAdditions/UIWebView+HackpadAdditions.h new file mode 100644 index 0000000..a4f60cb --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIWebView+HackpadAdditions.h @@ -0,0 +1,18 @@ +// +// UIWebView+HackpadAdditions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface UIWebView (HackpadAdditions) + ++ (NSString *)hp_defaultUserAgentString; + +- (NSString *)hp_clientVarValueForKey:(NSString *)key; +- (NSString *)hp_stringByEvaluatingJavaScriptNamed:(NSString *)name; + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/UIWebView+HackpadAdditions.m b/client/ios/Hackpad/HackpadAdditions/UIWebView+HackpadAdditions.m new file mode 100644 index 0000000..969e7f9 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/UIWebView+HackpadAdditions.m @@ -0,0 +1,58 @@ +// +// UIWebView+HackpadAdditions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "UIWebView+HackpadAdditions.h" + +#import "NSString+HackpadAdditions.h" + +@implementation UIWebView (HackpadAdditions) + ++ (NSString *)hp_defaultUserAgentString +{ + static NSString * const lock = @""; + static NSString *userAgent; + BOOL needsUserAgent; + @synchronized (lock) { + needsUserAgent = !userAgent; + } + if (needsUserAgent) { + NSString * __block tmpUserAgent; + dispatch_block_t block = ^{ + NSDate *date = [NSDate new]; + tmpUserAgent = [[UIWebView new] stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; + NSTimeInterval delta = -date.timeIntervalSinceNow; + if (delta > .1) { + HPLog(@"Took %.3fs to get user agent.", delta); + } + }; + if ([NSThread isMainThread]) { + block(); + } else { + dispatch_sync(dispatch_get_main_queue(), block); + } + @synchronized (lock) { + if (!userAgent) { + userAgent = tmpUserAgent; + } + } + } + return userAgent; +} + +- (NSString *)hp_clientVarValueForKey:(NSString *)key +{ + NSString *str = [NSString stringWithFormat:@"clientVars.%@", key]; + return [self stringByEvaluatingJavaScriptFromString:str]; +} + +- (NSString *)hp_stringByEvaluatingJavaScriptNamed:(NSString *)name +{ + return [self stringByEvaluatingJavaScriptFromString:[NSString hp_stringNamed:name]]; +} + +@end diff --git a/client/ios/Hackpad/HackpadAdditions/hprecursiveblock.c b/client/ios/Hackpad/HackpadAdditions/hprecursiveblock.c new file mode 100644 index 0000000..45e4224 --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/hprecursiveblock.c @@ -0,0 +1,17 @@ +// +// hprecursiveblock.c +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#include "hprecursiveblock.h" + +#include + +hp_recursive_block_t +hp_recursive_block(void (^block)(hp_recursive_block_t)) +{ + return Block_copy(^{ block(hp_recursive_block(block)); }); +} diff --git a/client/ios/Hackpad/HackpadAdditions/hprecursiveblock.h b/client/ios/Hackpad/HackpadAdditions/hprecursiveblock.h new file mode 100644 index 0000000..af3f1df --- /dev/null +++ b/client/ios/Hackpad/HackpadAdditions/hprecursiveblock.h @@ -0,0 +1,16 @@ +// +// hprecursiveblock.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#ifndef Hackpad_hprecursiveblock_h +#define Hackpad_hprecursiveblock_h + +typedef void (^hp_recursive_block_t)(void); + +hp_recursive_block_t hp_recursive_block(void (^block)(hp_recursive_block_t)); + +#endif diff --git a/client/ios/Hackpad/HackpadKit/HPAPI.h b/client/ios/Hackpad/HackpadKit/HPAPI.h new file mode 100644 index 0000000..597d63e --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPAPI.h @@ -0,0 +1,118 @@ +// +// HPAPI.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +FOUNDATION_EXTERN NSString * const HPAPIDidRequireUserActionNotification; +FOUNDATION_EXTERN NSString * const HPAPIDidFailToSignInNotification; +FOUNDATION_EXTERN NSString * const HPAPIDidSignInNotification; +FOUNDATION_EXTERN NSString * const HPAPIDidSignOutNotification; + +FOUNDATION_EXTERN NSString * const HPAPINewUserIDKey; +FOUNDATION_EXTERN NSString * const HPAPISignInErrorKey; + +FOUNDATION_EXTERN NSString * const HPAPIXSRFTokenParam; + +/* + Auth: + Add new space + enable guest mode + sign in to space + display sign in view controller, cont = special url + on success: + disable guest mode + hide sign in view + request api key + if fails + enable guest mode + if user id differs from previous + remove pads & collections from core data + bind space to user id + save creds in keychain + on cancel: + remove pads & collections from core data + enable guest mode + Reconnect to existing space + ensure session + fails: + enable guest mode + success: + signed in! + */ + +typedef NS_ENUM(NSUInteger, HPAuthenticationState) { + HPNotInitializedAuthenticationState, + HPRequiresSignInAuthenticationState, + HPSignInAsAuthenticationState, + HPSignInPromptAuthenticationState, + HPRequestAPISecretAuthenticationState, + HPReconnectAuthenticationState, + HPChangedUserAuthenticationState, + HPSignedInAuthenticationState, + HPSigningOutAuthenticationState, + HPInactiveAuthenticationState +}; + +typedef NS_ENUM(NSUInteger, HPURLType) { + HPUnknownURLType, + + HPExternalURLType, + + HPSpaceURLType, + HPCollectionURLType, + HPPadURLType, + HPUserProfileURLType, + HPSearchURLType +}; + +@class GTMOAuthAuthentication; +@class Reachability; + +@interface HPAPI : NSObject + +@property (copy, atomic, readonly) NSURL *URL; + +@property (assign, atomic) HPAuthenticationState authenticationState; +@property (assign, atomic, readonly, getter = isSignedIn) BOOL signedIn; +@property (copy, atomic) NSString *userID; +@property (strong, atomic) GTMOAuthAuthentication *oAuth; +@property (strong, atomic, readonly) Reachability *reachability; +@property (assign, atomic, readonly) NSUInteger sessionID; + ++ (id)APIWithURL:(NSURL *)URL; ++ (void)removeAPIWithURL:(NSURL *)URL; ++ (NSString *)stringWithAuthenticationState:(HPAuthenticationState)authenticationState; ++ (NSString *)XSRFTokenForURL:(NSURL *)URL; + ++ (id)JSONObjectWithResponse:(NSURLResponse *)response + data:(NSData *)data + JSONOptions:(NSJSONReadingOptions)opts + request:(NSURLRequest *)request + error:(NSError *__autoreleasing *)error; + ++ (NSOperationQueue *)sharedAPIQueue; ++ (HPURLType)URLTypeWithURL:(NSURL *)URL; + +- (void)signInEvenIfSignedIn:(BOOL)force; ++ (NSData *)sharedDeviceTokenData; ++ (void)setSharedDeviceTokenData:(NSData *)tokenData; ++ (NSDictionary *)sharedDeviceTokenParams; + +- (BOOL)isSignInRequiredForRequest:(NSURLRequest *)request + response:(NSURLResponse *)response + error:(NSError * __autoreleasing *)error; + +- (id)parseJSONResponse:(NSURLResponse *)response + data:(NSData *)data + request:(NSURLRequest *)request + error:(NSError * __autoreleasing *)error; + +- (void)hasGoneOnline; +- (BOOL)loadOAuthFromKeychain; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPAPI.m b/client/ios/Hackpad/HackpadKit/HPAPI.m new file mode 100644 index 0000000..b8a08c5 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPAPI.m @@ -0,0 +1,1048 @@ +// +// HPAPI.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPAPI.h" + +#import "HackpadKit.h" +#import "HackpadAdditions.h" +#import "HPReachability.h" + +#import "GTMOAuthAuthentication.h" +#import "GTMNSString+HTML.h" +#import "KeychainItemWrapper.h" +#import + +#import + +//#define DEBUG_COOKIES 1 + +NSString * const HPAPIDidRequireUserActionNotification = @"HPAPIDidRequireUserActionNotification"; +NSString * const HPAPIDidFailToSignInNotification = @"HPAPIDidFailToSignInNotification"; +NSString * const HPAPIDidSignInNotification = @"HPAPIDidSignInNotification"; +NSString * const HPAPIDidSignOutNotification = @"HPAPIDidSignOutNotification"; + +NSString * const HPAPINewUserIDKey = @"HPAPINewUserIDKey"; +NSString * const HPAPISignInErrorKey = @"HPAPISignInErrorKey"; + +NSString * const HPAPIXSRFTokenParam = @"xsrf"; + +static NSString * const HPAPIKeyPath = @"/ep/account/api-key"; +static NSString * const HPSessionSignInPath = @"/ep/account/session-sign-in"; +static NSString * const HPSignInPath = @"/ep/account/sign-in"; +static NSString * const SignedInPath = @"/ep/iOS/x-HackpadKit-signed-in"; + +static NSString * const SuccessKey = @"success"; +static NSString * const ErrorKey = @"error"; +static NSString * const KeyKey = @"key"; +static NSString * const SecretKey = @"secret"; + +static NSString * const TrackingCookieName = @"ET"; + +static NSMutableDictionary *APIs; +static NSData * deviceTokenData; + +@interface HPAPI () { + NSURLRequest * __weak _authenticationRequest; + KeychainItemWrapper *_keychainItem; + id _reachabilityObserver; + NSUInteger reconnectAttempts; + NSUInteger reconnectID; + HPAuthenticationState _authenticationState; + GTMOAuthAuthentication *_pendingOAuth; + NSOperationQueue *operationQueue; + NSUInteger _sessionID; +} + +@property (nonatomic, strong) NSCondition *signInAsCond; +@property (nonatomic, strong) NSMutableURLRequest *signInAsRequest; +@property (nonatomic, strong) id signInAsSignInObserver; +@property (nonatomic, strong) id signInAsSignOutObserver; + +- (id)initWithURL:(NSURL *)URL; + +- (void)requestAPISecret; +- (void)ensureAPISession; + +- (BOOL)loadOAuthFromKeychain; +- (void)savePendingOAuthToKeychain; + +- (void)updateAuthenticationStateValue:(HPAuthenticationState)authenticationState; +- (void)postSignInNotificationWithError:(NSError *)error; +- (id)addReachabilityObserver; +- (void)scheduleReconnect; +- (void)cancelReconnect; +@end + +@implementation HPAPI + ++ (NSData *)sharedDeviceTokenData +{ + NSAssert([NSThread isMainThread], @"%s called on non-main thread.", __PRETTY_FUNCTION__); + return deviceTokenData; +} + ++ (void)setSharedDeviceTokenData:(NSData *)tokenData +{ + NSAssert([NSThread isMainThread], @"%s called on non-main thread.", __PRETTY_FUNCTION__); + deviceTokenData = tokenData; +} + ++ (NSDictionary *)sharedDeviceTokenParams +{ + static NSString * const IOSDeviceTokenParam = @"iosDeviceToken"; + static NSString * const IOSAppIDParam= @"iosAppId"; + return deviceTokenData + ? @{IOSDeviceTokenParam: deviceTokenData.hp_hexEncodedString, + IOSAppIDParam: [[NSBundle mainBundle] bundleIdentifier]} + : @{}; +} + +#pragma mark - Object Initialization + +- (id)init +{ + NSAssert(NO, @"This object must be instantiated with initWithURL:"); + return nil; +} + +- (id)initWithURL:(NSURL *)URL +{ + NSParameterAssert([URL isKindOfClass:[NSURL class]]); + NSParameterAssert(URL.host.length); + self = [super init]; + if (self) { + _URL = URL; + _keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:URL.absoluteString + accessGroup:nil]; + _reachability = [HPReachability reachabilityForInternetConnection]; + _reachabilityObserver = [self addReachabilityObserver]; + operationQueue = [[NSOperationQueue alloc] init]; + // We @synchronize everything anyway... + operationQueue.maxConcurrentOperationCount = 1; + operationQueue.name = [URL.host stringByAppendingString:@" API Queue"]; + } + return self; +} + +- (void)addSignInAsObserversWithAPI:(HPAPI *)API +{ + HPLog(@"[%@] Deferring signInAs until %@ has signed in (or out).", + self.URL.host, API.URL.host); + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + self.signInAsSignInObserver = [nc addObserverForName:HPAPIDidSignInNotification + object:API + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + @synchronized (self) { + [self removeSignInAsObservers]; + if (self.authenticationState != HPSignInAsAuthenticationState) { + return; + } + [self signInAs]; + } + }]; + self.signInAsSignOutObserver = [nc addObserverForName:HPAPIDidSignOutNotification + object:API + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + @synchronized (self) { + [self removeSignInAsObservers]; + if (self.authenticationState != HPSignInAsAuthenticationState) { + return; + } + self.authenticationState = HPSignInPromptAuthenticationState; + } + }]; +} + +- (void)removeSignInAsObservers +{ + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + if (self.signInAsSignInObserver) { + [nc removeObserver:self.signInAsSignInObserver]; + self.signInAsSignInObserver = nil; + } + if (self.signInAsSignOutObserver) { + [nc removeObserver:self.signInAsSignOutObserver]; + self.signInAsSignOutObserver = nil; + } +} + +- (void)dealloc +{ + if (_reachabilityObserver) { + [[NSNotificationCenter defaultCenter] removeObserver:_reachabilityObserver]; + } + [_reachability stopNotifier]; + [self removeSignInAsObservers]; +} + +- (id)addReachabilityObserver +{ + NSParameterAssert(!_reachabilityObserver); + HPAPI * __weak weakSelf = self; + return [[NSNotificationCenter defaultCenter] addObserverForName:kReachabilityChangedNotification + object:_reachability + queue:operationQueue + usingBlock:^(NSNotification *note) + { + HPAPI *blockSelf = weakSelf; + NetworkStatus status = [note.object currentReachabilityStatus]; + HPLog(@"[%@] Going %@.", blockSelf.URL.host, status ? @"online" : @"offline"); + @synchronized (blockSelf) { + if (status) { + if (!blockSelf->_authenticationRequest) { + switch (blockSelf.authenticationState) { + case HPSignInAsAuthenticationState: + [blockSelf signInAs]; + break; + case HPRequestAPISecretAuthenticationState: + [blockSelf requestAPISecret]; + break; + case HPReconnectAuthenticationState: + [blockSelf ensureAPISession]; + break; + default: + break; + } + } + } else { + // Cancel any requests since we're offline. + blockSelf->_authenticationRequest = nil; + }; + } + }]; +} + +#pragma mark - Public API + ++ (id)APIWithURL:(NSURL *)URL +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + APIs = [NSMutableDictionary dictionary]; + }); + HPAPI *API; + URL = [[NSURL URLWithString:@"/" + relativeToURL:URL] absoluteURL]; + @synchronized (APIs) { + API = APIs[URL]; + if (!API) { + API = [[self alloc] initWithURL:URL]; + APIs[URL] = API; + } + } + return API; +} + ++ (void)removeAPIWithURL:(NSURL *)URL +{ + URL = [[NSURL URLWithString:@"/" + relativeToURL:URL] absoluteURL]; + HPAPI *API; + @synchronized (APIs) { + API = APIs[URL]; + [APIs removeObjectForKey:URL]; + } + API.authenticationState = HPInactiveAuthenticationState; +} + ++ (NSString *)stringWithAuthenticationState:(HPAuthenticationState)authenticationState +{ +#define CASE(_x) case (_x): return @#_x + switch (authenticationState) { + CASE(HPNotInitializedAuthenticationState); + CASE(HPRequiresSignInAuthenticationState); + CASE(HPSignInPromptAuthenticationState); + CASE(HPSignInAsAuthenticationState); + CASE(HPRequestAPISecretAuthenticationState); + CASE(HPReconnectAuthenticationState); + CASE(HPChangedUserAuthenticationState); + CASE(HPSignedInAuthenticationState); + CASE(HPSigningOutAuthenticationState); + CASE(HPInactiveAuthenticationState); + default: + return nil; + } +#undef CASE +} + ++ (NSOperationQueue *)sharedAPIQueue +{ + static NSOperationQueue *operationQueue; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + operationQueue = [NSOperationQueue new]; + operationQueue.maxConcurrentOperationCount = 1; + operationQueue.name = @"HPAPI sharedAPIQueue"; + }); + return operationQueue; +} + ++ (HPURLType)URLTypeWithURL:(NSURL *)URL +{ + static NSString * const HPPadSearchPath = @"/ep/search"; + static NSString * const ProfilePath = @"/ep/profile/"; + static NSString * const GroupPath = @"/ep/group/"; + static NSString * const CollectionPath = @"/collection/"; + + if (!URL.hp_isHackpadURL) { + return HPExternalURLType; + } + if (!URL.path.length || [URL.path isEqualToString:@"/"]) { + return HPSpaceURLType; + } + if ([HPPad padIDWithURL:URL]) { + return HPPadURLType; + } + if ([URL.path isEqualToString:HPPadSearchPath]) { + return HPSearchURLType; + } + if ([URL.path hasPrefix:ProfilePath] && URL.pathComponents.count == 4) { + return HPUserProfileURLType; + } + if (([URL.path hasPrefix:GroupPath] && URL.pathComponents.count == 4) || + ([URL.path hasPrefix:CollectionPath] && URL.pathComponents.count == 3)) { + return HPCollectionURLType; + } + return HPUnknownURLType; +} + +- (BOOL)isSignInRequiredForRequest:(NSURLRequest *)request + response:(NSURLResponse *)response + error:(NSError *__autoreleasing *)error +{ + @synchronized(self) { + if (self.authenticationState == HPInactiveAuthenticationState) { + HPLog(@"[%@] Ignoring response for removed space: %@", + self.URL.host, response.URL.hp_fullPath); + return YES; + } + + NSHTTPURLResponse *HTTPResponse; + if ([response isKindOfClass:[NSHTTPURLResponse class]]) { + HTTPResponse = (NSHTTPURLResponse *)response; + } + + if (error && + [[*error domain] isEqualToString:NSURLErrorDomain] && + [*error code] == NSURLErrorUserCancelledAuthentication) { + // "No oAuth token sent" -> need to reauth. + } else if (HTTPResponse.statusCode != 200 || + ![response.URL.path hasPrefix:HPSignInPath]) { +#if 0 + if (HTTPResponse.statusCode == 200 && + self.authenticationState == HPReconnectAuthenticationState && + !_authenticationRequest && + ![HPStaticCachingURLProtocol isCachedResponse:response]) { + [self ensureAPISession]; + } +#endif + return NO; + } + + if (error) { + NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: + @"Sign in is required.", NSLocalizedDescriptionKey, + request.URL, NSURLErrorFailingURLErrorKey, + request.URL.absoluteString, NSURLErrorFailingURLStringErrorKey, + request.HTTPMethod, HPURLErrorFailingHTTPMethod, + nil]; + if (HTTPResponse) { + userInfo[HPURLErrorFailingHTTPStatusCode] = @(HTTPResponse.statusCode); + } + if (*error) { + userInfo[NSUnderlyingErrorKey] = *error; + } + *error = [NSError errorWithDomain:HPHackpadErrorDomain + code:HPSignInRequired + userInfo:userInfo]; + } + [self signInEvenIfSignedIn:YES]; + } + return YES; +} + +- (id)parseJSONResponse:(NSURLResponse *)response + data:(NSData *)data + request:(NSURLRequest *)request + error:(NSError *__autoreleasing *)error +{ + return [self isSignInRequiredForRequest:request + response:response + error:error] + ? nil : [self.class JSONObjectWithResponse:response + data:data + JSONOptions:0 + request:request + error:error]; +} + ++ (NSString *)XSRFTokenForURL:(NSURL *)URL +{ + NSHTTPCookieStorage *jar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + NSString * __block tokenValue = @""; + [[jar cookiesForURL:URL] enumerateObjectsUsingBlock:^(NSHTTPCookie *cookie, NSUInteger idx, BOOL *stop) { + if (![cookie.name isEqualToString:TrackingCookieName]) { + return; + } + tokenValue = cookie.value; + *stop = YES; + }]; + return tokenValue; +} + +#pragma mark - State machine + +- (BOOL)isSignedIn +{ + return self.authenticationState == HPSignedInAuthenticationState; +} + +- (void)signInEvenIfSignedIn:(BOOL)force +{ + @synchronized (self) { + switch (self.authenticationState) { + case HPSignedInAuthenticationState: + if (!force) { + break; + } + self.authenticationState = HPReconnectAuthenticationState; + break; + case HPRequiresSignInAuthenticationState: + self.authenticationState = HPSignInAsAuthenticationState; + break; + default: + TFLog(@"[%@] Ignoring sign in request while in state %@", + self.URL.host, + [self.class stringWithAuthenticationState:self.authenticationState]); + } + } +} + +- (void)updateAuthenticationStateValue:(HPAuthenticationState)authenticationState +{ + HPLog(@"[%@] authenticationState %@ -> %@", self.URL.host, + [self.class stringWithAuthenticationState:_authenticationState], + [self.class stringWithAuthenticationState:authenticationState]); + + if (_authenticationState == HPSignInAsAuthenticationState) { + [self removeSignInAsObservers]; + } + + BOOL changeSignedIn = (_authenticationState == HPSignedInAuthenticationState || + authenticationState == HPSignedInAuthenticationState); + BOOL wasSigningOut = _authenticationState == HPSigningOutAuthenticationState; + + if (changeSignedIn) { + [self willChangeValueForKey:@"sessionID"]; + [self willChangeValueForKey:@"signedIn"]; + } + [self willChangeValueForKey:@"authenticationState"]; + + _authenticationState = authenticationState; + if (changeSignedIn) { + ++_sessionID; + } + + [self didChangeValueForKey:@"authenticationState"]; + if (changeSignedIn) { + [self didChangeValueForKey:@"signedIn"]; + } + if (_authenticationState == HPSignedInAuthenticationState) { + [self didChangeValueForKey:@"sessionID"]; + } + + if (!changeSignedIn && !wasSigningOut) { + return; + } + NSString *name = self.isSignedIn + ? HPAPIDidSignInNotification + : HPAPIDidSignOutNotification; + HPLog(@"[%@] Posting %@", self.URL.host, name); + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:name + object:self]; + }); +} + +- (void)setAuthenticationState:(HPAuthenticationState)authenticationState +{ +#define ASSERT_STATE(x) NSAssert((x), @"Illegal state transition: %@ to %@", \ + [self.class stringWithAuthenticationState:_authenticationState], \ + [self.class stringWithAuthenticationState:authenticationState]) + @synchronized (self) { + [self cancelReconnect]; + + if (_authenticationState == authenticationState) { + return; + } + + if (_authenticationState == HPNotInitializedAuthenticationState) { + [_reachability startNotifier]; + } + + _authenticationRequest = nil; + BOOL needsUserAction = NO; + NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; + + switch (authenticationState) { + case HPNotInitializedAuthenticationState: + ASSERT_STATE(authenticationState != HPNotInitializedAuthenticationState); + break; + + case HPRequiresSignInAuthenticationState: + // This is always allowed. + [_keychainItem resetKeychainItem]; + _pendingOAuth = nil; + _oAuth = nil; + self.userID = nil; + break; + + case HPSignInAsAuthenticationState: + ASSERT_STATE(_authenticationState == HPNotInitializedAuthenticationState || + _authenticationState == HPRequiresSignInAuthenticationState); + [self updateAuthenticationStateValue:authenticationState]; + [self signInAs]; + return; + + case HPSignInPromptAuthenticationState: + ASSERT_STATE(_authenticationState == HPNotInitializedAuthenticationState || + _authenticationState == HPRequiresSignInAuthenticationState || + _authenticationState == HPSignInAsAuthenticationState || + _authenticationState == HPReconnectAuthenticationState); + needsUserAction = YES; + break; + + case HPRequestAPISecretAuthenticationState: + ASSERT_STATE(_authenticationState == HPSignInPromptAuthenticationState || + _authenticationState == HPSignInAsAuthenticationState); + [self requestAPISecret]; + break; + + case HPReconnectAuthenticationState: + ASSERT_STATE(_authenticationState == HPNotInitializedAuthenticationState || + _authenticationState == HPSignedInAuthenticationState); + if (!self.oAuth && ![self loadOAuthFromKeychain]) { + HPLog(@"[%@] Cannot reconnect without credentials.", self.URL.host); + [self updateAuthenticationStateValue:authenticationState]; + self.authenticationState = HPSignInPromptAuthenticationState; + return; + } + if (_authenticationState == HPSignedInAuthenticationState) { + [self scheduleReconnect]; + } else { + [self ensureAPISession]; + } + break; + + case HPChangedUserAuthenticationState: + ASSERT_STATE(_authenticationState == HPRequestAPISecretAuthenticationState || + _authenticationState == HPReconnectAuthenticationState); + [userInfo setObject:_pendingOAuth.consumerKey + forKey:HPAPINewUserIDKey]; + needsUserAction = YES; + break; + + case HPSignedInAuthenticationState: + ASSERT_STATE(_authenticationState == HPNotInitializedAuthenticationState || + _authenticationState == HPRequestAPISecretAuthenticationState || + _authenticationState == HPReconnectAuthenticationState || + _authenticationState == HPChangedUserAuthenticationState); + if (_pendingOAuth) { + [self savePendingOAuthToKeychain]; + } + if (!self.oAuth && ![self loadOAuthFromKeychain]) { + HPLog(@"[%@] Cannot reconnect without credentials.", self.URL.host); + [self updateAuthenticationStateValue:authenticationState]; + self.authenticationState = HPSignInAsAuthenticationState; + return; + } + //reconnectAttempts = 0; + break; + + case HPSigningOutAuthenticationState: +#if 0 + ASSERT_STATE(_authenticationState == HPRequestAPISecretAuthenticationState || + _authenticationState == HPSignInPromptAuthenticationState || + _authenticationState == HPReconnectAuthenticationState || + _authenticationState == HPSignedInAuthenticationState); +#endif + // Always permitted? + break; + + case HPInactiveAuthenticationState: + // Always permitted. + break; + + default: + ASSERT_STATE(authenticationState > HPNotInitializedAuthenticationState && + authenticationState <= HPInactiveAuthenticationState); + return; + } + + [self updateAuthenticationStateValue:authenticationState]; + + if (needsUserAction) { + HPLog(@"[%@] posting notification: %@", self.URL.host, HPAPIDidRequireUserActionNotification); + [[NSNotificationCenter defaultCenter] postNotificationName:HPAPIDidRequireUserActionNotification + object:self + userInfo:userInfo]; + } + } +#undef ASSERT_STATE +} + +- (HPAuthenticationState)authenticationState +{ + HPAuthenticationState ret; + @synchronized (self) { + ret = _authenticationState; + } + return ret; +} + +- (NSUInteger)sessionID +{ + NSUInteger ret; + @synchronized (self) { + ret = _sessionID; + } + return ret; +} + +- (void)signInAs +{ + static NSString * const SignInAsPath = @"/ep/account/as"; + static NSString * const ContKey = @"cont"; + + if (!self.URL.hp_isHackpadSubdomain) { + self.authenticationState = HPSignInPromptAuthenticationState; + return; + } + + if (![_reachability currentReachabilityStatus]) { + HPLog(@"[%@] Deferring signInAs while offline.", self.URL.host); + return; + } + + NSURL *URL = [NSURL hp_sharedHackpadURL]; + HPAPI *API = [self.class APIWithURL:URL]; + GTMOAuthAuthentication *oAuth; + @synchronized (API) { + if (API.oAuth || [API loadOAuthFromKeychain]) { + oAuth = API.oAuth; + } else if (API.authenticationState != HPRequiresSignInAuthenticationState && + API.authenticationState != HPInactiveAuthenticationState) { + NSAssert(API.authenticationState != HPSignedInAuthenticationState, + @"Root API is signed in, so it should have oAuth information"); + [self addSignInAsObserversWithAPI:API]; + return; + } + } + if (!oAuth) { + TFLog(@"[%@] Can't sign in as since parent domain %@ has no oAuth", + self.URL.host, API.URL.host); + self.authenticationState = HPSignInPromptAuthenticationState; + return; + } + + HPAPI * __weak weakSelf = self; + [[self.class sharedAPIQueue] addOperationWithBlock:^{ + HPAPI *strongSelf = weakSelf; + if (!strongSelf) { + return; + } + NSURL *URL = [NSURL URLWithString:SignInAsPath + relativeToURL:strongSelf.URL]; + NSDictionary *params = @{ContKey:SignedInPath}; + strongSelf.signInAsRequest = [NSMutableURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + [oAuth addResourceTokenHeaderToRequest:strongSelf.signInAsRequest]; + strongSelf->_authenticationRequest = strongSelf.signInAsRequest; + + self.signInAsCond = [NSCondition new]; + [self.signInAsCond lock]; + + NSDate * __block date; + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + NSURLConnection *conn = [NSURLConnection connectionWithRequest:strongSelf.signInAsRequest + delegate:self]; + date = [NSDate date]; + [conn start]; + }]; + while (strongSelf.signInAsRequest) { + [self.signInAsCond wait]; + } + HPLog(@"[%@] Request %@ took %.3f seconds", URL.host, URL.hp_fullPath, + -date.timeIntervalSinceNow); + [self.signInAsCond unlock]; + self.signInAsCond = nil; + }]; +} + +- (void)requestAPISecret +{ + if (![_reachability currentReachabilityStatus]) { + HPLog(@"[%@] Deferring requestAPISecret while offline.", self.URL.host); + return; + } + NSURL *URL = [NSURL URLWithString:HPAPIKeyPath + relativeToURL:self.URL]; + NSMutableDictionary *params = [[self.class sharedDeviceTokenParams] mutableCopy]; + params[HPAPIXSRFTokenParam] = [HPAPI XSRFTokenForURL:URL]; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + _authenticationRequest = request; + [NSURLConnection sendAsynchronousRequest:request + queue:operationQueue + completionHandler:^(NSURLResponse *response, + NSData *data, + NSError *error) + { + @synchronized(self) { + if (_authenticationRequest != request) { + HPLog(@"[%@] Ignoring canceled request: %@", self.URL.host, + request.URL.hp_fullPath); + return; + } + + NSAssert(_authenticationState == HPRequestAPISecretAuthenticationState, + @"[%@] Unexpected state %lu; expected: %lu", + self.URL.host, (unsigned long)_authenticationState, + (unsigned long)HPRequestAPISecretAuthenticationState); + + id JSON = [self parseJSONResponse:response + data:data + request:request + error:&error]; + + if (error) { + [self postSignInNotificationWithError:error]; + self.authenticationState = HPRequiresSignInAuthenticationState; + return; + } + + NSString *consumerKey = JSON[KeyKey]; + NSString *privateKey = JSON[SecretKey]; + _pendingOAuth = [GTMOAuthAuthentication alloc]; + _pendingOAuth = [_pendingOAuth initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1 + consumerKey:consumerKey + privateKey:privateKey]; + _pendingOAuth.tokenSecret = @""; + + if ((self.userID && ![self.userID isEqualToString:_pendingOAuth.consumerKey]) || + (self.oAuth && ![self.oAuth.consumerKey isEqualToString:_pendingOAuth.consumerKey])) { + self.authenticationState = HPChangedUserAuthenticationState; + } else { + self.authenticationState = HPSignedInAuthenticationState; + } + } + }]; +} + +- (void)ensureAPISession +{ + if (![_reachability currentReachabilityStatus]) { + HPLog(@"[%@] Deferring ensureAPISession while offline.", self.URL.host); + return; + } + NSAssert(self.oAuth, @"[%@] Cannot ensure API session without credentials.", self.URL.host); + NSURL *URL = [NSURL URLWithString:HPSessionSignInPath + relativeToURL:self.URL]; + + NSMutableURLRequest *request = [NSMutableURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:[self.class sharedDeviceTokenParams]]; + request.cachePolicy = NSURLRequestReloadIgnoringCacheData; + [self.oAuth addResourceTokenHeaderToRequest:request]; + + _authenticationRequest = request; + + [[self.class sharedAPIQueue] addOperationWithBlock:^{ + @synchronized (self) { + if (_authenticationRequest != request) { + HPLog(@"[%@] Ignoring canceled request: %@", self.URL.host, + request.URL.hp_fullPath); + return; + } + } +#if DEBUG_COOKIES + [request.URL hp_dumpCookies]; +#endif + NSURLResponse *response; + NSError *error; +#if DEBUG + NSDate *date = [NSDate date]; +#endif + NSData *data = [NSURLConnection sendSynchronousRequest:request + returningResponse:&response + error:&error]; + HPLog(@"[%@] Request %@ took %.3f seconds", request.URL.host, + request.URL.hp_fullPath, -date.timeIntervalSinceNow); +#if DEBUG_COOKIES + HPLog(@"[%@] Headers for %@: %@", request.URL.host, + request.URL.hp_fullPath, + [(NSHTTPURLResponse *)response allHeaderFields]); + [request.URL hp_dumpCookies]; +#endif + + @synchronized(self) { + if (_authenticationRequest != request) { + HPLog(@"[%@] Ignoring canceled request: %@", self.URL.host, + request.URL.hp_fullPath); + return; + } + + NSAssert(self.authenticationState == HPReconnectAuthenticationState, + @"[%@] Unexpected state %d; expected: %d", + self.URL.host, (int)self.authenticationState, (int)HPReconnectAuthenticationState); + + if ([error.domain isEqualToString:NSURLErrorDomain] && + error.code == NSURLErrorUserCancelledAuthentication) { + // This means we got a 401, because the signature was invalid. + // The token may have been changed, the account deleted, etc. + TFLog(@"[%@] Session sign in failed, prompting for credentials: %@", + self.URL.host, error); + self.authenticationState = HPSignInPromptAuthenticationState; + return; + } else if (error) { + // Other errors here (can) mean a network error. we shouldn't + // sign out and delete cached pads just yet, in case they are in + // a forest. + // FIXME: just what should we do, though? + TFLog(@"[%@] Ignoring sign-in network error: %@", self.URL.host, error); + [self scheduleReconnect]; + return; + } + + if ([HPAPI JSONObjectWithResponse:response + data:data + JSONOptions:0 + request:request + error:&error]) { + self.authenticationState = HPSignedInAuthenticationState; + } else if (error) { + if ([response isKindOfClass:[NSHTTPURLResponse class]]) { + NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode]; + if (statusCode / 100 == 5) { + TFLog(@"[%@] Ignoring server error %ld: %@", self.URL.host, (long)statusCode, + [NSHTTPURLResponse localizedStringForStatusCode:statusCode]); + [self scheduleReconnect]; + return; + } + } + [self postSignInNotificationWithError:error]; + self.authenticationState = HPRequiresSignInAuthenticationState; + } + } + }]; +} + +- (void)scheduleReconnect +{ + NSUInteger attemptID = ++reconnectID; + double delayInSeconds = 1 + arc4random_uniform(1 << MIN(reconnectAttempts++, 8)); + HPLog(@"[%@] Attempting API reconnect %lu in %.0fs", self.URL.host, (unsigned long)reconnectAttempts, delayInSeconds); + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); + dispatch_after(popTime, dispatch_get_main_queue(), ^{ + @synchronized (self) { + if (reconnectID == attemptID) { + [self ensureAPISession]; + } + } + }); +} + +- (void)cancelReconnect +{ + reconnectID++; +} + +- (void)hasGoneOnline +{ + @synchronized(self) { + if (_authenticationState == HPReconnectAuthenticationState && !_authenticationRequest) { + [self ensureAPISession]; + } + } +} + +- (void)postSignInNotificationWithError:(NSError *)error +{ + [[NSNotificationCenter defaultCenter] postNotificationName:HPAPIDidFailToSignInNotification + object:self + userInfo:[NSDictionary dictionaryWithObject:error + forKey:HPAPISignInErrorKey]]; +} + +#pragma mark - Keychain access + +- (BOOL)loadOAuthFromKeychain +{ + NSString *consumeKey = [_keychainItem objectForKey:(__bridge NSString *)kSecAttrAccount]; + NSString *privateKey = [_keychainItem objectForKey:(__bridge NSString *)kSecValueData]; + + if (!consumeKey.length || !privateKey.length) { + return NO; + } + + GTMOAuthAuthentication *oAuth = [GTMOAuthAuthentication alloc]; + self.oAuth = [oAuth initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1 + consumerKey:consumeKey + privateKey:privateKey]; + return YES; +} + +- (void)savePendingOAuthToKeychain +{ + [_keychainItem setObject:_pendingOAuth.consumerKey + forKey:(__bridge NSString *)kSecAttrAccount]; + [_keychainItem setObject:_pendingOAuth.privateKey + forKey:(__bridge NSString *)kSecValueData]; + self.oAuth = _pendingOAuth; + _pendingOAuth = nil; + self.userID = self.oAuth.consumerKey; +} + ++ (id)JSONObjectWithResponse:(NSURLResponse *)response + data:(NSData *)data + JSONOptions:(NSJSONReadingOptions)opts + request:(NSURLRequest *)request + error:(NSError *__autoreleasing *)error +{ + id obj; + NSString *message = @"The server could not be contacted."; + if (data) { + message = @"The server sent an invalid response."; + obj = [NSJSONSerialization JSONObjectWithData:data + options:opts + error:error]; + } + if ([obj isKindOfClass:[NSDictionary class]] && + obj[SuccessKey] && ![obj[SuccessKey] boolValue]) { + message = obj[ErrorKey]; + if (!message) { + message = @"An unknown error occured."; + } + obj = nil; + } + if (!obj && error) { + NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: + message, NSLocalizedDescriptionKey, + request.URL, NSURLErrorFailingURLErrorKey, + request.URL.absoluteString, NSURLErrorFailingURLStringErrorKey, + request.HTTPMethod, HPURLErrorFailingHTTPMethod, + nil]; + if ([response isKindOfClass:[NSHTTPURLResponse class]]) { + userInfo[HPURLErrorFailingHTTPStatusCode] = @([(NSHTTPURLResponse *)response statusCode]); + } + if (*error) { + userInfo[NSUnderlyingErrorKey] = *error; + } + *error = [NSError errorWithDomain:HPHackpadErrorDomain + code:HPFailedRequestError + userInfo:userInfo]; + + } +#if 0 + HPLog(@"[%@] <<< %@: %@", response.URL.host, response.URL.hp_fullPath, + [[NSString alloc] initWithBytes:data.bytes + length:data.length + encoding:NSUTF8StringEncoding]); +#endif + return obj; +} + +#pragma mark - NSURLConnection delegate + +- (void)connection:(NSURLConnection *)connection + didFailWithError:(NSError *)error +{ + [self.signInAsCond lock]; + @try { + @synchronized (self) { + if (!self.signInAsRequest || _authenticationRequest != self.signInAsRequest) { + return; + } + TFLog(@"[%@] Sign In As request failed: %@", + connection.currentRequest.URL.host, error); + self.signInAsRequest = nil; + self.authenticationState = HPSignInPromptAuthenticationState; + } + self.signInAsRequest = nil; + [self.signInAsCond signal]; + } + @finally { + [self.signInAsCond unlock]; + } +} + +- (NSURLRequest *)connection:(NSURLConnection *)connection + willSendRequest:(NSURLRequest *)request + redirectResponse:(NSURLResponse *)response +{ + [self.signInAsCond lock]; + @try { + @synchronized (self) { + if (!self.signInAsRequest || _authenticationRequest != self.signInAsRequest) { + [connection cancel]; + return nil; + } + if (!request.URL.hp_isHackpadURL) { + TFLog(@"[%@] Sign In As redirected to external URL: %@", + connection.originalRequest.URL.host, + request.URL); + self.authenticationState = HPSignInPromptAuthenticationState; + } else if ([request.URL.path isEqualToString:HPSignInPath]) { + HPLog(@"[%@] Sign In As failed (redirected to %@", + request.URL.host, request.URL.hp_fullPath); + self.authenticationState = HPSignInPromptAuthenticationState; + } else if ([request.URL.path isEqualToString:SignedInPath]) { + self.authenticationState = HPRequestAPISecretAuthenticationState; + } else { + return request; + } + } + [connection cancel]; + self.signInAsRequest = nil; + [self.signInAsCond signal]; + } + @finally { + [self.signInAsCond unlock]; + } + return nil; +} + +- (void)connection:(NSURLConnection *)connection +didReceiveResponse:(NSURLResponse *)response +{ + [self.signInAsCond lock]; + @try { + @synchronized (self) { + if (!self.signInAsRequest || _authenticationRequest != self.signInAsRequest) { + return; + } + TFLog(@"[%@] Sign In As received a response: %@", + connection.currentRequest.URL.host, response); + self.authenticationState = HPSignInPromptAuthenticationState; + } + [connection cancel]; + self.signInAsRequest = nil; + [self.signInAsCond signal]; + } + @finally { + [self.signInAsCond unlock]; + } +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPAlertViewBlockDelegate.h b/client/ios/Hackpad/HackpadKit/HPAlertViewBlockDelegate.h new file mode 100644 index 0000000..4e88b1f --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPAlertViewBlockDelegate.h @@ -0,0 +1,13 @@ +// +// HPAlertViewBlockDelegate.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface HPAlertViewBlockDelegate : NSObject +- (id)initWithBlock:(void (^)(UIAlertView *, NSInteger))handler; +@end diff --git a/client/ios/Hackpad/HackpadKit/HPAlertViewBlockDelegate.m b/client/ios/Hackpad/HackpadKit/HPAlertViewBlockDelegate.m new file mode 100644 index 0000000..bccc1ae --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPAlertViewBlockDelegate.m @@ -0,0 +1,36 @@ +// +// HPAlertViewBlockDelegate.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPAlertViewBlockDelegate.h" + +@interface HPAlertViewBlockDelegate () +@property (nonatomic, copy) void (^didDismissBlock)(UIAlertView *, NSInteger); +@property (nonatomic, strong) HPAlertViewBlockDelegate *strongSelf; +@end + +@implementation HPAlertViewBlockDelegate + +- (id)initWithBlock:(void (^)(UIAlertView *, NSInteger))handler +{ + self = [super init]; + if (self) { + self.strongSelf = self; + self.didDismissBlock = handler; + } + return self; +} + +- (void)alertView:(UIAlertView *)alertView +didDismissWithButtonIndex:(NSInteger)buttonIndex +{ + alertView.delegate = nil; + self.didDismissBlock(alertView, buttonIndex); + self.strongSelf = nil; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPCollection+Impl.h b/client/ios/Hackpad/HackpadKit/HPCollection+Impl.h new file mode 100644 index 0000000..925c88e --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPCollection+Impl.h @@ -0,0 +1,29 @@ +// +// HPCollection+Impl.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPCollection.h" + +COREDATA_EXTERN NSString * const HPCollectionIdParam; + +#define HPCollectionEntity (NSStringFromClass([HPCollection class])) + +@interface HPCollection (Impl) + +@property (nonatomic, readonly) NSURL *APIURL; +- (void)deleteWithCompletion:(void (^)(HPCollection *collection, NSError *))handler; + +- (void)addPadsObject:(HPPad *)pad + completion:(void (^)(HPCollection *, NSError *))handler; + +- (void)removePadsObject:(HPPad *)pad + completion:(void (^)(HPCollection *, NSError *))handler; + +- (void)setFollowed:(BOOL)followed + completion:(void (^)(HPCollection *, NSError *))handler; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPCollection+Impl.m b/client/ios/Hackpad/HackpadKit/HPCollection+Impl.m new file mode 100644 index 0000000..80b558b --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPCollection+Impl.m @@ -0,0 +1,182 @@ +// +// HPCollection+Impl.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPCollection+Impl.h" + +#import "HackpadKit.h" +#import "HackpadAdditions.h" + +static NSString * const HPAddPadToCollectionPath = @"/ep/group/add-pad"; +static NSString * const HPCollectionAPIPath = @"/api/1.0/group"; +static NSString * const HPDeleteCollectionPath = @"/ep/group/destroy"; +static NSString * const HPFollowCollectionPath = @"/ep/group/join"; +static NSString * const HPRemovePadFromCollectionPath = @"/ep/group/removepad"; +static NSString * const HPUnfollowCollectionPath = @"/ep/group/remove"; + +NSString * const HPCollectionIdParam = @"groupId"; + +static NSString * const HPReallySureParam = @"reallySure"; + +@implementation HPCollection (Impl) + +- (NSURL *)APIURL +{ + return [NSURL URLWithString:[HPCollectionAPIPath stringByAppendingPathComponent:self.collectionID] + relativeToURL:self.space.URL]; +} + +- (void)deleteWithCompletion:(void (^)(HPCollection *, NSError *))handler +{ + NSURL *URL = [NSURL URLWithString:HPDeleteCollectionPath + relativeToURL:self.space.URL]; + NSDictionary *params = @{HPCollectionIdParam:self.collectionID, + HPReallySureParam:@"yes", + HPAPIXSRFTokenParam:[HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + [self hp_sendAsynchronousRequest:request + block:^(HPCollection *collection, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + if (![collection.space.API parseJSONResponse:response + data:data + request:request + error:error]) { + return; + } + [collection.managedObjectContext deleteObject:collection]; + } + completion:handler]; +} + +- (void)addPadsObject:(HPPad *)pad + completion:(void (^)(HPCollection *, NSError *))handler +{ + NSError * __autoreleasing error; + if (pad.objectID.isTemporaryID && + ![pad.managedObjectContext obtainPermanentIDsForObjects:@[pad] + error:&error]) { + if (handler) { + handler(self, error); + } + return; + } + NSURL *URL = [NSURL URLWithString:HPAddPadToCollectionPath + relativeToURL:self.space.URL]; + NSDictionary *params = @{HPCollectionIdParam: self.collectionID, + HPPadIdParam: pad.padID, + HPAPIXSRFTokenParam: [HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + NSManagedObjectID *padObjectID = pad.objectID; + [self hp_sendAsynchronousRequest:request + block:^(HPCollection *collection, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + if (![collection.space.API parseJSONResponse:response + data:data + request:request + error:error]) { + return; + } + HPPad *pad = (HPPad *)[collection.managedObjectContext existingObjectWithID:padObjectID + error:error]; + if (!pad) { + return; + } + [collection addPadsObject:pad]; + } + completion:handler]; +} + +- (void)removePadsObject:(HPPad *)pad + completion:(void (^)(HPCollection *, NSError *))handler +{ + NSError * __autoreleasing error; + if (pad.objectID.isTemporaryID && + ![pad.managedObjectContext obtainPermanentIDsForObjects:@[pad] + error:&error]) { + if (handler) { + handler(self, error); + } + return; + } + + NSURL *URL = [NSURL URLWithString:HPRemovePadFromCollectionPath + relativeToURL:self.space.URL]; + NSDictionary *params = @{HPCollectionIdParam: self.collectionID, + HPPadIdParam: pad.padID, + HPAPIXSRFTokenParam: [HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + NSManagedObjectID *padObjectID = pad.objectID; + [self hp_sendAsynchronousRequest:request + block:^(HPCollection *collection, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + if (![collection.space.API parseJSONResponse:response + data:data + request:request + error:error]) { + return; + } + HPPad *pad = (HPPad *)[collection.managedObjectContext existingObjectWithID:padObjectID + error:error]; + if (!pad) { + return; + } + [collection removePadsObject:pad]; + } + completion:handler]; +} + +- (void)setFollowed:(BOOL)followed + completion:(void (^)(HPCollection *, NSError *))handler +{ + if (self.followed == followed) { + if (handler) { + handler(self, nil); + } + return; + } + + NSURL *URL = [NSURL URLWithString:followed ? HPFollowCollectionPath : HPUnfollowCollectionPath + relativeToURL:self.space.URL]; + NSDictionary *params = @{ HPCollectionIdParam: self.collectionID, + HPUserIdParam: self.space.userID, + HPAPIXSRFTokenParam: [HPAPI XSRFTokenForURL:URL] }; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + [self hp_sendAsynchronousRequest:request + block:^(HPCollection *collection, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + if (![collection.space.API parseJSONResponse:response + data:data + request:request + error:error]) { + return; + } + collection.followed = followed; + } + completion:handler]; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPCollection.h b/client/ios/Hackpad/HackpadKit/HPCollection.h new file mode 100644 index 0000000..e9cfe78 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPCollection.h @@ -0,0 +1,31 @@ +// +// HPCollection.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import + +@class HPPad, HPSharingOptions, HPSpace; + +@interface HPCollection : NSManagedObject + +@property (nonatomic, retain) NSString * collectionID; +@property (nonatomic) BOOL followed; +@property (nonatomic, retain) NSString * title; +@property (nonatomic, retain) NSSet *pads; +@property (nonatomic, retain) HPSharingOptions *sharingOptions; +@property (nonatomic, retain) HPSpace *space; +@end + +@interface HPCollection (CoreDataGeneratedAccessors) + +- (void)addPadsObject:(HPPad *)value; +- (void)removePadsObject:(HPPad *)value; +- (void)addPads:(NSSet *)values; +- (void)removePads:(NSSet *)values; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPCollection.m b/client/ios/Hackpad/HackpadKit/HPCollection.m new file mode 100644 index 0000000..05fa537 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPCollection.m @@ -0,0 +1,24 @@ +// +// HPCollection.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPCollection.h" +#import "HPPad.h" +#import "HPSharingOptions.h" +#import "HPSpace.h" + + +@implementation HPCollection + +@dynamic collectionID; +@dynamic followed; +@dynamic title; +@dynamic pads; +@dynamic sharingOptions; +@dynamic space; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPCollectionSynchronizer.h b/client/ios/Hackpad/HackpadKit/HPCollectionSynchronizer.h new file mode 100644 index 0000000..3b6c015 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPCollectionSynchronizer.h @@ -0,0 +1,17 @@ +// +// HPCollectionSynchronizer.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPSynchronizer.h" + +@class HPSpace; + +@interface HPCollectionSynchronizer : HPSynchronizer + +- (id)initWithSpace:(HPSpace *)space; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPCollectionSynchronizer.m b/client/ios/Hackpad/HackpadKit/HPCollectionSynchronizer.m new file mode 100644 index 0000000..9b0b802 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPCollectionSynchronizer.m @@ -0,0 +1,118 @@ +// +// HPCollectionSynchronizer.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPCollectionSynchronizer.h" + +#import + +static NSString * const GroupIdKey = @"groupId"; +static NSString * const PadIdKey = @"localPadId"; +static NSString * const PadsKey = @"localPadIds"; + +@interface HPCollectionSynchronizer () +@property (nonatomic, strong) HPSpace *space; +@property (nonatomic, strong) NSMutableDictionary *padsByID; +@end + +@implementation HPCollectionSynchronizer + +- (id)initWithSpace:(HPSpace *)space +{ + NSParameterAssert(space); + + if (!(self = [super init])) { + return nil; + } + self.space = space; + self.padsByID = [NSMutableDictionary dictionary]; + return self; +} + +- (void)synchronizer:(HPSynchronizer *)synchronizer + willSaveObjects:(NSArray *)objects +{ + [objects enumerateObjectsUsingBlock:^(HPPad *pad, NSUInteger idx, BOOL *stop) { + self.padsByID[pad.padID] = pad; + }]; +} + +- (NSFetchRequest *)fetchRequestWithObjects:(NSArray *)JSONCollections + error:(NSError *__autoreleasing *)error +{ + static NSString * const CollectionIDKey = @"collectionID"; + + NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:HPCollectionEntity]; + fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:CollectionIDKey + ascending:YES]]; + fetchRequest.fetchBatchSize = 64; + fetchRequest.predicate = [NSPredicate predicateWithFormat:@"space == %@ && collectionID != nil", self.space]; + return fetchRequest; +} + +- (NSArray *)objectsSortDescriptors +{ + return @[[NSSortDescriptor sortDescriptorWithKey:GroupIdKey + ascending:YES]]; +} + +- (NSComparisonResult)compareObject:(NSDictionary *)JSONCollection + existingObject:(HPCollection *)collection +{ + if (!collection.collectionID) { + return NSOrderedAscending; + } + if (![JSONCollection isKindOfClass:[NSDictionary class]]) { + return NSOrderedDescending; + } + NSString *collectionID = JSONCollection[GroupIdKey]; + if (![collectionID isKindOfClass:[NSString class]]) { + return NSOrderedDescending; + } + return [collectionID compare:collection.collectionID]; +} + +- (BOOL)updateExistingObject:(HPCollection *)collection + object:(NSDictionary *)JSONCollection +{ + static NSString * const TitleKey = @"title"; + + if (![collection.title isEqualToString:JSONCollection[TitleKey]]) { + collection.title = JSONCollection[TitleKey]; + } + if (!collection.followed) { + collection.followed = YES; + } + NSArray *JSONPads = JSONCollection[PadsKey]; + NSMutableSet *pads = [NSMutableSet setWithCapacity:JSONPads.count]; + [JSONPads enumerateObjectsUsingBlock:^(NSDictionary *JSONPad, NSUInteger idx, BOOL *stop) { + if (![JSONPad isKindOfClass:[NSString class]]) { + return; + } + HPPad *pad = self.padsByID[JSONPad]; + if (!pad) { + return; + } + [pads addObject:pad]; + }]; + if (![collection.pads isEqualToSet:pads]) { + collection.pads = pads; + } + if (collection.collectionID) { + return YES; + } + collection.collectionID = JSONCollection[GroupIdKey]; + collection.space = self.space; + return YES; +} + +- (void)existingObjectNotFound:(HPCollection *)existingObject +{ + existingObject.followed = NO; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPCoreDataStack.h b/client/ios/Hackpad/HackpadKit/HPCoreDataStack.h new file mode 100644 index 0000000..cd7c3d5 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPCoreDataStack.h @@ -0,0 +1,28 @@ +// +// HPCoreDataStack.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@protocol HPCoreDataStackDelegate; + +@interface HPCoreDataStack : NSObject + +@property (strong, readonly, nonatomic) NSManagedObjectContext *mainContext; +@property (strong, readonly, nonatomic) NSManagedObjectModel *managedObjectModel; +@property (strong, readonly, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; +@property (nonatomic, readonly, getter=isMigrationNeeded) BOOL migrationNeeded; +@property (nonatomic, strong) NSURL *storeURL; +@property (nonatomic, strong) NSString *storeType; + ++ (void)setSharedStateRestorationCoreDataStack:(HPCoreDataStack *)coreDataStack; ++ (HPCoreDataStack *)sharedStateRestorationCoreDataStack; + +// Completion block will always be executed on the main queue. +- (void)saveWithBlock:(void(^)(NSManagedObjectContext *localContext))block + completion:(void(^)(NSError *error))completion; +@end diff --git a/client/ios/Hackpad/HackpadKit/HPCoreDataStack.m b/client/ios/Hackpad/HackpadKit/HPCoreDataStack.m new file mode 100644 index 0000000..9e8a7fb --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPCoreDataStack.m @@ -0,0 +1,162 @@ +// +// HPCoreDataStack.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPCoreDataStack.h" + +#import + +#import "HackpadAdditions.h" +#import "HPRollbackDeletedObjectsMergePolicy.h" + +#import + +static HPCoreDataStack *SharedStateRestorationCoreDataStack; + +@interface HPCoreDataStack () + +@property (strong, nonatomic) NSManagedObjectContext *rootContext; +@property (strong, nonatomic) NSManagedObjectContext *workerContext; + +@property (strong, readwrite, nonatomic) NSManagedObjectContext *mainContext; +@property (strong, readwrite, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; +@property (strong, readwrite, nonatomic) NSManagedObjectModel *managedObjectModel; + +@end + +@implementation HPCoreDataStack + ++ (void)setSharedStateRestorationCoreDataStack:(HPCoreDataStack *)coreDataStack +{ + SharedStateRestorationCoreDataStack = coreDataStack; +} + ++ (HPCoreDataStack *)sharedStateRestorationCoreDataStack +{ + return SharedStateRestorationCoreDataStack; +} + +- (NSString *)storeType +{ + if (_storeType) { + return _storeType; + } + _storeType = NSSQLiteStoreType; + return _storeType; +} + +- (void)saveWithBlock:(void(^)(NSManagedObjectContext *localContext))block + completion:(void(^)(NSError *error))completion +{ + NSManagedObjectContext *workerContext = self.workerContext; + [self.workerContext performBlock:^{ + block(workerContext); + NSError *error; + if (workerContext.hasChanges) { + [workerContext hp_saveToStore:&error]; + } + if (completion) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + completion(error); + }]; + } + [workerContext reset]; + }]; +} + +#pragma mark - Accessors + +- (NSManagedObjectContext *)mainContext +{ + if (!_mainContext) { + _mainContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; + _mainContext.mergePolicy = [[HPRollbackDeletedObjectsMergePolicy alloc] initWithMergeType:NSMergeByPropertyObjectTrumpMergePolicyType]; + _mainContext.parentContext = self.rootContext; + _mainContext.hp_name = @"Main Context"; + [_mainContext hp_setStack:self]; + } + return _mainContext; +} + +- (NSManagedObjectContext *)rootContext +{ + if (!_rootContext) { + _rootContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; + NSPersistentStoreCoordinator *persistentStoreCoordinator = self.persistentStoreCoordinator; + [_rootContext performBlockAndWait:^{ + _rootContext.persistentStoreCoordinator = persistentStoreCoordinator; + _rootContext.hp_name = @"Root Context"; + [_rootContext hp_setStack:self]; + }]; + } + return _rootContext; +} + +- (NSManagedObjectModel *)managedObjectModel +{ + if (!_managedObjectModel) { + NSURL *modelURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"Hackpad" withExtension:@"momd"]; + _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; + } + + return _managedObjectModel; +} + +- (NSPersistentStoreCoordinator *)persistentStoreCoordinator +{ + if (_persistentStoreCoordinator) { + return _persistentStoreCoordinator; + } + + NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption:@YES, + NSInferMappingModelAutomaticallyOption:@YES}; + _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel]; + + NSError * __autoreleasing error; + if (![_persistentStoreCoordinator addPersistentStoreWithType:self.storeType + configuration:nil + URL:self.storeURL + options:options + error:&error]) { + TFLog(@"Could not add persisitent store: %@", error); + abort(); + } + return _persistentStoreCoordinator; +} + +- (NSManagedObjectContext *)workerContext +{ + if (!_workerContext) { + _workerContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; + _workerContext.hp_name = @"Worker Context"; + _workerContext.parentContext = self.mainContext; + [_workerContext hp_setStack:self]; + } + return _workerContext; +} + +- (BOOL)isMigrationNeeded +{ + NSError *error; + + // Check if we need to migrate + NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:self.storeType + URL:self.storeURL + error:&error]; + BOOL isMigrationNeeded = NO; + + if (sourceMetadata != nil) { + NSManagedObjectModel *destinationModel = [self managedObjectModel]; + // Migration is needed if destinationModel is NOT compatible + isMigrationNeeded = ![destinationModel isConfiguration:nil + compatibleWithStoreMetadata:sourceMetadata]; + } + + return isMigrationNeeded; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPEntityMigrationPolicy.h b/client/ios/Hackpad/HackpadKit/HPEntityMigrationPolicy.h new file mode 100644 index 0000000..fd478a9 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPEntityMigrationPolicy.h @@ -0,0 +1,13 @@ +// +// HPEntityMigrationPolicy.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface HPEntityMigrationPolicy : NSEntityMigrationPolicy + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPEntityMigrationPolicy.m b/client/ios/Hackpad/HackpadKit/HPEntityMigrationPolicy.m new file mode 100644 index 0000000..f0cbb94 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPEntityMigrationPolicy.m @@ -0,0 +1,18 @@ +// +// HPEntityMigrationPolicy.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPEntityMigrationPolicy.h" + +@implementation HPEntityMigrationPolicy + +- (NSDate *)dateWithNumberSince1970:(NSNumber *)timeInterval +{ + return [NSDate dateWithTimeIntervalSince1970:timeInterval.doubleValue]; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPError.h b/client/ios/Hackpad/HackpadKit/HPError.h new file mode 100644 index 0000000..61f06ca --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPError.h @@ -0,0 +1,23 @@ +// +// HPError.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +FOUNDATION_EXTERN NSString * const HPHackpadErrorDomain; + +FOUNDATION_EXTERN NSString * const HPURLErrorFailingHTTPStatusCode; +FOUNDATION_EXTERN NSString * const HPURLErrorFailingHTTPMethod; + +enum { + HPFailedRequestError = 0, + HPSignInRequired, + HPDeletedObjectError, + HPDuplicateEntityError, + HPInvalidURLError, + HPPadInitializationError +}; diff --git a/client/ios/Hackpad/HackpadKit/HPError.m b/client/ios/Hackpad/HackpadKit/HPError.m new file mode 100644 index 0000000..8c29fbf --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPError.m @@ -0,0 +1,13 @@ +// +// HPError.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPError.h" + +NSString * const HPHackpadErrorDomain = @"HPHackpadErrorDomain"; +NSString * const HPURLErrorFailingHTTPStatusCode = @"HPURLErrorFailingHTTPStatusCode"; +NSString * const HPURLErrorFailingHTTPMethod = @"HPURLErrorFailingHTTPMethod"; diff --git a/client/ios/Hackpad/HackpadKit/HPImageUpload+Impl.h b/client/ios/Hackpad/HackpadKit/HPImageUpload+Impl.h new file mode 100644 index 0000000..a54f433 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPImageUpload+Impl.h @@ -0,0 +1,17 @@ +// +// HPImageUpload+Impl.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPImageUpload.h" + +#define HPImageUploadEntity (NSStringFromClass([HPImageUpload class])) + +@interface HPImageUpload (Impl) +@property (nonatomic, readonly) NSString *key; +@property (nonatomic, readonly) NSURL *URL; +- (void)uploadWithCompletion:(void (^)(NSError *))handler; +@end diff --git a/client/ios/Hackpad/HackpadKit/HPImageUpload+Impl.m b/client/ios/Hackpad/HackpadKit/HPImageUpload+Impl.m new file mode 100644 index 0000000..b2f9547 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPImageUpload+Impl.m @@ -0,0 +1,82 @@ +// +// HPImageUpload+Impl.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPImageUpload+Impl.h" + +#import +#import + +@implementation HPImageUpload (Impl) + +- (NSString *)key +{ + NSParameterAssert(self.pad.padID); + NSParameterAssert(self.attachmentID); + NSParameterAssert(self.fileName); + return [@[self.pad.URL.host, self.pad.padID, self.attachmentID, self.fileName] componentsJoinedByString:@"_"]; +} + +- (NSURL *)URL +{ + static NSString * const S3URL = @""; + return [NSURL URLWithString:[(self.rootURL ?: S3URL) stringByAppendingString:self.key]]; +} + +- (void)uploadWithCompletion:(void (^)(NSError *))handler +{ + static NSString * const AmzAclHeader = @"x-amz-acl"; + static NSString * const ContentTypeHeader = @"Content-Type"; + static NSString * const PublicReadACL = @"public-read"; + + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.URL + cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData + timeoutInterval:300]; + request.HTTPMethod = @"PUT"; + [request setValue:self.contentType + forHTTPHeaderField:ContentTypeHeader]; + [request setValue:PublicReadACL + forHTTPHeaderField:AmzAclHeader]; + request.HTTPBody = self.image; + + NSError * __block connectionError; + [self hp_sendAsynchronousRequest:request + block:^(HPImageUpload *image, + NSURLResponse *response, + NSData *data, + NSError *__autoreleasing *error) + { + if (*error) { + connectionError = *error; + return; + } + NSAssert([response isKindOfClass:[NSHTTPURLResponse class]], + @"Unexpected response type: %@", + NSStringFromClass(response.class)); + NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response; + if (!HTTPResponse.statusCode == 200) { + NSDictionary *userInfo = @{NSURLErrorFailingURLErrorKey:request.URL, + NSURLErrorFailingURLStringErrorKey:request.URL.absoluteString, + HPURLErrorFailingHTTPMethod:request.HTTPMethod, + HPURLErrorFailingHTTPStatusCode:@(HTTPResponse.statusCode)}; + connectionError = [NSError errorWithDomain:HPHackpadErrorDomain + code:HPFailedRequestError + userInfo:userInfo]; + return; + } + [image.managedObjectContext deleteObject:image]; + } completion:^(HPImageUpload *image, NSError *error) { + if (handler) { + if (!error) { + error = connectionError; + } + handler(error); + } + }]; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPImageUpload.h b/client/ios/Hackpad/HackpadKit/HPImageUpload.h new file mode 100644 index 0000000..a6f1e49 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPImageUpload.h @@ -0,0 +1,23 @@ +// +// HPImageUpload.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import +#import + +@class HPPad; + +@interface HPImageUpload : NSManagedObject + +@property (nonatomic, retain) NSString * attachmentID; +@property (nonatomic, retain) NSString * contentType; +@property (nonatomic, retain) NSString * fileName; +@property (nonatomic, retain) NSData * image; +@property (nonatomic, retain) NSString * rootURL; +@property (nonatomic, retain) HPPad *pad; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPImageUpload.m b/client/ios/Hackpad/HackpadKit/HPImageUpload.m new file mode 100644 index 0000000..a856721 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPImageUpload.m @@ -0,0 +1,22 @@ +// +// HPImageUpload.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPImageUpload.h" +#import "HPPad.h" + + +@implementation HPImageUpload + +@dynamic attachmentID; +@dynamic contentType; +@dynamic fileName; +@dynamic image; +@dynamic rootURL; +@dynamic pad; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPImageUploadURLProtocol.h b/client/ios/Hackpad/HackpadKit/HPImageUploadURLProtocol.h new file mode 100644 index 0000000..d239fe7 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPImageUploadURLProtocol.h @@ -0,0 +1,17 @@ +// +// HPImageUploadURLProtocol.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPCoreDataStack; + +FOUNDATION_EXTERN NSString * const HPImageUploadScheme; + +@interface HPImageUploadURLProtocol : NSURLProtocol ++ (void)setSharedCoreDataStack:(HPCoreDataStack *)coreDataStack; +@end diff --git a/client/ios/Hackpad/HackpadKit/HPImageUploadURLProtocol.m b/client/ios/Hackpad/HackpadKit/HPImageUploadURLProtocol.m new file mode 100644 index 0000000..3d7fef5 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPImageUploadURLProtocol.m @@ -0,0 +1,111 @@ +// +// HPImageUploadURLProtocol.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPImageUploadURLProtocol.h" + +#import + +#if 0 +#define d(x) x +#else +#define d(x) +#endif + +NSString * const HPImageUploadScheme = @"x-hackpad-image-upload"; + +static HPCoreDataStack *CoreDataStack; + +@interface HPImageUploadURLProtocol () +@property (nonatomic, assign) BOOL stopped; +@end + +@implementation HPImageUploadURLProtocol + ++ (void)setSharedCoreDataStack:(HPCoreDataStack *)coreDataStack +{ + CoreDataStack = coreDataStack; +} + ++ (NSURL *)coreDataURLWithRequestURL:(NSURL *)URL +{ + static NSString * const XCoreDataScheme = @"x-coredata"; + NSString *URLString = [NSString stringWithFormat:@"%@://%@%@", + XCoreDataScheme, URL.host, URL.path]; + return [NSURL URLWithString:URLString]; +} + ++ (NSManagedObjectID *)objectIDWithRequestURL:(NSURL *)URL +{ + URL = [self coreDataURLWithRequestURL:URL]; + return [CoreDataStack.persistentStoreCoordinator managedObjectIDForURIRepresentation:URL]; +} + ++ (BOOL)canInitWithRequest:(NSURLRequest *)request +{ + d(HPLog(@"%s %@", __PRETTY_FUNCTION__, request.URL)); + if (![request.URL.scheme isEqualToString:HPImageUploadScheme]) { + return NO; + } + NSManagedObjectID *objectID = [self objectIDWithRequestURL:request.URL]; + return [objectID.entity.name isEqualToString:HPImageUploadEntity]; +} + ++ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request +{ + return request; +} + +- (void)startLoading +{ + d(HPLog(@"%s %@", __PRETTY_FUNCTION__, self.request.URL)); + id client = self.client; + NSURLRequest *request = self.request; + HPImageUploadURLProtocol * __weak weakSelf = self; + [CoreDataStack saveWithBlock:^(NSManagedObjectContext *localContext) { + d(HPLog(@"%s %@", __PRETTY_FUNCTION__, request.URL)); + HPImageUploadURLProtocol *strongSelf = weakSelf; + if (!strongSelf) { + return; + } + NSManagedObjectID *objectID = [HPImageUploadURLProtocol objectIDWithRequestURL:request.URL]; + NSError * __autoreleasing error; + HPImageUpload *imageUpload = (HPImageUpload *)[localContext existingObjectWithID:objectID + error:&error]; + if (error) { + [client URLProtocol:weakSelf + didFailWithError:error]; + return; + } + NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL + MIMEType:imageUpload.contentType + expectedContentLength:imageUpload.image.length + textEncodingName:nil]; + @synchronized (strongSelf) { + // The docs say "should" but not "must" - so races are acceptable? + if (strongSelf.stopped) { + return; + } + } + [client URLProtocol:strongSelf + didReceiveResponse:response + cacheStoragePolicy:NSURLCacheStorageAllowedInMemoryOnly]; + [client URLProtocol:strongSelf + didLoadData:imageUpload.image]; + [client URLProtocolDidFinishLoading:strongSelf]; + } completion:nil]; +} + +- (void)stopLoading +{ + d(HPLog(@"%s %@", __PRETTY_FUNCTION__, self.request.URL)); + @synchronized (self) { + self.stopped = YES; + } +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPLog.h b/client/ios/Hackpad/HackpadKit/HPLog.h new file mode 100644 index 0000000..ea1baf8 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPLog.h @@ -0,0 +1,19 @@ +// +// HPLog.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#ifndef Hackpad_HPLog_h +#define Hackpad_HPLog_h + +#if DEBUG +#define HPLog( s, ... ) NSLog( @"<%s:%d> %@", __PRETTY_FUNCTION__, __LINE__, \ + [NSString stringWithFormat:(s), ##__VA_ARGS__] ) +#else +#define HPLog( s, ... ) +#endif + +#endif diff --git a/client/ios/Hackpad/HackpadKit/HPPad+Impl.h b/client/ios/Hackpad/HackpadKit/HPPad+Impl.h new file mode 100644 index 0000000..cb7c95b --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPad+Impl.h @@ -0,0 +1,94 @@ +// +// HPPad+Impl.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPad.h" + +#define HPPadEntity (NSStringFromClass([HPPad class])) + +COREDATA_EXTERN NSString * const HPPadDidGetGlobalPadIDNotification; +COREDATA_EXTERN NSString * const HPGlobalPadIDKey; + +COREDATA_EXTERN NSString * const HPLimitParam; +COREDATA_EXTERN NSString * const HPPadIdParam; +COREDATA_EXTERN NSString * const HPUserIdParam; + +COREDATA_EXTERN NSString * const HPPadClientVarsPath; + +@interface HPPad (Impl) + +@property (nonatomic, readonly) NSURL *URL; +@property (nonatomic, readonly) NSURL *APIURL; +@property (nonatomic, readonly, getter = isWelcomePad) BOOL welcomePad; +@property (nonatomic, readonly, getter = isFeatureHelpPad) BOOL featureHelpPad; +@property (nonatomic, readonly, getter = isTermsOfServicePad) BOOL termsOfServicePad; +@property (nonatomic, readonly, getter = isPrivacyPolicyPad) BOOL privacyPolicyPad; +@property (nonatomic, readonly) NSString *fullSnippetHTML; +@property (nonatomic, readonly, getter = isCreator) BOOL creator; +@property (nonatomic, readonly) NSDictionary *clientVars; +@property (nonatomic, readonly) BOOL hasClientVars; + ++ (NSString *)fullSnippetHTMLWithSnippetHTML:(NSString *)snippetHTML; ++ (NSString *)padIDWithURL:(NSURL *)URL; + ++ (id)padWithID:(NSString *)padID + inSpace:(HPSpace *)space + error:(NSError *__autoreleasing *)error; + ++ (id)padWithID:(NSString *)padID + title:(NSString *)title + spaceURL:(NSURL *)URL +managedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error; ++ (id)padWithURL:(NSURL *)URL +managedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error; + ++ (id)welcomePadInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error; + ++ (id)featureHelpPadInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error; + ++ (id)termsOfServicePadInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error; + ++ (id)privacyPolicyPadInObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error; + +- (void)deleteWithCompletion:(void (^)(HPPad *, NSError *))handler; + +- (void)setFollowed:(BOOL)followed + completion:(void (^)(HPPad *, NSError *))handler; + + +- (void)sendInvitationWithUserId:(NSString *)userId + completion:(void (^)(HPPad *, NSError *))handler; + +- (void)sendInvitationWithEmail:(NSString *)email + completion:(void (^)(HPPad *, NSError *))handler; + +- (void)sendInvitationWithFacebookID:(NSString *)friendID + name:(NSString *)friendName + completion:(void (^)(HPPad *, NSError *))handler; + +- (void)removeUserWithId:(NSString *)userID + completion:(void (^)(HPPad *, NSError *))handler; + +- (void)requestClientVarsWithRefresh:(BOOL)refresh + completion:(void (^)(HPPad *, NSError *))handler; + +- (void)getPadIDWithCompletion:(void (^)(HPPad *, NSError *))handler; +- (void)requestAuthorsWithCompletion:(void (^)(HPPad *, NSError *))handler; +- (void)requestContentWithCompletion:(void (^)(HPPad *, NSError *))handler; +- (void)applyMissedChangesWithCompletion:(void (^)(HPPad *, NSError *))handler; +- (void)discardMissedChangesWithCompletion:(void (^)(HPPad *, NSError *))handler; +- (void)setClientVars:(NSDictionary *)clientVars + lastEditedDate:(NSTimeInterval)lastEditedDate; +- (void)requestAccessWithCompletion:(void (^)(HPPad *, NSError *))handler; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPad+Impl.m b/client/ios/Hackpad/HackpadKit/HPPad+Impl.m new file mode 100644 index 0000000..b4d922f --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPad+Impl.m @@ -0,0 +1,915 @@ +// +// HPPad+Impl.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPad+Impl.h" + +#import "HackpadKit.h" +#import "HackpadUIAdditions.h" + +#import +#import +#import "GTMOAuthAuthentication.h" + +NSString * const HPPadDidGetGlobalPadIDNotification = @"HPPadDidGetGlobalPadIDNotification"; +NSString * const HPGlobalPadIDKey = @"HPGlobalPadID"; + +NSString * const HPLimitParam = @"limit"; +NSString * const HPPadIdParam = @"padId"; +NSString * const HPUserIdParam = @"userId"; + +NSString * const HPPadClientVarsPath = @"/ep/pad/client-vars"; + +static NSString * const HPDeletePadPath = @"/ep/padlist/delete"; +static NSString * const HPEmailInvitePath = @"/ep/pad/emailinvite"; +static NSString * const HPFacebookInvitePath = @"/ep/pad/facebookinvite"; +static NSString * const HPFollowPadPath = @"/ep/pad/follow"; +static NSString * const HPHackpadInvitePath = @"/ep/pad/hackpadinvite"; +static NSString * const HPNewPadPath = @"/api/1.0/pad/create"; +static NSString * const HPPadAPIPath = @"/api/1.0/pad"; +static NSString * const HPPadApplyMissedChangesPath = @"/ep/pad/apply-missed-changes"; +static NSString * const HPPadInviteesPathComponent = @"invitees"; +static NSString * const HPPadRemoveUserPath = @"/ep/pad/removeuser"; + +static NSString * const AjaxParam = @"ajax"; +static NSString * const FollowPrefParam = @"followPref"; +static NSString * const HPEncryptedUserIdParam = @"encryptedUserId"; +static NSString * const HPFacebookPostIdParam = @"facebookPostId"; +static NSString * const HPFriendIdParam = @"friend_id"; +static NSString * const HPFriendNameParam = @"friendName"; +static NSString * const HPGlobalPadIdParam = @"globalPadId"; +static NSString * const HPPadIdToDeleteParam = @"padIdToDelete"; +static NSString * const HPToAddressParam = @"toAddress"; + +static NSString * const ClientVarsKey = @"clientVars"; +static NSString * const ClientVarsLastEditedDateKey = @"clientVarsLastEditedDate"; +static NSString * const CollabClientVarsKey = @"collab_client_vars"; +static NSString * const CommittedChangesetKey = @"committedChangeset"; +static NSString * const FurtherChangesetKey = @"furtherChangeset"; +static NSString * const HTMLDiffKey = @"htmlDiff"; +static NSString * const MissedChangesKey = @"missedChanges"; +static NSString * const PadIDKey = @"padID"; +static NSString * const PadTitleKey = @"padTitle"; +static NSString * const RequestKey = @"request"; +static NSString * const RevKey = @"rev"; + +static NSString * const MissedChangesParam = @"missedChanges"; + +static NSString * const FeatureHelpPadID = @"mlZvEsJykI5"; +static NSString * const PrivacyPolicyPadID = @"RpTWPko6ER2"; +static NSString * const TermsOfServicePadID = @"83netTWokps"; +static NSString * const WelcomePadID = @"AWELCOMEPAD"; +#if TARGET_IPHONE_SIMULATOR +static NSString * const DevServerKey = @"devServer"; +static NSString * const DevWelcomePadID = @"ElgHCg3Ej0r"; +#endif + +static NSString * const ContentPathComponent = @"content.txt"; +static NSString * const RevisionsPathComponent = @"revisions"; + +static NSString * const LastEditedDateHeader = @"X-Hackpad-LastEditedDate"; + +static NSString * const SnippetHTMLFormat = +@"\nTitle%@"; + +@implementation HPPad (Impl) + ++ (id)padWithID:(NSString *)padID + title:(NSString *)title + inSpace:(HPSpace *)space + error:(NSError *__autoreleasing *)error +{ + if (padID) { + NSParameterAssert(padID.length); + } + NSParameterAssert(space); + + HPPad *pad; + + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPPadEntity]; + fetch.predicate = [NSPredicate predicateWithFormat:@"(padID == %@) AND (space == %@)", + padID, space]; + fetch.fetchLimit = 1; + NSArray *pads = [space.managedObjectContext executeFetchRequest:fetch + error:error]; + if (!pads) { + return nil; + } + if (pads.count) { + return pads[0]; + } + pad = [NSEntityDescription insertNewObjectForEntityForName:HPPadEntity + inManagedObjectContext:space.managedObjectContext]; + pad.space = space; + pad.padID = padID; + pad.title = title; + + return pad; +} + ++ (id)padWithID:(NSString *)padID + inSpace:(HPSpace *)space + error:(NSError *__autoreleasing *)error +{ + return [self padWithID:padID + title:@"Untitled" + inSpace:space + error:error]; +} + ++ (id)padWithID:(NSString *)padID + title:(NSString *)title + spaceURL:(NSURL *)URL +managedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error +{ + NSParameterAssert([URL isKindOfClass:[NSURL class]]); + NSError * __autoreleasing localError; + + HPSpace *space = [HPSpace spaceWithURL:URL + inManagedObjectContext:managedObjectContext + error:&localError]; + if (localError) { + if (error) { + *error = localError; + } + return nil; + } + + if (!space) { + space = [HPSpace insertSpaceWithURL:URL + name:nil + managedObjectContext:managedObjectContext]; + } + + return [self padWithID:padID + title:title + inSpace:space + error:error]; +} + ++ (NSString *)padIDWithURL:(NSURL *)URL +{ + if (!URL.hp_isHackpadURL) { + return nil; + } + static NSString * const prettyPattern = @"^\\/[^\\/]+-([a-zA-Z0-9]{11})$"; + static NSString * const padIDPattern = @"^\\/([^\\/]+)$"; + NSString * __block padID; + NSString *path = URL.path; + [@[prettyPattern, padIDPattern] enumerateObjectsUsingBlock:^(NSString *pattern, NSUInteger idx, BOOL *stop) { + NSError * __autoreleasing error; + NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:pattern + options:0 + error:&error]; + if (!regExp) { + TFLog(@"[%@] Invalid regexp for pattern %@: %@", URL.host, pattern, error); + return; + } + NSTextCheckingResult *match = [regExp firstMatchInString:path + options:0 + range:NSMakeRange(0, path.length)]; + if (match) { + NSRange range = [match rangeAtIndex:1]; + if (range.location != NSNotFound) { + padID = [path substringWithRange:range]; + *stop = YES; + } + } + }]; + return padID; +} + ++ (id)padWithURL:(NSURL *)URL +managedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error +{ + NSString *padID = [self padIDWithURL:URL]; + if (padID) { + return [self padWithID:padID + title:@"Untitled" + spaceURL:URL + managedObjectContext:managedObjectContext + error:error]; + } else if (error) { + *error = [NSError errorWithDomain:HPHackpadErrorDomain + code:HPInvalidURLError + userInfo:@{NSLocalizedDescriptionKey:@"The URL is not a valid Hackpad URL", + NSURLErrorFailingURLErrorKey:URL}]; + } + return nil; +} + ++ (id)welcomePadInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError *__autoreleasing *)error +{ + NSString *padID = WelcomePadID; +#if TARGET_IPHONE_SIMULATOR + if ([[NSUserDefaults standardUserDefaults] boolForKey:DevServerKey]) { + padID = DevWelcomePadID; + } +#endif + return [self padWithID:padID + title:@"Welcome to Hackpad" + spaceURL:[NSURL hp_sharedHackpadURL] + managedObjectContext:managedObjectContext + error:error]; +} + ++ (id)privacyPolicyPadInObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError *__autoreleasing *)error +{ + return [self padWithID:PrivacyPolicyPadID + title:@"Hackpad Privacy Policy" + spaceURL:[NSURL hp_sharedHackpadURL] + managedObjectContext:managedObjectContext + error:error]; +} + ++ (id)termsOfServicePadInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError *__autoreleasing *)error +{ + return [self padWithID:TermsOfServicePadID + title:@"Hackpad Terms of Service" + spaceURL:[NSURL hp_sharedHackpadURL] + managedObjectContext:managedObjectContext + error:error]; +} + ++ (id)featureHelpPadInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError *__autoreleasing *)error +{ + return [self padWithID:FeatureHelpPadID + title:@"Hackpad Feature Help" + spaceURL:[NSURL hp_sharedHackpadURL] + managedObjectContext:managedObjectContext + error:error]; +} + +- (NSURL *)URL +{ + return [NSURL URLWithString:self.padID + relativeToURL:self.space.URL]; +} + +- (NSURL *)APIURL +{ + return [NSURL URLWithString:[HPPadAPIPath stringByAppendingPathComponent:self.padID] + relativeToURL:self.space.URL]; +} + +- (void)deleteWithCompletion:(void (^)(HPPad *, NSError *))handler +{ + if (!self.padID) { + [self hp_performBlock:^(HPPad *pad, NSError *__autoreleasing *error) { + [pad.managedObjectContext deleteObject:pad]; + } completion:handler]; + return; + } + [self hp_performBlock:^(HPPad *pad, NSError *__autoreleasing *error) { + pad.deleting = YES; + } completion:^(HPPad *pad, NSError *error) { + NSURL *URL = [NSURL URLWithString:HPDeletePadPath + relativeToURL:pad.space.URL]; + NSDictionary *params = @{HPPadIdToDeleteParam:pad.padID, + HPAPIXSRFTokenParam:[HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + [pad hp_sendAsynchronousRequest:request + block:^(HPPad *pad, + NSURLResponse * response, + NSData *data, + NSError *__autoreleasing *error) + { + if (![pad.space.API parseJSONResponse:response + data:data + request:request + error:error]) { + pad.deleting = NO; + return; + } + [pad.managedObjectContext deleteObject:pad]; + } completion:handler]; + }]; +} + +- (void)setFollowed:(BOOL)followed + completion:(void (^)(HPPad *, NSError *))handler +{ + NSParameterAssert(self.padID); + if (self.followed == followed) { + if (handler) { + handler(self, nil); + } + return; + } + + NSURL *URL = [NSURL URLWithString:[HPFollowPadPath stringByAppendingPathComponent:self.padID] + relativeToURL:self.space.URL]; + NSDictionary *params = @{FollowPrefParam: followed ? @"2" : @"1", + AjaxParam: @"true", + HPAPIXSRFTokenParam:[HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + [self hp_sendAsynchronousRequest:request + block:^(HPPad *pad, + NSURLResponse *response, + NSData *data, + NSError *__autoreleasing *error) + { + if (![pad.space.API parseJSONResponse:response + data:data + request:request + error:error]) { + return; + } + pad.followed = followed; + } + completion:handler]; +} + +- (BOOL)isFeatureHelpPad +{ + return [self.padID isEqualToString:FeatureHelpPadID] && self.space.URL.hp_isToplevelHackpadURL; +} + +- (BOOL)isPrivacyPolicyPad +{ + return [self.padID isEqualToString:PrivacyPolicyPadID] && self.space.URL.hp_isToplevelHackpadURL; +} + +- (BOOL)isTermsOfServicePad +{ + return [self.padID isEqualToString:TermsOfServicePadID] && self.space.URL.hp_isToplevelHackpadURL; +} + +- (BOOL)isWelcomePad +{ + NSString *padID = WelcomePadID; +#if TARGET_IPHONE_SIMULATOR + if ([[NSUserDefaults standardUserDefaults] boolForKey:DevServerKey]) { + padID = DevWelcomePadID; + } +#endif + return [self.padID isEqualToString:padID] && self.space.URL.hp_isToplevelHackpadURL; +} + +- (BOOL)isCreator +{ + static NSString * const IsCreatorKey = @"isCreator"; + NSDictionary *clientVars = self.clientVars; + if (![clientVars isKindOfClass:[NSDictionary class]] || + ![clientVars[IsCreatorKey] isKindOfClass:[NSNumber class]]) { + return NO; + } + return [clientVars[IsCreatorKey] boolValue]; +} + +- (void)sendInvitationWithRequest:(NSURLRequest *)request + completion:(void (^)(HPPad *, NSError *))handler +{ + NSParameterAssert(self.padID); + + [self hp_sendAsynchronousRequest:request + block:^(HPPad *pad, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + [pad.space.API isSignInRequiredForRequest:request + response:response + error:error]; + } + completion:handler]; +} + +- (void)sendInvitationWithUserId:(NSString *)userId + completion:(void (^)(HPPad *, NSError *))handler +{ + NSURL *URL = [NSURL URLWithString:HPHackpadInvitePath + relativeToURL:self.space.URL]; + NSDictionary *params = @{HPEncryptedUserIdParam: userId, + HPPadIdParam: self.padID, + HPAPIXSRFTokenParam: [HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + [self sendInvitationWithRequest:request + completion:handler]; +} + +- (void)sendInvitationWithEmail:(NSString *)email + completion:(void (^)(HPPad *, NSError *))handler +{ + NSURL *URL = [NSURL URLWithString:HPEmailInvitePath + relativeToURL:self.space.URL]; + NSDictionary *params = @{HPToAddressParam: email, + HPPadIdParam: self.padID, + HPAPIXSRFTokenParam: [HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + [self sendInvitationWithRequest:request + completion:handler]; +} + +- (void)sendInvitationWithFacebookID:(NSString *)friendID + name:(NSString *)friendName + postID:(NSString *)postID + completion:(void (^)(HPPad *, NSError *))handler +{ + NSURL *URL = [NSURL URLWithString:HPFacebookInvitePath + relativeToURL:self.space.URL]; + NSDictionary *params = @{HPFriendIdParam:friendID, + HPFriendNameParam:friendName, + HPPadIdParam:self.padID, + HPAPIXSRFTokenParam:[HPAPI XSRFTokenForURL:URL]}; + if (postID) { + NSMutableDictionary *tmp = [params mutableCopy]; + tmp[HPFacebookPostIdParam] = postID; + } + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + [self sendInvitationWithRequest:request + completion:handler]; + +} + +- (void)sendInvitationWithFacebookID:(NSString *)friendID + name:(NSString *)friendName + completion:(void (^)(HPPad *, NSError *))handler +{ + [self sendInvitationWithFacebookID:friendID + name:friendName + postID:nil + completion:^(HPPad *pad, NSError *error) + { + if (error) { + [FBWebDialogs presentRequestsDialogModallyWithSession:[FBSession activeSession] + message:[NSString stringWithFormat:@"Come hack '%@' with me.", self.title] + title:@"Send Private Hackpad Invite" + parameters:@{@"to":friendID, @"data":self.padID} + handler:^(FBWebDialogResult result, + NSURL *resultURL, + NSError *error) + { + if (!error && result == FBWebDialogResultDialogCompleted) { + [self sendInvitationWithFacebookID:friendName + name:friendName + postID:[resultURL.query hp_dictionaryByParsingURLParameters][RequestKey] + completion:handler]; + } else { + if (handler) { + handler(pad, error); + } + } + }]; + } else if (handler) { + handler(pad, nil); + } + }]; +} + +- (void)removeUserWithId:(NSString *)userID + completion:(void (^)(HPPad *, NSError *))handler +{ + NSParameterAssert(self.padID); + NSURL *URL = [NSURL URLWithString:HPPadRemoveUserPath + relativeToURL:self.space.URL]; + NSDictionary *params = @{HPPadIdParam:self.padID, + HPUserIdParam:userID, + HPAPIXSRFTokenParam:[HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + + [self hp_sendAsynchronousRequest:request + block:^(HPPad *pad, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + [pad.space.API parseJSONResponse:response + data:data + request:request + error:error]; + } + completion:handler]; +} + +- (NSString *)searchTextWithClientVars:(NSDictionary *)clientVars +{ + static NSString * const InitialAttributedTextKey = @"initialAttributedText"; + static NSString * const TextKey = @"text"; + + NSDictionary *collabClientVars = clientVars[CollabClientVarsKey]; + if (![collabClientVars isKindOfClass:[NSDictionary class]]) { + return nil; + } + + NSDictionary *initialAttributedText = collabClientVars[InitialAttributedTextKey]; + if (![initialAttributedText isKindOfClass:[NSDictionary class]]) { + return nil; + } + NSString *text = initialAttributedText[TextKey]; + if (![text isKindOfClass:[NSString class]]) { + return nil; + } + return [text.hp_stringByReplacingPercentEscapes stringByReplacingOccurrencesOfString:@"\n*" + withString:@"\n"]; +} + +- (void)setClientVars:(NSDictionary *)clientVars + lastEditedDate:(NSTimeInterval)lastEditedDate +{ + NSDictionary *collabClientVars = clientVars[CollabClientVarsKey]; + if (![collabClientVars isKindOfClass:[NSDictionary class]]) { + return; + } + + id oldRev = self.clientVars[CollabClientVarsKey][RevKey]; + id newRev = collabClientVars[RevKey]; + + if (![newRev isKindOfClass:[NSNumber class]]) { + TFLog(@"[%@] %@.clientVars not updating to rev %@, as we already have rev %@.", + self.URL.host, self.padID, newRev, oldRev); + return; + } + + if ([newRev integerValue] < [oldRev integerValue]) { + TFLog(@"[%@] %@.clientVars rolling back from revision %@ to %@", + self.URL.host, self.padID, oldRev, newRev); + } + + NSDictionary *missedChanges = collabClientVars[MissedChangesKey]; + self.hasMissedChanges = [missedChanges isKindOfClass:[NSDictionary class]] && + ([missedChanges[CommittedChangesetKey] isKindOfClass:[NSString class]] || + [missedChanges[FurtherChangesetKey] isKindOfClass:[NSString class]]); + + if (self.hasMissedChanges || ![oldRev isEqual:newRev]) { + self.lastEditedDate = lastEditedDate; +#if 0 + self.snippetUserPics = nil; + self.authorNames = nil; +#endif + } + + if (!self.editor) { + self.editor = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([HPPadEditor class]) + inManagedObjectContext:self.managedObjectContext]; + } + self.editor.clientVars = nil; + NSError * __autoreleasing error; + self.editor.clientVarsJSON = [NSJSONSerialization dataWithJSONObject:clientVars + options:0 + error:&error]; + if (!self.editor.clientVarsJSON) { + TFLog(@"[%@ %@] Error serializing clientVars: %@", self.URL.host, + self.padID, error); + } + self.editor.clientVarsLastEditedDate = lastEditedDate; + self.title = clientVars[PadTitleKey]; + + if (!self.search) { + self.search = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([HPPadSearch class]) + inManagedObjectContext:self.managedObjectContext]; + } + self.search.content = [self searchTextWithClientVars:clientVars]; + self.search.lastEditedDate = lastEditedDate; +} + +- (void)requestClientVarsWithRefresh:(BOOL)refresh + completion:(void (^)(HPPad *, NSError *))handler +{ + static NSString * const UserAgentHeader = @"User-Agent"; + + if (!refresh && self.hasClientVars) { + if (handler) { + handler(self, nil); + } + return; + } + NSParameterAssert(self.padID); + NSParameterAssert(!self.hasMissedChanges); + + NSMutableURLRequest *request; + request = [NSMutableURLRequest hp_requestWithURL:[NSURL URLWithString:HPPadClientVarsPath + relativeToURL:self.space.URL] + HTTPMethod:@"GET" + parameters:@{HPPadIdParam:self.padID}]; + [request addValue:[UIWebView hp_defaultUserAgentString] + forHTTPHeaderField:UserAgentHeader]; + request.cachePolicy = refresh + ? NSURLRequestReloadIgnoringCacheData + : NSURLRequestReturnCacheDataElseLoad; + [self.space.API.oAuth addResourceTokenHeaderToRequest:request]; + + [self hp_sendAsynchronousRequest:request + block:^(HPPad *pad, + NSURLResponse *response, + NSData *data, + NSError *__autoreleasing *error) + { + id JSON = [pad.space.API parseJSONResponse:response + data:data + request:request + error:error]; + if (![JSON isKindOfClass:[NSDictionary class]] || + ![JSON[ClientVarsKey] isKindOfClass:[NSDictionary class]]) { + return; + } + + NSDictionary *headers = [(NSHTTPURLResponse *)response allHeaderFields]; + NSTimeInterval clientVarsLastEditedDate = [headers[LastEditedDateHeader] longLongValue] - NSTimeIntervalSince1970; + +#if 0 + HPLog(@"[%@ %@] Last edit date: %f headers: %f, cached request headers: %@", + request.URL.host, pad.padID, pad.lastEditedDate, + clientVarsLastEditedDate, headers); +#endif + + [pad setClientVars:JSON[ClientVarsKey] + lastEditedDate:clientVarsLastEditedDate]; + } completion:handler]; +} + +- (void)getPadIDWithCompletion:(void (^)(HPPad *, NSError *))handler +{ + // FIXME: need to make sure this is only called once per pad + NSParameterAssert(!self.padID); + NSURL *URL = [NSURL URLWithString:HPNewPadPath + relativeToURL:self.space.URL]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL + cachePolicy:NSURLRequestReloadIgnoringCacheData + timeoutInterval:60]; + request.HTTPMethod = @"POST"; + request.HTTPBody = [@"\n\n\n" dataUsingEncoding:NSUTF8StringEncoding]; + [request setValue:@"text/plain" + forHTTPHeaderField:@"Content-Type"]; + [self.space.API.oAuth addResourceTokenHeaderToRequest:request]; + + NSString * __block globalPadID; + [self hp_sendAsynchronousRequest:request + block:^(HPPad *pad, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + id JSON = [pad.space.API parseJSONResponse:response + data:data + request:request + error:error]; + if (![JSON isKindOfClass:[NSDictionary class]] || + ![JSON[HPPadIdParam] isKindOfClass:[NSString class]] || + ![JSON[HPGlobalPadIdParam] isKindOfClass:[NSString class]]) { + return; + } + pad.padID = JSON[HPPadIdParam]; + globalPadID = JSON[HPGlobalPadIdParam]; + NSMutableDictionary *clientVars = pad.clientVars.mutableCopy; + if (!clientVars) { + return; + } + if ([clientVars[CollabClientVarsKey] isKindOfClass:[NSDictionary class]]) { + NSMutableDictionary *collabClientVars = [clientVars[CollabClientVarsKey] mutableCopy]; + collabClientVars[HPGlobalPadIdParam] = globalPadID; + collabClientVars[HPPadIdParam] = pad.padID; + clientVars[CollabClientVarsKey] = collabClientVars; + } + clientVars[HPGlobalPadIdParam] = globalPadID; + clientVars[HPPadIdParam] = pad.padID; + [pad setClientVars:clientVars + lastEditedDate:pad.editor.clientVarsLastEditedDate]; + } completion:^(HPPad *pad, NSError *error) { + if (pad && globalPadID) { + [[NSNotificationCenter defaultCenter] postNotificationName:HPPadDidGetGlobalPadIDNotification + object:pad + userInfo:@{HPGlobalPadIDKey:globalPadID}]; + } + if (handler) { + handler(pad, error); + } + }]; +} + ++ (NSString *)fullSnippetHTMLWithSnippetHTML:(NSString *)snippetHTML +{ + return [NSString stringWithFormat:SnippetHTMLFormat, snippetHTML.length ? snippetHTML : @""]; +} + +- (NSString *)fullSnippetHTML +{ + return [self.class fullSnippetHTMLWithSnippetHTML:self.snippetHTML]; +} + +- (void)requestAuthorsWithCompletion:(void (^)(HPPad *, NSError *))handler +{ + static NSString * const AuthorPicsKey = @"authorPics"; + static NSString * const AuthorsKey = @"authors"; + static NSString * const TimestampKey = @"timestamp"; + + NSParameterAssert(self.padID); + NSMutableURLRequest *request; + request = [NSMutableURLRequest hp_requestWithURL:[self.APIURL URLByAppendingPathComponent:RevisionsPathComponent] + HTTPMethod:@"GET" + parameters:@{HPLimitParam:@"1"}]; + if (!request.URL) { + TFLog(@"[%@] Invalid pad URL: %@", self.space.URL.host, self.padID); + handler(nil, nil); + return; + } + [self.space.API.oAuth addResourceTokenHeaderToRequest:request]; + [self hp_sendAsynchronousRequest:request + block:^(HPPad *pad, + NSURLResponse *response, + NSData *data, + NSError *__autoreleasing *error) + { + id JSON = [pad.space.API parseJSONResponse:response + data:data + request:request + error:error]; + if (![JSON isKindOfClass:[NSArray class]] || + ![JSON count] || + ![JSON[0] isKindOfClass:[NSDictionary class]]) { + return; + } + NSDictionary *revision = JSON[0]; + NSArray *authors = revision[AuthorsKey]; + pad.authorName = [authors isKindOfClass:[NSArray class]] && + [authors.firstObject isKindOfClass:[NSString class]] + ? authors[0] : @"Someone"; + authors = revision[AuthorPicsKey]; + pad.authorPic = [authors isKindOfClass:[NSArray class]] && + [authors.firstObject isKindOfClass:[NSString class]] + ? authors[0] : @"/static/img/nophoto.png"; + pad.snippetHTML = nil; // JSON[0][HTMLDiffKey]; + if ([revision[TimestampKey] isKindOfClass:[NSNumber class]]) { + pad.authorLastEditedDate = [revision[TimestampKey] longLongValue] - NSTimeIntervalSince1970; + } else { + pad.authorLastEditedDate = pad.lastEditedDate; + } + } completion:handler]; +} + +- (void)requestContentWithCompletion:(void (^)(HPPad *, NSError *))handler +{ + NSParameterAssert(self.padID); + NSMutableURLRequest *request; + request = [NSMutableURLRequest requestWithURL:[self.APIURL URLByAppendingPathComponent:ContentPathComponent]]; + [self.space.API.oAuth addResourceTokenHeaderToRequest:request]; + + [self hp_sendAsynchronousRequest:request + block:^(HPPad *pad, + NSURLResponse *response, + NSData *data, + NSError *__autoreleasing *error) + { + if ([pad.space.API isSignInRequiredForRequest:request + response:response + error:error] || + ![response isKindOfClass:[NSHTTPURLResponse class]]) { + return; + } + NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response; + if (HTTPResponse.statusCode / 100 != 2) { + if (!error) { + return; + } + NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: + @"The server sent an invalid response", + NSLocalizedDescriptionKey, + request.URL, NSURLErrorFailingURLErrorKey, + request.URL.absoluteString, NSURLErrorFailingURLStringErrorKey, + request.HTTPMethod, HPURLErrorFailingHTTPMethod, + nil]; + if (HTTPResponse) { + userInfo[HPURLErrorFailingHTTPStatusCode] = @(HTTPResponse.statusCode); + } + if (*error) { + userInfo[NSUnderlyingErrorKey] = *error; + } + *error = [NSError errorWithDomain:HPHackpadErrorDomain + code:HPFailedRequestError + userInfo:userInfo]; + return; + } + if (!pad.search) { + pad.search = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([HPPadSearch class]) + inManagedObjectContext:pad.managedObjectContext]; + } + pad.search.content = [[NSString alloc] initWithData:data + encoding:NSUTF8StringEncoding]; + } + completion:handler]; +} + +- (void)applyMissedChangesWithCompletion:(void (^)(HPPad *, NSError *))handler +{ + NSParameterAssert(self.padID); + NSParameterAssert(self.hasMissedChanges); + NSURL *URL = [NSURL URLWithString:HPPadApplyMissedChangesPath + relativeToURL:self.URL]; + NSDictionary *collabClientVars = self.clientVars[CollabClientVarsKey]; + NSError * __autoreleasing error; + NSData *missedChanges = [NSJSONSerialization dataWithJSONObject:collabClientVars[MissedChangesKey] + options:0 + error:&error]; + if (!missedChanges) { + TFLog(@"[%@] Could not serialize apool: %@", URL.host, error); + if (handler) { + handler(nil, error); + } + return; + } + NSDictionary *params = @{MissedChangesKey:[[NSString alloc] initWithData:missedChanges + encoding:NSUTF8StringEncoding], + HPPadIdParam:self.padID}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + + [self hp_sendAsynchronousRequest:request + block:^(HPPad *pad, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + if (![pad.space.API parseJSONResponse:response + data:data + request:request + error:error]) { + return; + } + pad.hasMissedChanges = NO; + } + completion:handler]; +} + +- (void)requestAccessWithCompletion:(void (^)(HPPad *, NSError *))handler +{ + static NSString * const RequestAccessPath = @"/ep/account/guest/guest-request-access"; + + NSParameterAssert(self.padID); + NSURL *URL = [NSURL URLWithString:RequestAccessPath + relativeToURL:self.space.URL]; + NSDictionary *params = @{HPPadIdParam:self.padID, + HPAPIXSRFTokenParam:[HPAPI XSRFTokenForURL:URL]}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + + [self hp_sendAsynchronousRequest:request + block:^(HPPad *pad, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + [pad.space.API parseJSONResponse:response + data:data + request:request + error:error]; + } completion:handler]; +} + +- (void)discardMissedChangesWithCompletion:(void (^)(HPPad *, NSError *))handler +{ + [self hp_performBlock:^(HPPad *pad, NSError *__autoreleasing *error) { + NSMutableDictionary *clientVars = pad.clientVars.mutableCopy; + NSMutableDictionary *collabClientVars = [clientVars[CollabClientVarsKey] mutableCopy]; + [collabClientVars removeObjectForKey:MissedChangesKey]; + clientVars[CollabClientVarsKey] = collabClientVars; + [pad setClientVars:clientVars + lastEditedDate:pad.editor.clientVarsLastEditedDate]; + pad.hasMissedChanges = NO; + } completion:handler]; +} + +- (NSDictionary *)clientVars +{ + return self.editor.clientVarsJSON + ? [NSJSONSerialization JSONObjectWithData:self.editor.clientVarsJSON + options:0 + error:nil] + : self.editor.clientVars; +} + +- (BOOL)hasClientVars +{ + return self.editor.clientVarsJSON || self.editor.clientVars; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPad.h b/client/ios/Hackpad/HackpadKit/HPPad.h new file mode 100644 index 0000000..9f1ef68 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPad.h @@ -0,0 +1,50 @@ +// +// HPPad.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import +#import + +@class HPCollection, HPImageUpload, HPPadEditor, HPPadSearch, HPSharingOptions, HPSpace; + +@interface HPPad : NSManagedObject + +@property (nonatomic, retain) NSString * authorName; +@property (nonatomic, retain) id authorNames; +@property (nonatomic, retain) NSString * authorPic; +@property (nonatomic) BOOL deleting; +@property (nonatomic) float expandedSnippetHeight; +@property (nonatomic) BOOL followed; +@property (nonatomic) BOOL hasMissedChanges; +@property (nonatomic) NSTimeInterval lastEditedDate; +@property (nonatomic, retain) NSString * padID; +@property (nonatomic) float snippetHeight; +@property (nonatomic, retain) NSString * snippetHTML; +@property (nonatomic, retain) id snippetUserPics; +@property (nonatomic, retain) NSString * title; +@property (nonatomic) NSTimeInterval authorLastEditedDate; +@property (nonatomic, retain) NSSet *collections; +@property (nonatomic, retain) HPPadEditor *editor; +@property (nonatomic, retain) NSSet *imageUploads; +@property (nonatomic, retain) HPPadSearch *search; +@property (nonatomic, retain) HPSharingOptions *sharingOptions; +@property (nonatomic, retain) HPSpace *space; +@end + +@interface HPPad (CoreDataGeneratedAccessors) + +- (void)addCollectionsObject:(HPCollection *)value; +- (void)removeCollectionsObject:(HPCollection *)value; +- (void)addCollections:(NSSet *)values; +- (void)removeCollections:(NSSet *)values; + +- (void)addImageUploadsObject:(HPImageUpload *)value; +- (void)removeImageUploadsObject:(HPImageUpload *)value; +- (void)addImageUploads:(NSSet *)values; +- (void)removeImageUploads:(NSSet *)values; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPad.m b/client/ios/Hackpad/HackpadKit/HPPad.m new file mode 100644 index 0000000..68807b5 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPad.m @@ -0,0 +1,41 @@ +// +// HPPad.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPPad.h" +#import "HPCollection.h" +#import "HPImageUpload.h" +#import "HPPadEditor.h" +#import "HPPadSearch.h" +#import "HPSharingOptions.h" +#import "HPSpace.h" + + +@implementation HPPad + +@dynamic authorName; +@dynamic authorNames; +@dynamic authorPic; +@dynamic deleting; +@dynamic expandedSnippetHeight; +@dynamic followed; +@dynamic hasMissedChanges; +@dynamic lastEditedDate; +@dynamic padID; +@dynamic snippetHeight; +@dynamic snippetHTML; +@dynamic snippetUserPics; +@dynamic title; +@dynamic authorLastEditedDate; +@dynamic collections; +@dynamic editor; +@dynamic imageUploads; +@dynamic search; +@dynamic sharingOptions; +@dynamic space; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPadCacheController.h b/client/ios/Hackpad/HackpadKit/HPPadCacheController.h new file mode 100644 index 0000000..4a052e1 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadCacheController.h @@ -0,0 +1,23 @@ +// +// HPPadCacheController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPCoreDataStack; +@class HPPad; + +@interface HPPadCacheController : NSObject + +@property (atomic, assign, getter = isDisabled) BOOL disabled; + ++ (id)sharedPadCacheController; +- (void)setCoreDataStack:(HPCoreDataStack *)coreDataStack; +- (void)setPad:(HPPad *)pad + editing:(BOOL)editing; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPadCacheController.m b/client/ios/Hackpad/HackpadKit/HPPadCacheController.m new file mode 100644 index 0000000..b5b39b1 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadCacheController.m @@ -0,0 +1,608 @@ +// +// HPPadCacheController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadCacheController.h" + +// #define UPDATE_SNIPPETS 1 + +#import +#import + +#import +#import +#import + +#if UPDATE_SNIPPETS +#import +#endif + +static NSString * const ClientVarsLastEditedDateKey = @"clientVarsLastEditedDate"; +static NSString * const HasMissedChangesKey = @"hasMissedChanges"; +static NSString * const LastEditedDateKey = @"lastEditedDate"; + +static NSString * const LastEditedDateHeader = @"X-Hackpad-LastEditedDate"; + +// #define UPDATE_SEARCH_TEXT 1 + +typedef void(^cache_action_block)(id, NSError *); + +@interface HPPadCacheController () + +@property (nonatomic, strong) HPCoreDataStack *coreDataStack; +@property (nonatomic, strong) HPPadWebController *padWebController; +@property (nonatomic, strong) NSFetchedResultsController *results; +@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext; +@property (nonatomic, strong) NSMutableSet *badPads; +@property (nonatomic, strong) NSCountedSet *editingPads; +@property (nonatomic, strong) NSMutableSet *ignoredPads; +@property (nonatomic, strong) NSURLRequest *request; +@property (nonatomic, copy) cache_action_block missedChangesHandler; +@property (nonatomic, strong) id reachabilityObserver; +@property (nonatomic, strong) id saveObserver; +@property (nonatomic, strong) id signInObserver; +@property (nonatomic, assign) NSUInteger currentRequestID; +@property (nonatomic, assign) BOOL requestPending; +@property (nonatomic, assign) BOOL rebuildPredicateWhenIdle; + +- (void)queueRequest; + +@end + +@implementation HPPadCacheController + +@synthesize disabled = _disabled; + ++ (id)sharedPadCacheController +{ + static HPPadCacheController *cacheController; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + cacheController = [[self alloc] init]; + }); + return cacheController; +} + +- (id)init +{ + self = [super init]; + if (self) { + _badPads = [NSMutableSet set]; + _editingPads = [NSCountedSet set]; + _ignoredPads = [NSMutableSet set]; + _disabled = YES; + } + return self; +} + +- (void)dealloc +{ + if (_signInObserver) { + [[NSNotificationCenter defaultCenter] removeObserver:_signInObserver]; + } + if (_saveObserver) { + [[NSNotificationCenter defaultCenter] removeObserver:_saveObserver]; + } + if (_reachabilityObserver) { + [[NSNotificationCenter defaultCenter] removeObserver:_reachabilityObserver]; + } +} + ++ (NSPredicate *)invalidPadIDPredicate +{ + static NSPredicate *predicate; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + predicate = [NSPredicate predicateWithBlock:^BOOL(HPPad *pad, NSDictionary *bindings) { + return pad.padID && ![NSURL URLWithString:pad.padID]; + }]; + }); + return predicate; +} + ++ (NSPredicate *)needsPadIDPredicate +{ + static NSPredicate *predicate; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + predicate = [NSPredicate predicateWithFormat:@"padID == nil"]; + }); + return predicate; +} + ++ (NSPredicate *)hasMissedChangesPredicate +{ + static NSPredicate *predicate; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + predicate = [NSPredicate predicateWithFormat:@"hasMissedChanges == YES"]; + }); + return predicate; +} + ++ (NSPredicate *)needsRevisionsPredicate +{ + // 413316657 = 2014-02-05 18:10:57 +0000 + // authorLastEditedDate will be 0, but we don't want to force everyone to + // update everything when upgrading, so just do pads in the last week. + static NSPredicate *predicate; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + predicate = [NSPredicate predicateWithFormat:@"(authorName == nil && authorNames == nil) OR (authorPic == nil && snippetUserPics == nil) OR (authorLastEditedDate < lastEditedDate && lastEditedDate > %@)", [NSDate dateWithTimeIntervalSinceReferenceDate:413316657]]; + }); + return predicate; +} + ++ (NSPredicate *)needsClientVarsPredicate +{ + static NSPredicate *predicate; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + predicate = [NSPredicate predicateWithFormat:@"editor == nil OR editor.clientVarsLastEditedDate == nil OR editor.clientVarsLastEditedDate < lastEditedDate"]; + }); + return predicate; +} + +#if UPDATE_SEARCH_TEXT ++ (NSPredicate *)needsSearchTextPredicate +{ + static NSPredicate *predicate; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + predicate = [NSPredicate predicateWithFormat:@"search == nil"]; + }); + return predicate; +} +#endif + ++ (NSPredicate *)needsImagesUploadedPredicate +{ + static NSPredicate *predicate; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + predicate = [NSPredicate predicateWithFormat:@"ANY imageUploads.attachmentID != nil"]; + }); + return predicate; +} + +- (void)buildPredicateAndPerformFetch +{ + NSPredicate *predicate; + predicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[[self.class hasMissedChangesPredicate], + [self.class needsClientVarsPredicate], + [self.class needsRevisionsPredicate], +#if UPDATE_SEARCH_TEXT + [self.class needsSearchTextPredicate] +#endif + ]]; + NSPredicate *editing = [NSPredicate predicateWithFormat:@"NOT SELF IN %@", self.editingPads]; + predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[editing, predicate]]; + predicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[[self.class needsPadIDPredicate], + [self.class needsImagesUploadedPredicate], + predicate]]; + self.results.fetchRequest.predicate = predicate; + NSSet *pads = [self.badPads setByAddingObjectsFromSet:self.ignoredPads]; + if (pads.count) { + NSArray *subpredicates = @[[NSPredicate predicateWithFormat:@"NOT SELF IN %@", pads], + self.results.fetchRequest.predicate]; + self.results.fetchRequest.predicate = [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates]; + } + self.rebuildPredicateWhenIdle = NO; + NSError *__autoreleasing error; + if ([self.results performFetch:&error]) { + [self queueRequest]; + } else { + TFLog(@"Could not initialize cache: %@", error); + } +} + +- (void)setCoreDataStack:(HPCoreDataStack *)coreDataStack +{ + NSParameterAssert([[NSOperationQueue currentQueue] isEqual:[NSOperationQueue mainQueue]]); + NSAssert(!_managedObjectContext, @"coreDataStack already set."); + + _coreDataStack = coreDataStack; + self.managedObjectContext = coreDataStack.mainContext; + + HPPadCacheController * __weak weakSelf = self; + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + self.signInObserver = [nc addObserverForName:HPAPIDidSignInNotification + object:nil + queue:nil + usingBlock:^(NSNotification *note) + { + HPPadCacheController *strongSelf = weakSelf; + if (strongSelf) { + [strongSelf->_managedObjectContext performBlock:^{ + NSPredicate *pred = [NSPredicate predicateWithBlock:^BOOL(NSManagedObjectID *objectID, NSDictionary *bindings) { + HPPad *pad = (HPPad *)[strongSelf->_managedObjectContext existingObjectWithID:objectID + error:nil]; + if (pad.space.API == note.object) { + strongSelf->_rebuildPredicateWhenIdle = YES; + return NO; + } + return YES; + }]; + [strongSelf->_badPads filterUsingPredicate:pred]; + [strongSelf queueRequest]; + }]; + } + }]; + self.reachabilityObserver = [nc addObserverForName:kReachabilityChangedNotification + object:nil + queue:nil + usingBlock:^(NSNotification *note) + { + HPPadCacheController *strongSelf = weakSelf; + Reachability *reachability = note.object; + if (reachability.currentReachabilityStatus && strongSelf) { + [strongSelf->_managedObjectContext performBlock:^{ + NSPredicate *pred = [NSPredicate predicateWithBlock:^BOOL(NSManagedObjectID *objectID, NSDictionary *bindings) { + HPPad *pad = (HPPad *)[strongSelf->_managedObjectContext existingObjectWithID:objectID + error:nil]; + if (pad.space.API.reachability == reachability) { + strongSelf->_rebuildPredicateWhenIdle = YES; + return NO; + } + return YES; + }]; + [strongSelf->_badPads filterUsingPredicate:pred]; + [strongSelf queueRequest]; + }]; + } + }]; + + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPPadEntity]; + fetch.fetchBatchSize = 12; + fetch.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:HasMissedChangesKey + ascending:NO], + [NSSortDescriptor sortDescriptorWithKey:LastEditedDateKey + ascending:NO]]; + fetch.shouldRefreshRefetchedObjects = YES; + _results = [[NSFetchedResultsController alloc] initWithFetchRequest:fetch + managedObjectContext:_managedObjectContext + sectionNameKeyPath:nil + cacheName:nil]; + _results.delegate = self; + [self buildPredicateAndPerformFetch]; +} + +- (void)setDisabled:(BOOL)disabled +{ + HPLog(@"Setting cache controller disabled: %d", (int)disabled); + @synchronized (self) { + _disabled = disabled; + if (!_disabled) { + __weak HPPadCacheController *weakSelf = self; + [_managedObjectContext performBlock:^{ + [weakSelf queueRequest]; + }]; + } + } +} + +- (BOOL)isDisabled +{ + BOOL ret; + @synchronized (self) { + ret = _disabled; + } + return ret; +} + +- (void)setPad:(HPPad *)pad + editing:(BOOL)editing +{ + NSManagedObjectID *objectID = pad.objectID; + [self.managedObjectContext performBlock:^{ + if (editing) { + [_editingPads addObject:objectID]; + } else { + [_editingPads removeObject:objectID]; + } + [self buildPredicateAndPerformFetch]; + }]; +} + +- (HPPad *)firstSignedInPad +{ + NSUInteger idx = [_results.fetchedObjects indexOfObjectPassingTest:^BOOL(HPPad *pad, NSUInteger idx, BOOL *stop) { + return pad.space.API.isSignedIn && + ![_badPads member:pad.objectID] && + ![_ignoredPads member:pad.objectID]; + }]; + return idx == NSNotFound ? nil : [_results.fetchedObjects objectAtIndex:idx]; +} + +- (void)addBadPad:(HPPad *)pad + error:(NSError *)error +{ + TFLog(@"[%@] Adding bad pad %@: %@", pad.URL.host, pad.padID, error); + [_badPads addObject:pad.objectID]; + _rebuildPredicateWhenIdle = YES; +} + +- (void)applyMissedChangesWithPad:(HPPad *)pad + completion:(cache_action_block)handler +{ + TFLog(@"[%@] Applying offline changes for %@...", pad.URL.host, pad.padID); + self.missedChangesHandler = handler; + self.padWebController = [HPPadWebController sharedPadWebControllerWithPad:pad]; + self.padWebController.collabClientDelegate = self; + [self.padWebController loadWithCompletion:^(NSError *error) { + if (error) { + handler(nil, error); + } + }]; +} + +- (void)uploadImagesWithPad:(HPPad *)pad + completion:(cache_action_block)handler +{ + static NSString * const HTTPSecureScheme = @"https"; + static NSString * const HackpadAttachmentsCloudfrontHost = @"dchtm6r471mui.cloudfront.net"; + + HPImageUpload *image = [pad.imageUploads anyObject]; + TFLog(@"[%@] Uploading attachment %@ to %@...", pad.URL.host, + image.attachmentID, image.URL); + + // When the upload is complete, the image will be deleted, so save these; + NSString *attachmentID = image.attachmentID; + NSURL *URL = image.URL; + NSString *key = image.key; + NSString *contentType = image.contentType; + NSData *imageData = image.image; + + HPPadCacheController * __weak weakSelf = self; + [image uploadWithCompletion:^(NSError *error) { + if (error) { + TFLog(@"[%@] Could not upload image %@: %@", pad.URL.host, + image.attachmentID, error); + handler(nil, error); + return; + } + weakSelf.padWebController = [HPPadWebController sharedPadWebControllerWithPad:pad]; + [weakSelf.padWebController loadWithCompletion:^(NSError *error) { + if (error) { + weakSelf.padWebController = nil; + handler(nil, error); + return; + } + NSURL *cacheURL = [[NSURL alloc] initWithScheme:HTTPSecureScheme + host:HackpadAttachmentsCloudfrontHost + path:URL.path]; + NSURLRequest *request = [NSURLRequest requestWithURL:cacheURL]; + NSURLResponse *response = [[NSURLResponse alloc] initWithURL:cacheURL + MIMEType:contentType + expectedContentLength:imageData.length + textEncodingName:nil]; + [HPStaticCachingURLProtocol cacheResponse:response + data:imageData + request:request]; + [weakSelf.padWebController updateAttachmentWithID:attachmentID + URL:URL + key:key + completion:^{ + handler(nil, nil); + }]; + }]; + }]; +} + +- (BOOL)performCacheActionWithPad:(HPPad *)pad + predicate:(NSPredicate *)predicate + block:(void (^)(cache_action_block))handler +{ + if (![predicate evaluateWithObject:pad]) { + return NO; + } + NSUInteger request = ++_currentRequestID; + _requestPending = YES; + HPPadCacheController * __weak weakSelf = self; + handler(^(id result, NSError *error) { + HPPadCacheController *strongSelf = weakSelf; + if (!strongSelf) { + return; + } + BOOL evaluated = [predicate evaluateWithObject:pad]; + if (strongSelf->_currentRequestID == request) { + if (error || evaluated) { + [strongSelf addBadPad:pad + error:error]; + } + strongSelf->_requestPending = NO; + [strongSelf queueRequest]; + } + }); + return YES; +} + +- (void)queueRequest +{ + if (_requestPending) { + return; + } + @synchronized (self) { + if (_disabled) { + return; + } + } + HPPad * __block pad; + HPPadCacheController * __weak weakSelf = self; + NSArray *predicates = @[[[self class] invalidPadIDPredicate], + [[self class] needsPadIDPredicate], + [[self class] needsImagesUploadedPredicate], + [[self class] hasMissedChangesPredicate], + [[self class] needsClientVarsPredicate], + [[self class] needsRevisionsPredicate], +#if UPDATE_SEARCH_TEXT + [[self class] needsSearchTextPrefix] +#endif + ]; + NSArray *blocks = @[ + ^(cache_action_block completion) { + TFLog(@"[%@] Deleting invalid pad: %@", pad.space.URL.host, pad.padID); + [pad hp_performBlock:^(HPPad *pad, NSError *__autoreleasing *error) { + [pad.managedObjectContext deleteObject:pad]; + } completion:completion]; + }, + ^(cache_action_block completion) { + [pad getPadIDWithCompletion:completion]; + }, + ^(cache_action_block completion) { + [weakSelf uploadImagesWithPad:pad + completion:completion]; + }, + ^(cache_action_block completion) { + //[pad applyMissedChangesWithCompletion:completion]; + [weakSelf applyMissedChangesWithPad:pad + completion:completion]; + }, + ^(cache_action_block completion) { + [pad requestClientVarsWithRefresh:YES + completion:completion]; + }, + ^(cache_action_block completion) { + [pad requestAuthorsWithCompletion:completion]; + }, +#if UPDATE_SEARCH_TEXT + ^(cache_action_block completion) { + [pad requestContentWithCompletion:completion]; + } +#endif + ]; + while ((pad = [self firstSignedInPad])) { + for (NSUInteger i = 0; i < predicates.count; i++) { + if ([self performCacheActionWithPad:pad + predicate:predicates[i] + block:blocks[i]]) { + return; + } + } + if (![_ignoredPads member:pad.objectID]) { + TFLog(@"[%@] Ignoring pad: %@", pad.URL.host, pad.debugDescription); + [_ignoredPads addObject:pad.objectID]; + } + _rebuildPredicateWhenIdle = YES; + } + if (_rebuildPredicateWhenIdle) { + [self buildPredicateAndPerformFetch]; + } +} + +#pragma mark - Fetched results delegate + +- (void)controller:(NSFetchedResultsController *)controller + didChangeObject:(NSManagedObject *)anObject + atIndexPath:(NSIndexPath *)indexPath + forChangeType:(NSFetchedResultsChangeType)type + newIndexPath:(NSIndexPath *)newIndexPath +{ +// HPLog(@"%s", __PRETTY_FUNCTION__); + switch (type) { + case NSFetchedResultsChangeDelete: + if ([_badPads member:anObject.objectID]) { + [_badPads removeObject:anObject.objectID]; + _rebuildPredicateWhenIdle = YES; + } + // fall through + case NSFetchedResultsChangeUpdate: + case NSFetchedResultsChangeMove: + if ([_ignoredPads member:anObject.objectID]) { + [_ignoredPads removeObject:anObject.objectID]; + _rebuildPredicateWhenIdle = YES; + } + break; + } +} + +- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller +{ +// HPLog(@"%s", __PRETTY_FUNCTION__); + if (_rebuildPredicateWhenIdle) { + [self buildPredicateAndPerformFetch]; + } else { + [self queueRequest]; + } +} + +#pragma mark - Web view delegate +#if UPDATE_SNIPPETS +- (void)webViewDidFinishLoad:(UIWebView *)webView +{ + CGFloat expandedHeight = 0; + CGFloat height = 0; + for (UIView *view in webView.scrollView.subviews) { + if ([view isKindOfClass:[UIImageView class]]) { + continue; + } + [view layoutIfNeeded]; + height = expandedHeight = view.frame.size.height; + if (height > 160) { + height = [webView hp_stringByEvaluatingJavaScriptNamed:@"GetSnippetHeight.js"].floatValue; + } + break; + } + + [managedObjectContext performBlock:^{ + NSAssert(snippetPad, @"No snippet pad available."); + if (height) { + snippetPad.expandedSnippetHeight = expandedHeight; + snippetPad.snippetHeight = height; + HPLog(@"[%@] %@ %@ -> %f, %f", snippetPad.URL.host, + snippetPad.padID, snippetPad.title, + (double)snippetPad.snippetHeight, + (double)snippetPad.expandedSnippetHeight); + } + if (snippetHTML) { + snippetPad.snippetHTML = snippetHTML; + snippetPad.snippetUserPics = snippetUserPics; + } + NSError * __autoreleasing error; + if (![managedObjectContext save:&error]) { + TFLog(@"[%@] Could not save snippet for %@: %@", + snippetPad.URL.host, snippetPad.padID, error); + abort(); + } + + _request = nil; + snippetHTML = nil; + snippetUserPics = nil; + snippetPad = nil; + + [self queueRequest]; + }]; +} +#endif + +#pragma mark - Pad Web Controller Collab Client delegate + +- (void)padWebControllerCollabClientDidSynchronize:(HPPadWebController *)padWebController +{ + TFLog(@"[%@] Offline synchronization for %@ succeeded, saving changes.", + padWebController.pad.URL.host, padWebController.pad.padID); + HPPadCacheController * __weak weakSelf = self; + [padWebController saveClientVarsAndTextWithCompletion:^{ + TFLog(@"[%@] Offline synchronization for %@ complete.", + padWebController.pad.URL.host, padWebController.pad.padID); + padWebController.delegate = nil; + weakSelf.padWebController = nil; + weakSelf.missedChangesHandler(nil, nil); + }]; +} + +- (void)padWebController:(HPPadWebController *)padWebController +collabClientDidDisconnectWithUncommittedChanges:(BOOL)hasUncommittedChanges +{ + TFLog(@"[%@] Offline synchronization for %@ failed.", + padWebController.pad.URL.host, padWebController.pad.padID); + padWebController.delegate = nil; + self.padWebController = nil; + self.missedChangesHandler(nil, nil); +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPadEditor.h b/client/ios/Hackpad/HackpadKit/HPPadEditor.h new file mode 100644 index 0000000..9af1e8b --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadEditor.h @@ -0,0 +1,21 @@ +// +// HPPadEditor.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import +#import + +@class HPPad; + +@interface HPPadEditor : NSManagedObject + +@property (nonatomic, retain) id clientVars; +@property (nonatomic) NSTimeInterval clientVarsLastEditedDate; +@property (nonatomic, retain) NSData * clientVarsJSON; +@property (nonatomic, retain) HPPad *pad; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPadEditor.m b/client/ios/Hackpad/HackpadKit/HPPadEditor.m new file mode 100644 index 0000000..8adf532 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadEditor.m @@ -0,0 +1,20 @@ +// +// HPPadEditor.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPPadEditor.h" +#import "HPPad.h" + + +@implementation HPPadEditor + +@dynamic clientVars; +@dynamic clientVarsLastEditedDate; +@dynamic clientVarsJSON; +@dynamic pad; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPadScope.h b/client/ios/Hackpad/HackpadKit/HPPadScope.h new file mode 100644 index 0000000..54ed5e1 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadScope.h @@ -0,0 +1,23 @@ +// +// HPPadScope.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPCoreDataStack; +@class HPCollection; +@class HPSpace; + +FOUNDATION_EXTERN NSString * const HPPadScopeDidChangeNotification; + +@interface HPPadScope : NSObject +@property (strong, nonatomic, readonly) HPCoreDataStack *coreDataStack; +@property (strong, nonatomic) HPSpace *space; +@property (strong, nonatomic) HPCollection *collection; + +- (id)initWithCoreDataStack:(HPCoreDataStack *)coreDataStack; +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPadScope.m b/client/ios/Hackpad/HackpadKit/HPPadScope.m new file mode 100644 index 0000000..b9cab97 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadScope.m @@ -0,0 +1,132 @@ +// +// HPPadScope.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadScope.h" + +#import "HackpadKit/HackpadKit.h" +#import "HackpadAdditions/HackpadAdditions.h" + +#import + +NSString * const HPPadScopeDidChangeNotification = @"HPPadScopeDidChangeNotification"; + +@interface HPPadScope () + +@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController; + +@end + +@implementation HPPadScope + +- (id)initWithCoreDataStack:(HPCoreDataStack *)coreDataStack +{ + self = [super init]; + if (self) { + _coreDataStack = coreDataStack; + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPSpaceEntity]; + fetch.fetchLimit = 1; + fetch.shouldRefreshRefetchedObjects = YES; + fetch.predicate = [NSPredicate predicateWithValue:NO]; + fetch.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"rootURL" + ascending:YES]]; + NSManagedObjectContext *managedObjectContext = coreDataStack.mainContext; + _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetch + managedObjectContext:managedObjectContext + sectionNameKeyPath:nil + cacheName:nil]; + _fetchedResultsController.delegate = self; + [self updateFetchedResultsController]; + } + return self; +} + +- (void)dealloc +{ + _fetchedResultsController.delegate = nil; +} + +- (void)updateFetchedResultsController +{ + if (_space) { + self.fetchedResultsController.fetchRequest.predicate = [NSPredicate predicateWithFormat:@"rootURL = %@", + _space.rootURL]; + } else { + self.fetchedResultsController.fetchRequest.predicate = [NSPredicate predicateWithValue:NO]; + } + NSError *error; + if (![self.fetchedResultsController performFetch:&error]) { + TFLog(@"[PadScope] Could not perform space fetch: %@", error); + } + [[NSNotificationCenter defaultCenter] postNotificationName:HPPadScopeDidChangeNotification + object:self]; +} + +- (void)setSpace:(HPSpace *)space +{ + _collection = nil; + if (space && space.managedObjectContext != self.fetchedResultsController.managedObjectContext) { + NSParameterAssert(space.managedObjectContext.concurrencyType == NSMainQueueConcurrencyType); + NSError * __autoreleasing error; + if (space.objectID.isTemporaryID && + ![space.managedObjectContext obtainPermanentIDsForObjects:@[space] + error:&error]) { + TFLog(@"[%@] Could not obtain permanent ID for %@", space.URL.host, space.objectID); + return; + } + _space = (HPSpace *)[self.fetchedResultsController.managedObjectContext existingObjectWithID:space.objectID + error:&error]; + if (error) { + TFLog(@"[%@] Could not fetch space: %@", space.URL.host, space.objectID); + } + } else { + _space = space; + } + [self updateFetchedResultsController]; +} + +- (void)setCollection:(HPCollection *)collection +{ + if (collection && collection.managedObjectContext != self.fetchedResultsController.managedObjectContext) { + NSParameterAssert(collection.managedObjectContext.concurrencyType == NSMainQueueConcurrencyType); + NSError * __autoreleasing error; + if (collection.objectID.isTemporaryID && + ![collection.managedObjectContext obtainPermanentIDsForObjects:@[collection] + error:&error]) { + TFLog(@"[%@] Could not obtain permanent ID for %@", + collection.space.URL.host, collection.space.objectID); + return; + } + _collection = (HPCollection *)[self.fetchedResultsController.managedObjectContext existingObjectWithID:collection.objectID + error:&error]; + if (error) { + TFLog(@"[%@] Could not fetch collection: %@", collection.space.URL.host, collection.objectID); + } + } else { + _collection = collection; + } + _space = _collection.space; + [self updateFetchedResultsController]; +} + +#pragma mark - Fetched results controller delegate + +- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller +{ + if (self.fetchedResultsController.fetchedObjects.count) { + if (self.fetchedResultsController.fetchedObjects[0] != self.space) { + self.space = self.fetchedResultsController.fetchedObjects[0]; + } + } else { + // If there's no space, there's no space. + self.space = [HPSpace spaceWithURL:[NSURL hp_sharedHackpadURL] + inManagedObjectContext:self.fetchedResultsController.managedObjectContext + error:NULL]; + } +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPadSearch.h b/client/ios/Hackpad/HackpadKit/HPPadSearch.h new file mode 100644 index 0000000..ac22cef --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadSearch.h @@ -0,0 +1,20 @@ +// +// HPPadSearch.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import + +@class HPPad; + +@interface HPPadSearch : NSManagedObject + +@property (nonatomic, retain) NSString * content; +@property (nonatomic) NSTimeInterval lastEditedDate; +@property (nonatomic, retain) HPPad *pad; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPadSearch.m b/client/ios/Hackpad/HackpadKit/HPPadSearch.m new file mode 100644 index 0000000..d1fc75f --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadSearch.m @@ -0,0 +1,19 @@ +// +// HPPadSearch.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadSearch.h" +#import "HPPad.h" + + +@implementation HPPadSearch + +@dynamic content; +@dynamic lastEditedDate; +@dynamic pad; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPadSynchronizer.h b/client/ios/Hackpad/HackpadKit/HPPadSynchronizer.h new file mode 100644 index 0000000..8d60aa2 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadSynchronizer.h @@ -0,0 +1,26 @@ +// +// HPPadSynchronizer.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPSynchronizer.h" + +typedef NS_ENUM(NSUInteger, HPPadSynchronizerMode) { + HPDefaultPadSynchronizerMode, + HPFollowedPadsPadSynchronizerMode, + HPCollectionInfoPadSynchronizer +}; + +@interface HPPadSynchronizer : HPSynchronizer + +@property (nonatomic, strong) NSArray *editorNames; +@property (nonatomic, strong) NSArray *editorPics; + +- (id)initWithSpace:(HPSpace *)space + padIDKey:(NSString *)padIDKey +padSynchronizerMode:(HPPadSynchronizerMode)padSynchronizerMode; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPadSynchronizer.m b/client/ios/Hackpad/HackpadKit/HPPadSynchronizer.m new file mode 100644 index 0000000..134a658 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadSynchronizer.m @@ -0,0 +1,189 @@ +// +// HPPadSynchronizer.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPPadSynchronizer.h" + +#import + +#import + +static NSString * const TitleKey = @"title"; + +@interface HPPadSynchronizer () +@property (nonatomic, assign) HPPadSynchronizerMode padSynchronizerMode; +@property (nonatomic, strong) HPSpace *space; +@property (nonatomic, copy) NSString *padIDKey; +@end + +@implementation HPPadSynchronizer + +- (id)initWithSpace:(HPSpace *)space + padIDKey:(NSString *)padIDKey +padSynchronizerMode:(HPPadSynchronizerMode)padSynchronizerMode +{ + NSParameterAssert(space); + NSParameterAssert(padIDKey); + NSParameterAssert(padSynchronizerMode >= HPDefaultPadSynchronizerMode && + padSynchronizerMode <= HPCollectionInfoPadSynchronizer); + if (!(self = [super init])) { + return nil; + } + self.space = space; + self.padIDKey = padIDKey; + self.padSynchronizerMode = padSynchronizerMode; + return self; +} + +- (NSFetchRequest *)fetchRequestWithObjects:(NSArray *)objects + error:(NSError *__autoreleasing *)error +{ + static NSString * const PadIDKey = @"padID"; + + NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:HPPadEntity]; + fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:PadIDKey + ascending:YES]]; + fetchRequest.fetchBatchSize = 64; + + switch (self.padSynchronizerMode) { + case HPFollowedPadsPadSynchronizerMode: + case HPCollectionInfoPadSynchronizer: + fetchRequest.predicate = [NSPredicate predicateWithFormat:@"space == %@ && padID != nil", self.space]; + break; + + case HPDefaultPadSynchronizerMode: { + NSMutableSet *padIDs = [NSMutableSet setWithCapacity:objects.count]; + [objects enumerateObjectsUsingBlock:^(NSDictionary *pad, NSUInteger idx, BOOL *stop) { + if ([pad isKindOfClass:[NSDictionary class]]) { + [padIDs addObject:pad[self.padIDKey]]; + } + }]; + fetchRequest.predicate = [NSPredicate predicateWithFormat:@"space == %@ && padID IN %@", self.space, padIDs]; + break; + } + default: + return nil; + } + return fetchRequest; +} + +- (NSArray *)objectsSortDescriptors +{ + return @[[NSSortDescriptor sortDescriptorWithKey:self.padIDKey + ascending:YES]]; +} + +- (NSComparisonResult)compareObject:(NSDictionary *)object + existingObject:(HPPad *)existingObject +{ + if (!existingObject.padID) { + return NSOrderedAscending; + } + if (![object isKindOfClass:[NSDictionary class]]) { + return NSOrderedDescending; + } + NSString *padID = object[self.padIDKey]; + if (![padID isKindOfClass:[NSString class]]) { + return NSOrderedDescending; + } + // HPLog(@"obj %@ (%@) / existing %@ (%@)...", padID, object[TitleKey], existingObject.padID, existingObject.title); + return [padID compare:existingObject.padID]; +} + +- (BOOL)updateExistingObject:(HPPad *)pad + object:(NSDictionary *)JSONPad +{ + static NSString * const LastEditedDateKey = @"lastEditedDate"; + static NSString * const FollowedKey = @"followed"; + static NSString * const EditorKey = @"editor"; + + if (![JSONPad isKindOfClass:[NSDictionary class]]) { + return NO; + } + NSString *padID = JSONPad[self.padIDKey]; + // Some pad IDs exist with non-encoded URIs; skip them since + // we can't actually access them anyway. + if (![NSURL URLWithString:padID]) { + TFLog(@"[%@ %@] Ignoring invalid padID", self.space.URL.host, padID); + [pad.managedObjectContext deleteObject:pad]; + return NO; + } + + NSTimeInterval lastEdited = [JSONPad[LastEditedDateKey] longLongValue] - NSTimeIntervalSince1970; + if (lastEdited > pad.lastEditedDate) { + pad.lastEditedDate = lastEdited; + } + + NSString *title = JSONPad[TitleKey]; + if (!title) { + title = @"Untitled"; + } + if (![title isEqualToString:pad.title]) { + pad.title = title; + } + if (self.padSynchronizerMode == HPFollowedPadsPadSynchronizerMode) { + NSNumber *val = JSONPad[FollowedKey]; + BOOL followed = [val isKindOfClass:[NSNumber class]] && val.boolValue; + if (pad.followed != followed) { + pad.followed = followed; + } + } + if (self.editorNames) { + NSNumber *editor = JSONPad[EditorKey]; + if ([editor isKindOfClass:[NSNumber class]]) { + if (editor.unsignedIntegerValue < self.editorNames.count) { + NSString *editorName = self.editorNames[editor.unsignedIntegerValue]; + if (![pad.authorName isEqual:editorName]) { + pad.authorName = editorName; + pad.authorLastEditedDate = pad.lastEditedDate; + } + } + if (editor.unsignedIntegerValue < self.editorPics.count) { + NSString *editorPic = self.editorPics[editor.unsignedIntegerValue]; + if (![editorPic isKindOfClass:[NSString class]]) { + editorPic = @"/static/img/nophoto.png"; + } + if (![pad.authorPic isEqual:editorPic]) { + pad.authorPic = editorPic; + pad.authorLastEditedDate = pad.lastEditedDate; + } + } + } + } else { + if (pad.authorNames) { + pad.authorName = [pad.authorNames firstObject]; + if (!pad.authorName) { + pad.authorName = @"Someone"; + } + pad.authorNames = nil; + } + if (pad.snippetUserPics) { + pad.authorPic = [[pad.snippetUserPics firstObject] absoluteString]; + if (!pad.authorPic) { + pad.authorPic = @"/static/img/nophoto.png"; + } + pad.snippetUserPics = nil; + } + } + if (pad.padID) { + return YES; + } + + pad.padID = padID; + pad.space = self.space; + return YES; +} + +- (void)existingObjectNotFound:(HPPad *)pad +{ + if (self.padSynchronizerMode != HPFollowedPadsPadSynchronizerMode) { + return; + } + pad.followed = NO; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPPadWebController.h b/client/ios/Hackpad/HackpadKit/HPPadWebController.h new file mode 100644 index 0000000..2e91a37 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadWebController.h @@ -0,0 +1,102 @@ +// +// HPPadWebController.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPImageUpload; +@class HPPad; +@class HPPadAutocompleteTableViewDataSource; +@class HPUserInfo; +@class HPUserInfoCollection; + +@protocol HPPadWebControllerDelegate; +@protocol HPPadWebControllerCollabClientDelegate; + +@interface HPPadWebController : NSObject +@property (nonatomic, strong, readonly) HPPad *pad; +@property (nonatomic, strong, readonly) HPSpace *space; +@property (nonatomic, strong, readonly) UIWebView *webView; +@property (nonatomic, strong) UISearchBar *searchBar; +@property (nonatomic, strong, readonly) HPPadAutocompleteTableViewDataSource *autocompleteDataSource; +@property (nonatomic, strong, readonly) HPUserInfoCollection *userInfos; + +@property (nonatomic, assign) id delegate; +@property (nonatomic, assign) id collabClientDelegate; +@property (nonatomic, assign, readonly, getter = hasNetworkActivity) BOOL networkActivity; +@property (nonatomic, assign) CGFloat visibleEditorHeight; +@property (nonatomic, assign, readonly, getter = isLoading) BOOL loading; +@property (nonatomic, assign, readonly, getter = isLoaded) BOOL loaded; + ++ (id)sharedPadWebControllerWithPad:(HPPad *)pad; ++ (id)sharedPadWebControllerWithPad:(HPPad *)pad + padWebController:(HPPadWebController *)padWebController; + +- (id)initWithSpace:(HPSpace *)space + frame:(CGRect)frame; + +- (void)loadWithCompletion:(void (^)(NSError *))handler; +- (void)loadWithCachePolicy:(NSURLRequestCachePolicy)cachePolicy + completion:(void (^)(NSError *))handler; +- (void)reloadDiscardingChanges:(BOOL)discardChanges + cachePolicy:(NSURLRequestCachePolicy)cachePolicy + completion:(void (^)(NSError *))handler; + +- (void)reconnectCollabClient; +- (void)updateViewportWidth; +- (void)quickCam; +- (void)clickToolbarWithCommand:(NSString *)command; +- (void)insertImage:(UIImage *)image; +- (void)insertString:(NSString *)text; +- (void)deleteText; +- (void)insertNewLine; +- (void)selectAutocompleteData:(NSString *)selectedData + atIndex:(NSUInteger)index; +- (void)canUndoOrRedoWithCompletion:(void (^)(BOOL canUndo, BOOL canRedo))handler; +- (void)undo; +- (void)redo; + +- (void)getClientVarsAndTextWithCompletion:(void (^)(NSDictionary *, NSString *))handler; +- (void)saveClientVarsAndTextWithCompletion:(void (^)(void))handler; + +- (BOOL)saveFocus; +- (void)restoreFocus; + +- (void)updateAttachmentWithID:(NSString *)attachmentID + URL:(NSURL *)URL + key:(NSString *)key + completion:(void (^)(void))handler; + +- (void)setSearchBarScrolledOffScreen:(BOOL)scrolledOffScreen + animated:(BOOL)animated; + +@end + +@protocol HPPadWebControllerDelegate +@optional +- (void)padWebControllerDidUpdateUserInfo:(HPPadWebController *)padWebController; +- (void)padWebController:(HPPadWebController *)padWebController + didUpdateChannelState:(NSString *)channelState + collabState:(NSString *)collabState; + +- (void)padWebController:(HPPadWebController *)padWebController + didOpenURL:(NSURL *)URL; + +- (void)padWebControllerDidBeginAutocomplete:(HPPadWebController *)padWebController; +- (void)padWebControllerDidUpdateAutocomplete:(HPPadWebController *)padWebController; +- (void)padWebControllerDidFinishAutocomplete:(HPPadWebController *)padWebController; +- (void)padWebControllerDidDeletePad:(HPPadWebController *)padWebController; +- (void)padWebControllerDidFreakOut:(HPPadWebController *)padWebController; +@end + +@protocol HPPadWebControllerCollabClientDelegate +@optional +- (void)padWebControllerCollabClientDidConnect:(HPPadWebController *)padWebController; +- (void)padWebControllerCollabClientDidSynchronize:(HPPadWebController *)padWebController; +- (void)padWebController:(HPPadWebController *)padWebController +collabClientDidDisconnectWithUncommittedChanges:(BOOL)hasUncommittedChanges; +@end \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/HPPadWebController.m b/client/ios/Hackpad/HackpadKit/HPPadWebController.m new file mode 100644 index 0000000..c6c3af0 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPPadWebController.m @@ -0,0 +1,1188 @@ +// +// HPPadWebController.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPPadWebController.h" + +#import "HPPadAutocompleteTableViewDataSource.h" + +#import +#import +#import + +#import +#import +#import +#import + +static NSString * const AutocompleteHandler = @"autocomplete"; +static NSString * const CanUndoRedoHandler = @"canUndoRedo"; +static NSString * const CollabClientDidConnectHandler = @"collabClientDidConnect"; +static NSString * const CollabClientDidDisconnectHandler = @"collabClientDidDisconnect"; +static NSString * const CollabClientDidSynchronizeHandler = @"collabClientDidSynchronize"; +static NSString * const ConnectionTroubleHandler = @"connectionTrouble"; +static NSString * const DocumentDidFailLoadHandler = @"documentDidFailLoad"; +static NSString * const DoDeleteKeyHandler = @"doDeleteKey"; +static NSString * const DoToolbarClickHandler = @"doToolbarClick"; +static NSString * const DoReturnKeyHandler = @"doReturnKey"; +static NSString * const DoUndoRedoHandler = @"doUndoRedo"; +static NSString * const GetClientVarsAndTextHandler = @"getClientVarsAndText"; +static NSString * const GetViewportWidthHandler = @"getViewportWidth"; +static NSString * const InsertImageHandler = @"insertImage"; +static NSString * const InsertTextHandler = @"insertText"; +static NSString * const LogHandler = @"log"; +static NSString * const OpenLinkHandler = @"openLink"; +static NSString * const QuickCamHandler = @"quickCam"; +static NSString * const ReconnectCollabClientHandler = @"reconnectCollabClient"; +static NSString * const SetHasNetworkActivityHandler = @"setHasNetworkActivity"; +static NSString * const SetSharingOptionsHandler = @"setSharingOptions"; +static NSString * const SetTitleHandler = @"setTitle"; +static NSString * const SetVisibleEditorHeight = @"setVisibleEditorHeight"; +static NSString * const SignInHandler = @"signIn"; +static NSString * const UserInfoHandler = @"userInfo"; +static NSString * const UpdateNetworkActivityHandler = @"updateNetworkActivity"; +static NSString * const UpdateViewportWidthHandler = @"updateViewportWidth"; + +static NSString * const AddUserKey = @"addUser"; +static NSString * const ArgumentsKey = @"arguments"; +static NSString * const AttachmentIDKey = @"attachmentId"; +static NSString * const ChannelStateKey = @"channelState"; +static NSString * const ClientVarsKey = @"clientVars"; +static NSString * const CollabClientVarsKey = @"collab_client_vars"; +static NSString * const CollabStateKey = @"collabState"; +static NSString * const DataKey = @"data"; +static NSString * const DebugMessagesKey = @"debugMessages"; +static NSString * const ErrorKey = @"error"; +static NSString * const FailedURLsKey = @"failedURLs"; +static NSString * const FinishKey = @"finish"; +static NSString * const GlobalPadIdKey = @"globalPadId"; +static NSString * const GuestPolicyKey = @"guestPolicy"; +static NSString * const HrefKey = @"href"; +static NSString * const InvitedUserInfosKey = @"invitedUserInfos"; +static NSString * const IsModeratedKey = @"isModerated"; +static NSString * const LoadedKey = @"loaded"; +static NSString * const MessageKey = @"message"; +static NSString * const MethodKey = @"method"; +static NSString * const PadIdKey = @"padId"; +static NSString * const RedoKey = @"redo"; +static NSString * const SelectedKey = @"selected"; +static NSString * const SelectedIndexKey = @"selectedIndex"; +static NSString * const StatusKey = @"status"; +static NSString * const TextKey = @"text"; +static NSString * const UndoKey = @"undo"; +static NSString * const UserIDKey = @"userId"; +static NSString * const UserInfoKey = @"userInfo"; + +static NSString * const PadEditorPath = @"/ep/pad/editor"; + +static NSString * const ConnectedStatus = @"connected"; + +static NSString * const AboutBlank = @"about:blank"; + +static CGFloat const MaxImageSize = 800.0; + +@interface HPPadWebController () +@property (nonatomic, strong, readwrite) HPPad *pad; +@property (nonatomic, strong, readwrite) HPSpace *space; +@property (nonatomic, strong, readwrite) UIWebView *webView; +@property (nonatomic, assign, readwrite, getter = hasNetworkActivity) BOOL networkActivity; +@property (nonatomic, strong, readwrite) HPPadAutocompleteTableViewDataSource *autocompleteDataSource; +@property (nonatomic, strong, readwrite) HPUserInfoCollection *userInfos; + +@property (nonatomic, strong) HPAPI *API; +@property (nonatomic, strong) WebViewJavascriptBridge *bridge; +@property (nonatomic, strong) NSError *onloadError; +@property (nonatomic, strong) NSOperation *clientVarsOperation; +@property (nonatomic, strong) NSOperation *webViewLoadOperation; +@property (nonatomic, strong) NSOperation *loadCallbackOperation; +@property (nonatomic, strong) NSString *globalPadID; +@property (nonatomic, strong) NSString *userID; +@property (nonatomic, strong) NSData *insertingImageData; +@property (nonatomic, strong) UIRefreshControl *refreshControl; +@property (nonatomic, assign) NSInteger loadingFrameCount; +@property (nonatomic, strong) id signInObserver; +@property (nonatomic, assign, readwrite, getter = isLoading) BOOL loading; +@property (nonatomic, assign, readwrite, getter = isLoaded) BOOL loaded; +@end + +@implementation HPPadWebController + ++ (id)sharedPadWebControllerWithPad:(HPPad *)pad +{ + return [self sharedPadWebControllerWithPad:pad + padWebController:nil]; +} + ++ (id)sharedPadWebControllerWithPad:(HPPad *)pad + padWebController:(HPPadWebController *)preloadedPadWebController +{ + static NSMapTable *pads; + + NSParameterAssert(pad.objectID); + NSParameterAssert(!pad.objectID.isTemporaryID); + if (preloadedPadWebController) { + NSParameterAssert(pad.space == preloadedPadWebController.space); + NSParameterAssert(!preloadedPadWebController.pad); + } + + if (!pads) { + pads = [NSMapTable strongToWeakObjectsMapTable]; + } + + HPPadWebController *padWebController; + padWebController = [pads objectForKey:pad.objectID]; + if (padWebController) { + return padWebController; + } + if (preloadedPadWebController) { + padWebController = preloadedPadWebController; + padWebController.pad = pad; + } else { + padWebController = [[self alloc] initWithPad:pad + frame:CGRectMake(0, 0, 320, 420)]; + } + [pads setObject:padWebController + forKey:pad.objectID]; + return padWebController; +} + +- (id)initWithPad:(HPPad *)pad + frame:(CGRect)frame +{ + self = [self initWithSpace:pad.space + frame:frame]; + if (!self) { + return self; + } + self.pad = pad; + return self; +} + +- (id)initWithSpace:(HPSpace *)space + frame:(CGRect)frame +{ + self = [super init]; + if (!self) { + return self; + } + self.space = space; + self.webView = [[UIWebView alloc] initWithFrame:frame]; + self.webView.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal; + [self buildBridge]; + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + [nc addObserver:self + selector:@selector(saveClientVarsAndTextWithNotification:) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; + self.API = space.API; + [nc addObserver:self + selector:@selector(APIDidSignInWithNotification:) + name:HPAPIDidSignInNotification + object:self.API]; + [nc addObserver:self + selector:@selector(managedObjectContextDidSaveWithNotification:) + name:NSManagedObjectContextDidSaveNotification + object:space.managedObjectContext]; + + return self; +} + +- (void)dealloc +{ + self.webView.scrollView.delegate = nil; + self.webView.delegate = nil; + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (void)setSearchBar:(UISearchBar *)searchBar +{ + if (_searchBar == searchBar) { + return; + } + if (_searchBar) { + [_searchBar removeFromSuperview]; + } + _searchBar = searchBar; + if (!searchBar) { + return; + } + CGRect frame = searchBar.bounds; + if (HP_SYSTEM_MAJOR_VERSION() >= 7) { + [self.webView.scrollView.subviews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) { + if ([view isKindOfClass:[UIRefreshControl class]]) { + return; + } + CGRect frame = view.frame; + frame.origin.y = CGRectGetHeight(searchBar.bounds); + view.frame = frame; + }]; + } else { + frame.origin.y = -CGRectGetHeight(frame); + self.webView.scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(CGRectGetHeight(frame), 0, 0, 0); + } + searchBar.frame = frame; + [self.webView.scrollView addSubview:searchBar]; + [self.webView.scrollView layoutIfNeeded]; + self.webView.scrollView.delegate = self; +} + +#pragma mark - Loading + +- (void)setPad:(HPPad *)pad +{ + _pad = pad; + if (!pad || !self.isLoading) { + return; + } + [self loadPad]; +} + +- (void)loadPad +{ + NSParameterAssert(self.pad); + + HPPadWebController * __weak weakSelf = self; + if (!self.pad.padID) { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(padDidGetGlobalPadIDWithNotification:) + name:HPPadDidGetGlobalPadIDNotification + object:self.pad]; + } + if (self.pad.hasClientVars || !self.pad.padID) { + [[NSOperationQueue mainQueue] addOperation:self.clientVarsOperation]; + HPLog(@"Adding clientVars operation."); + } else { + [self.pad requestClientVarsWithRefresh:NO + completion:^(HPPad *pad, NSError *error) + { + HPLog(@"Adding clientVars operation."); + [[NSOperationQueue mainQueue] addOperation:weakSelf.clientVarsOperation]; + if (error && !weakSelf.onloadError) { + weakSelf.onloadError = error; + } + }]; + } +} + +- (void)loadWithCompletion:(void (^)(NSError *))handler +{ + [self loadWithCachePolicy:NSURLRequestReturnCacheDataElseLoad + completion:handler]; +} + +- (void)loadWithCachePolicy:(NSURLRequestCachePolicy)cachePolicy + completion:(void (^)(NSError *))handler +{ + if (self.isLoaded) { + if (!handler) { + return; + } + handler(self.onloadError); + return; + } + + HPPadWebController * __weak weakSelf = self; + if (!self.isLoading) { + self.onloadError = nil; + self.webViewLoadOperation = [NSBlockOperation blockOperationWithBlock:^{ + HPLog(@"webViewLoadOperation called."); + }]; + self.loadCallbackOperation = [NSBlockOperation blockOperationWithBlock:^{ + HPLog(@"loadCallbackOperation called."); + weakSelf.loaded = YES; + weakSelf.loading = NO; + }]; + [self.loadCallbackOperation addDependency:self.webViewLoadOperation]; + HPLog(@"Adding loadCallbackOperation."); + [[NSOperationQueue mainQueue] addOperation:self.loadCallbackOperation]; + } + + if (handler) { + NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ + HPLog(@"Callback operation called."); + handler(weakSelf.onloadError); + }]; + [operation addDependency:self.loadCallbackOperation]; + [[NSOperationQueue mainQueue] addOperation:operation]; + HPLog(@"Adding callback operation."); + } + + if (self.isLoading) { + return; + } + + self.loading = YES; + NSURL *URL = [NSURL URLWithString:PadEditorPath + relativeToURL:self.space.URL]; + self.clientVarsOperation = [NSBlockOperation blockOperationWithBlock:^{ + HPLog(@"clientVars operation called."); + if (weakSelf.onloadError) { + return; + } + [weakSelf addPadClientVars]; + }]; + if (self.pad) { + [self loadPad]; + } + [self.loadCallbackOperation addDependency:self.clientVarsOperation]; + [self.clientVarsOperation addDependency:self.webViewLoadOperation]; + + self.userInfos = [[HPUserInfoCollection alloc] initWithArray:@[]]; + /* + * UIWebView will (correctly) use the cachePolicy of the initial request for + * everything, but that's not what we want in this case (we just want to + * refresh /ep/pad/editor). So use a hack. + */ + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; + switch (cachePolicy) { + case NSURLRequestReloadIgnoringLocalCacheData: + case NSURLRequestReloadIgnoringLocalAndRemoteCacheData: + case NSURLRequestReloadRevalidatingCacheData: + [HPStaticCachingURLProtocol doNotCacheRequestIfOnline:request]; + break; + default: + break; + } + [self.webView loadRequest:request]; +} + +- (void)reloadDiscardingChanges:(BOOL)discardChanges + cachePolicy:(NSURLRequestCachePolicy)cachePolicy + completion:(void (^)(NSError *))handler +{ + if (self.isLoading) { + return; + } + self.loaded = NO; + HPPadWebController * __weak weakSelf = self; + void (^load)(void) = ^{ + [weakSelf loadWithCachePolicy:cachePolicy + completion:handler]; + }; + if (discardChanges) { + load(); + } else { + [self saveClientVarsAndTextWithCompletion:load]; + } +} + +- (void)refresh:(id)sender +{ + [self reloadDiscardingChanges:NO + cachePolicy:NSURLRequestReloadRevalidatingCacheData + completion:nil]; +} + +- (void)addClientVars:(NSDictionary *)clientVars +{ + static NSString * const AddClientVarsHandler = @"addClientVars"; + static NSString * const SuccessKey = @"success"; + + NSOperation *deferred = [NSOperation new]; + [self.loadCallbackOperation addDependency:deferred]; + + HPPadWebController * __weak weakSelf = self; + [self.bridge callHandler:AddClientVarsHandler + data:clientVars + responseCallback:^(NSDictionary *data) + { + [[NSOperationQueue mainQueue] addOperation:deferred]; + if (weakSelf.onloadError) { + return; + } + if (![data isKindOfClass:[NSDictionary class]] || + ![data[SuccessKey] isKindOfClass:[NSNumber class]] || + ![data[SuccessKey] boolValue]) { + TFLog(@"[%@ %@] Could not initialize client vars: %@", + weakSelf.webView.request.URL, weakSelf.pad.padID, data); + weakSelf.onloadError = [NSError errorWithDomain:HPHackpadErrorDomain + code:HPPadInitializationError + userInfo:nil]; + } + }]; +} + +- (void)addPadClientVars +{ + NSParameterAssert(self.pad); + + NSDictionary *clientVars = self.pad.clientVars; + [self addClientVars:clientVars]; + if (!clientVars) { + return; + } + + static NSString * const InvitedUserInfosKey = @"invitedUserInfos"; + static NSString * const StatusKey = @"status"; + static NSString * const ConnectedStatus = @"connected"; + + NSArray *userInfos = clientVars[InvitedUserInfosKey]; + NSString *userID = clientVars[UserIDKey]; + if (![userInfos isKindOfClass:[NSArray class]]) { + self.userInfos = nil; + return; + } + [userInfos enumerateObjectsUsingBlock:^(NSDictionary *userInfo, NSUInteger idx, BOOL *stop) { + if (![userInfo isKindOfClass:[NSDictionary class]]) { + return; + } + if ([userInfo[UserIDKey] isEqualToString:userID]) { + NSMutableDictionary *tmpUserInfo = [userInfo mutableCopy]; + tmpUserInfo[StatusKey] = ConnectedStatus; + userInfo = tmpUserInfo; + } + [self.userInfos addUserInfo:[[HPUserInfo alloc] initWithDictionary:userInfo]]; + }]; + if (![self.delegate respondsToSelector:@selector(padWebControllerDidUpdateUserInfo:)]) { + return; + } + [self.delegate padWebControllerDidUpdateUserInfo:self]; +} + +#pragma mark - JS Bridge + +- (void)buildBridge +{ + static NSString * const FinishMethod = @"finish"; + static NSString * const UploadImageHandler = @"uploadImage"; + static NSString * const DeletePadHandler = @"deletePad"; + static NSString * const FreakOutHandler = @"freakOut"; + + Class WVJB = [WebViewJavascriptBridge class]; + HPPadWebController * __weak weakSelf = self; + self.bridge = [WVJB bridgeForWebView:self.webView + webViewDelegate:self + handler:^(id data, WVJBResponseCallback responseCallback) {}]; + + // Please keep these sorted alphabetically by handler. + [self.bridge registerHandler:AutocompleteHandler + handler:^(NSDictionary *data, + WVJBResponseCallback responseCallback) + { + if (![data isKindOfClass:[NSDictionary class]]) { + return; + } + + if ([data[MethodKey] isEqual:FinishMethod]) { + if (![weakSelf.delegate respondsToSelector:@selector(padWebControllerDidFinishAutocomplete:)]) { + return; + } + [weakSelf.delegate padWebControllerDidFinishAutocomplete:weakSelf]; + weakSelf.autocompleteDataSource = nil; + return; + } + + if (![data[DataKey] isKindOfClass:[NSArray class]]) { + return; + } + + if (weakSelf.autocompleteDataSource) { + weakSelf.autocompleteDataSource.autocompleteData = data[DataKey]; + if (![weakSelf.delegate respondsToSelector:@selector(padWebControllerDidUpdateAutocomplete:)]) { + return; + } + [weakSelf.delegate padWebControllerDidUpdateAutocomplete:weakSelf]; + return; + } + + weakSelf.autocompleteDataSource = [HPPadAutocompleteTableViewDataSource new]; + weakSelf.autocompleteDataSource.autocompleteData = data[DataKey]; + if (![weakSelf.delegate respondsToSelector:@selector(padWebControllerDidBeginAutocomplete:)]) { + return; + } + [weakSelf.delegate padWebControllerDidBeginAutocomplete:weakSelf]; + }]; + + [self.bridge registerHandler:CollabClientDidConnectHandler + handler:^(id data, WVJBResponseCallback responseCallback) + { + [weakSelf.API hasGoneOnline]; + if (![weakSelf.collabClientDelegate respondsToSelector:@selector(padWebControllerCollabClientDidConnect:)]) { + return; + } + [weakSelf.collabClientDelegate padWebControllerCollabClientDidConnect:weakSelf]; + }]; + + [self.bridge registerHandler:CollabClientDidDisconnectHandler + handler:^(NSNumber *hasUncommittedChanges, WVJBResponseCallback responseCallback) + { + if (![hasUncommittedChanges isKindOfClass:[NSNumber class]]) { + TFLog(@"[%@ %@] hasUncommittedChanges is not a number: %@", + weakSelf.webView.request.URL.host, weakSelf.pad.padID, + NSStringFromClass(hasUncommittedChanges.class)); + return; + } + if (hasUncommittedChanges.boolValue) { + @synchronized (weakSelf.API) { + if (weakSelf.API.isSignedIn) { + weakSelf.API.authenticationState = HPReconnectAuthenticationState; + } + } + } + if (![weakSelf.collabClientDelegate respondsToSelector:@selector(padWebController:collabClientDidDisconnectWithUncommittedChanges:)]) { + return; + } + [weakSelf.collabClientDelegate padWebController:weakSelf + collabClientDidDisconnectWithUncommittedChanges:hasUncommittedChanges.boolValue]; + }]; + + [self.bridge registerHandler:CollabClientDidSynchronizeHandler + handler:^(id data, WVJBResponseCallback responseCallback) + { + if (![weakSelf.collabClientDelegate respondsToSelector:@selector(padWebControllerCollabClientDidSynchronize:)]) { + return; + } + [weakSelf.collabClientDelegate padWebControllerCollabClientDidSynchronize:weakSelf]; + }]; + + [self.bridge registerHandler:ConnectionTroubleHandler + handler:^(NSDictionary *data, + WVJBResponseCallback responseCallback) + { + TFLog(@"[%@ %@] Connection trouble for: %@: %@", + weakSelf.space.URL.host, weakSelf.pad.padID, + data[MessageKey], data[DebugMessagesKey]); +#if 0 + [[[UIAlertView alloc] initWithTitle:@"Connection Trouble" + message:data + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; +#endif + }]; + + [self.bridge registerHandler:DocumentDidFailLoadHandler + handler:^(id data, + WVJBResponseCallback responseCallback) + { + TFLog(@"[%@ %@] Failed to load page.", weakSelf.space.URL.host, + weakSelf.pad.padID); + }]; + + [self.bridge registerHandler:FreakOutHandler + handler:^(id data, WVJBResponseCallback responseCallback) + { + if (![weakSelf.delegate respondsToSelector:@selector(padWebControllerDidFreakOut:)]) { + return; + } + [weakSelf.delegate padWebControllerDidFreakOut:weakSelf]; + }]; + + [self.bridge registerHandler:GetViewportWidthHandler + handler:^(id data, + WVJBResponseCallback responseCallback) + { + responseCallback([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad + ? [NSNumber numberWithInt:CGRectGetWidth(weakSelf.webView.frame)] + : [NSNull null]); + }]; + + [self.bridge registerHandler:LogHandler + handler:^(id data, + WVJBResponseCallback responseCallback) + { + if (![data isKindOfClass:[NSDictionary class]] || + ![data[ArgumentsKey] isKindOfClass:[NSArray class]]) { + return; + } + NSMutableString *s = [NSMutableString stringWithFormat:@"[%@ %@] JavaScript:", + weakSelf.webView.request.URL.host, weakSelf.pad.padID]; + for (id obj in data[ArgumentsKey]) { + [s appendString:@" "]; + [s appendString:[obj description]]; + } + NSNumber *isError = data[ErrorKey]; + if ([isError isKindOfClass:[NSNumber class]] && [isError boolValue]) { + TFLog(@"%@", s); + } else { + HPLog(@"%@", s); + } + }]; + + [self.bridge registerHandler:OpenLinkHandler + handler:^(id data, + WVJBResponseCallback responseCallback) + { + NSString *URLString = data[HrefKey]; + if (![URLString isKindOfClass:[NSString class]] || + ![weakSelf.delegate respondsToSelector:@selector(padWebController:didOpenURL:)]) { + return; + } + NSURL *URL = [NSURL URLWithString:URLString + relativeToURL:weakSelf.webView.request.URL]; + [weakSelf.delegate padWebController:weakSelf + didOpenURL:URL]; + }]; + + [self.bridge registerHandler:SetHasNetworkActivityHandler + handler:^(NSNumber *hasNetworkActivity, + WVJBResponseCallback responseCallback) + { + if (![hasNetworkActivity isKindOfClass:[NSNumber class]]) { + TFLog(@"[%@ %@] hasNetworkAcvitity is not a number: %@", + weakSelf.webView.request.URL.host, weakSelf.pad.padID, + NSStringFromClass(hasNetworkActivity.class)); + return; + } + weakSelf.networkActivity = hasNetworkActivity.boolValue; + }]; + + [self.bridge registerHandler:SetSharingOptionsHandler + handler:^(id data, + WVJBResponseCallback responseCallback) + { + [weakSelf.pad.sharingOptions hp_performBlock:^(HPSharingOptions *sharingOptions, + NSError *__autoreleasing *error) + { + if (![data isKindOfClass:[NSDictionary class]]) { + return; + } + NSString *guestPolicy = data[GuestPolicyKey]; + if ([guestPolicy isKindOfClass:[NSString class]]) { + sharingOptions.sharingType = [HPSharingOptions sharingTypeWithString:guestPolicy]; + } + NSNumber *isModerated = data[IsModeratedKey]; + if ([isModerated isKindOfClass:[NSNumber class]]) { + sharingOptions.moderated = [isModerated boolValue]; + } + } completion:^(HPSharingOptions *sharingOptions, NSError *error) { + if (error) { + TFLog(@"[%@ %@] Couldn't save sharing options: %@", + weakSelf.space.URL.host, weakSelf.pad.padID, error); + } + }]; + }]; + + [self.bridge registerHandler:SetTitleHandler + handler:^(id data, + WVJBResponseCallback responseCallback) + { + if (![data isKindOfClass:[NSString class]]) { + return; + } + [weakSelf.pad hp_performBlock:^(HPPad *pad, NSError *__autoreleasing *error) { + pad.title = data; + } completion:^(HPPad *pad, NSError *error) { + if (error) { + TFLog(@"[%@ %@] Couldn't save title change: %@", + weakSelf.space.URL.host, weakSelf.pad.padID, error); + } + }]; + }]; + + [self.bridge registerHandler:SignInHandler + handler:^(id data, + WVJBResponseCallback responseCallback) + { + [weakSelf.API signInEvenIfSignedIn:YES]; + }]; + + [self.bridge registerHandler:UpdateNetworkActivityHandler + handler:^(id data, + WVJBResponseCallback responseCallback) + { + if (![weakSelf.delegate respondsToSelector:@selector(padWebController:didUpdateChannelState:collabState:)] || + ![data isKindOfClass:[NSDictionary class]] || + ![data[ChannelStateKey] isKindOfClass:[NSString class]] || + ![data[CollabStateKey] isKindOfClass:[NSString class]]) { + return; + } + [weakSelf.delegate padWebController:weakSelf + didUpdateChannelState:data[ChannelStateKey] + collabState:data[CollabStateKey]]; + }]; + + [self.bridge registerHandler:UploadImageHandler + handler:^(NSDictionary *data, WVJBResponseCallback responseCallback) + { + if (![data isKindOfClass:[NSDictionary class] ] || + ![data[AttachmentIDKey] isKindOfClass:[NSString class]] || + !weakSelf.insertingImageData) { + return; + } + NSData *imageData = weakSelf.insertingImageData; + NSManagedObjectID * __block objectID; + [weakSelf.pad hp_performBlock:^(HPPad *pad, NSError *__autoreleasing *error) { + static NSString * const ImageJPEGContentType = @"image/jpeg"; + static NSString * const DefaultFileName = @"photo.jpg"; + static NSString * const RootURLKey = @"rootURL"; + HPImageUpload *imageUpload = [NSEntityDescription insertNewObjectForEntityForName:HPImageUploadEntity + inManagedObjectContext:pad.managedObjectContext]; + imageUpload.image = imageData; + imageUpload.contentType = ImageJPEGContentType; + imageUpload.fileName = DefaultFileName; + imageUpload.attachmentID = data[AttachmentIDKey]; + imageUpload.rootURL = data[RootURLKey]; + if (![pad.managedObjectContext obtainPermanentIDsForObjects:@[imageUpload] + error:error]) { + [pad.managedObjectContext deleteObject:imageUpload]; + } + [pad addImageUploadsObject:imageUpload]; + // Trigger HPPadCacheController's FRC to refresh the pad object + pad.padID = pad.padID; + objectID = imageUpload.objectID; + } completion:^(HPPad *pad, NSError *error) { + weakSelf.insertingImageData = nil; + NSURL *URL = [[NSURL alloc] initWithScheme:HPImageUploadScheme + host:objectID.URIRepresentation.host + path:objectID.URIRepresentation.path]; + [weakSelf updateAttachmentWithID:data[AttachmentIDKey] + URL:URL + key:@"" + completion:nil]; + }]; + }]; + + [self.bridge registerHandler:UserInfoHandler + handler:^(id data, + WVJBResponseCallback responseCallback) + { + if (![data isKindOfClass:[NSDictionary class]]) { + return; + } + NSDictionary *userInfoDictionary = data[UserInfoKey]; + NSNumber *addUser = data[AddUserKey]; + if (![userInfoDictionary isKindOfClass:[NSDictionary class]] || + ![addUser isKindOfClass:[NSNumber class]]) { + return; + } + HPUserInfo *userInfo = [[HPUserInfo alloc] initWithDictionary:userInfoDictionary]; + [weakSelf.userInfos removeUserInfo:userInfo]; + if (addUser.boolValue) { + [weakSelf.userInfos addUserInfo:userInfo]; + } + if (![weakSelf.delegate respondsToSelector:@selector(padWebControllerDidUpdateUserInfo:)]) { + return; + } + [weakSelf.delegate padWebControllerDidUpdateUserInfo:weakSelf]; + }]; + + [self.bridge registerHandler:DeletePadHandler + handler:^(id data, WVJBResponseCallback responseCallback) + { + if (weakSelf.pad.deleting) { + return; + } + NSString * host = weakSelf.pad.URL.host; + [[[UIAlertView alloc] initWithTitle:weakSelf.pad.title + message:@"This pad has been deleted." + delegate:nil + cancelButtonTitle:nil + otherButtonTitles:@"OK", nil] show]; + [weakSelf.pad hp_performBlock:^(HPPad *pad, NSError *__autoreleasing *error) { + [pad.managedObjectContext deleteObject:pad]; + } completion:^(HPPad *pad, NSError *error) { + if (!error) { + return; + } + TFLog(@"[%@ %@] Could not delete pad: %@", host, pad.padID, error); + }]; + }]; +} + +- (void)reconnectCollabClient +{ + [self.bridge callHandler:ReconnectCollabClientHandler]; +} + +- (void)updateViewportWidth +{ + if ([UIDevice currentDevice].userInterfaceIdiom != UIUserInterfaceIdiomPad) { + return; + } + [self.bridge callHandler:UpdateViewportWidthHandler + data:@(CGRectGetWidth(self.webView.frame))]; +} + +- (void)quickCam +{ + [self.bridge callHandler:QuickCamHandler]; +} + +// These can't use the bridge as they need to block +- (BOOL)saveFocus +{ + return [self.webView stringByEvaluatingJavaScriptFromString:@"hackpadKit.saveFocus()"].boolValue; +} + +- (void)restoreFocus +{ + [self.webView stringByEvaluatingJavaScriptFromString:@"hackpadKit.restoreFocus()"]; +} + +- (void)clickToolbarWithCommand:(NSString *)command +{ + [self.bridge callHandler:DoToolbarClickHandler + data:command]; +} + +- (void)insertImage:(UIImage *)image +{ + @autoreleasepool { + if (MAX(image.size.width, image.size.height) > MaxImageSize) { + image = [image resizedImageWithContentMode:UIViewContentModeScaleAspectFit + bounds:CGSizeMake(MaxImageSize, MaxImageSize) + interpolationQuality:kCGInterpolationHigh]; + } + self.insertingImageData = UIImageJPEGRepresentation(image, 0.85); + } + [self.bridge callHandler:InsertImageHandler]; +} + +- (void)setVisibleEditorHeight:(CGFloat)visibleEditorHeight +{ + _visibleEditorHeight = visibleEditorHeight; + [self.bridge callHandler:SetVisibleEditorHeight + data:@(visibleEditorHeight)]; +} + +- (void)insertString:(NSString *)text +{ + [self.bridge callHandler:InsertTextHandler + data:text]; +} + +- (void)insertNewLine +{ + [self.bridge callHandler:DoReturnKeyHandler]; +} + +- (void)deleteText +{ + [self.bridge callHandler:DoDeleteKeyHandler]; +} + +- (void)selectAutocompleteData:(NSString *)selectedData + atIndex:(NSUInteger)index +{ + NSDictionary *data = @{SelectedKey:selectedData, + SelectedIndexKey:@(index)}; + [self.bridge callHandler:AutocompleteHandler + data:data]; +} + +- (void)canUndoOrRedoWithCompletion:(void (^)(BOOL, BOOL))handler +{ + [self.bridge callHandler:CanUndoRedoHandler + data:nil + responseCallback:^(NSDictionary *data) + { + if (![data isKindOfClass:[NSDictionary class]] || + ![data[UndoKey] isKindOfClass:[NSNumber class]] || + ![data[RedoKey] isKindOfClass:[NSNumber class]]) { + handler(NO, NO); + } + handler([data[UndoKey] boolValue], [data[RedoKey] boolValue]); + }]; +} + +- (void)undo +{ + [self.bridge callHandler:DoUndoRedoHandler + data:UndoKey]; +} + +- (void)redo +{ + [self.bridge callHandler:DoUndoRedoHandler + data:RedoKey]; +} + +- (void)updateAttachmentWithID:(NSString *)attachmentID + URL:(NSURL *)URL + key:(NSString *)key + completion:(void (^)(void))handler +{ + static NSString * const SetAttachmentURLHandler = @"setAttachmentURL"; + static NSString * const KeyKey = @"key"; + static NSString * const URLKey = @"url"; + + NSDictionary *data = @{AttachmentIDKey:attachmentID, + URLKey:URL.absoluteString, + KeyKey:key}; + [self.bridge callHandler:SetAttachmentURLHandler + data:data + responseCallback:^(id responseData) { + if (handler) { + handler(); + } + }]; +} + +#pragma mark - Client vars + +- (void)getClientVarsAndTextWithCompletion:(void (^)(NSDictionary *, NSString *))handler +{ + NSString * const InvalidClientVarsDataCheckpoint = @"InvalidClientVarsData"; + NSParameterAssert(self.pad); + NSParameterAssert(handler); + HPPadWebController * __weak weakSelf = self; + [self.bridge callHandler:GetClientVarsAndTextHandler + data:self.pad.clientVars + responseCallback:^(NSDictionary *data) { + if (![data isKindOfClass:[NSDictionary class]] || + ![data[ClientVarsKey] isKindOfClass:[NSDictionary class]] || + ![data[TextKey] isKindOfClass:[NSString class]]) { + [TestFlight passCheckpoint:InvalidClientVarsDataCheckpoint]; + TFLog(@"[%@ %@] Invalid data from %@: %@", + weakSelf.webView.request.URL.host, + weakSelf.pad.padID, + GetClientVarsAndTextHandler, + data); + handler(nil, nil); + return; + } + handler(data[ClientVarsKey], data[TextKey]); + }]; +} + +- (void)saveClientVarsAndTextWithCompletion:(void (^)(void))handler +{ + [self getClientVarsAndTextWithCompletion:^(NSDictionary *clientVars, NSString *text) { + if (!clientVars) { + if (handler) { + handler(); + } + return; + } + // Use strong reference to self here so we don't get released before saving state. + [self.pad hp_performBlock:^(HPPad *pad, NSError *__autoreleasing *error) { + [pad setClientVars:clientVars + lastEditedDate:[NSDate date].timeIntervalSinceReferenceDate]; + if (!pad.search) { + pad.search = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([HPPadSearch class]) + inManagedObjectContext:pad.managedObjectContext]; + } + // setting clientVars updates search text, but that doesn't account + // for offline edits, so still set it here. + pad.search.content = text; + pad.search.lastEditedDate = pad.editor.clientVarsLastEditedDate; + } completion:^(HPPad *pad, NSError *error) { + if (!handler) { + return; + } + handler(); + }]; + }]; +} + +#pragma mark - Notifications + +- (void)APIDidSignInWithNotification:(NSNotification *)note +{ + if (!self.isLoaded) { + return; + } + [self reconnectCollabClient]; +} + +- (void)padDidGetGlobalPadIDWithNotification:(NSNotification *)note +{ + [[NSNotificationCenter defaultCenter] removeObserver:self + name:HPPadDidGetGlobalPadIDNotification + object:self.pad]; + HPPadWebController * __weak weakSelf = self; + NSOperation *op = [NSBlockOperation blockOperationWithBlock:^{ + + NSDictionary *clientVars = @{PadIdKey:weakSelf.pad.padID, + GlobalPadIdKey:note.userInfo[HPGlobalPadIDKey], + CollabClientVarsKey:@{ + PadIdKey:weakSelf.pad.padID, + GlobalPadIdKey:note.userInfo[HPGlobalPadIDKey] + } + }; + [weakSelf addClientVars:clientVars]; + }]; + [self.loadCallbackOperation addDependency:op]; + [op addDependency:self.clientVarsOperation]; + [[NSOperationQueue mainQueue] addOperation:op]; +} + +- (void)saveClientVarsAndTextWithNotification:(NSNotification *)note +{ + if (!self.pad) { + return; + } + [self saveClientVarsAndTextWithCompletion:nil]; +} + +- (void)managedObjectContextDidSaveWithNotification:(NSNotification *)note +{ + if (!self.pad || ![note.userInfo[NSDeletedObjectsKey] member:self.pad]) { + return; + } + HPLog(@"[%@] Pad was deleted, unloading web view.", self.pad.URL.host); + self.webView.delegate = nil; + [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:AboutBlank]]]; + + if ([self.delegate respondsToSelector:@selector(padWebControllerDidDeletePad:)]) { + [self.delegate padWebControllerDidDeletePad:self]; + } + + if (![self.collabClientDelegate respondsToSelector:@selector(padWebController:collabClientDidDisconnectWithUncommittedChanges:)]) { + return; + } + [self.collabClientDelegate padWebController:self +collabClientDidDisconnectWithUncommittedChanges:NO]; + self.pad = nil; +} + +#pragma mark - Web view delegate + +- (BOOL)webView:(UIWebView *)webView +shouldStartLoadWithRequest:(NSURLRequest *)request + navigationType:(UIWebViewNavigationType)navigationType +{ + NSParameterAssert(request); + HPLog(@"[%@] shouldStartLoading? %@", self.space.URL.host, request.URL); + if (![self.delegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) { + return YES; + } + return [self.delegate webView:webView + shouldStartLoadWithRequest:request + navigationType:navigationType]; +} + +- (void)webViewDidStartLoad:(UIWebView *)webView +{ + ++self.loadingFrameCount; + if (![self.delegate respondsToSelector:@selector(webViewDidStartLoad:)]) { + return; + } + [self.delegate webViewDidStartLoad:webView]; +} + +- (void)webViewDidFinishLoad:(UIWebView *)webView +{ + static NSString * const TypeofClientVarsKey = @"typeofClientVars"; + static NSString * const TypeofJQueryKey = @"typeofJQuery"; + + static NSString * const TypeofUndefined = @"undefined"; + + if ([self.delegate respondsToSelector:@selector(webViewDidFinishLoad:)]) { + [self.delegate webViewDidFinishLoad:webView]; + } + HPLog(@"%ld (%@ - %@)", (long)(self.loadingFrameCount - 1), + [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"], + [webView stringByEvaluatingJavaScriptFromString:@"typeof $"]); + if (--self.loadingFrameCount) { + return; + } + if (self.refreshControl.isRefreshing) { + [self.refreshControl endRefreshing]; + } + // Quick check to see if we've already run the Hackpad script. + // This could be part of the script, but this can be called multiple times + // while the script is only run once per page. + if (!webView.request.URL.hp_isHackpadURL || + [webView stringByEvaluatingJavaScriptFromString:@"'hackpadKit' in window"].boolValue) { + return; + } + + //self.networkActivityState = self.networkActivityState & ~DownloadingMask; + + NSString *JSONString = [webView hp_stringByEvaluatingJavaScriptNamed:@"Hackpad.js"]; + NSError * __autoreleasing error; + NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:[JSONString dataUsingEncoding:NSUTF8StringEncoding] + options:0 + error:&error]; + if (!JSONString.length) { + TFLog(@"[%@ %@] Hackpad.js returned an empty string.", + self.space.URL.host, self.pad.padID); + } else if (error) { + TFLog(@"[%@ %@] Could not parse Hackpad.js result: %@", + self.space.URL.host, self.pad.padID, error); + self.onloadError = error; + } else if (![JSON isKindOfClass:[NSDictionary class]]) { + TFLog(@"[%@ %@] Hackpad.js returned non-dictionary: %@", + self.space.URL.host, self.pad.padID, + NSStringFromClass([JSON class])); + self.onloadError = [NSError errorWithDomain:HPHackpadErrorDomain + code:HPPadInitializationError + userInfo:nil]; + } else if (![JSON[LoadedKey] isKindOfClass:[NSNumber class]] || ![JSON[LoadedKey] boolValue]) { + self.onloadError = [NSError errorWithDomain:HPHackpadErrorDomain + code:HPPadInitializationError + userInfo:nil]; + if ([TypeofUndefined isEqual:JSON[TypeofJQueryKey]]) { + TFLog(@"[%@ %@] jQuery failed to load.", self.space.URL.host, + self.pad.padID); + } else if ([TypeofUndefined isEqual:JSON[TypeofClientVarsKey]]) { + TFLog(@"[%@ %@] clientVars wasn't set.", self.space.URL.host, + self.pad.padID); + } else if ([JSON[FailedURLsKey] isKindOfClass:[NSArray class]] && [JSON[FailedURLsKey] count]) { + TFLog(@"[%@ %@] CSS failed to load: %@", self.space.URL.host, + self.pad.padID, JSON[FailedURLsKey]); + } else { + TFLog(@"[%@ %@] Not sure why page failed to load.", + self.space.URL.host, self.pad.padID); + } + } else { + // Loaded OK so far! Force-load this now instead of waiting for everything. + [webView hp_stringByEvaluatingJavaScriptNamed:@"WebViewJavascriptBridge.js.txt"]; + } + if (self.webViewLoadOperation.isFinished || + [[[NSOperationQueue mainQueue] operations] containsObject:self.webViewLoadOperation]) { + return; + } + [[NSOperationQueue mainQueue] addOperation:self.webViewLoadOperation]; + HPLog(@"Adding webViewLoad operation"); +} + +- (void)webView:(UIWebView *)webView +didFailLoadWithError:(NSError *)error +{ + --self.loadingFrameCount; + TFLog(@"[%@ %@] Content failed to load: %@", self.space.URL.host, + self.pad.padID, error); + if (![self.delegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) { + return; + } + [self.delegate webView:webView + didFailLoadWithError:error]; +} + +- (void)setSearchBarScrolledOffScreen:(BOOL)scrolledOffScreen + animated:(BOOL)animated +{ + CGFloat offset = scrolledOffScreen ? CGRectGetHeight(self.searchBar.bounds) : 0; + offset -= self.webView.scrollView.contentInset.top; + [self.webView.scrollView setContentOffset:CGPointMake(0, offset) + animated:animated]; +} + +- (void)maybeScrollSearchBarOffScreen +{ + if (!self.searchBar) { + return; + } + + CGFloat offset = self.webView.scrollView.contentOffset.y + self.webView.scrollView.contentInset.top; + CGFloat height = CGRectGetHeight(self.searchBar.bounds); + if (offset >= height) { + return; + } + [self.webView.scrollView bringSubviewToFront:self.searchBar]; + [self setSearchBarScrolledOffScreen:offset > height / 3 + animated:YES]; +} + +- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView + willDecelerate:(BOOL)decelerate +{ + if (decelerate) { + return; + } + [self maybeScrollSearchBarOffScreen]; +} + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView +{ + [self maybeScrollSearchBarOffScreen]; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPReachability.h b/client/ios/Hackpad/HackpadKit/HPReachability.h new file mode 100644 index 0000000..f2f3920 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPReachability.h @@ -0,0 +1,12 @@ +// +// HPReachability.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "Reachability.h" + +@interface HPReachability : Reachability +@end diff --git a/client/ios/Hackpad/HackpadKit/HPReachability.m b/client/ios/Hackpad/HackpadKit/HPReachability.m new file mode 100644 index 0000000..4feee0e --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPReachability.m @@ -0,0 +1,105 @@ +// +// HPReachability.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPReachability.h" + +#import + +@interface HPReachability () { + BOOL connectionRequired; + NetworkStatus currentReachabilityStatus; +} +@end + +@interface Reachability (PrivateMethods) +- (NetworkStatus) networkStatusForFlags: (SCNetworkReachabilityFlags) flags; +- (NetworkStatus) localWiFiStatusForFlags: (SCNetworkReachabilityFlags) flags; +@end + +@implementation HPReachability + +static void PrintReachabilityFlags(SCNetworkReachabilityFlags flags, const char* comment) +{ +#if DEBUG || AD_HOC + TFLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s", + (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-', + (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-', + + (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-', + (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-', + (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-', + (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-', + comment + ); +#endif +} + +- (void)updateStatusWithFlags:(SCNetworkConnectionFlags)flags +{ + PrintReachabilityFlags(flags, "updateStatusWithFlags"); + @synchronized(self) { + connectionRequired = flags & kSCNetworkFlagsConnectionRequired; + currentReachabilityStatus = localWiFiRef + ? [self localWiFiStatusForFlags:flags] + : [self networkStatusForFlags:flags]; + } +} + +static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) +{ +#pragma unused (target, flags) + NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback"); + NSCAssert([(__bridge NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback"); + + HPReachability* noteObject = (__bridge HPReachability *)info; + [noteObject updateStatusWithFlags:flags]; + // Post a notification to notify the client that the network reachability changed. + [[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject]; +} + +- (BOOL)startNotifier +{ + BOOL returnValue = NO; + SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; + + if (SCNetworkReachabilitySetCallback(reachabilityRef, ReachabilityCallback, &context)) + { + if (SCNetworkReachabilityScheduleWithRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) + { + returnValue = YES; + } + } + SCNetworkReachabilityFlags flags; + if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) { + [self updateStatusWithFlags:flags]; + } + return returnValue; +} + +- (BOOL)connectionRequired +{ + BOOL ret; + @synchronized (self) { + ret = connectionRequired; + } + return ret; +} + +- (NetworkStatus) currentReachabilityStatus +{ + NetworkStatus status; + @synchronized (self) { + status = currentReachabilityStatus; + } + return status; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPRollbackDeletedObjectsMergePolicy.h b/client/ios/Hackpad/HackpadKit/HPRollbackDeletedObjectsMergePolicy.h new file mode 100644 index 0000000..6f13998 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPRollbackDeletedObjectsMergePolicy.h @@ -0,0 +1,12 @@ +// +// HPRollbackDeletedObjectsMergePolicy.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@interface HPRollbackDeletedObjectsMergePolicy : NSMergePolicy +@end diff --git a/client/ios/Hackpad/HackpadKit/HPRollbackDeletedObjectsMergePolicy.m b/client/ios/Hackpad/HackpadKit/HPRollbackDeletedObjectsMergePolicy.m new file mode 100644 index 0000000..a018d4c --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPRollbackDeletedObjectsMergePolicy.m @@ -0,0 +1,27 @@ +// +// HPRollbackDeletedObjectsMergePolicy.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPRollbackDeletedObjectsMergePolicy.h" + +@implementation HPRollbackDeletedObjectsMergePolicy + +- (BOOL)resolveConflicts:(NSArray *)list + error:(NSError *__autoreleasing *)error +{ + BOOL ret = [super resolveConflicts:list + error:error]; + [list enumerateObjectsUsingBlock:^(NSMergeConflict *mergeConflict, NSUInteger idx, BOOL *stop) { + if (!mergeConflict.newVersionNumber) { + HPLog(@"Deleting due to merge policy: %@", mergeConflict.sourceObject.objectID); + [mergeConflict.sourceObject.managedObjectContext deleteObject:mergeConflict.sourceObject]; + } + }]; + return ret; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSharingOptions+Impl.h b/client/ios/Hackpad/HackpadKit/HPSharingOptions+Impl.h new file mode 100644 index 0000000..6219cd3 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSharingOptions+Impl.h @@ -0,0 +1,39 @@ +// +// HPSharingOptions+Impl.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPSharingOptions.h" + +@class HPSpace; + +typedef NS_ENUM(int32_t, HPSharingType) { + HPInvalidSharingType = 0, + HPLinkSharingType = 1, + HPDenySharingType = 1 << 1, + HPAllowSharingType = 1 << 2, + HPDomainSharingType = 1 << 3, + HPAnonymousSharingType = 1 << 4, + HPFriendsSharingType = 1 << 5, + HPAskSharingType = 1 << 6 +}; + +@interface HPSharingOptions (Impl) + +@property (nonatomic, readonly) HPSpace *space; + ++ (NSString *)stringWithSharingType:(HPSharingType)sharingType; ++ (HPSharingType)sharingTypeWithString:(NSString *)sharingType; + +- (void)refreshWithCompletion:(void (^)(HPSharingOptions *, NSError *))handler; + +- (void)setModerated:(BOOL)moderated + completion:(void (^)(HPSharingOptions *, NSError *))handler; + +- (void)setSharingType:(HPSharingType)sharingType + completion:(void (^)(HPSharingOptions *, NSError *))handler; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSharingOptions+Impl.m b/client/ios/Hackpad/HackpadKit/HPSharingOptions+Impl.m new file mode 100644 index 0000000..7ad07a7 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSharingOptions+Impl.m @@ -0,0 +1,182 @@ +// +// HPSharingOptions+Impl.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPSharingOptions+Impl.h" + +#import "HackpadKit/HackpadKit.h" +#import "HackpadAdditions/HackpadAdditions.h" + +#import "GTMOAuthAuthentication.h" + +static NSString * const HPCollectionSearchPath = @"/ep/invite/group_autocomplete"; +static NSString * const HPCollectionOptionsPathComponent = @"options"; +static NSString * const HPPadOptionsPathComponent = @"options"; + +static NSString * const LinkSharingName = @"link"; +static NSString * const DenySharingName = @"deny"; +static NSString * const AllowSharingName = @"allow"; +static NSString * const DomainSharingName = @"domain"; + +static NSString * const IsModeratedKey = @"isModerated"; +static NSString * const IsPublicKey = @"isPublic"; +static NSString * const IsSubdomainKey = @"isSubdomain"; +static NSString * const GuestPolicyKey = @"guestPolicy"; +static NSString * const GuestPoliciesKey = @"guestPolicies"; +static NSString * const PadOptionsKey = @"options"; +static NSString * const SiteOptionsKey = @"siteOptions"; + +@interface HPSharingOptions () +@property (nonatomic, readonly) NSURL *APIURL; +@end + +@implementation HPSharingOptions (Impl) + ++ (NSString *)stringWithSharingType:(HPSharingType)sharingType +{ + switch (sharingType) { + case HPLinkSharingType: return LinkSharingName; + case HPDenySharingType: return DenySharingName; + case HPAllowSharingType: return AllowSharingName; + case HPDomainSharingType: return DomainSharingName; + default: return nil; + } +} + ++ (HPSharingType)sharingTypeWithString:(NSString *)sharingType +{ + switch ([sharingType characterAtIndex:0]) { + case 'l': return [sharingType isEqualToString:LinkSharingName] ? HPLinkSharingType : HPInvalidSharingType; + case 'd': + return [sharingType isEqualToString:DenySharingName] + ? HPDenySharingType + : [sharingType isEqualToString:DomainSharingName] + ? HPDomainSharingType + : HPInvalidSharingType; + case 'a': return [sharingType isEqualToString:AllowSharingName] ? HPAllowSharingType : HPInvalidSharingType; + default: return HPInvalidSharingType; + } +} + +- (void)setJSON:(id)JSON +{ + if (!JSON) { + return; + } +} + +- (NSURL *)APIURL +{ + if (self.pad) { + return [self.pad.APIURL URLByAppendingPathComponent:HPPadOptionsPathComponent]; + } else if (self.collection) { + return [self.collection.APIURL URLByAppendingPathComponent:HPCollectionOptionsPathComponent]; + } + return nil; +} + +- (HPSpace *)space +{ + return self.pad ? self.pad.space : self.collection.space; +} + +- (void)refreshWithCompletion:(void (^)(HPSharingOptions *, NSError *))handler +{ + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.APIURL + cachePolicy:NSURLRequestReloadIgnoringCacheData + timeoutInterval:60]; + [self.space.API.oAuth addResourceTokenHeaderToRequest:request]; + [self hp_sendAsynchronousRequest:request + block:^(HPSharingOptions *sharingOptions, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + id JSON = [sharingOptions.space.API parseJSONResponse:response + data:data + request:request + error:error]; + if (![JSON isKindOfClass:[NSDictionary class]] || + ![JSON[PadOptionsKey] isKindOfClass:[NSDictionary class]] || + ![JSON[SiteOptionsKey] isKindOfClass:[NSDictionary class]]) { + return; + } + + NSDictionary *options = JSON[PadOptionsKey]; + if ([options[GuestPolicyKey] isKindOfClass:[NSString class]]) { + sharingOptions.sharingType = [sharingOptions.class sharingTypeWithString:options[GuestPolicyKey]]; + } + if ([options[IsModeratedKey] isKindOfClass:[NSNumber class]]) { + sharingOptions.moderated = [options[IsModeratedKey] boolValue]; + } + options = JSON[SiteOptionsKey]; + if ([options[GuestPoliciesKey] isKindOfClass:[NSArray class]]) { + sharingOptions.allowedSharingTypes = 0; + [options[GuestPoliciesKey] enumerateObjectsUsingBlock:^(NSString *guestPolicy, NSUInteger idx, BOOL *stop) { + if ([guestPolicy isKindOfClass:[NSString class]]) { + sharingOptions.allowedSharingTypes |= [sharingOptions.class sharingTypeWithString:guestPolicy]; + } + }]; + } + if ([options[IsSubdomainKey] isKindOfClass:[NSNumber class]] && + [options[IsSubdomainKey] boolValue]) { + sharingOptions.space.public = [options[IsPublicKey] boolValue]; + } + } + completion:handler]; +} + +- (void)setModerated:(BOOL)moderated + completion:(void (^)(HPSharingOptions *, NSError *))handler +{ + NSMutableURLRequest *request = [NSMutableURLRequest hp_requestWithURL:self.APIURL + HTTPMethod:@"POST" + parameters:@{IsModeratedKey:moderated ? @"true" : @"false"}]; + [self.space.API.oAuth addResourceTokenHeaderToRequest:request]; + [self hp_sendAsynchronousRequest:request + block:^(HPSharingOptions *sharingOptions, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + if (![sharingOptions.space.API parseJSONResponse:response + data:data + request:request + error:error]) { + return; + } + sharingOptions.moderated = moderated; + } + completion:handler]; +} + +- (void)setSharingType:(HPSharingType)sharingType + completion:(void (^)(HPSharingOptions *, NSError *))handler +{ + NSString *guestPolicy = [self.class stringWithSharingType:sharingType]; + NSMutableURLRequest *request = [NSMutableURLRequest hp_requestWithURL:self.APIURL + HTTPMethod:@"POST" + parameters:@{GuestPolicyKey:guestPolicy}]; + [self.space.API.oAuth addResourceTokenHeaderToRequest:request]; + [self hp_sendAsynchronousRequest:request + block:^(HPSharingOptions *sharingOptions, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + if (![sharingOptions.space.API parseJSONResponse:response + data:data + request:request + error:error]) { + return; + } + sharingOptions.sharingType = sharingType; + } + completion:handler]; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSharingOptions.h b/client/ios/Hackpad/HackpadKit/HPSharingOptions.h new file mode 100644 index 0000000..5900b02 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSharingOptions.h @@ -0,0 +1,22 @@ +// +// HPSharingOptions.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import + +@class HPCollection, HPPad; + +@interface HPSharingOptions : NSManagedObject + +@property (nonatomic) int32_t allowedSharingTypes; +@property (nonatomic) BOOL moderated; +@property (nonatomic) int32_t sharingType; +@property (nonatomic, retain) HPCollection *collection; +@property (nonatomic, retain) HPPad *pad; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSharingOptions.m b/client/ios/Hackpad/HackpadKit/HPSharingOptions.m new file mode 100644 index 0000000..5f39bc1 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSharingOptions.m @@ -0,0 +1,22 @@ +// +// HPSharingOptions.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPSharingOptions.h" +#import "HPCollection.h" +#import "HPPad.h" + + +@implementation HPSharingOptions + +@dynamic allowedSharingTypes; +@dynamic moderated; +@dynamic sharingType; +@dynamic collection; +@dynamic pad; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSpace+Impl.h b/client/ios/Hackpad/HackpadKit/HPSpace+Impl.h new file mode 100644 index 0000000..7a6d269 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSpace+Impl.h @@ -0,0 +1,85 @@ +// +// HPSpace+Impl.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPSpace.h" + +@class HPAPI; + +#define HPSpaceEntity (NSStringFromClass([HPSpace class])) + +COREDATA_EXTERN NSString * const HPQueryParam; +COREDATA_EXTERN NSString * const HPFullNameProfileKey; +COREDATA_EXTERN NSString * const HPPhotoURLProfileKey; +COREDATA_EXTERN NSString * const HPLargePhotoURLProfileKey; + +typedef NS_ENUM(int32_t, HPSignInMethodsMask) { + HPPasswordSignInMask = 1, + HPGoogleSignInMask = 1 << 1, + HPFaceboookSignInMask = 1 << 2, +}; +typedef NS_ENUM(int32_t, HPDomainType) { + HPToplevelDomainType = 1, + HPHostedDomainType, + HPWorkspaceDomainType +}; +@interface HPSpace (Impl) + +@property (strong, nonatomic) NSArray *followedPads; +@property (weak, nonatomic, readonly) HPAPI *API; + ++ (id)firstSpaceInContext:(NSManagedObjectContext *)context error:(NSError *__autoreleasing *)error; + ++ (instancetype)insertSpaceWithURL:(NSURL *)URL + name:(NSString *)name + managedObjectContext:(NSManagedObjectContext *)managedObjectContext; + ++ (id)spaceWithURL:(NSURL *)URL +inManagedObjectContext:(NSManagedObjectContext *)context + error:(NSError * __autoreleasing *)error; + ++ (id)spaceWithAPI:(HPAPI *)API +inManagedObjectContext:(NSManagedObjectContext *)context + error:(NSError * __autoreleasing *)error; + ++ (BOOL)removeNonfollowedPadsInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error; + ++ (BOOL)migrateRootURLsInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error; + +- (NSURL *)URL; + +- (void)refreshOptionsWithCompletion:(void (^)(HPSpace *, NSError *))handler; + +- (void)requestFollowedPadsWithRefresh:(BOOL)refresh + completion:(void (^)(HPSpace *, NSError *))handler; + +- (void)requestPadsMatchingText:(NSString *)searchText + refresh:(BOOL)refresh + completion:(void (^)(HPSpace *, NSArray *, NSDictionary *, NSError *))handler; + +- (void)createCollectionWithName:(NSString *)name + pad:(HPPad *)pad + completion:(void (^)(HPSpace *, HPCollection *, NSError *))handler; + +- (void)signOutWithCompletion:(void (^)(HPSpace *, NSError *))handler; +- (void)leaveWithCompletion:(void (^)(HPSpace *, NSError *))handler; + +- (void)refreshSpacesWithCompletion:(void (^)(HPSpace *, NSError *))handler; + +- (void)blankPadWithTitle:(NSString *)title + followed:(BOOL)followed + completion:(void (^)(HPPad *, NSError *))handler; + +- (void)requestContactsMatchingText:(NSString *)searchText + completion:(void (^)(HPSpace *, NSArray *, NSError *))handler; + +- (void)requestUserProfileWithID:(NSString *)encryptedUserID + completion:(void (^)(HPSpace *, NSDictionary *, NSError *))handler; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSpace+Impl.m b/client/ios/Hackpad/HackpadKit/HPSpace+Impl.m new file mode 100644 index 0000000..fef8ad2 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSpace+Impl.m @@ -0,0 +1,667 @@ + // +// HPSpace+Impl.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPSpace+Impl.h" + +#import "HackpadKit.h" +#import "HackpadAdditions.h" + +#import "GTMOAuthAuthentication.h" +#import "GTMNSString+HTML.h" + +#import + +NSString * const HPQueryParam = @"q"; +NSString * const HPFullNameProfileKey = @"fullName"; +NSString * const HPPhotoURLProfileKey = @"photoUrl"; +NSString * const HPLargePhotoURLProfileKey = @"largePhotoUrl"; + +static NSString * const HPCollectionInfoPath = @"/ep/api/collection-info"; +static NSString * const HPCreateCollectionPath = @"/ep/group/create-with-pad"; +static NSString * const HPPadAutocompletePath = @"/ep/search/autocomplete"; +static NSString * const HPSignOutPath = @"/ep/account/sign-out"; +static NSString * const HPSiteOptionsPath = @"/api/1.0/options"; +static NSString * const HPUserSitesPath = @"/api/1.0/user/sites"; + +static NSString * const HPCollectionNameParam = @"groupName"; + +static NSString * const DataKey = @"data"; +static NSString * const PadIDKey = @"padID"; +static NSString * const ServerPadIdKey = @"padId"; +static NSString * const LocalPadIdKey = @"localPadId"; +static NSString * const CollectionIDKey = @"collectionID"; +static NSString * const FollowedKey = @"followed"; +static NSString * const SpaceKey = @"space"; +static NSString * const SiteNameKey = @"siteName"; +static NSString * const SignInMethodsKey = @"signInMethods"; +static NSString * const PasswordMethod = @"password"; +static NSString * const GoogleMethod = @"google"; +static NSString * const FacebookMethod = @"facebook"; +static NSString * const SitesKey = @"sites"; +static NSString * const TitleKey = @"title"; +static NSString * const OptionsKey = @"options"; +static NSString * const URLKey = @"url"; + +@implementation HPSpace (Impl) + +@dynamic followedPads; + ++ (id)firstSpaceInContext:(NSManagedObjectContext *)context error:(NSError *__autoreleasing *)error +{ + NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:HPSpaceEntity]; + fetchRequest.fetchLimit = 1; + return [context executeFetchRequest:fetchRequest error:error].firstObject; +} + ++ (instancetype)insertSpaceWithURL:(NSURL *)URL + name:(NSString *)name + managedObjectContext:(NSManagedObjectContext *)managedObjectContext; +{ + HPSpace *space = [NSEntityDescription insertNewObjectForEntityForName:HPSpaceEntity + inManagedObjectContext:managedObjectContext]; + space.rootURL = [[NSURL URLWithString:@"/" + relativeToURL:URL] absoluteString]; + [space setDomainTypeForURL:URL]; + if (name) { + space.name = name; + return space; + } + NSRange dot = [URL.host rangeOfString:@"."]; + if (dot.location == NSNotFound){ + space.name = URL.host; + } else { + space.name = [URL.host substringToIndex:dot.location]; + } + return space; +} + ++ (id)spaceWithURL:(NSURL *)URL +inManagedObjectContext:(NSManagedObjectContext *)context + error:(NSError *__autoreleasing *)error +{ + NSParameterAssert([URL isKindOfClass:[NSURL class]]); + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPSpaceEntity]; + fetch.fetchLimit = 1; + NSString *rootURL = [[NSURL URLWithString:@"/" + relativeToURL:URL] absoluteString]; + fetch.predicate = [NSPredicate predicateWithFormat:@"rootURL == %@", rootURL]; + NSString *subdomain = URL.hp_hackpadSubdomain; + if (subdomain) { + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"subdomain == %@", subdomain]; + fetch.predicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[fetch.predicate, predicate]]; + } + return [context executeFetchRequest:fetch + error:error].firstObject; +} + ++ (id)spaceWithAPI:(HPAPI *)API +inManagedObjectContext:(NSManagedObjectContext *)context + error:(NSError *__autoreleasing *)error +{ + return [self spaceWithURL:API.URL + inManagedObjectContext:context + error:error]; +} + ++ (BOOL)removeNonfollowedPadsInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError *__autoreleasing *)error +{ + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPPadEntity]; + fetch.predicate = [NSPredicate predicateWithFormat:@"hasMissedChanges == NO AND padID != nil AND followed == NO AND (collections.@count == 0 || NONE collections.followed == YES)"]; + NSArray *pads = [managedObjectContext executeFetchRequest:fetch + error:error]; + if (!pads) { + return NO; + } + TFLog(@"Pruning %lu pads.", (unsigned long)pads.count); + [pads enumerateObjectsUsingBlock:^(HPPad *pad, NSUInteger idx, BOOL *stop) { + [managedObjectContext deleteObject:pad]; + }]; + return YES; +} + ++ (BOOL)migrateRootURLsInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError *__autoreleasing *)error +{ + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPSpaceEntity]; + fetch.predicate = [NSPredicate predicateWithFormat:@"rootURL == nil || domainType == nil"]; + NSArray *spaces = [managedObjectContext executeFetchRequest:fetch + error:error]; + if (!spaces) { + return NO; + } + TFLog(@"Migrating %lu spaces to rootURLs.", (unsigned long)spaces.count); + [spaces enumerateObjectsUsingBlock:^(HPSpace *space, NSUInteger idx, BOOL *stop) { + NSURL *URL = space.URL; + space.rootURL = URL.absoluteString; + [space setDomainTypeForURL:URL]; + }]; + return YES; +} + +- (NSURL *)URL +{ + return self.rootURL ? [NSURL URLWithString:self.rootURL] + : [NSURL hp_URLForSubdomain:self.subdomain + relativeToURL:[NSURL hp_sharedHackpadURL]]; +} + +- (void)setDomainTypeForURL:(NSURL *)URL +{ + if (URL.hp_isToplevelHackpadURL) { + self.domainType = HPToplevelDomainType; + } else if (URL.hp_isHackpadSubdomain) { + self.domainType = HPWorkspaceDomainType; + } else { + self.domainType = HPHostedDomainType; + } +} + +- (HPAPI *)API +{ + HPAPI *API = [HPAPI APIWithURL:self.URL]; + @synchronized (API) { + if (API.authenticationState == HPNotInitializedAuthenticationState) { + API.userID = self.userID; + API.authenticationState = self.userID.length ? HPReconnectAuthenticationState : HPRequiresSignInAuthenticationState; + } + } + return API; +} + +- (void)refreshOptionsWithCompletion:(void (^)(HPSpace *, NSError *))handler +{ + NSDictionary *params = @{}; + NSURL *URL = [NSURL URLWithString:HPSiteOptionsPath + relativeToURL:self.URL]; + if (![HPAPI XSRFTokenForURL:URL].length) { + static NSString * const ContUrlParam = @"contUrl"; + static NSString * const SetCookieParam = @"setCookie"; + params = @{ContUrlParam:URL.absoluteString, + SetCookieParam:@"1"}; + URL = [NSURL hp_sharedHackpadURL]; + } + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"GET" + parameters:params]; + [self hp_sendAsynchronousRequest:request + block:^(HPSpace *space, + NSURLResponse *response, + NSData *data, + NSError *__autoreleasing *error) + { + id JSON = [space.API parseJSONResponse:response + data:data + request:request + error:error]; + if (![JSON isKindOfClass:[NSDictionary class]] || + ![JSON[OptionsKey] isKindOfClass:[NSDictionary class]] || + ![JSON[OptionsKey][SignInMethodsKey] isKindOfClass:[NSArray class]]) { + return; + } + JSON = JSON[OptionsKey]; + space.name = JSON[SiteNameKey]; + space.signInMethods = 0; + for (NSString *method in JSON[SignInMethodsKey]) { + if (![method isKindOfClass:[NSString class]]) { + continue; + } else if ([method isEqualToString:PasswordMethod]) { + space.signInMethods |= HPPasswordSignInMask; + } else if ([method isEqualToString:GoogleMethod]) { + space.signInMethods |= HPGoogleSignInMask; + } else if ([method isEqualToString:FacebookMethod]) { + space.signInMethods |= HPFaceboookSignInMask; + } + } + } completion:handler]; +} + +- (void)requestFollowedPadsWithRefresh:(BOOL)refresh + completion:(void (^)(HPSpace *, NSError *))handler +{ + static NSString * const PadsPath = @"/ep/api/pads"; + static NSString * const PadsKey = @"pads"; + static NSString * const CollectionsKey = @"collections"; + static NSString * const EditorNamesKey = @"editorNames"; + static NSString * const EditorPicsKey = @"editorPics"; + + NSURL *URL = [NSURL URLWithString:PadsPath + relativeToURL:self.URL]; + NSURLRequestCachePolicy cachePolicy = refresh + ? NSURLRequestReloadIgnoringCacheData + : NSURLRequestUseProtocolCachePolicy; + NSURLRequest *request = [NSURLRequest requestWithURL:URL + cachePolicy:cachePolicy + timeoutInterval:60]; + + [self hp_sendAsynchronousRequest:request + block:^(HPSpace *space, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + id JSON = [space.API parseJSONResponse:response + data:data + request:request + error:error]; + if (![JSON isKindOfClass:[NSDictionary class]] || + ![JSON[PadsKey] isKindOfClass:[NSArray class]] || + ![JSON[CollectionsKey] isKindOfClass:[NSArray class]] || + ![JSON[EditorNamesKey] isKindOfClass:[NSArray class]] || + ![JSON[EditorPicsKey] isKindOfClass:[NSArray class]]) { + return; + } + + NSArray *pads = JSON[PadsKey]; + NSArray *collections = JSON[CollectionsKey]; + + HPPadSynchronizer *padSync = [[HPPadSynchronizer alloc] initWithSpace:space + padIDKey:LocalPadIdKey + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + padSync.editorNames = JSON[EditorNamesKey]; + padSync.editorPics = JSON[EditorPicsKey]; + + HPCollectionSynchronizer *collectionSync = [[HPCollectionSynchronizer alloc] initWithSpace:space]; + padSync.delegate = collectionSync; + + TFLog(@"[%@] Received %lu pads, %lu collections, and %lu editors from %@", + URL.host, (unsigned long)pads.count, + (unsigned long)collections.count, + (unsigned long)padSync.editorNames.count, + URL.hp_fullPath); + + if (![padSync synchronizeObjects:pads + managedObjectContext:space.managedObjectContext + error:error]) { + padSync.delegate = nil; + return; + } + padSync.delegate = nil; + [collectionSync synchronizeObjects:collections + managedObjectContext:space.managedObjectContext + error:error]; + } completion:handler]; +} + +- (void)requestPadsMatchingText:(NSString *)searchText + refresh:(BOOL)refresh + completion:(void (^)(HPSpace *, NSArray *, NSDictionary *, NSError *))handler +{ + NSDictionary *params = @{HPQueryParam: searchText}; + NSURL *URL = [NSURL URLWithString:HPPadAutocompletePath + relativeToURL:self.URL]; + NSMutableURLRequest *request = [NSMutableURLRequest hp_requestWithURL:URL + HTTPMethod:@"GET" + parameters:params]; + request.cachePolicy = refresh + ? NSURLRequestReloadIgnoringCacheData + : NSURLRequestUseProtocolCachePolicy; + + NSMutableArray * __block objectIDs; + NSMutableDictionary *searchSnippets = [NSMutableDictionary dictionary]; + [self hp_sendAsynchronousRequest:request + block:^(HPSpace *space, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + id JSON = [space.API parseJSONResponse:response + data:data + request:request + error:error]; + if (![JSON isKindOfClass:[NSDictionary class]] || + ![JSON[DataKey] isKindOfClass:[NSString class]]) { + return; + } + JSON = [JSON[DataKey] componentsSeparatedByString:@"\n"]; + //HPLog(@"[%@] Lines: %@", request.URL.host, JSON); + NSMutableArray *searchPads = [NSMutableArray arrayWithCapacity:[JSON count]]; + [JSON enumerateObjectsUsingBlock:^(NSString *line, NSUInteger idx, BOOL *stop) { + if (!line.length) { + return; + } + NSArray *fields = [line componentsSeparatedByString:@"|"]; + if (fields.count < 2) { + HPLog(@"[%@], Could not parse line: %@", request.URL.host, line); + return; + } + NSString *padID = [fields[1] gtm_stringByUnescapingFromHTML]; + NSString *searchSnippet = (fields.count > 2) ? fields[2] : nil; + if (searchSnippet) { + searchSnippets[padID] = searchSnippet; + } + [searchPads addObject:@{TitleKey:[fields[0] gtm_stringByUnescapingFromHTML], + PadIDKey:padID}]; + + }]; + HPPadSynchronizer *sync = [[HPPadSynchronizer alloc] initWithSpace:space + padIDKey:PadIDKey + padSynchronizerMode:HPDefaultPadSynchronizerMode]; + [sync synchronizeObjects:searchPads + managedObjectContext:space.managedObjectContext + error:error]; + NSArray *pads = [sync synchronizeObjects:searchPads + managedObjectContext:space.managedObjectContext + error:error]; + if (!pads || ![space.managedObjectContext obtainPermanentIDsForObjects:pads + error:error]) { + return; + } + objectIDs = [NSMutableArray arrayWithCapacity:pads.count]; + [pads enumerateObjectsUsingBlock:^(HPPad *pad, NSUInteger idx, BOOL *stop) { + [objectIDs addObject:pad.objectID]; + }]; + } completion:^(HPSpace *space, NSError *error) { + if (handler) { + handler(space, objectIDs, searchSnippets, error); + } + }]; +} + +- (void)createCollectionWithName:(NSString *)name + pad:(HPPad *)pad + completion:(void (^)(HPSpace *, HPCollection *, NSError *))handler +{ + NSError * __autoreleasing error; + if (pad.objectID.isTemporaryID && + ![pad.managedObjectContext obtainPermanentIDsForObjects:@[pad] + error:&error]) { + if (handler) { + handler(self, nil, error); + } + return; + } + + NSURL *URL = [NSURL URLWithString:HPCreateCollectionPath + relativeToURL:self.URL]; + NSDictionary *params = @{HPCollectionNameParam: name, + HPPadIdParam: pad.padID, + HPAPIXSRFTokenParam: [HPAPI XSRFTokenForURL:URL]}; + NSURLRequest * request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + NSManagedObjectID *padObjectID = pad.objectID; + NSManagedObjectID * __block collectionObjectID; + [self hp_sendAsynchronousRequest:request + block:^(HPSpace *space, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + id JSON = [space.API parseJSONResponse:response + data:data + request:request + error:error]; + if (![JSON isKindOfClass:[NSDictionary class]] || + ![JSON[HPCollectionIdParam] isKindOfClass:[NSString class]]) { + return; + } + HPPad *pad = (HPPad *)[space.managedObjectContext existingObjectWithID:padObjectID + error:error]; + if (!pad) { + return; + } + HPCollection *collection = [NSEntityDescription insertNewObjectForEntityForName:HPCollectionEntity + inManagedObjectContext:space.managedObjectContext]; + collection.collectionID = JSON[HPCollectionIdParam]; + collection.title = name; + collection.space = space; + collection.followed = YES; + [collection addPadsObject:pad]; + + if (![space.managedObjectContext obtainPermanentIDsForObjects:@[collection] + error:error]) { + return; + } + collectionObjectID = collection.objectID; + } + completion:^(HPSpace *space, NSError *error) + { + if (handler) { + HPCollection *collection; + if (!error && collectionObjectID) { + collection = (HPCollection *)[space.managedObjectContext existingObjectWithID:collectionObjectID + error:&error]; + } + handler(space, collection, error); + } + }]; +} + +- (void)signOutWithCompletion:(void (^)(HPSpace *, NSError *))handler +{ + self.API.authenticationState = HPSigningOutAuthenticationState; + + NSURL *URL = [NSURL URLWithString:HPSignOutPath + relativeToURL:self.URL]; + NSString *XSRFToken = [HPAPI XSRFTokenForURL:URL]; + NSMutableDictionary *params = [HPAPI sharedDeviceTokenParams].mutableCopy; + params[HPAPIXSRFTokenParam] = XSRFToken; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + [self hp_sendAsynchronousRequest:request + block:^(HPSpace *space, + NSURLResponse *response, + NSData *data, + NSError * __autoreleasing *error) + { + @synchronized (space.API) { + if (space.API.authenticationState != HPSigningOutAuthenticationState) { + return; + } + space.API.authenticationState = HPRequiresSignInAuthenticationState; + } + } completion:handler]; +} + +- (void)leaveWithCompletion:(void (^)(HPSpace *, NSError *))handler +{ + static NSString * const HPDeleteAccountPath = @"/ep/account/settings/delete"; + + self.API.authenticationState = HPSigningOutAuthenticationState; + + NSURL *URL = [NSURL URLWithString:HPDeleteAccountPath + relativeToURL:self.URL]; + NSString *XSRFToken = [HPAPI XSRFTokenForURL:URL]; + NSDictionary *params = @{HPAPIXSRFTokenParam:XSRFToken}; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"POST" + parameters:params]; + HPAPI *API = self.API; + [self hp_sendAsynchronousRequest:request + block:^(HPSpace *space, + NSURLResponse *response, + NSData *data, + NSError *__autoreleasing *error) + { + @synchronized (API) { + if (API.authenticationState != HPSigningOutAuthenticationState) { + return; + } + [HPAPI removeAPIWithURL:API.URL]; + } + [HPStaticCachingURLProtocol removeCacheWithHost:API.URL.host + error:nil]; + [space.managedObjectContext deleteObject:space]; + } completion:handler]; +} + ++ (NSArray *)createOrUpdateSpacesWithJSON:(id)JSON + inManagedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error +{ + NSParameterAssert([JSON isKindOfClass:[NSArray class]]); + NSMutableArray *spaces = [NSMutableArray arrayWithCapacity:[JSON count]]; + [JSON enumerateObjectsUsingBlock:^(NSDictionary *JSONSite, NSUInteger idx, BOOL *stop) { + NSURL *URL = [NSURL URLWithString:JSONSite[URLKey]]; + HPSpace *space = [self spaceWithURL:URL + inManagedObjectContext:managedObjectContext + error:nil]; + if (!space) { + space = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass(self) + inManagedObjectContext:managedObjectContext]; + space.rootURL = [[NSURL URLWithString:@"/" + relativeToURL:URL] absoluteString]; + space.name = JSONSite[SiteNameKey]; + } + [spaces addObject:space]; + }]; + return spaces; +} + +- (void)refreshSpacesWithCompletion:(void (^)(HPSpace *, NSError *))handler +{ + NSURL *URL = [NSURL URLWithString:HPUserSitesPath + relativeToURL:self.URL]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL + cachePolicy:NSURLRequestReloadIgnoringCacheData + timeoutInterval:60]; + [self.API.oAuth addResourceTokenHeaderToRequest:request]; + [self hp_sendAsynchronousRequest:request + block:^(HPSpace *space, + NSURLResponse *response, + NSData *data, + NSError *__autoreleasing *error) + { + id JSON = [space.API parseJSONResponse:response + data:data + request:request + error:error]; + if (![JSON isKindOfClass:[NSDictionary class]] || + ![JSON[SitesKey] isKindOfClass:[NSArray class]]) { + return; + } + NSArray *JSONSites = JSON[SitesKey]; + TFLog(@"[%@] Received %lu sites from %@", URL.host, + (unsigned long)[JSONSites count], URL.hp_fullPath); + HPSpaceSynchronizer *sync = [HPSpaceSynchronizer new]; + [sync synchronizeObjects:JSONSites + managedObjectContext:space.managedObjectContext + error:error]; + } completion:handler]; +} + +- (void)blankPadWithTitle:(NSString *)title + followed:(BOOL)followed + completion:(void (^)(HPPad *, NSError *))handler +{ + NSManagedObjectID * __block padObjectID; + [self hp_performBlock:^(HPSpace *space, + NSError *__autoreleasing *error) + { + HPPad *pad = (HPPad *)[NSEntityDescription insertNewObjectForEntityForName:HPPadEntity + inManagedObjectContext:space.managedObjectContext]; + pad.title = title; + pad.space = space; + pad.followed = followed; + pad.lastEditedDate = [[NSDate date] timeIntervalSinceReferenceDate] - 60; + if (![pad.managedObjectContext obtainPermanentIDsForObjects:@[pad] + error:error]) { + return; + } + padObjectID = pad.objectID; + } completion:^(HPSpace *space, NSError *error) { + if (!space || !handler) { + return; + } + if (error) { + handler(nil, error); + return; + } + HPPad *pad = (HPPad *)[space.managedObjectContext existingObjectWithID:padObjectID + error:&error]; + if (!pad) { + handler(nil, error); + return; + } + handler(pad, nil); + }]; +} + +- (void)requestContactsMatchingText:(NSString *)searchText + completion:(void (^)(HPSpace *, NSArray *, NSError *))handler +{ + static NSString * const HPInviteeAutocompletePath = @"/api/1.0/user/contacts"; + static NSString * const ContactsKey = @"contacts"; + + NSURL *URL = [NSURL URLWithString:HPInviteeAutocompletePath + relativeToURL:self.URL]; + NSDictionary *params = @{HPQueryParam:searchText}; // HPLimitParam:@"10"} + NSMutableURLRequest *request = [NSMutableURLRequest hp_requestWithURL:URL + HTTPMethod:@"GET" + parameters:params]; + [self.API.oAuth addResourceTokenHeaderToRequest:request]; + HPSpace * __weak weakSelf = self; + [NSURLConnection sendAsynchronousRequest:request + queue:[NSOperationQueue mainQueue] + completionHandler:^(NSURLResponse *response, + NSData *data, + NSError *error) + { + if (!weakSelf) { + return; + } + id JSON = [weakSelf.API parseJSONResponse:response + data:data + request:request + error:&error]; + if (!handler) { + return; + } + if (![JSON isKindOfClass:[NSDictionary class]] || + ![JSON[ContactsKey] isKindOfClass:[NSArray class]]) { + handler(weakSelf, nil, error); + return; + } + + handler(weakSelf, JSON[ContactsKey], nil); + }]; +} + +- (void)requestUserProfileWithID:(NSString *)encryptedUserID + completion:(void (^)(HPSpace *, NSDictionary *, NSError *))handler +{ + static NSString * const UserPath = @"/api/1.0/user"; + static NSString * const ProfilePathComponent = @"profile"; + static NSString * const ProfileKey = @"profile"; + + NSURL *URL = [NSURL URLWithString:UserPath + relativeToURL:self.URL]; + URL = [[URL URLByAppendingPathComponent:encryptedUserID] URLByAppendingPathComponent:ProfilePathComponent]; + NSMutableURLRequest *request = [NSMutableURLRequest hp_requestWithURL:URL + HTTPMethod:@"GET" + parameters:nil]; + [self.API.oAuth addResourceTokenHeaderToRequest:request]; + HPSpace * __weak weakSelf = self; + [NSURLConnection sendAsynchronousRequest:request + queue:[NSOperationQueue mainQueue] + completionHandler:^(NSURLResponse *response, + NSData *data, + NSError *error) + { + if (!weakSelf) { + return; + } + id JSON = [weakSelf.API parseJSONResponse:response + data:data + request:request + error:&error]; + if (!handler) { + return; + } + if (![JSON isKindOfClass:[NSDictionary class]] || + ![JSON[ProfileKey] isKindOfClass:[NSDictionary class]]) { + handler(weakSelf, nil, error); + return; + } + handler(weakSelf, JSON[ProfileKey], nil); + }]; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSpace.h b/client/ios/Hackpad/HackpadKit/HPSpace.h new file mode 100644 index 0000000..a73d812 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSpace.h @@ -0,0 +1,40 @@ +// +// HPSpace.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import +#import + +@class HPCollection, HPPad; + +@interface HPSpace : NSManagedObject + +@property (nonatomic) BOOL hidden; +@property (nonatomic, retain) NSString * name; +@property (nonatomic) BOOL public; +@property (nonatomic, retain) NSString * rootURL; +@property (nonatomic) int32_t signInMethods; +@property (nonatomic, retain) NSString * subdomain; +@property (nonatomic, retain) NSString * userID; +@property (nonatomic) int32_t domainType; +@property (nonatomic, retain) NSSet *collections; +@property (nonatomic, retain) NSSet *pads; +@end + +@interface HPSpace (CoreDataGeneratedAccessors) + +- (void)addCollectionsObject:(HPCollection *)value; +- (void)removeCollectionsObject:(HPCollection *)value; +- (void)addCollections:(NSSet *)values; +- (void)removeCollections:(NSSet *)values; + +- (void)addPadsObject:(HPPad *)value; +- (void)removePadsObject:(HPPad *)value; +- (void)addPads:(NSSet *)values; +- (void)removePads:(NSSet *)values; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSpace.m b/client/ios/Hackpad/HackpadKit/HPSpace.m new file mode 100644 index 0000000..debc348 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSpace.m @@ -0,0 +1,27 @@ +// +// HPSpace.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPSpace.h" +#import "HPCollection.h" +#import "HPPad.h" + + +@implementation HPSpace + +@dynamic hidden; +@dynamic name; +@dynamic public; +@dynamic rootURL; +@dynamic signInMethods; +@dynamic subdomain; +@dynamic userID; +@dynamic domainType; +@dynamic collections; +@dynamic pads; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSpaceSynchronizer.h b/client/ios/Hackpad/HackpadKit/HPSpaceSynchronizer.h new file mode 100644 index 0000000..3846470 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSpaceSynchronizer.h @@ -0,0 +1,13 @@ +// +// HPSpaceSynchronizer.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPSynchronizer.h" + +@interface HPSpaceSynchronizer : HPSynchronizer + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSpaceSynchronizer.m b/client/ios/Hackpad/HackpadKit/HPSpaceSynchronizer.m new file mode 100644 index 0000000..8ef50c2 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSpaceSynchronizer.m @@ -0,0 +1,87 @@ +// +// HPSpaceSynchronizer.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPSpaceSynchronizer.h" + +#import +#import + +static NSString * const URLKey = @"url"; + +@implementation HPSpaceSynchronizer + +- (NSFetchRequest *)fetchRequestWithObjects:(NSArray *)objects + error:(NSError *__autoreleasing *)error +{ + static NSString * const RootURLKey = @"rootURL"; + + NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:HPSpaceEntity]; + fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:RootURLKey + ascending:YES]]; + fetchRequest.fetchBatchSize = 64; + fetchRequest.predicate = [NSPredicate predicateWithValue:YES]; + return fetchRequest; +} + +- (NSArray *)objectsSortDescriptors +{ + return @[[NSSortDescriptor sortDescriptorWithKey:URLKey + ascending:YES + comparator:^NSComparisonResult(NSString *space1, + NSString *space2) + { + if (![space1 isKindOfClass:[NSString class]]) { + return NSOrderedDescending; + } else if (![space2 isKindOfClass:[NSString class]]) { + return NSOrderedAscending; + } + return [space1 compare:space2]; + }]]; +} + +- (NSComparisonResult)compareObject:(NSDictionary *)JSONSpace + existingObject:(HPSpace *)space +{ + if (!space.rootURL) { + return NSOrderedAscending; + } + if (![JSONSpace isKindOfClass:[NSDictionary class]]) { + return NSOrderedDescending; + } + NSString *URLString = JSONSpace[URLKey]; + if (![URLString isKindOfClass:[NSString class]]) { + return NSOrderedDescending; + } + return [URLString compare:space.rootURL]; +} + +- (BOOL)updateExistingObject:(HPSpace *)space + object:(NSDictionary *)JSONSpace +{ + static NSString * const SiteNameKey = @"siteName"; + + if (![JSONSpace isKindOfClass:[NSDictionary class]]) { + return NO; + } + if ([JSONSpace[SiteNameKey] isKindOfClass:[NSString class]] && + ![space.name isEqualToString:JSONSpace[SiteNameKey]]) { + space.name = JSONSpace[SiteNameKey]; + } + if (space.rootURL) { + return YES; + } + space.rootURL = JSONSpace[URLKey]; + return YES; +} + +- (void)existingObjectNotFound:(HPSpace *)space +{ + // noop +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPStaticCachingURLProtocol.h b/client/ios/Hackpad/HackpadKit/HPStaticCachingURLProtocol.h new file mode 100644 index 0000000..67025d0 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPStaticCachingURLProtocol.h @@ -0,0 +1,27 @@ +// +// HPStaticCachingURLProtocol.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "RNCachingURLProtocol.h" + +@interface HPStaticCachingURLProtocol : RNCachingURLProtocol + ++ (BOOL)removeCacheWithError:(NSError * __autoreleasing *)error; ++ (BOOL)removeCacheWithHost:(NSString *)host + error:(NSError * __autoreleasing *)error; ++ (BOOL)removeCacheWithURLRequest:(NSURLRequest *)request + error:(NSError * __autoreleasing *)error; ++ (void)logCacheWithHost:(NSString *)host; ++ (NSData *)cachedDataWithRequest:(NSURLRequest *)request + returningResponse:(NSURLResponse * __autoreleasing *)response + error:(NSError * __autoreleasing *)error; ++ (BOOL)isCachedResponse:(NSURLResponse *)response; ++ (void)cacheResponse:(NSURLResponse *)response + data:(NSData *)data + request:(NSURLRequest *)request; ++ (void)doNotCacheRequestIfOnline:(NSMutableURLRequest *)request; +@end diff --git a/client/ios/Hackpad/HackpadKit/HPStaticCachingURLProtocol.m b/client/ios/Hackpad/HackpadKit/HPStaticCachingURLProtocol.m new file mode 100644 index 0000000..4336aeb --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPStaticCachingURLProtocol.m @@ -0,0 +1,332 @@ +// +// HPStaticCachingURLProtocol.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPStaticCachingURLProtocol.h" + +#import "HackpadAdditions.h" +#import "HPError.h" + +#import "HPReachability.h" + +#define CACHE_PROFILE_PICS 1 + +#if 0 +#define d(x) x +#else +#define d(x) +#endif + +// Defined by super. +static NSString * const RNCachingURLHeader = @"X-RNCache"; +static NSString * const FromCacheHeader = @"X-HPFromCache"; +static NSString * const DoNotCacheHeader = @"X-HPK-DoNotCacheIfOnline"; + +@interface RNCachingURLProtocol (HackpadAdditions) +- (void)connectionDidFinishLoading:(NSURLConnection *)connection; +- (NSURLRequest *)connection:(NSURLConnection *)connection + willSendRequest:(NSURLRequest *)request + redirectResponse:(NSURLResponse *)response; +@property (nonatomic, readwrite, strong) NSURLResponse *response; +@end + +@interface RNCachedData : NSObject +@property (nonatomic, readwrite, strong) NSData *data; +@property (nonatomic, readwrite, strong) NSURLResponse *response; +@property (nonatomic, readwrite, strong) NSURLRequest *redirectRequest; +@end + +@implementation HPStaticCachingURLProtocol + ++ (BOOL)canInitWithRequest:(NSURLRequest *)request +{ +#define ACCEPT d(HPLog(@"[%@] $$$ %@", request.URL.host, request.URL.hp_fullPath)); return YES +#define REJECT d(HPLog(@"[%@] XXX %@ (%@)", request.URL.host, request.URL.hp_fullPath, request.URL.pathExtension)); return NO + + // Set by super to mark download requests. + if ([request valueForHTTPHeaderField:RNCachingURLHeader]) { + return NO; + } + + if (![request.URL.scheme isEqualToString:@"http"] && + ![request.URL.scheme isEqualToString:@"https"]) { + REJECT; + } + + if (request.URL.hp_isHackpadURL) { + if ([request.URL.path isEqualToString:@"/"] || + [request.URL.path hasPrefix:@"/api/"] || + ([request.URL.path hasPrefix:@"/comet/"] && ![request.URL.pathExtension isEqualToString:@"js"]) || + ([request.URL.path hasPrefix:@"/ep/"] && + !([request.URL.path isEqualToString:@"/ep/pad/editor"] || + [request.URL.path isEqualToString:@"/ep/sheet"]))) { + REJECT; + } + ACCEPT; + } else if ([request.URL.host isEqualToString:@"__cdn_hostname__"] || + [request.URL.pathExtension isEqualToString:@"js"] || + [request.URL.pathExtension isEqualToString:@"css"]) { + ACCEPT; +#if CACHE_PROFILE_PICS + } else if (([request.URL.host isEqualToString:@"fbcdn-profile-a.akamaihd.net"] && + ([request.URL.pathExtension isEqualToString:@"jpg"] || + [request.URL.pathExtension isEqualToString:@"gif"])) || + ([request.URL.host isEqualToString:@"graph.facebook.com"] && + [request.URL.path hasSuffix:@"/picture"]) || + ([request.URL.host hasPrefix:@"profile-"] && + [request.URL.host hasSuffix:@".xx.fbcdn.net"]) || + ([request.URL.host isEqualToString:@"www.gravatar.com"] && + ([request.URL.path hasPrefix:@"/avatar.php"] || + [request.URL.path hasPrefix:@"/avatar/"])) || + ([request.URL.host isEqualToString:@"i2.wp.com"] && + [request.URL.path hasPrefix:@"/hackpad.com/"]) ) { + ACCEPT; +#endif + } + + REJECT; +#undef ACCEPT +#undef REJECT +} + ++ (NSString *)cachePath +{ + NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; + return [cachesPath stringByAppendingPathComponent:@"StaticURLCache"]; +} + ++ (BOOL)removeCacheWithError:(NSError * __autoreleasing *)error +{ + return [[NSFileManager defaultManager] removeItemAtPath:[self cachePath] + error:error]; +} + ++ (BOOL)removeCacheWithHost:(NSString *)host + error:(NSError *__autoreleasing *)error +{ + return [[NSFileManager defaultManager] removeItemAtPath:[[self cachePath] stringByAppendingPathComponent:host] + error:error]; +} + ++ (BOOL)removeCacheWithURLRequest:(NSURLRequest *)request + error:(NSError *__autoreleasing *)error +{ + HPLog(@"[%@] Removing item %@ (%@)", request.URL.host, + request.URL.hp_fullPath, + [self cachePathForRequest:request]); + return [[NSFileManager defaultManager] removeItemAtPath:[self cachePathForRequest:request] + error:error]; +} + ++ (NSString *)cachePathForRequest:(NSURLRequest *)aRequest +{ + NSString *cachePath = [self.class.cachePath stringByAppendingPathComponent:aRequest.URL.host]; + [[NSFileManager defaultManager] createDirectoryAtPath:cachePath + withIntermediateDirectories:YES + attributes:nil + error:nil]; + NSURL *URL = aRequest.URL; + if (URL.fragment.length) { + URL = [NSURL URLWithString:URL.path + relativeToURL:URL]; + } + return [cachePath stringByAppendingPathComponent:[URL.absoluteString hp_SHA1Digest]]; +} + +- (NSString *)cachePathForRequest:(NSURLRequest *)aRequest +{ + return [self.class cachePathForRequest:aRequest]; +} + ++ (Reachability *)sharedInternetReachability +{ + static Reachability *internetConnectionReachability; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + internetConnectionReachability = [HPReachability reachabilityForInternetConnection]; + [internetConnectionReachability startNotifier]; + }); + return internetConnectionReachability; +} + +- (BOOL)allowNetwork +{ + return self.request.cachePolicy != NSURLRequestReturnCacheDataDontLoad; +} + +- (BOOL)useCache +{ + d(NSDate *date); + switch (self.request.cachePolicy) { + case NSURLRequestReturnCacheDataDontLoad: + d(HPLog(@"[%@] useCache: YES (forced) %@", self.request.URL.host, + self.request.URL.hp_fullPath)); + return YES; + case NSURLRequestReloadIgnoringCacheData: + case NSURLRequestReloadIgnoringLocalAndRemoteCacheData: + d(HPLog(@"[%@] useCache: NO (reload ignoring) %@", self.request.URL.host, + self.request.URL.hp_fullPath)); + return NO; + default: +#if 0 + @try { + if ([NSKeyedUnarchiver unarchiveObjectWithFile:[self cachePathForRequest:[self request]]]) { + d(HPLog(@"[%@] useCache: YES (found cache) %@", self.request.URL.host, + self.request.URL.hp_fullPath)); + return YES; + } + } + @catch (NSException *exception) { } + // fall through... +#endif + if (self.request.allHTTPHeaderFields[DoNotCacheHeader] && + [self.class sharedInternetReachability].currentReachabilityStatus) { + d(HPLog(@"[%@] useCache: NO (header override) %@", self.request.URL.host, + self.request.URL.hp_fullPath)); + return NO; + } + d(HPLog(@"[%@] useCache: YES (try cache: %lu) %@", self.request.URL.host, + (unsigned long)self.request.cachePolicy, + self.request.URL.hp_fullPath)); + return YES; + case NSURLRequestReloadRevalidatingCacheData: + d(date = [NSDate date]); + if ([self.class sharedInternetReachability].currentReachabilityStatus) { + d(HPLog(@"[%@] useCache: NO (loading) %@ (%.3f)", self.request.URL.host, + self.request.URL.hp_fullPath, + -date.timeIntervalSinceNow)); + return NO; + } + d(HPLog(@"[%@] useCache: NO (offline) %@ (%.3f)", self.request.URL.host, + self.request.URL.hp_fullPath, -date.timeIntervalSinceNow)); + return YES; + } +} + ++ (void)doNotCacheRequestIfOnline:(NSMutableURLRequest *)request +{ + [request addValue:@"" + forHTTPHeaderField:DoNotCacheHeader]; +} + +- (BOOL)shouldCacheResponse:(NSURLResponse *)response +{ + return [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse *)response statusCode] / 100 == 2; +} + +- (void)connectionDidFinishLoading:(NSURLConnection *)connection +{ + BOOL shouldCache = [self shouldCacheResponse:[self response]]; + if (shouldCache) { + NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)self.response; + NSMutableDictionary *allHeaderFields = HTTPResponse.allHeaderFields.mutableCopy; + allHeaderFields[FromCacheHeader] = @"YES"; + self.response = [[NSHTTPURLResponse alloc] initWithURL:HTTPResponse.URL + statusCode:HTTPResponse.statusCode + HTTPVersion:@"HTTP/1.1" + headerFields:allHeaderFields]; + } + [super connectionDidFinishLoading:connection]; + if (!shouldCache) { + [self.class removeCacheWithURLRequest:[self request] + error:NULL]; + } +} + ++ (BOOL)isCachedResponse:(NSURLResponse *)response +{ + return [response isKindOfClass:[NSHTTPURLResponse class]] && + [[(NSHTTPURLResponse *)response allHeaderFields][FromCacheHeader] boolValue]; +} + +- (NSURLRequest *)connection:(NSURLConnection *)connection + willSendRequest:(NSURLRequest *)request + redirectResponse:(NSURLResponse *)response +{ + NSURLRequest *ret = [super connection:connection + willSendRequest:request + redirectResponse:response]; + if (response) { + [self.class removeCacheWithURLRequest:[self request] + error:NULL]; + } + return ret; +} + ++ (void)logCacheWithHost:(NSString *)host +{ + NSString *path = [[self cachePath] stringByAppendingPathComponent:host]; + for (NSString *file in [[NSFileManager defaultManager] enumeratorAtPath:path]) { + if ([file isEqualToString:@".DS_Store"]) { + continue; + } + id cache; + @try { + cache = [NSKeyedUnarchiver unarchiveObjectWithFile:[path stringByAppendingPathComponent:file]]; + } @catch (NSException *exception) { + HPLog(@"[%@] Invalid archive: %@", host, file); + continue; + } + NSURLResponse *response = [cache response]; + if ([response isKindOfClass:[NSHTTPURLResponse class]]) { +#if DEBUG + NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response; +#endif + HPLog(@"[%@] %@: %@ -> %ld %d %@ %@", host, file, HTTPResponse.URL, (long)HTTPResponse.statusCode, (int)HTTPResponse.expectedContentLength, HTTPResponse.MIMEType, HTTPResponse.allHeaderFields); + } else { + HPLog(@"[%@] %@: %@ -> %d %@", host, file, response.URL, (int)response.expectedContentLength, response.MIMEType); + } + } +} + ++ (NSData *)cachedDataWithRequest:(NSURLRequest *)request + returningResponse:(NSURLResponse *__autoreleasing *)response + error:(NSError *__autoreleasing *)error +{ + RNCachedData *cachedData; + @try { + cachedData = [NSKeyedUnarchiver unarchiveObjectWithFile:[self cachePathForRequest:request]]; + } + @catch (NSException *exception) { + if (error) { + NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:exception.userInfo]; + dict[NSLocalizedDescriptionKey] = exception.reason; + *error = [NSError errorWithDomain:HPHackpadErrorDomain + code:HPFailedRequestError + userInfo:dict]; + } + return nil; + } + if (!cachedData) { + if (error) { + *error = [NSError errorWithDomain:HPHackpadErrorDomain + code:HPFailedRequestError + userInfo:@{NSLocalizedDescriptionKey:@"Request not found in cache."}]; + } + } else if (cachedData.redirectRequest) { + return [self cachedDataWithRequest:cachedData.redirectRequest + returningResponse:response + error:error]; + } else if (response) { + *response = cachedData.response; + } + return cachedData.data; +} + ++ (void)cacheResponse:(NSURLResponse *)response + data:(NSData *)data + request:(NSURLRequest *)request +{ + NSString *cachePath = [self cachePathForRequest:request]; + RNCachedData *cacheData = [RNCachedData new]; + cacheData.response = response; + cacheData.data = data; + [NSKeyedArchiver archiveRootObject:cacheData + toFile:cachePath]; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSynchronizer.h b/client/ios/Hackpad/HackpadKit/HPSynchronizer.h new file mode 100644 index 0000000..0b1658d --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSynchronizer.h @@ -0,0 +1,42 @@ +// +// HPSynchronizer.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import + +@protocol HPSynchronizerDelegate; + +@interface HPSynchronizer : NSObject + +@property (nonatomic, assign) id delegate; + +- (NSArray *)synchronizeObjects:(NSArray *)objects + managedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError * __autoreleasing *)error; + +@end + +@protocol HPSynchronizerDelegate +@optional + +- (void)synchronizer:(HPSynchronizer *)synchronizer + willSaveObjects:(NSArray *)objects; + +@end + +@interface HPSynchronizer (Implementation) + +- (NSFetchRequest *)fetchRequestWithObjects:(NSArray *)objects + error:(NSError * __autoreleasing *)error; +- (NSArray *)objectsSortDescriptors; +- (NSComparisonResult)compareObject:(id)object + existingObject:(id)existingObject; +- (BOOL)updateExistingObject:(id)existingObject + object:(id)object; +- (void)existingObjectNotFound:(id)existingObject; + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPSynchronizer.m b/client/ios/Hackpad/HackpadKit/HPSynchronizer.m new file mode 100644 index 0000000..5e099a5 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPSynchronizer.m @@ -0,0 +1,240 @@ +// +// HPSynchronizer.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPSynchronizer.h" + +#import + +@implementation HPSynchronizer + +#pragma mark - algorithm implementation + +- (void)noop +{ +} + +- (void)syncBarrier +{ + // We want to avoid going through the main thread while it's busy scrolling, + // AKA in UITrackingRunLoopMode. This call waits until that's done. + [self performSelectorOnMainThread:@selector(noop) + withObject:nil + waitUntilDone:YES + modes:@[NSDefaultRunLoopMode]]; +} + +- (NSEnumerator *)enumeratorWithFetchRequest:(NSFetchRequest *)fetchRequest + managedObjectContext:(NSManagedObjectContext *)managedObjectContext + stop:(BOOL *)stop + error:(NSError * __autoreleasing *)error +{ + [self syncBarrier]; + NSArray *existingObjects = [managedObjectContext executeFetchRequest:fetchRequest + error:error]; + if (!existingObjects) { + return nil; + } + fetchRequest.fetchOffset += existingObjects.count; + if (existingObjects.count < fetchRequest.fetchLimit) { + *stop = YES; + } + return existingObjects.objectEnumerator; +} + +- (BOOL)saveBatch:(NSMutableArray *)batch +managedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError *__autoreleasing *)error +{ + if (batch.count && [self.delegate respondsToSelector:@selector(synchronizer:willSaveObjects:)]) { + [self.delegate synchronizer:self + willSaveObjects:batch]; + } + if (managedObjectContext.hasChanges) { + [self syncBarrier]; + if (![managedObjectContext hp_saveToStore:error]) { + return NO; + } + } + // Turn objects into faults to reduce memory usage. + [batch enumerateObjectsUsingBlock:^(NSManagedObject *managedObject, + NSUInteger idx, BOOL *stop) { + [managedObjectContext refreshObject:managedObject + mergeChanges:NO]; + }]; + return YES; +} + +- (NSArray *)synchronizeObjects:(NSArray *)objects + managedObjectContext:(NSManagedObjectContext *)managedObjectContext + error:(NSError *__autoreleasing *)error +{ + NSFetchRequest *fetchRequest = [self fetchRequestWithObjects:objects + error:error]; + if (!fetchRequest) { + return nil; + } + + NSMutableArray * __block ret = [NSMutableArray arrayWithCapacity:objects.count]; + NSMutableArray *batch = [NSMutableArray arrayWithCapacity:fetchRequest.fetchBatchSize]; + + NSEnumerator * __block existingEnumerator; + BOOL __block fetchingComplete = NO; + + id (^getNextExistingObject)(void) = ^{ + id nextObject = existingEnumerator.nextObject; + if (nextObject || fetchingComplete) { + return nextObject; + } + /* + * Fetch offset is ignored if context has saved data? + * http://stackoverflow.com/questions/10725252/possible-issue-with-fetchlimit-and-fetchoffset-in-a-core-data-query + * + * This workaround doesn't work, since we go in batches and eventually + * our pending changes become nonpending: + * http://stackoverflow.com/questions/16422961/nsfetchrequest-fetchoffset-broke-after-setting-nsmanagedobjects-property + */ + if (managedObjectContext.hasChanges && ![self saveBatch:batch + managedObjectContext:managedObjectContext + error:error]) { + ret = nil; + return nextObject; + } + [ret addObjectsFromArray:batch]; + [batch removeAllObjects]; + existingEnumerator = [self enumeratorWithFetchRequest:fetchRequest + managedObjectContext:managedObjectContext + stop:&fetchingComplete + error:error]; + if (!existingEnumerator) { + ret = nil; + return nextObject; + } + return existingEnumerator.nextObject; + }; + + BOOL (^saveBatch)(void) = ^{ + NSUInteger dirty = managedObjectContext.insertedObjects.count + + managedObjectContext.updatedObjects.count + + managedObjectContext.deletedObjects.count; + if (dirty < fetchRequest.fetchBatchSize) { + return YES; + } + BOOL saved = [self saveBatch:batch + managedObjectContext:managedObjectContext + error:error]; + [ret addObjectsFromArray:batch]; + [batch removeAllObjects]; + return saved; + }; + + fetchRequest.fetchOffset = 0; + fetchRequest.fetchLimit = fetchRequest.fetchBatchSize; + fetchRequest.returnsObjectsAsFaults = NO; + fetchRequest.resultType = NSManagedObjectResultType; + + objects = [objects sortedArrayUsingDescriptors:[self objectsSortDescriptors]]; + + id __block existingObject = getNextExistingObject(); + [objects enumerateObjectsUsingBlock:^(id object, NSUInteger idx, BOOL *stop) { + do { + if (!ret) { + *stop = YES; + return; + } + if (!saveBatch()) { + ret = nil; + *stop = YES; + return; + } + id updatedObject; + switch ([self compareObject:object + existingObject:existingObject]) { + case NSOrderedAscending: + // HPLog(@"...create (%lu)", (unsigned long)idx); + updatedObject = [NSEntityDescription insertNewObjectForEntityForName:fetchRequest.entityName + inManagedObjectContext:managedObjectContext]; + ++fetchRequest.fetchOffset; + break; + + case NSOrderedSame: + // HPLog(@"...update (%lu)", (unsigned long)idx); + updatedObject = existingObject; + existingObject = getNextExistingObject(); + break; + + case NSOrderedDescending: + // HPLog(@"...delete (%lu)", (unsigned long)idx); + [self existingObjectNotFound:existingObject]; + existingObject = getNextExistingObject(); + continue; + } + if ([self updateExistingObject:updatedObject + object:object]) { + [batch addObject:updatedObject]; + } + break; + } while (existingObject); + }]; + while (ret && existingObject) { + // HPLog(@"...delete 2: %@", existingObject); + [self existingObjectNotFound:existingObject]; + existingObject = getNextExistingObject(); + } + if (ret && ![self saveBatch:batch + managedObjectContext:managedObjectContext + error:error]) { + return nil; + } + [ret addObjectsFromArray:batch]; + [batch removeAllObjects]; + return ret; +} + +@end + +@implementation HPSynchronizer (Implementation) + +- (NSFetchRequest *)fetchRequestWithObjects:(NSArray *)objects + error:(NSError *__autoreleasing *)error +{ + [self doesNotRecognizeSelector:_cmd]; + return nil; +} + +- (NSArray *)objectsSortDescriptors +{ + [self doesNotRecognizeSelector:_cmd]; + return nil; +} + +- (NSComparisonResult)compareObject:(id)object + existingObject:(id)existingObject +{ + [self doesNotRecognizeSelector:_cmd]; + return NSOrderedSame; +} + +- (id)importObject:(id)object +{ + [self doesNotRecognizeSelector:_cmd]; + return nil; +} + +- (BOOL)updateExistingObject:(id)existingObject + object:(id)object +{ + [self doesNotRecognizeSelector:_cmd]; + return NO; +} + +- (void)existingObjectNotFound:(id)existingObject +{ + [self doesNotRecognizeSelector:_cmd]; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPUserInfo.h b/client/ios/Hackpad/HackpadKit/HPUserInfo.h new file mode 100644 index 0000000..a437364 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPUserInfo.h @@ -0,0 +1,29 @@ +// +// HPUserInfo.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +typedef NS_ENUM(NSUInteger, HPUserInfoStatus) { + HPUnknownUserInfoStatus, + HPInvitedUserInfoStatus, + HPFollowingUserInfoStatus, + HPCreatorUserInfoStatus, + HPConnectedUserInfoStatus +}; + +@interface HPUserInfo : NSObject +@property (nonatomic, readonly) NSDictionary *userInfo; +@property (nonatomic, readonly) NSString *userID; +@property (nonatomic, readonly) NSString *name; +@property (nonatomic, readonly) NSString *userPic; +@property (nonatomic, readonly) NSString *statusText; +@property (nonatomic, readonly) HPUserInfoStatus status; +@property (nonatomic, readonly) NSURL *userPicURL; + +- (id)initWithDictionary:(NSDictionary *)userInfo; +@end diff --git a/client/ios/Hackpad/HackpadKit/HPUserInfo.m b/client/ios/Hackpad/HackpadKit/HPUserInfo.m new file mode 100644 index 0000000..798cecc --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPUserInfo.m @@ -0,0 +1,91 @@ +// +// HPUserInfo.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPUserInfo.h" + +#import + +#import "GTMNSString+HTML.h" + +static NSString *NameKey = @"name"; +static NSString *StatusKey = @"status"; +static NSString *UserIDKey = @"userId"; +static NSString *UserPicKey = @"userPic"; + +@interface HPUserInfo () { + NSMutableSet *_handlers; +} +@end + +@implementation HPUserInfo + +@synthesize status = _status; + +- (id)initWithDictionary:(NSDictionary *)userInfo +{ + self = [super init]; + if (self) { + _userInfo = userInfo; + } + return self; +} + +- (HPUserInfoStatus)status +{ + if (_status == HPUnknownUserInfoStatus) { + NSString *status = self.statusText; + if ([status isEqualToString:@"invited"]) { + _status = HPInvitedUserInfoStatus; + } else if ([status isEqualToString:@"following"]) { + _status = HPFollowingUserInfoStatus; + } else if ([status isEqualToString:@"creator"]) { + _status = HPCreatorUserInfoStatus; + } else if ([status isEqualToString:@"connected"]) { + _status = HPConnectedUserInfoStatus; + } + } + return _status; +} + +- (NSString *)userID +{ + return _userInfo[UserIDKey]; +} + +- (NSString *)userPic +{ + return _userInfo[UserPicKey]; +} + +- (NSURL *)userPicURL +{ + NSString *userPic = self.userPic; + return userPic.length + ? [NSURL URLWithString:userPic + relativeToURL:[userPic hasPrefix:@"/"] ? [NSURL hp_sharedHackpadURL] : nil] + : nil; +} + +- (NSString *)name +{ + return [_userInfo[NameKey] gtm_stringByUnescapingFromHTML]; +} + +- (NSString *)statusText +{ + return _userInfo[StatusKey]; +} + +- (NSString *)description +{ + return [NSString stringWithFormat:@"%@ '%@' %@ %@", + self.userID, self.name, self.statusText, + self.userPic]; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/HPUserInfoCollection.h b/client/ios/Hackpad/HackpadKit/HPUserInfoCollection.h new file mode 100644 index 0000000..e31146e --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPUserInfoCollection.h @@ -0,0 +1,26 @@ +// +// HPUserInfoCollection.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPUserInfo; + +FOUNDATION_EXTERN NSString * const HPUserInfoCollectionDidAddUserInfoNotification; +FOUNDATION_EXTERN NSString * const HPUserInfoCollectionDidRemoveUserInfoNotification; + +FOUNDATION_EXTERN NSString * const HPUserInfoCollectionUserInfoIndexKey; + +@interface HPUserInfoCollection : NSObject +@property (nonatomic, readonly) NSArray *userInfos; +@property (nonatomic, readonly) NSDictionary *userInfosByID; + +- (id)initWithArray:(NSArray *)userInfos; +- (NSUInteger)addUserInfo:(HPUserInfo *)userInfo; +- (NSUInteger)removeUserInfo:(HPUserInfo *)userInfo; +@end + diff --git a/client/ios/Hackpad/HackpadKit/HPUserInfoCollection.m b/client/ios/Hackpad/HackpadKit/HPUserInfoCollection.m new file mode 100644 index 0000000..7460a60 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HPUserInfoCollection.m @@ -0,0 +1,106 @@ +// +// HPUserInfoCollection.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPUserInfoCollection.h" +#import "HPUserInfo.h" + +NSString * const HPUserInfoCollectionDidAddUserInfoNotification = @"HPUserInfoCollectionDidAddUserInfoNotification"; +NSString * const HPUserInfoCollectionDidRemoveUserInfoNotification = @"HPUserInfoCollectionDidRemoveUserInfoNotification"; + +NSString * const HPUserInfoCollectionUserInfoIndexKey = @"HPUserInfoCollectionUserInfoIndexKey"; + +@interface HPUserInfoCollection () { + NSMutableArray *_userInfos; + NSMutableDictionary *_userInfosByID; +} + +@end + +@implementation HPUserInfoCollection + +- (id)initWithArray:(NSArray *)userInfos +{ + self = [super init]; + if (self) { + _userInfos = [userInfos mutableCopy]; + _userInfosByID = [NSMutableDictionary dictionaryWithCapacity:_userInfos.count]; + for (HPUserInfo *userInfo in _userInfos) { + NSParameterAssert([userInfo isKindOfClass:[HPUserInfo class]]); + _userInfosByID[userInfo.userID] = userInfo; + } + [_userInfos sortUsingComparator:[self.class comparator]]; + } + return self; +} + +- (NSUInteger)addUserInfo:(HPUserInfo *)userInfo +{ + NSParameterAssert(!_userInfosByID[userInfo.userID]); + NSUInteger i = [_userInfos indexOfObject:userInfo + inSortedRange:NSMakeRange(0, _userInfos.count) + options:NSBinarySearchingInsertionIndex + usingComparator:[self.class comparator]]; + [_userInfos insertObject:userInfo + atIndex:i]; + _userInfosByID[userInfo.userID] = userInfo; + [[NSNotificationCenter defaultCenter] postNotificationName:HPUserInfoCollectionDidAddUserInfoNotification + object:self + userInfo:@{HPUserInfoCollectionUserInfoIndexKey:[NSNumber numberWithUnsignedInteger:i]}]; + return i; +} + +- (NSUInteger)removeUserInfo:(HPUserInfo *)userInfo +{ + HPUserInfo *oldInfo = _userInfosByID[userInfo.userID]; + NSUInteger ret = NSNotFound; + if (oldInfo) { + ret = [_userInfos indexOfObject:oldInfo + inSortedRange:NSMakeRange(0, _userInfos.count) + options:NSBinarySearchingFirstEqual + usingComparator:[self.class comparator]]; + if (ret != NSNotFound) { + [_userInfos removeObjectAtIndex:ret]; + } + } + [_userInfosByID removeObjectForKey:userInfo.userID]; + if (ret != NSNotFound) { + [[NSNotificationCenter defaultCenter] postNotificationName:HPUserInfoCollectionDidRemoveUserInfoNotification + object:self + userInfo:@{HPUserInfoCollectionUserInfoIndexKey:[NSNumber numberWithUnsignedInteger:ret]}]; + } + return ret; +} + ++ (NSComparator)comparator +{ + return ^(id obj1, id obj2) + { +#define IS_CONNECTED(obj) ([obj status] == HPConnectedUserInfoStatus) +#define HAS_PIC(obj) (!![[obj userPic] length]) + + NSParameterAssert([obj1 isKindOfClass:[HPUserInfo class]]); + NSParameterAssert([obj2 isKindOfClass:[HPUserInfo class]]); + BOOL obj1connected = IS_CONNECTED(obj1); + if (obj1connected != IS_CONNECTED(obj2)) { + return (NSComparisonResult)(obj1connected ? NSOrderedAscending : NSOrderedDescending); + } + + BOOL obj1hasPic = HAS_PIC(obj1); + if (obj1hasPic != HAS_PIC(obj2)) { + return (NSComparisonResult)(obj1hasPic ? NSOrderedAscending : NSOrderedDescending); + } + + NSComparisonResult ret = [[obj1 name] caseInsensitiveCompare:[obj2 name]]; + return (NSComparisonResult)(ret == NSOrderedSame ? [[obj1 userID] compare:[obj2 userID]] : ret); + +#undef IS_CONNECTED +#undef HAS_PIC + }; +} + +@end diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/.xccurrentversion b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/.xccurrentversion new file mode 100644 index 0000000..007dc70 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/.xccurrentversion @@ -0,0 +1,8 @@ + + + + + _XCCurrentVersionName + Hackpad 15.xcdatamodel + + diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 10.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 10.xcdatamodel/contents new file mode 100644 index 0000000..037d666 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 10.xcdatamodel/contents @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 11.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 11.xcdatamodel/contents new file mode 100644 index 0000000..7a711df --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 11.xcdatamodel/contents @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 12.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 12.xcdatamodel/contents new file mode 100644 index 0000000..01f002f --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 12.xcdatamodel/contents @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 13.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 13.xcdatamodel/contents new file mode 100644 index 0000000..522e2b4 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 13.xcdatamodel/contents @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 14.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 14.xcdatamodel/contents new file mode 100644 index 0000000..4fc5895 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 14.xcdatamodel/contents @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 15.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 15.xcdatamodel/contents new file mode 100644 index 0000000..52553c3 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 15.xcdatamodel/contents @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 2.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 2.xcdatamodel/contents new file mode 100644 index 0000000..425d160 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 2.xcdatamodel/contents @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 3.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 3.xcdatamodel/contents new file mode 100644 index 0000000..1bd6a34 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 3.xcdatamodel/contents @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 4.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 4.xcdatamodel/contents new file mode 100644 index 0000000..470e094 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 4.xcdatamodel/contents @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 5.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 5.xcdatamodel/contents new file mode 100644 index 0000000..20302e8 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 5.xcdatamodel/contents @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 6.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 6.xcdatamodel/contents new file mode 100644 index 0000000..609a665 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 6.xcdatamodel/contents @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 7.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 7.xcdatamodel/contents new file mode 100644 index 0000000..eea6f29 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 7.xcdatamodel/contents @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 8.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 8.xcdatamodel/contents new file mode 100644 index 0000000..8f9b116 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 8.xcdatamodel/contents @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 9.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 9.xcdatamodel/contents new file mode 100644 index 0000000..02d59e3 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad 9.xcdatamodel/contents @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad.xcdatamodel/contents b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad.xcdatamodel/contents new file mode 100644 index 0000000..119d9fd --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/Hackpad.xcdatamodeld/Hackpad.xcdatamodel/contents @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/ios/Hackpad/HackpadKit/HackpadKit-Prefix.pch b/client/ios/Hackpad/HackpadKit/HackpadKit-Prefix.pch new file mode 100644 index 0000000..58742a5 --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HackpadKit-Prefix.pch @@ -0,0 +1,11 @@ +// +// Prefix header for all source files of the 'HackpadKit' target in the 'HackpadKit' project +// + +#ifdef __OBJC__ + #import + #import + #import + #import + #import "HPLog.h" +#endif diff --git a/client/ios/Hackpad/HackpadKit/HackpadKit.h b/client/ios/Hackpad/HackpadKit/HackpadKit.h new file mode 100644 index 0000000..e9546ff --- /dev/null +++ b/client/ios/Hackpad/HackpadKit/HackpadKit.h @@ -0,0 +1,30 @@ +// +// HackpadKit.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +#import +#import +#import +#import +#import +#import +#import +#import diff --git a/client/ios/Hackpad/HackpadKitTests/HPAPITests.m b/client/ios/Hackpad/HackpadKitTests/HPAPITests.m new file mode 100644 index 0000000..d1a197a --- /dev/null +++ b/client/ios/Hackpad/HackpadKitTests/HPAPITests.m @@ -0,0 +1,54 @@ +// +// HPAPITests.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +#import + +@interface HPAPITests : SenTestCase + +@end + +@implementation HPAPITests + +- (void)testURLTypeWithURL +{ +#define URLType(s) ([HPAPI URLTypeWithURL:[NSURL URLWithString:(s)]]) + + STAssertEquals(URLType(@"http://example.com"), HPExternalURLType, + @"External URL"); + + STAssertEquals(URLType(@"https://hackpad.com"), HPSpaceURLType, + @"Main site"); + + STAssertEquals(URLType(@"https://subdomain.hackpad.com/"), HPSpaceURLType, + @"subdomain site"); + + STAssertEquals(URLType(@"https://hackpad.com/AWELCOMEPAD"), + HPPadURLType, @"Welcome pad"); + + STAssertEquals(URLType(@"https://hackpad.com/Welcome-to-Hackpad-Quick-Intro-AWELCOMEPAD"), + HPPadURLType, @"Pretty welcome pad"); + + STAssertEquals(URLType(@"https://hackpad.com/ep/search/?q=%23todo"), + HPSearchURLType, @"Search"); + + STAssertEquals(URLType(@"https://hackpad.com/ep/profile/AEry7xCgpHI"), + HPUserProfileURLType, @"user profile"); + + STAssertEquals(URLType(@"https://hackpad.com/ep/group/orP4w9k83eZ"), + HPCollectionURLType, @"Collection home"); + + STAssertEquals(URLType(@"https://hackpad.com/collection/orP4w9k83eZ"), + HPCollectionURLType, @"Collection home"); + + STAssertEquals(URLType(@"https://hackpad.com/api/1.0/options"), + HPUnknownURLType, @"site options"); +} + +@end diff --git a/client/ios/Hackpad/HackpadKitTests/HPImportTests.m b/client/ios/Hackpad/HackpadKitTests/HPImportTests.m new file mode 100644 index 0000000..81f9111 --- /dev/null +++ b/client/ios/Hackpad/HackpadKitTests/HPImportTests.m @@ -0,0 +1,782 @@ +// +// HPImportJSONTests.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import +#import + +static NSString * const PadIDKey = @"localPadId"; +static NSString * const TitleKey = @"title"; +static NSString * const CreatedDateKey = @"createdDate"; +static NSString * const LastEditedDate = @"lastEditedDate"; +static NSString * const CollectionIDKey = @"groupId"; +static NSString * const PadsKey = @"pads"; +static NSString * const SiteNameKey = @"siteName"; +static NSString * const URLKey = @"url"; + +static NSString * const FirstPadID = @"1"; +static NSString * const FirstPadTitle = @"A single pad"; +static NSString * const FirstCollectionID = @"1"; +static NSString * const FirstCollectionTitle = @"A Lone Collection"; +static NSString * const DefaultSpaceName = @"hackpad"; +static NSString * const DefaultSpaceURL = @"https://hackpad.com"; +static NSString * const InvalidPadID = @"invalid pad id"; +static NSString * const TestSpaceName = @"Test Site"; +static NSString * const TestSpaceURL = @"https://test.hackpad.com"; + +static NSUInteger MultipleBatchListSize = 200; +static NSUInteger LargePadListSize = 5000; +static NSUInteger LargeCollectionListSize = 500; +static NSUInteger LargeCollectionListPadListSize = 100; + +@interface HPImportTests : HPCoreDataStackTestCase + +@end + +@implementation HPImportTests + +- (id)singlePadList +{ + return @[@{PadIDKey:FirstPadID, + TitleKey:FirstPadTitle, + CreatedDateKey:@0, + LastEditedDate:@(NSTimeIntervalSince1970)}]; +} + +- (id)padListWithCount:(NSUInteger)count +{ + NSMutableArray *JSON = [NSMutableArray arrayWithCapacity:count]; + for (NSUInteger i = 0; i < count; i++) { + id pad = @{PadIDKey:@(i).stringValue, + TitleKey:[NSString stringWithFormat:@"Pad Title %lu", (unsigned long)i], + CreatedDateKey:@(i), + LastEditedDate:@(i + NSTimeIntervalSince1970)}; + [JSON addObject:pad]; + } + return JSON; +} + +- (id)invalidPadList +{ + return @[@{PadIDKey:InvalidPadID, + TitleKey:FirstPadTitle, + CreatedDateKey:@0, + LastEditedDate:@(NSTimeIntervalSince1970)}]; + +} + +- (id)singleCollectionList +{ + return @[@{CollectionIDKey:FirstCollectionID, + TitleKey:FirstCollectionTitle, + PadsKey:self.singlePadList}]; +} + +- (id)singleSpaceList +{ + return @[@{SiteNameKey:DefaultSpaceName, + URLKey:DefaultSpaceURL}]; +} + +- (id)testSpaceList +{ + return @[@{SiteNameKey:DefaultSpaceName, + URLKey:DefaultSpaceURL}, + @{SiteNameKey:TestSpaceName, + URLKey:TestSpaceURL}]; +} + +- (id)largeCollectionList +{ + NSMutableArray *JSON = [NSMutableArray arrayWithCapacity:LargeCollectionListSize]; + for (NSUInteger i = 0; i < LargeCollectionListSize; i++) { + NSMutableArray *JSONPads = [NSMutableArray arrayWithCapacity:LargeCollectionListPadListSize]; + for (NSUInteger j = 0; j < LargeCollectionListPadListSize; j++) { + NSUInteger padID = i * LargeCollectionListPadListSize + j; + id pad = @{PadIDKey:@(padID).stringValue, + TitleKey:[NSString stringWithFormat:@"Pad Title %lu", (unsigned long)padID], + CreatedDateKey:@(padID), + LastEditedDate:@(padID + NSTimeIntervalSince1970)}; + [JSONPads addObject:pad]; + } + id collection = @{CollectionIDKey:@(i).stringValue, + TitleKey:[NSString stringWithFormat:@"Collection Title %lu", (unsigned long)i], + PadsKey:JSONPads}; + [JSON addObject:collection]; + } + return JSON; +} + +- (void)synchronizePadsWithJSON:(id)JSON + space:(HPSpace *)space + padSynchronizationMode:(HPPadSynchronizerMode)padSynchronizerMode +{ + NSError *error; + HPPadSynchronizer *sync = [[HPPadSynchronizer alloc] initWithSpace:space + padIDKey:PadIDKey + padSynchronizerMode:padSynchronizerMode]; + NSArray *pads = [sync synchronizeObjects:JSON + managedObjectContext:space.managedObjectContext + error:&error]; + STAssertEquals(pads.count, [JSON count], @"Incorrect number of pads"); + STAssertNil(error, @"Import pads failed with error: %@", error); +} + +- (void)synchronizePadsWithJSON:(id)JSON + padSynchronizerMode:(HPPadSynchronizerMode)padSynchronizerMode +{ + [self synchronizePadsWithJSON:JSON + space:self.defaultSpace + padSynchronizationMode:padSynchronizerMode]; +} + +- (void)createOrUpdateCollectionsWithJSON:(id)JSON + inSpace:(HPSpace *)space +{ + NSError *error; + HPCollectionSynchronizer *sync; + sync = [[HPCollectionSynchronizer alloc] initWithSpace:space]; + NSArray *collections = [sync synchronizeObjects:JSON + managedObjectContext:space.managedObjectContext + error:&error]; + STAssertEquals(collections.count, [JSON count], @"Incorrect number of collections"); + STAssertNil(error, @"Import collections failed with error: %@", error); +} + +- (void)createOrUpdateCollectionsWithJSON:(id)JSON +{ + [self createOrUpdateCollectionsWithJSON:JSON + inSpace:self.defaultSpace]; +} + +- (void)createOrUpdateSpacesWithJSON:(id)JSON + inManagedObjectContext:(NSManagedObjectContext *)managedObjectContext +{ + NSError *error; + NSArray *spaces = [[HPSpaceSynchronizer new] synchronizeObjects:JSON + managedObjectContext:managedObjectContext + error:&error]; + STAssertEquals(spaces.count, [JSON count], @"Incorrect number of spaces"); + STAssertNil(error, @"Error creating spaces: %@", error); +} + +- (void)test_0001_SinglePad +{ + [self synchronizePadsWithJSON:self.singlePadList + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + + STAssertEquals(self.defaultSpace.pads.count, 1u, + @"Incorrect number of pads created."); + + HPPad *pad = [self.defaultSpace.pads anyObject]; + STAssertNotNil(pad, @"nil pad in space"); + + STAssertEqualObjects(pad.padID, FirstPadID, @"Pad ID mismatch."); + STAssertEqualObjects(pad.title, FirstPadTitle, @"Pad title mismatch."); +} + +- (void)test_0002_BigPadList +{ + [self synchronizePadsWithJSON:[self padListWithCount:LargePadListSize] + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + STAssertEquals(self.defaultSpace.pads.count, LargePadListSize, + @"Incorrect number of pads created."); +} + +- (void)test_0003_BigPadList10 +{ + id JSON = [self padListWithCount:LargePadListSize]; + for (NSUInteger i = 0; i < 10; i++) { + [self synchronizePadsWithJSON:JSON + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + } +} + +- (void)test_0004_SingleCollection +{ + [self createOrUpdateCollectionsWithJSON:self.singleCollectionList]; + + STAssertEquals(self.defaultSpace.pads.count, 1u, + @"Incorrect number of pads created."); + STAssertEquals(self.defaultSpace.collections.count, 1u, + @"Incorrect number of collections created."); + STAssertEquals([self.defaultSpace.collections.anyObject pads].count, 1u, + @"Incorrect number of pads in collection."); + + HPCollection *collection = self.defaultSpace.collections.anyObject; + STAssertNotNil(collection, @"nil collection in space"); + + STAssertEqualObjects(collection.collectionID, FirstCollectionID, + @"Collection ID mismatch"); + STAssertEqualObjects(collection.title, FirstCollectionTitle, + @"Collection title mismatch"); +} + +- (void)test_0005_BigCollectionList +{ + [self createOrUpdateCollectionsWithJSON:self.largeCollectionList]; + + STAssertEquals(self.defaultSpace.collections.count, LargeCollectionListSize, + @"Incorrect number of collections created"); + STAssertEquals(self.defaultSpace.pads.count, LargeCollectionListSize * LargeCollectionListPadListSize, + @"Incorrect number of pads created"); +} + +- (void)test_0006_BigCollectionList10 +{ + id JSON = self.largeCollectionList; + for (NSUInteger i = 0; i < 10; i++) { + [self createOrUpdateCollectionsWithJSON:JSON]; + } +} + +- (void)test_0007_BigPadListUpdate +{ + id JSON = [self padListWithCount:LargePadListSize]; + [self synchronizePadsWithJSON:JSON + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + [self.coreDataStack.mainContext hp_saveToStore:nil]; + [self.coreDataStack.mainContext.parentContext hp_saveToStore:nil]; + [self resetStack]; + [self synchronizePadsWithJSON:JSON + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; +} + +#if 0 +/* + * Change the default space's name in both contexts, saving in the worker + * context first. + */ +- (void)testSimulataneousEdit +{ + NSError * __block error; + HPSpace * __block space; + + STAssertNotNil(self.defaultSpace, @"Could not create default space"); + [self save]; + + NSManagedObjectContext *moc = [self.coreDataStack newWorkerManagedObjectContextWithName:@"Test Context"]; + [moc performBlockAndWait:^{ + space = [HPSpace spaceWithSubdomain:@"" + inManagedObjectContext:moc + error:&error]; + STAssertNotNil(space, @"Failed to find space: %@", error); + STAssertNil(error, @"Failed to find space: %@", error); + }]; + + self.defaultSpace.name = @"New name from the main thread."; + + [moc performBlockAndWait:^{ + space.name = @"New name from the import thread."; + [self saveWithManagedObjectContext:moc]; + }]; + + [self save]; + STAssertEqualObjects(self.defaultSpace.name, @"New name from the main thread.", + @"Main thread didn't overwrite worker"); +} + +/* + * Change the default space's name in the worker after deleting it in main. + */ +- (void)testEditAfterDelete +{ + NSError * __block error; + HPSpace * __block space; + + STAssertNotNil(self.defaultSpace, @"Could not create default space"); + [self save]; + + NSManagedObjectContext *moc = [self.coreDataStack newWorkerManagedObjectContextWithName:@"Test Context"]; + [moc performBlockAndWait:^{ + space = [HPSpace spaceWithSubdomain:@"" + inManagedObjectContext:moc + error:&error]; + STAssertNotNil(space, @"Failed to find space: %@", error); + STAssertNil(error, @"Failed to find space: %@", error); + // Make sure object is faulted in. + [space willAccessValueForKey:nil]; + }]; + + [self.managedObjectContext deleteObject:self.defaultSpace]; + self.defaultSpace = nil; + + [self save]; + + [moc performBlockAndWait:^{ + space.name = @"New name from the import thread."; + [self saveWithManagedObjectContext:moc]; + STAssertNil(space.managedObjectContext, @"Deleted object has a context."); + }]; +} + +/* + * This simulates loading a pad list after having signed out from that space. + */ +- (void)testSignOutBeforeParsingPadList +{ + NSError * __block error; + HPSpace * __block space; + + STAssertNotNil(self.defaultSpace, @"Could not create default space"); + [self save]; + + NSManagedObjectContext *moc = [self.coreDataStack newWorkerManagedObjectContextWithName:@"Test Context"]; + [moc performBlockAndWait:^{ + space = [HPSpace spaceWithSubdomain:@"" + inManagedObjectContext:moc + error:&error]; + STAssertNotNil(space, @"Failed to find space: %@", error); + STAssertNil(error, @"Failed to find space: %@", error); + }]; + + [self.managedObjectContext deleteObject:self.defaultSpace]; + self.defaultSpace = nil; + + [self save]; + + [moc performBlockAndWait:^{ + STAssertThrowsSpecificNamed([HPPad synchronizePadsWithJSON:self.singlePadList + inSpace:space + padIDKey:PadIDKey + follow:NO + error:&error], + NSException, @"NSObjectInaccessibleException", + @"This space should have been a fault that CoreData could not fulfill."); + }]; +} + +/* + * This simulates loading a pad list after having signed out from that space. + */ +- (void)testSignOutAfterParsingPadList +{ + NSError * __block error; + HPSpace * __block space; + + STAssertNotNil(self.defaultSpace, @"Could not create default space"); + [self save]; + + NSManagedObjectContext *moc = [self.coreDataStack newWorkerManagedObjectContextWithName:@"Test Context"]; + [moc performBlockAndWait:^{ + space = [HPSpace spaceWithSubdomain:@"" + inManagedObjectContext:moc + error:&error]; + STAssertNotNil(space, @"Failed to find space: %@", error); + STAssertNil(error, @"Failed to find space: %@", error); + + HPPad *pad = [NSEntityDescription insertNewObjectForEntityForName:HPPadEntity + inManagedObjectContext:moc]; + pad.padID = FirstPadID; + pad.title = FirstPadTitle; + pad.space = space; + }]; + + [self.managedObjectContext deleteObject:self.defaultSpace]; + self.defaultSpace = nil; + + [self save]; + + [moc performBlockAndWait:^{ + // Merge policy will delete new space + pads. + [self saveWithManagedObjectContext:moc]; + STAssertNil(space.managedObjectContext, @"Space wasn't deleted."); + }]; +} + +/* + * This simulates loading a pad list after having signed out from that space. + */ +- (void)testSignOutBeforeParsingPadListNotFaulted +{ + NSError * __block error; + HPSpace * __block space; + + STAssertNotNil(self.defaultSpace, @"Could not create default space"); + [self save]; + + NSManagedObjectContext *moc = [self.coreDataStack newWorkerManagedObjectContextWithName:@"Test Context"]; + [moc performBlockAndWait:^{ + space = [HPSpace spaceWithSubdomain:@"" + inManagedObjectContext:moc + error:&error]; + STAssertNotNil(space, @"Failed to find space: %@", error); + STAssertNil(error, @"Failed to find space: %@", error); + // Fault-in the space first, this time. + [space willAccessValueForKey:nil]; + }]; + + [self.managedObjectContext deleteObject:self.defaultSpace]; + self.defaultSpace = nil; + + [self save]; + + [moc performBlockAndWait:^{ + [HPPad synchronizePadsWithJSON:self.singlePadList + inSpace:space + padIDKey:PadIDKey + follow:NO + error:&error]; + // Merge policy will delete new space + pads. + [self saveWithManagedObjectContext:moc]; + STAssertNil(space.managedObjectContext, @"Space wasn't deleted."); + }]; +} + +- (void)testDuplicateSpace +{ + STAssertNotNil(self.defaultSpace, @"Could not create default space"); + [self save]; + + HPSpace *space = [NSEntityDescription insertNewObjectForEntityForName:HPSpaceEntity + inManagedObjectContext:self.managedObjectContext]; + space.subdomain = self.defaultSpace.subdomain; + space.name = @"Duplicate"; + + NSError *error = [self saveFailsWithDomain:HPHackpadErrorDomain + code:HPDuplicateEntityError]; + STAssertTrue([HPSpace hp_resolveValidationByDeletingDuplicatesWithError:&error], + @"Could not resolve validation error by deleting duplicates"); + STAssertNil(error, @"Error left over from deleting duplicates: %@", error); + [self save]; +} + +- (void)testDuplicateCollection +{ + [self createOrUpdateCollectionsWithJSON:self.singleCollectionList]; + + HPCollection *orig = self.defaultSpace.collections.anyObject; + HPCollection *collection = (HPCollection *)[NSEntityDescription insertNewObjectForEntityForName:HPCollectionEntity + inManagedObjectContext:self.managedObjectContext]; + collection.title = @"Duplicate"; + collection.collectionID = orig.collectionID; + collection.space = self.defaultSpace; + + NSError *error = [self saveFailsWithDomain:HPHackpadErrorDomain + code:HPDuplicateEntityError]; + STAssertTrue([HPCollection resolveValidationByMovingPadsToStoreCollectionsWithError:&error], + @"Could not resolve validation error by deleting duplicates"); + STAssertNil(error, @"Error left over from deleting duplicates: %@", error); + [self save]; +} + +- (void)testDuplicatePad +{ + [self synchronizePadsWithJSON:self.singlePadList]; + + HPPad *orig = self.defaultSpace.pads.anyObject; + HPPad *pad = (HPPad *)[NSEntityDescription insertNewObjectForEntityForName:HPPadEntity + inManagedObjectContext:self.managedObjectContext]; + + pad.title = @"Duplicate"; + pad.padID = orig.padID; + pad.space = self.defaultSpace; + + NSError *error = [self saveFailsWithDomain:HPHackpadErrorDomain + code:HPDuplicateEntityError]; + STAssertTrue([HPPad hp_resolveValidationByDeletingDuplicatesWithError:&error], + @"Could not resolve validation error by deleting duplicates"); + STAssertNil(error, @"Error left over from deleting duplicates: %@", error); + [self save]; +} + +- (void)testImportDuplicateSpace +{ + NSManagedObjectContext *moc = [self.coreDataStack newWorkerManagedObjectContextWithName:@"Test Context"]; + [moc performBlockAndWait:^{ + [self createOrUpdateSpacesWithJSON:self.testSpaceList + inManagedObjectContext:moc]; + }]; + + [self createOrUpdateSpacesWithJSON:self.testSpaceList + inManagedObjectContext:self.managedObjectContext]; + [self save]; + + [moc performBlockAndWait:^{ + NSError *error = [self saveFailsWithManagedObjectContext:moc + domain:NSCocoaErrorDomain + code:NSValidationMultipleErrorsError]; + STAssertTrue([HPSpace hp_resolveValidationByDeletingDuplicatesWithError:&error], + @"Could not remove duplicates."); + STAssertNil(error, @"Could not resolve all errors: %@", error); + [self saveWithManagedObjectContext:moc]; + }]; +} + +- (void)testImportDuplicateCollection +{ + STAssertNotNil(self.defaultSpace, @"Could not create default space"); + [self save]; + + NSManagedObjectContext *moc = [self.coreDataStack newWorkerManagedObjectContextWithName:@"Test Context"]; + [moc performBlockAndWait:^{ + NSError *error; + HPSpace *space = [HPSpace spaceWithSubdomain:@"" + inManagedObjectContext:moc + error:&error]; + STAssertNotNil(space, @"Failed to find space: %@", error); + STAssertNil(error, @"Failed to find space: %@", error); + HPCollection *collection = [NSEntityDescription insertNewObjectForEntityForName:HPCollectionEntity + inManagedObjectContext:moc]; + collection.collectionID = FirstCollectionID; + collection.title = FirstCollectionTitle; + collection.space = space; + }]; + + HPCollection *collection = [NSEntityDescription insertNewObjectForEntityForName:HPCollectionEntity + inManagedObjectContext:self.managedObjectContext]; + collection.collectionID = FirstCollectionID; + collection.title = FirstCollectionTitle; + collection.space = self.defaultSpace; + [self save]; + + [moc performBlockAndWait:^{ + NSError *error = [self saveFailsWithManagedObjectContext:moc + domain:HPHackpadErrorDomain + code:HPDuplicateEntityError]; + if (error) { + // These NSParamaterAssert(*error), but the above will fail if this returns nil. + STAssertTrue([HPCollection resolveValidationByMovingPadsToStoreCollectionsWithError:&error], + @"Could not remove duplicate collections"); + STAssertNil(error, @"Could not resolve validation errors: %@", error); + } + [self saveWithManagedObjectContext:moc]; + }]; +} + +- (void)testImportDuplicatePad +{ + STAssertNotNil(self.defaultSpace, @"Could not create default space"); + [self save]; + + HPSpace * __block space; + NSManagedObjectContext *moc = [self.coreDataStack newWorkerManagedObjectContextWithName:@"Test Context"]; + [moc performBlockAndWait:^{ + NSError *error; + space = [HPSpace spaceWithSubdomain:@"" + inManagedObjectContext:moc + error:&error]; + STAssertNotNil(space, @"Failed to find space: %@", error); + STAssertNil(error, @"Failed to find space: %@", error); + HPPad *pad = [NSEntityDescription insertNewObjectForEntityForName:HPPadEntity + inManagedObjectContext:moc]; + pad.padID = FirstPadID; + pad.title = FirstPadTitle; + pad.space = space; + }]; + + HPPad *pad = [NSEntityDescription insertNewObjectForEntityForName:HPPadEntity + inManagedObjectContext:self.managedObjectContext]; + pad.padID = FirstPadID; + pad.title = FirstPadTitle; + pad.space = self.defaultSpace; + [self save]; + + [moc performBlockAndWait:^{ + NSError *saveError = [self saveFailsWithManagedObjectContext:moc + domain:HPHackpadErrorDomain + code:HPDuplicateEntityError]; + HPPad *pad = saveError.userInfo[NSValidationObjectErrorKey]; + NSError *error; + HPPad *newPad = [HPPad padWithID:pad.padID + inSpace:space + error:&error]; + STAssertNotNil(newPad, @"Could not find conflicting pad"); + STAssertNil(error, @"Error finding conflicting pad: %@", error); + STAssertTrue([HPPad hp_resolveValidationByDeletingDuplicatesWithError:&saveError], + @"Could not remove duplicates."); + STAssertNil(saveError, @"Could not resolve all errors: %@", saveError); + [self saveWithManagedObjectContext:moc]; + }]; +} + +- (void)testSimultaneousPadCreate +{ + STAssertNotNil(self.defaultSpace, @"Could not create default space"); + [self save]; + + HPSpace * __block space; + NSManagedObjectContext *moc = [self.coreDataStack newWorkerManagedObjectContextWithName:@"Test Context"]; + [moc performBlockAndWait:^{ + NSError *error; + moc.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy; + space = [HPSpace spaceWithSubdomain:@"" + inManagedObjectContext:moc + error:&error]; + STAssertNotNil(space, @"Failed to find space: %@", error); + STAssertNil(error, @"Failed to find space: %@", error); + STAssertEquals(space.pads.count, 0u, @"No pads yet"); + }]; + + NSError *error; + HPPad *pad = [HPPad padWithID:@"0" + inSpace:self.defaultSpace + error:&error]; + STAssertNotNil(pad, @"Could not create new pad"); + STAssertNil(error, @"Error creating pad: %@", error); + STAssertEquals(self.defaultSpace.pads.count, 1u, + @"Default space should see its pad"); + + [moc performBlockAndWait:^{ + NSError *error; + HPPad *pad = [HPPad padWithID:@"2" + inSpace:space + error:&error]; + STAssertNotNil(pad, @"Could not create new pad"); + STAssertNil(error, @"Error creating pad: %@", error); + STAssertEquals(space.pads.count, 1u, + @"Space shouldn't see the other pad (yet)"); + }]; + + STAssertEquals(self.defaultSpace.pads.count, 1u, + @"Default space shouldn't see the other pad (yet)"); + [self.managedObjectContext refreshObject:self.defaultSpace + mergeChanges:YES]; + STAssertEquals(self.defaultSpace.pads.count, 2u, @"Didn't refresh space"); +} + +- (void)testRemovePadFromCollection +{ + STAssertNotNil(self.defaultSpace, @"Could not create default space"); + [self save]; + + [self createOrUpdateCollectionsWithJSON:self.singleCollectionList]; + [self save]; + + STAssertEquals(self.defaultSpace.pads.count, 1u, + @"Incorrect number of pads created."); + STAssertEquals(self.defaultSpace.collections.count, 1u, + @"Incorrect number of collections created."); + STAssertEquals([self.defaultSpace.collections.anyObject pads].count, 1u, + @"Incorrect number of pads in collection."); + + [self createOrUpdateCollectionsWithJSON:@[@{CollectionIDKey:FirstCollectionID, + TitleKey:FirstCollectionTitle, + PadsKey:@[]}]]; + [self save]; + + NSError * __autoreleasing error; + STAssertTrue([HPSpace removeNonfollowedPadsInManagedObjectContext:self.managedObjectContext + error:&error], + @"Could not prune pads: %@", error); + STAssertEquals(self.defaultSpace.pads.count, 0u, + @"Incorrect number of pads created."); + STAssertEquals(self.defaultSpace.collections.count, 1u, + @"Incorrect number of collections created."); + STAssertEquals([self.defaultSpace.collections.anyObject pads].count, 0u, + @"Incorrect number of pads in collection."); +} +#endif + +- (void)testInvalidPadID +{ + NSError *error; + HPPadSynchronizer *sync = [[HPPadSynchronizer alloc] initWithSpace:self.defaultSpace + padIDKey:PadIDKey + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + NSArray *pads = [sync synchronizeObjects:[self invalidPadList] + managedObjectContext:self.managedObjectContext + error:&error]; + STAssertEquals(pads.count, 0u, @"Incorrect number of pads"); + STAssertNil(error, @"Import pads failed with error: %@", error); +} + +- (void)testUpdatedPad +{ + static NSString * const UpdatedTitle = @"A New Title"; + NSArray *pads = self.singlePadList; + + [self synchronizePadsWithJSON:pads + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + + NSMutableDictionary *updatedPad = [pads[0] mutableCopy]; + updatedPad[TitleKey] = UpdatedTitle; + + [self synchronizePadsWithJSON:@[updatedPad] + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + + STAssertEquals(self.defaultSpace.pads.count, 1u, + @"Incorrect number of pads created."); + STAssertEqualObjects([self.defaultSpace.pads.anyObject title], + UpdatedTitle, @"Pad title mismatch."); +} + +- (void)testUnfollowPad +{ + [self synchronizePadsWithJSON:self.singlePadList + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + + STAssertEquals(self.defaultSpace.pads.count, 1u, + @"Incorrect number of pads created."); + + [self synchronizePadsWithJSON:@[] + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + + STAssertEquals(self.defaultSpace.pads.count, 1u, + @"Incorrect number of pads created."); + STAssertFalse([self.defaultSpace.pads.anyObject followed], + @"Pad is still followed."); +} + +- (void)testRefollowPad +{ + [self synchronizePadsWithJSON:self.singlePadList + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + [self synchronizePadsWithJSON:@[] + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + [self synchronizePadsWithJSON:self.singlePadList + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + + STAssertEquals(self.defaultSpace.pads.count, 1u, + @"Incorrect number of pads created."); + STAssertTrue([self.defaultSpace.pads.anyObject followed], + @"Pad is not followed."); +} + +- (void)testRefresh +{ + [self synchronizePadsWithJSON:self.singlePadList + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + [self synchronizePadsWithJSON:self.singlePadList + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + + STAssertEquals(self.defaultSpace.pads.count, 1u, + @"Incorrect number of pads created."); + STAssertTrue([self.defaultSpace.pads.anyObject followed], + @"Pad is not followed."); +} + +- (void)testRefreshMultipleBatches +{ + id JSON = [self padListWithCount:MultipleBatchListSize]; + [self synchronizePadsWithJSON:JSON + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + STAssertEquals(self.defaultSpace.pads.count, MultipleBatchListSize, + @"Incorrect number of pads created."); + [self synchronizePadsWithJSON:JSON + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + STAssertEquals(self.defaultSpace.pads.count, MultipleBatchListSize, + @"Incorrect number of pads created."); +} + +- (void)testReimportWithUnfollowedPads +{ + HPPad *pad = [NSEntityDescription insertNewObjectForEntityForName:HPPadEntity + inManagedObjectContext:self.managedObjectContext]; + pad.space = self.defaultSpace; + pad.padID = @"_unfollowedPad"; + pad.title = @"Unfollowed"; + [self synchronizePadsWithJSON:[self padListWithCount:MultipleBatchListSize] + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + STAssertEquals(self.defaultSpace.pads.count, MultipleBatchListSize + 1, @"Invalid import"); + [self synchronizePadsWithJSON:[self padListWithCount:MultipleBatchListSize] + padSynchronizerMode:HPFollowedPadsPadSynchronizerMode]; + STAssertEquals(self.defaultSpace.pads.count, MultipleBatchListSize + 1, @"Invalid import"); +} + +@end diff --git a/client/ios/Hackpad/HackpadKitTests/HPMigrationTests.m b/client/ios/Hackpad/HackpadKitTests/HPMigrationTests.m new file mode 100644 index 0000000..42213bf --- /dev/null +++ b/client/ios/Hackpad/HackpadKitTests/HPMigrationTests.m @@ -0,0 +1,30 @@ +// +// HPMigrationTests.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import + +#define MIGRATION_TEST2(Version, Impl) \ +@interface HP##Version##MigrationTests : HPMigrationTestCase \ +@end \ +@implementation HP##Version##MigrationTests \ +- (void)setUp \ +{ \ + [super setUpWithStoreURL:[self URLForResource:@#Version \ + withExtension:@"sqlite"]]; \ +}\ +Impl \ +@end +#define MIGRATION_TEST(Version) MIGRATION_TEST2(Version, HP_MIGRATION_TEST_CASE_IMPL) + +MIGRATION_TEST(Hackpad9) +MIGRATION_TEST(Hackpad10) +MIGRATION_TEST(Hackpad11) +MIGRATION_TEST(Hackpad12) +MIGRATION_TEST(Hackpad13) +MIGRATION_TEST(Hackpad14) +MIGRATION_TEST(Hackpad15) diff --git a/client/ios/Hackpad/HackpadKitTests/HPPadScopeTests.m b/client/ios/Hackpad/HackpadKitTests/HPPadScopeTests.m new file mode 100644 index 0000000..c696c79 --- /dev/null +++ b/client/ios/Hackpad/HackpadKitTests/HPPadScopeTests.m @@ -0,0 +1,187 @@ +// +// HPPadScopeTests.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +#import + +@interface HPPadScopeTests : HPCoreDataStackTestCase +@property (nonatomic, strong) HPPadScope *padScope; +@end + +@implementation HPPadScopeTests + +- (void)setUp +{ + [super setUp]; + self.padScope = [[HPPadScope alloc] initWithCoreDataStack:self.coreDataStack]; +} + +- (void)tearDown +{ + self.padScope = nil; + [super tearDown]; +} + +- (void)expectEmptyStore +{ + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + STAssertNil(self.padScope.space, @"Unexpected space selected"); +} + +- (void)expectDefaultSpace +{ + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + STAssertEqualObjects(self.padScope.space.objectID, + self.defaultSpace.objectID, + @"Unexpected space selected"); +} + +- (void)test_0001_EmptyStore +{ + [self expectEmptyStore]; +} + +- (void)test_0002_DefaultSpace +{ + [self defaultSpace]; + [self save]; + + self.padScope.space = self.defaultSpace; + [self save]; + [self expectDefaultSpace]; +} + +- (void)test_0004_RemoveSpace +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + self.padScope.space = self.defaultSpace; + + [self.managedObjectContext deleteObject:self.defaultSpace]; + + [self save]; + [self expectEmptyStore]; +} + +- (void)test_0005_ReplaceSpace +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + self.padScope.space = self.defaultSpace; + + [self.managedObjectContext deleteObject:self.defaultSpace]; + self.defaultSpace = nil; + [self defaultSpace]; + + [self save]; + [self expectDefaultSpace]; +} + +- (void)test_0006_RemoveCollection +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + self.padScope.space = self.defaultSpace; + + HPCollection *collection = [NSEntityDescription insertNewObjectForEntityForName:HPCollectionEntity + inManagedObjectContext:self.managedObjectContext]; + collection.title = @"Test Collection"; + collection.followed = YES; + collection.collectionID = @"1"; + [self.defaultSpace addCollectionsObject:collection]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + self.padScope.collection = collection; + [self.managedObjectContext deleteObject:collection]; + + [self save]; + [self expectDefaultSpace]; +} + +- (void)test_0007_RemoveSpaceWithCollection +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + self.padScope.space = self.defaultSpace; + + HPCollection *collection = [NSEntityDescription insertNewObjectForEntityForName:HPCollectionEntity + inManagedObjectContext:self.managedObjectContext]; + collection.title = @"Test Collection"; + collection.followed = YES; + collection.collectionID = @"1"; + [self.defaultSpace addCollectionsObject:collection]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + self.padScope.collection = collection; + [self.managedObjectContext deleteObject:self.defaultSpace]; + [self save]; + [self expectEmptyStore]; +} + +- (void)test_0008_ReplaceSpaceWithCollection +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + self.padScope.space = self.defaultSpace; + + HPCollection *collection = [NSEntityDescription insertNewObjectForEntityForName:HPCollectionEntity + inManagedObjectContext:self.managedObjectContext]; + collection.title = @"Test Collection"; + collection.followed = YES; + collection.collectionID = @"1"; + [self.defaultSpace addCollectionsObject:collection]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + self.padScope.collection = collection; + [self.managedObjectContext deleteObject:self.defaultSpace]; + self.defaultSpace = nil; + [self defaultSpace]; + + [self save]; + [self expectDefaultSpace]; +} + +- (void)test_0009_RemoveSecondSpace +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + self.padScope.space = self.defaultSpace; + + HPSpace *space = [NSEntityDescription insertNewObjectForEntityForName:HPSpaceEntity + inManagedObjectContext:self.managedObjectContext]; + space.name = @"Test"; + space.hidden = NO; + space.subdomain = @"test"; + + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + self.padScope.space = space; + [self.managedObjectContext deleteObject:space]; + + [self save]; + [self expectDefaultSpace]; +} + +@end diff --git a/client/ios/Hackpad/HackpadKitTests/HPPadTests.m b/client/ios/Hackpad/HackpadKitTests/HPPadTests.m new file mode 100644 index 0000000..47dd545 --- /dev/null +++ b/client/ios/Hackpad/HackpadKitTests/HPPadTests.m @@ -0,0 +1,141 @@ +// +// HPPadTests.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import +#import + +static NSString * const WelcomePadID = @"AWELCOMEPAD"; +static NSString * const WelcomePrettyPath = @"Welcome-to-Hackpad-Quick-Intro-AWELCOMEPAD"; +static NSString * const MainDomain = @""; +static NSString * const ProSubdomain = @"test"; +static NSString * const InvalidPadPath = @"/invalid/pad/path"; +static NSString * const InvalidURL = @"http://hackpad.invalid"; + +@interface HPPadTests : HPCoreDataStackTestCase + +@end + +@implementation HPPadTests + +- (void)testPadIDWithBasicURL +{ + NSURL *URL = [NSURL URLWithString:WelcomePadID + relativeToURL:[NSURL hp_sharedHackpadURL]]; + STAssertEqualObjects([HPPad padIDWithURL:URL], WelcomePadID, + @"Incorrect pad ID"); +} + +- (void)testPadIDWithPrettyURL +{ + NSURL *URL = [NSURL URLWithString:WelcomePrettyPath + relativeToURL:[NSURL hp_sharedHackpadURL]]; + STAssertEqualObjects([HPPad padIDWithURL:URL], WelcomePadID, + @"Incorrect pad ID"); +} + +- (void)testPadIDWithAPIURL +{ + NSURL *URL = [NSURL URLWithString:InvalidPadPath + relativeToURL:[NSURL hp_sharedHackpadURL]]; + STAssertNil([HPPad padIDWithURL:URL], + @"An API path should not return a valid pad ID."); +} + +- (void)testPadIDWithInvalidURL +{ + NSURL *URL = [NSURL URLWithString:InvalidURL]; + STAssertNil([HPPad padIDWithURL:URL], + @"An invalid URL should not return a valid pad"); +} + +- (void)testPadWithBasicMainURL +{ + NSError * __autoreleasing error; + NSURL *URL = [NSURL URLWithString:WelcomePadID + relativeToURL:[NSURL hp_sharedHackpadURL]]; + HPPad *pad = [HPPad padWithURL:URL + managedObjectContext:self.managedObjectContext + error:&error]; + STAssertNotNil(pad, @"Could not create pad"); + STAssertEqualObjects(pad.padID, WelcomePadID, @"Mismatched pad ID"); + STAssertEqualObjects(pad.space.URL.hp_hackpadSubdomain, MainDomain, @"Incorrect space subdomain"); +} + +- (void)testPadWithBasicProURL +{ + NSError * __autoreleasing error; + NSURL *URL = [NSURL URLWithString:WelcomePadID + relativeToURL:[NSURL hp_URLForSubdomain:ProSubdomain + relativeToURL:[NSURL hp_sharedHackpadURL]]]; + HPPad *pad = [HPPad padWithURL:URL + managedObjectContext:self.managedObjectContext + error:&error]; + STAssertNotNil(pad, @"Could not create pad"); + STAssertEqualObjects(pad.padID, WelcomePadID, @"Mismatched pad ID"); + STAssertEqualObjects(pad.space.URL.hp_hackpadSubdomain, ProSubdomain, @"Incorrect space subdomain"); +} + +- (void)testPadWithPrettyMainURL +{ + NSError * __autoreleasing error; + NSURL *URL = [NSURL URLWithString:WelcomePrettyPath + relativeToURL:[NSURL hp_sharedHackpadURL]]; + HPPad *pad = [HPPad padWithURL:URL + managedObjectContext:self.managedObjectContext + error:&error]; + STAssertNotNil(pad, @"Could not create pad"); + STAssertEqualObjects(pad.padID, WelcomePadID, @"Mismatched pad ID"); + STAssertEqualObjects(pad.space.URL.hp_hackpadSubdomain, MainDomain, @"Incorrect space subdomain"); +} + +- (void)testPadWithPrettyProURL +{ + NSError * __autoreleasing error; + NSURL *URL = [NSURL URLWithString:WelcomePrettyPath + relativeToURL:[NSURL hp_URLForSubdomain:ProSubdomain + relativeToURL:[NSURL hp_sharedHackpadURL]]]; + HPPad *pad = [HPPad padWithURL:URL + managedObjectContext:self.managedObjectContext + error:&error]; + STAssertNotNil(pad, @"Could not create pad"); + STAssertEqualObjects(pad.padID, WelcomePadID, @"Mismatched pad ID"); + STAssertEqualObjects(pad.space.URL.hp_hackpadSubdomain, ProSubdomain, @"Incorrect space subdomain"); +} + +- (void)testPadWithAPIURL +{ + NSError * __autoreleasing error; + NSURL *URL = [NSURL URLWithString:InvalidPadPath + relativeToURL:[NSURL hp_sharedHackpadURL]]; + HPPad *pad = [HPPad padWithURL:URL + managedObjectContext:self.managedObjectContext + error:&error]; + STAssertNil(pad, @"This URL should not have created a pad."); + STAssertNotNil(error, @"An error should have been returned."); + STAssertEqualObjects(error.domain, HPHackpadErrorDomain, + @"Unexpected error domain"); + STAssertEquals(error.code, HPInvalidURLError, @"Unexpected error code"); + +} + +- (void)testPadWithExternalURL +{ + NSError * __autoreleasing error; + NSURL *URL = [NSURL URLWithString:InvalidURL]; + HPPad *pad = [HPPad padWithURL:URL + managedObjectContext:self.managedObjectContext + error:&error]; + STAssertNil(pad, @"This URL should not have created a pad."); + STAssertNotNil(error, @"An error should have been returned."); + STAssertEqualObjects(error.domain, HPHackpadErrorDomain, + @"Unexpected error domain"); + STAssertEquals(error.code, HPInvalidURLError, @"Unexpected error code"); +} + +@end diff --git a/client/ios/Hackpad/HackpadKitTests/HPSearchSnippetsTests.m b/client/ios/Hackpad/HackpadKitTests/HPSearchSnippetsTests.m new file mode 100644 index 0000000..ce9eede --- /dev/null +++ b/client/ios/Hackpad/HackpadKitTests/HPSearchSnippetsTests.m @@ -0,0 +1,205 @@ +// +// HPSearchSnippetsTests.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "NSAttributedString+HackpadAdditions.h" + +#import + +#import + +static NSUInteger const MaxLengthOfKeywordRange = 40; + +@interface HPSearchSnippetsTests : SenTestCase { + NSDictionary *_regularAttributes; + NSDictionary *_highlightingAttributes; +} + +@end + +@implementation HPSearchSnippetsTests + +- (void)setUp +{ + [super setUp]; + _regularAttributes = @{NSUnderlineStyleAttributeName:@1}; + _highlightingAttributes = @{NSUnderlineStyleAttributeName:@2}; +} + +- (void)testOneKeyword +{ + NSString *string = @"hey there dog hey"; + + NSAttributedString *searchSnippets = [NSAttributedString hp_initWithString:string + attributes:_regularAttributes + highlightingKeywords:@"hey" + highlightingAttributes:_highlightingAttributes + maxLengthOfKeywordRange:MaxLengthOfKeywordRange]; + + NSMutableAttributedString *expectedSearchSnippets = [[NSMutableAttributedString alloc] initWithString:string + attributes:_regularAttributes]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(0, 3)]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(14, 3)]; + + STAssertEqualObjects(searchSnippets, expectedSearchSnippets, + @"Failed to find search snippets with one keyword"); +} + +- (void)testFewKeywords +{ + NSString *string = @"hey there dog hey"; + + NSAttributedString *searchSnippets = [NSAttributedString hp_initWithString:string + attributes:_regularAttributes + highlightingKeywords:@"hey-dog" + highlightingAttributes:_highlightingAttributes + maxLengthOfKeywordRange:MaxLengthOfKeywordRange]; + + NSMutableAttributedString *expectedSearchSnippets = [[NSMutableAttributedString alloc] initWithString:string + attributes:_regularAttributes]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(0, 3)]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(14, 3)]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(10, 3)]; + + STAssertEqualObjects(searchSnippets, expectedSearchSnippets, + @"Failed to find search snippets with few keywords"); +} + +- (void)testFewKeywordsAndFewLines +{ + NSString *string = @"hey there dog hey \n hey mr Smith"; + + NSAttributedString *searchSnippets = [NSAttributedString hp_initWithString:string + attributes:_regularAttributes + highlightingKeywords:@"hey dog" + highlightingAttributes:_highlightingAttributes + maxLengthOfKeywordRange:MaxLengthOfKeywordRange]; + + NSMutableAttributedString *expectedSearchSnippets = [[NSMutableAttributedString alloc] initWithString:@"hey there dog hey hey mr Smith" + attributes:_regularAttributes]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(0, 3)]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(14, 3)]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(10, 3)]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(18, 3)]; + + STAssertEqualObjects(searchSnippets, expectedSearchSnippets, + @"Failed to find search snippets in few lines with few keywords"); +} + +- (void)testOneKeywordAtTheEndOfLongLine +{ + NSString *string = @"There is no one who loves pain itself, who seeks after it and wants" + "to have it, simply because it is pain...Lorem ipsum dolor sit amet, consectetuer adipiscing " + "elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. " + "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut " + "aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit " + "esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et " + "iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait " + "nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming " + "id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis " + "in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod " + "ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium " + "lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit " + "litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui " + "nunc nobis videntur parum clari, fiant sollemnes in futurum. Heytheredog"; + + NSAttributedString *searchSnippets = [NSAttributedString hp_initWithString:string + attributes:_regularAttributes + highlightingKeywords:@"dog" + highlightingAttributes:_highlightingAttributes + maxLengthOfKeywordRange:MaxLengthOfKeywordRange]; + + NSMutableAttributedString *expectedSearchSnippets = [[NSMutableAttributedString alloc] initWithString:@"n futurum. Heytheredog" + attributes:_regularAttributes]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(19, 3)]; + + STAssertEqualObjects(searchSnippets, expectedSearchSnippets, + @"Failed to find search snippets in the one long line with the one keyword"); + //STAssertEquals(searchSnippets.length, MaxLengthOfKeywordRange, + // @"Snippet length is incorrect"); +} + +- (void)testFewKeywordsWithLongGapInBetween +{ + NSString *string = @"There is no one who loves pain itself"; + + NSAttributedString *searchSnippets = [NSAttributedString hp_initWithString:string + attributes:_regularAttributes + highlightingKeywords:@"one, who" + highlightingAttributes:_highlightingAttributes + maxLengthOfKeywordRange:MaxLengthOfKeywordRange]; + + NSMutableAttributedString *expectedSearchSnippets = [[NSMutableAttributedString alloc] initWithString:@"There is no one who loves pain itself" + attributes:_regularAttributes]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(12, 3)]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(16, 3)]; + + STAssertEqualObjects(searchSnippets, expectedSearchSnippets, + @"Failed to find search snippets in the long line with the gap in between"); + //STAssertEquals(searchSnippets.length, MaxLengthOfKeywordRange, + // @"Snippet length is incorrect"); +} + +- (void)testNoResultsFoundInLongLineWithoutKeywords +{ + NSString *string = @"There is no one who loves pain itself, who seeks after it and wants" + "to have it, simply because it is pain...Lorem ipsum dolor sit amet, consectetuer adipiscing " + "elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. " + "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut " + "aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit " + "esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et " + "iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait " + "nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming " + "id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis " + "in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod " + "ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium " + "lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit " + "litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui " + "nunc nobis videntur parum clari, fiant sollemnes in futurum."; + + NSAttributedString *searchSnippets = [NSAttributedString hp_initWithString:string + attributes:_regularAttributes + highlightingKeywords:@"hey dog" + highlightingAttributes:_highlightingAttributes + maxLengthOfKeywordRange:MaxLengthOfKeywordRange]; + + STAssertNil(searchSnippets, + @"Found search snippets in the long line without keywords"); +} + +- (void)testFewKeywordsAreIntersectedInOneWord +{ + NSString *string = @"hey alonsky mr Smith"; + + NSAttributedString *searchSnippets = [NSAttributedString hp_initWithString:string + attributes:_regularAttributes + highlightingKeywords:@"lonsky alo" + highlightingAttributes:_highlightingAttributes + maxLengthOfKeywordRange:MaxLengthOfKeywordRange]; + + NSMutableAttributedString *expectedSearchSnippets = [[NSMutableAttributedString alloc] initWithString:string + attributes:_regularAttributes]; + [expectedSearchSnippets setAttributes:_highlightingAttributes + range:NSMakeRange(4, 7)]; + + STAssertEqualObjects(searchSnippets, expectedSearchSnippets, + @"Failed to find search snippets when two keywords are intersected in one word"); +} + +@end diff --git a/client/ios/Hackpad/HackpadKitTests/Hackpad10.sqlite b/client/ios/Hackpad/HackpadKitTests/Hackpad10.sqlite new file mode 100644 index 0000000..123719b Binary files /dev/null and b/client/ios/Hackpad/HackpadKitTests/Hackpad10.sqlite differ diff --git a/client/ios/Hackpad/HackpadKitTests/Hackpad11.sqlite b/client/ios/Hackpad/HackpadKitTests/Hackpad11.sqlite new file mode 100644 index 0000000..3c43d01 Binary files /dev/null and b/client/ios/Hackpad/HackpadKitTests/Hackpad11.sqlite differ diff --git a/client/ios/Hackpad/HackpadKitTests/Hackpad12.sqlite b/client/ios/Hackpad/HackpadKitTests/Hackpad12.sqlite new file mode 100644 index 0000000..9b53090 Binary files /dev/null and b/client/ios/Hackpad/HackpadKitTests/Hackpad12.sqlite differ diff --git a/client/ios/Hackpad/HackpadKitTests/Hackpad13.sqlite b/client/ios/Hackpad/HackpadKitTests/Hackpad13.sqlite new file mode 100644 index 0000000..8ff4e54 Binary files /dev/null and b/client/ios/Hackpad/HackpadKitTests/Hackpad13.sqlite differ diff --git a/client/ios/Hackpad/HackpadKitTests/Hackpad14.sqlite b/client/ios/Hackpad/HackpadKitTests/Hackpad14.sqlite new file mode 100644 index 0000000..ec8d4bf Binary files /dev/null and b/client/ios/Hackpad/HackpadKitTests/Hackpad14.sqlite differ diff --git a/client/ios/Hackpad/HackpadKitTests/Hackpad15.sqlite b/client/ios/Hackpad/HackpadKitTests/Hackpad15.sqlite new file mode 100644 index 0000000..2701f91 Binary files /dev/null and b/client/ios/Hackpad/HackpadKitTests/Hackpad15.sqlite differ diff --git a/client/ios/Hackpad/HackpadKitTests/Hackpad9.sqlite b/client/ios/Hackpad/HackpadKitTests/Hackpad9.sqlite new file mode 100644 index 0000000..098ca2b Binary files /dev/null and b/client/ios/Hackpad/HackpadKitTests/Hackpad9.sqlite differ diff --git a/client/ios/Hackpad/HackpadKitTests/HackpadKitTests-Info.plist b/client/ios/Hackpad/HackpadKitTests/HackpadKitTests-Info.plist new file mode 100644 index 0000000..96e9937 --- /dev/null +++ b/client/ios/Hackpad/HackpadKitTests/HackpadKitTests-Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.hackpad.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/client/ios/Hackpad/HackpadKitTests/NSURLRequestHackpadAdditionsTests.m b/client/ios/Hackpad/HackpadKitTests/NSURLRequestHackpadAdditionsTests.m new file mode 100644 index 0000000..f11ebdc --- /dev/null +++ b/client/ios/Hackpad/HackpadKitTests/NSURLRequestHackpadAdditionsTests.m @@ -0,0 +1,36 @@ +// +// NSURLRequestHackpadAdditionsTests.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +#import + +static NSString * const BaseURL = @"https://hackpad.com"; + +static NSString * const PathWithEscapeSpace = @"path%20with%20escaped%20space"; + +@interface NSURLRequestHackpadAdditionsTests : SenTestCase + +@end + +@implementation NSURLRequestHackpadAdditionsTests + +- (void)testURLWithSpaceInPath +{ + NSURL *URL = [NSURL URLWithString:PathWithEscapeSpace + relativeToURL:[NSURL URLWithString:BaseURL]]; + NSURLRequest *request = [NSURLRequest hp_requestWithURL:URL + HTTPMethod:@"GET" + parameters:@{@"key":@"value"}]; + STAssertNotNil(request.URL, @"URL should not be nil"); + STAssertEqualObjects(request.URL.absoluteString, + @"https://hackpad.com/path%20with%20escaped%20space?key=value", + @"Unexpected URL value"); +} + +@end diff --git a/client/ios/Hackpad/HackpadKitTests/en.lproj/InfoPlist.strings b/client/ios/Hackpad/HackpadKitTests/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..477b28f --- /dev/null +++ b/client/ios/Hackpad/HackpadKitTests/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/client/ios/Hackpad/HackpadTestingKit/HPCoreDataStackTestCase.h b/client/ios/Hackpad/HackpadTestingKit/HPCoreDataStackTestCase.h new file mode 100644 index 0000000..e30bcde --- /dev/null +++ b/client/ios/Hackpad/HackpadTestingKit/HPCoreDataStackTestCase.h @@ -0,0 +1,23 @@ +// +// HPCoreDataStackTestCase.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import + +@class HPCoreDataStack; +@class HPSpace; +@class NSManagedObjectContext; + +@interface HPCoreDataStackTestCase : HPMockTestCase +@property (nonatomic, strong) HPCoreDataStack *coreDataStack; +@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext; +@property (nonatomic, strong) HPSpace *defaultSpace; +- (void)setUpWithStoreURL:(NSURL *)storeURL; +- (void)save; +- (void)saveWithManagedObjectContext:(NSManagedObjectContext *)managedObjectContext; +- (void)resetStack; +@end diff --git a/client/ios/Hackpad/HackpadTestingKit/HPCoreDataStackTestCase.m b/client/ios/Hackpad/HackpadTestingKit/HPCoreDataStackTestCase.m new file mode 100644 index 0000000..299baf8 --- /dev/null +++ b/client/ios/Hackpad/HackpadTestingKit/HPCoreDataStackTestCase.m @@ -0,0 +1,171 @@ +// +// HPCoreDataStackTestCase.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPCoreDataStackTestCase.h" + +#import "HackpadKit/HPCoreDataStack.h" +#import "HackpadKit/HPSpace+Impl.h" + +@interface HPCoreDataStackTestCase () +@property (nonatomic, strong) NSURL *storeDirectory; +@property (nonatomic, strong) NSURL *storeURL; +@end + +@implementation HPCoreDataStackTestCase + +@synthesize defaultSpace = _defaultSpace; + +- (void)resetStack +{ + self.defaultSpace = nil; + self.managedObjectContext = nil; + self.coreDataStack = nil; +} + +- (NSURL *)storeDirectory +{ + return self.storeURL.URLByDeletingLastPathComponent; +} + +- (NSURL *)storeURL +{ + if (_storeURL) { + return _storeURL; + } + NSError *error; + NSURL *URL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory + inDomain:NSUserDomainMask + appropriateForURL:nil + create:YES + error:&error]; + STAssertNil(error, @"Failed to get documents URL: %@", error); + STAssertNotNil(URL, @"Failed to get documents URL: %@", error); + + URL = [[NSFileManager defaultManager] URLForDirectory:NSItemReplacementDirectory + inDomain:NSUserDomainMask + appropriateForURL:URL + create:YES + error:&error]; + STAssertNil(error, @"Failed to get temporary documents URL: %@", error); + STAssertNotNil(URL, @"Failed to get temporary documents URL: %@", error); + + _storeURL = [URL URLByAppendingPathComponent:@"test.data"]; + return _storeURL; +} + +- (HPCoreDataStack *)coreDataStack +{ + if (_coreDataStack) { + return _coreDataStack; + } + _coreDataStack = [HPCoreDataStack new]; + _coreDataStack.storeURL = self.storeURL; + return _coreDataStack; +} + +- (NSManagedObjectContext *)managedObjectContext +{ + if (_managedObjectContext) { + return _managedObjectContext; + } + _managedObjectContext = self.coreDataStack.mainContext; + return _managedObjectContext; +} + +- (void)setUp +{ + [self setUpWithStoreURL:nil]; +} + +- (void)setUpWithStoreURL:(NSURL *)storeURL +{ + [super setUp]; + STAssertNil(_storeURL, @"storeURL already initialized to: %@", _storeURL); + STAssertNil(_coreDataStack, @"coreDataStack already initialized."); + STAssertNil(_defaultSpace, @"defaultSpace already initialized."); + + STAssertNotNil(self.storeURL, @"Could not initialize CoreData store URL."); + if (storeURL) { + NSError * __autoreleasing error; + STAssertTrue([[NSFileManager defaultManager] copyItemAtURL:storeURL + toURL:self.storeURL + error:&error], + @"Unable to copy store URL"); + STAssertNil(error, @"Error copying store URL: %@", error); + sync(); + sleep(1); + } + STAssertNotNil(self.coreDataStack, @"Could not create CoreData stack in %@.", self.storeDirectory); + + if (self.coreDataStack.isMigrationNeeded) { + HPLog(@"Not migrating CoreData..."); +#if 0 + HPMigrationController *migrationController = [HPMigrationController new]; + MHWMigrationManager *migrationManager = [MHWMigrationManager new]; + migrationManager.delegate = migrationController; + + NSError * __autoreleasing error; + STAssertTrue([migrationManager progressivelyMigrateURL:self.coreDataStack.storeURL + ofType:self.coreDataStack.storeType + toModel:self.coreDataStack.managedObjectModel + error:&error], + @"CoreData migration failed."); + STAssertNil(error, @"Error migrating CoreData: %@", error); +#endif + } + + STAssertNotNil(self.managedObjectContext, @"Could not create managed object context"); +} + +- (void)tearDown +{ + [self resetStack]; + if (self.storeDirectory) { + NSError *error; + [[NSFileManager defaultManager] removeItemAtURL:self.storeDirectory + error:&error]; + STAssertNil(error, @"Could not remove store directory '%@': %@", self.storeDirectory, error); + self.storeDirectory = nil; + } + [super tearDown]; +} + +- (HPSpace *)defaultSpace +{ + if (_defaultSpace) { + return _defaultSpace; + } + _defaultSpace = [HPSpace spaceWithURL:[NSURL hp_sharedHackpadURL] + inManagedObjectContext:self.managedObjectContext + error:nil]; + if (_defaultSpace) { + return _defaultSpace; + } + _defaultSpace = [HPSpace insertSpaceWithURL:[NSURL hp_sharedHackpadURL] + name:nil + managedObjectContext:self.managedObjectContext]; + STAssertNotNil(_defaultSpace, @"Could not create default space."); + + return _defaultSpace; +} + +- (void)saveWithManagedObjectContext:(NSManagedObjectContext *)managedObjectContext +{ + NSError *error; + STAssertTrue([managedObjectContext hp_saveToStore:&error], + @"[%@] Saving context failed.", managedObjectContext.hp_name); + STAssertNil(error, @"[%@] Error saving %@: %@", + managedObjectContext.hp_name, error); +} + +- (void)save +{ + [self saveWithManagedObjectContext:self.managedObjectContext]; +} + +@end diff --git a/client/ios/Hackpad/HackpadTestingKit/HPMigrationTestCase.h b/client/ios/Hackpad/HackpadTestingKit/HPMigrationTestCase.h new file mode 100644 index 0000000..d20f658 --- /dev/null +++ b/client/ios/Hackpad/HackpadTestingKit/HPMigrationTestCase.h @@ -0,0 +1,20 @@ +// +// HPMigrationTestCase.h +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import + +#define HP_MIGRATION_TEST_CASE_IMPL \ +- (void)testSpaceMigration { [self doTestSpaceMigration]; } \ +- (void)testCollectionMigration { [self doTestCollectionMigration]; } \ +- (void)testPadMigration { [self doTestPadMigration]; } + +@interface HPMigrationTestCase : HPCoreDataStackTestCase +- (void)doTestSpaceMigration; +- (void)doTestCollectionMigration; +- (void)doTestPadMigration; +@end diff --git a/client/ios/Hackpad/HackpadTestingKit/HPMigrationTestCase.m b/client/ios/Hackpad/HackpadTestingKit/HPMigrationTestCase.m new file mode 100644 index 0000000..a74a22e --- /dev/null +++ b/client/ios/Hackpad/HackpadTestingKit/HPMigrationTestCase.m @@ -0,0 +1,60 @@ +// +// HPMigrationTestCase.m +// Hackpad +// +// +// Copyright (c) 2014 Hackpad. All rights reserved. +// + +#import "HPMigrationTestCase.h" + +#import + +@implementation HPMigrationTestCase + +- (void)doTestSpaceMigration +{ + NSError * __autoreleasing error; + STAssertTrue([HPSpace migrateRootURLsInManagedObjectContext:self.managedObjectContext + error:&error], + @"Could not migrate spaces to rootURL"); + STAssertNil(error, @"Error migrating root URLs: %@", error); + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPSpaceEntity]; + fetch.predicate = [NSPredicate predicateWithValue:YES]; + NSArray *spaces = [self.coreDataStack.mainContext executeFetchRequest:fetch + error:&error]; + STAssertNotNil(spaces, @"Could not fetch spaces"); + STAssertNil(error, @"Error fetching spaces"); + STAssertTrue(!!(spaces.count > 0), @"No spaces were fetched"); + [spaces enumerateObjectsUsingBlock:^(HPSpace *space, NSUInteger idx, BOOL *stop) { + STAssertNotNil(space.URL, @"Space doesn't have a URL"); + STAssertFalse(space.domainType < HPToplevelDomainType, @"Invalid domain type"); + STAssertFalse(space.domainType > HPWorkspaceDomainType, @"Invalid domain type"); + }]; +} + +- (void)doTestCollectionMigration +{ + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPCollectionEntity]; + fetch.predicate = [NSPredicate predicateWithValue:YES]; + NSError * __autoreleasing error; + NSArray *collections = [self.coreDataStack.mainContext executeFetchRequest:fetch + error:&error]; + STAssertNotNil(collections, @"Could not fetch collections"); + STAssertNil(error, @"Error fetching collections"); + STAssertTrue(collections.count > 0, @"No collections were fetched"); +} + +- (void)doTestPadMigration +{ + NSFetchRequest *fetch = [NSFetchRequest fetchRequestWithEntityName:HPPadEntity]; + fetch.predicate = [NSPredicate predicateWithValue:YES]; + NSError * __autoreleasing error; + NSArray *pads = [self.coreDataStack.mainContext executeFetchRequest:fetch + error:&error]; + STAssertNotNil(pads, @"Could not fetch pads"); + STAssertNil(error, @"Error fetching pads"); + STAssertTrue(pads.count > 0, @"No pads were fetched"); +} + +@end diff --git a/client/ios/Hackpad/HackpadTestingKit/HPMockTestCase.h b/client/ios/Hackpad/HackpadTestingKit/HPMockTestCase.h new file mode 100644 index 0000000..c320620 --- /dev/null +++ b/client/ios/Hackpad/HackpadTestingKit/HPMockTestCase.h @@ -0,0 +1,26 @@ +// +// HPMockTestCase.h +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// +// Based on objc.io example project (issue #1) + +#import + +@interface HPMockTestCase : SenTestCase + +/// Returns the URL for a resource that's been added to the test target. +- (NSURL *)URLForResource:(NSString *)name + withExtension:(NSString *)extension; + +/// Calls +[OCMockObject mockForClass:] and adds the mock and call -verify on it during -tearDown +- (id)autoVerifiedMockForClass:(Class)aClass; +/// C.f. -autoVerifiedMockForClass: +- (id)autoVerifiedPartialMockForObject:(id)object; + +/// Calls -verify on the mock during -tearDown +- (void)verifyDuringTearDown:(id)mock; + +@end diff --git a/client/ios/Hackpad/HackpadTestingKit/HPMockTestCase.m b/client/ios/Hackpad/HackpadTestingKit/HPMockTestCase.m new file mode 100644 index 0000000..ef5167d --- /dev/null +++ b/client/ios/Hackpad/HackpadTestingKit/HPMockTestCase.m @@ -0,0 +1,58 @@ +// +// HPMockTestCase.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import "HPMockTestCase.h" + +#import + +@interface HPMockTestCase () +@property (nonatomic, strong) NSMutableArray *mocksToVerify; +@end + +@implementation HPMockTestCase + +- (void)tearDown +{ + [self.mocksToVerify enumerateObjectsUsingBlock:^(id mock, NSUInteger idx, BOOL *stop) { + [mock verify]; + }]; + self.mocksToVerify = nil; + [super tearDown]; +} + +- (NSURL *)URLForResource:(NSString *)name + withExtension:(NSString *)extension +{ + return [[NSBundle bundleForClass:self.class] URLForResource:name + withExtension:extension]; +} + +- (id)autoVerifiedMockForClass:(Class)aClass +{ + id mock = [OCMockObject mockForClass:aClass]; + [self verifyDuringTearDown:mock]; + return mock; +} + +- (id)autoVerifiedPartialMockForObject:(id)object +{ + id mock = [OCMockObject partialMockForObject:object]; + [self verifyDuringTearDown:mock]; + return mock; +} + +- (void)verifyDuringTearDown:(id)mock +{ + if (self.mocksToVerify) { + [self.mocksToVerify addObject:mock]; + } else { + self.mocksToVerify = [NSMutableArray arrayWithObject:mock]; + } +} + +@end diff --git a/client/ios/Hackpad/HackpadTestingKit/HackpadTestingKit-Prefix.pch b/client/ios/Hackpad/HackpadTestingKit/HackpadTestingKit-Prefix.pch new file mode 100644 index 0000000..d45f8bc --- /dev/null +++ b/client/ios/Hackpad/HackpadTestingKit/HackpadTestingKit-Prefix.pch @@ -0,0 +1,11 @@ +// +// Prefix header for all source files of the 'HackpadTestingKit' target in the 'HackpadTestingKit' project +// + +#ifdef __OBJC__ + #import + #import + #import + #import + #import "HPLog.h" +#endif diff --git a/client/ios/Hackpad/HackpadTestingKit/HackpadTestingKit.h b/client/ios/Hackpad/HackpadTestingKit/HackpadTestingKit.h new file mode 100644 index 0000000..f8c4f23 --- /dev/null +++ b/client/ios/Hackpad/HackpadTestingKit/HackpadTestingKit.h @@ -0,0 +1,10 @@ +// +// HackpadTestingKit.h +// HackpadTestingKit +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import diff --git a/client/ios/Hackpad/HackpadTests/HPPadScopeTableViewDataSourceTests.m b/client/ios/Hackpad/HackpadTests/HPPadScopeTableViewDataSourceTests.m new file mode 100644 index 0000000..3743fe5 --- /dev/null +++ b/client/ios/Hackpad/HackpadTests/HPPadScopeTableViewDataSourceTests.m @@ -0,0 +1,314 @@ +// +// HPPadScopeViewControllerTests.m +// Hackpad +// +// +// Copyright (c) 2013 Hackpad. All rights reserved. +// + +#import +#import +#import + +#import "HPPadScopeTableViewDataSource.h" + +#import + +@interface HPPadScopeTableViewDataSourceTests : HPCoreDataStackTestCase +@property (nonatomic, strong) HPPadScopeTableViewDataSource *dataSource; +@property (nonatomic, strong) id mockDataSource; +@property (nonatomic, strong) id mockTableView; +@end + +#define CHECK_OBJECT_ID(obj1) \ +[OCMArg checkWithBlock:^BOOL(NSManagedObject *obj2) \ +{ \ + HPLog(@"%d %p %@ ?= %p %@", (int)[obj1.objectID isEqual:obj2.objectID], obj1.objectID, obj1.objectID, obj2.objectID, obj2.objectID); \ + return [obj1.objectID isEqual:obj2.objectID]; \ +}] + +@implementation HPPadScopeTableViewDataSourceTests + +- (void)setUp +{ + [super setUp]; + + self.dataSource = [[HPPadScopeTableViewDataSource alloc] init]; + self.mockDataSource = [self autoVerifiedPartialMockForObject:self.dataSource]; + self.mockTableView = [self autoVerifiedMockForClass:[UITableView class]]; + + self.dataSource.managedObjectContext = self.coreDataStack.mainContext; + + // Initializes the fetched results controller. + [self.dataSource numberOfSectionsInTableView:self.mockTableView]; +} + +- (void)tearDown +{ + self.mockDataSource = nil; + self.dataSource = nil; + self.mockTableView = nil; + + [super tearDown]; +} + +- (void)expectEmptyStore +{ + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + STAssertEquals([self.dataSource numberOfSectionsInTableView:self.mockTableView], + 0, @"Empty store"); +} + +- (void)expectDefaultSpace +{ + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + STAssertEquals([self.dataSource numberOfSectionsInTableView:self.mockTableView], + 1, @"Default space"); + STAssertEquals([self.dataSource tableView:self.mockTableView + numberOfRowsInSection:0], + 1, @"Default space"); +} + +- (void)test_0001_EmptyStore +{ + [self expectEmptyStore]; +} + +- (void)test_0002_DefaultSpace +{ + [self defaultSpace]; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:CHECK_OBJECT_ID(self.defaultSpace) + atIndexPath:nil + forChangeType:NSFetchedResultsChangeInsert + newIndexPath:[NSIndexPath indexPathForRow:0 + inSection:0]]; + + [self save]; + [self expectDefaultSpace]; +} + +- (void)test_0003_DefaultSpaceWithCollection +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + + HPCollection *collection = [NSEntityDescription insertNewObjectForEntityForName:HPCollectionEntity + inManagedObjectContext:self.managedObjectContext]; + collection.title = @"Test Collection"; + collection.followed = YES; + collection.collectionID = @"1"; + collection.space = self.defaultSpace; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:CHECK_OBJECT_ID(self.defaultSpace) + atIndexPath:[NSIndexPath indexPathForRow:0 + inSection:0] + forChangeType:NSFetchedResultsChangeUpdate + newIndexPath:nil]; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:CHECK_OBJECT_ID(collection) + atIndexPath:nil + forChangeType:NSFetchedResultsChangeInsert + newIndexPath:[NSIndexPath indexPathForRow:0 + inSection:0]]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + STAssertEquals([self.dataSource numberOfSectionsInTableView:self.mockTableView], + 1, @"Default space"); + STAssertEquals([self.dataSource tableView:self.mockTableView + numberOfRowsInSection:0], + 2, @"Default space and test collection"); +} + +- (void)test_0004_RemoveSpace +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + [self.managedObjectContext deleteObject:self.defaultSpace]; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:CHECK_OBJECT_ID(self.defaultSpace) + atIndexPath:[NSIndexPath indexPathForRow:0 + inSection:0] + forChangeType:NSFetchedResultsChangeDelete + newIndexPath:nil]; + [self save]; + [self expectEmptyStore]; +} + +- (void)test_0005_ReplaceSpace +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + NSManagedObjectID *oldSpace = self.defaultSpace.objectID; + [self.managedObjectContext deleteObject:self.defaultSpace]; + self.defaultSpace = nil; + [self defaultSpace]; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:[OCMArg checkWithBlock:^BOOL(id obj) + { + return [oldSpace isEqual:[obj objectID]]; + }] + atIndexPath:[OCMArg any] + forChangeType:NSFetchedResultsChangeDelete + newIndexPath:nil]; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:CHECK_OBJECT_ID(self.defaultSpace) + atIndexPath:nil + forChangeType:NSFetchedResultsChangeInsert + newIndexPath:[OCMArg any]]; + + [self save]; + [self expectDefaultSpace]; +} + +- (void)test_0006_RemoveCollection +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + HPCollection *collection = [NSEntityDescription insertNewObjectForEntityForName:HPCollectionEntity + inManagedObjectContext:self.managedObjectContext]; + collection.title = @"Test Collection"; + collection.followed = YES; + collection.collectionID = @"1"; + [self.defaultSpace addCollectionsObject:collection]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + NSManagedObjectID *collectionID = collection.objectID; + [self.managedObjectContext deleteObject:collection]; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:CHECK_OBJECT_ID(self.defaultSpace) + atIndexPath:[NSIndexPath indexPathForRow:0 + inSection:0] + forChangeType:NSFetchedResultsChangeUpdate + newIndexPath:nil]; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:[OCMArg checkWithBlock:^BOOL(id obj) + { + return [collectionID isEqual:[obj objectID]]; + }] + atIndexPath:[NSIndexPath indexPathForRow:0 + inSection:0] + forChangeType:NSFetchedResultsChangeDelete + newIndexPath:nil]; + [self save]; + [self expectDefaultSpace]; +} + +- (void)test_0007_RemoveSpaceWithCollection +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + HPCollection *collection = [NSEntityDescription insertNewObjectForEntityForName:HPCollectionEntity + inManagedObjectContext:self.managedObjectContext]; + collection.title = @"Test Collection"; + collection.followed = YES; + collection.collectionID = @"1"; + [self.defaultSpace addCollectionsObject:collection]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + [self.managedObjectContext deleteObject:self.defaultSpace]; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:CHECK_OBJECT_ID(self.defaultSpace) + atIndexPath:[NSIndexPath indexPathForRow:0 + inSection:0] + forChangeType:NSFetchedResultsChangeDelete + newIndexPath:nil]; + [self save]; + [self expectEmptyStore]; +} + +- (void)test_0008_ReplaceSpaceWithCollection +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + HPCollection *collection = [NSEntityDescription insertNewObjectForEntityForName:HPCollectionEntity + inManagedObjectContext:self.managedObjectContext]; + collection.title = @"Test Collection"; + collection.followed = YES; + collection.collectionID = @"1"; + [self.defaultSpace addCollectionsObject:collection]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + + NSManagedObjectID *oldSpace = self.defaultSpace.objectID; + [self.managedObjectContext deleteObject:self.defaultSpace]; + self.defaultSpace = nil; + [self defaultSpace]; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:CHECK_OBJECT_ID(self.defaultSpace) + atIndexPath:nil + forChangeType:NSFetchedResultsChangeInsert + newIndexPath:[NSIndexPath indexPathForRow:0 + inSection:0]]; + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:[OCMArg checkWithBlock:^BOOL(id obj) + { + return [oldSpace isEqual:[obj objectID]]; + }] + atIndexPath:[OCMArg any] + forChangeType:NSFetchedResultsChangeDelete + newIndexPath:nil]; + [self save]; + [self expectDefaultSpace]; +} + +- (void)test_0009_RemoveSecondSpace +{ + [self defaultSpace]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + HPSpace *space = [NSEntityDescription insertNewObjectForEntityForName:HPSpaceEntity + inManagedObjectContext:self.managedObjectContext]; + space.name = @"Test"; + space.hidden = NO; + space.subdomain = @"test"; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:CHECK_OBJECT_ID(space) + atIndexPath:nil + forChangeType:NSFetchedResultsChangeInsert + newIndexPath:[NSIndexPath indexPathForRow:1 + inSection:0]]; + [self save]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + + [self.managedObjectContext deleteObject:space]; + + [[[self.mockDataSource expect] andForwardToRealObject] controller:[OCMArg any] + didChangeObject:CHECK_OBJECT_ID(space) + atIndexPath:[NSIndexPath indexPathForRow:1 + inSection:0] + forChangeType:NSFetchedResultsChangeDelete + newIndexPath:nil]; + [self save]; + [self expectDefaultSpace]; +} + +@end diff --git a/client/ios/Hackpad/HackpadTests/HackpadTests-Info.plist b/client/ios/Hackpad/HackpadTests/HackpadTests-Info.plist new file mode 100644 index 0000000..96e9937 --- /dev/null +++ b/client/ios/Hackpad/HackpadTests/HackpadTests-Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.hackpad.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/client/ios/Hackpad/HackpadTests/HackpadTests-Prefix.pch b/client/ios/Hackpad/HackpadTests/HackpadTests-Prefix.pch new file mode 100644 index 0000000..56dd3ce --- /dev/null +++ b/client/ios/Hackpad/HackpadTests/HackpadTests-Prefix.pch @@ -0,0 +1,12 @@ +// +// Prefix header for all source files of the 'HackpadTests' target in the 'HackpadTests' project +// + +#ifdef __OBJC__ + #import + #import + #import + #import + #import + #import "HPLog.h" +#endif diff --git a/client/ios/Hackpad/HackpadTests/en.lproj/InfoPlist.strings b/client/ios/Hackpad/HackpadTests/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..477b28f --- /dev/null +++ b/client/ios/Hackpad/HackpadTests/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/Contents.json b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..9b993b9 --- /dev/null +++ b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,107 @@ +{ + "images" : [ + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "icon-29.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "icon-58.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "icon-80.png", + "scale" : "2x" + }, + { + "size" : "57x57", + "idiom" : "iphone", + "filename" : "Icon.png", + "scale" : "1x" + }, + { + "size" : "57x57", + "idiom" : "iphone", + "filename" : "Icon@2x.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "icon-120.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "icon-29.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "icon-58.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "icon-40.png", + "scale" : "1x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "icon-80.png", + "scale" : "2x" + }, + { + "size" : "50x50", + "idiom" : "ipad", + "filename" : "icon-50.png", + "scale" : "1x" + }, + { + "size" : "50x50", + "idiom" : "ipad", + "filename" : "icon-100.png", + "scale" : "2x" + }, + { + "size" : "72x72", + "idiom" : "ipad", + "filename" : "icon-72.png", + "scale" : "1x" + }, + { + "size" : "72x72", + "idiom" : "ipad", + "filename" : "icon-144.png", + "scale" : "2x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "icon-76.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "icon-152.png", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + }, + "properties" : { + "pre-rendered" : true + } +} \ No newline at end of file diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/Icon.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/Icon.png new file mode 100644 index 0000000..5d7e7b7 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/Icon.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/Icon@2x.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/Icon@2x.png new file mode 100644 index 0000000..b9215cb Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/Icon@2x.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-100.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-100.png new file mode 100644 index 0000000..f77ce6b Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-100.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-120.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-120.png new file mode 100644 index 0000000..2dbcfd0 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-120.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-144.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-144.png new file mode 100644 index 0000000..687dbaf Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-144.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-152.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-152.png new file mode 100644 index 0000000..c9e827f Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-152.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-29.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-29.png new file mode 100644 index 0000000..f46c935 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-29.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-40.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-40.png new file mode 100644 index 0000000..e4eec1f Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-40.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-50.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-50.png new file mode 100644 index 0000000..1fe28a8 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-50.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-58.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-58.png new file mode 100644 index 0000000..baf58f2 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-58.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-72.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-72.png new file mode 100644 index 0000000..2cdb5e1 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-72.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-76.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-76.png new file mode 100644 index 0000000..8a1fa9c Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-76.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-80.png b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-80.png new file mode 100644 index 0000000..ee5b437 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/AppIcon.appiconset/icon-80.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Contents.json b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Contents.json new file mode 100644 index 0000000..818a7e5 --- /dev/null +++ b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Contents.json @@ -0,0 +1,107 @@ +{ + "images" : [ + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "filename" : "iOS7Default@2x.png", + "scale" : "2x" + }, + { + "extent" : "full-screen", + "idiom" : "iphone", + "subtype" : "retina4", + "filename" : "ios7Default-568h@2x.png", + "minimum-system-version" : "7.0", + "orientation" : "portrait", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "filename" : "iOS7Default-Portrait~ipad.png", + "scale" : "1x" + }, + { + "orientation" : "landscape", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "filename" : "iOS7-Default-Landscape~ipad.png", + "scale" : "1x" + }, + { + "orientation" : "portrait", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "filename" : "iOS7Default-Portrait@2x~ipad.png", + "scale" : "2x" + }, + { + "orientation" : "landscape", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "filename" : "iOS7Default-Landscape@2x~ipad.png", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "filename" : "Default.png", + "scale" : "1x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "filename" : "Default@2x.png", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "filename" : "Default-568h@2x.png", + "subtype" : "retina4", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "ipad", + "extent" : "to-status-bar", + "filename" : "Default-Portrait~ipad.png", + "scale" : "1x" + }, + { + "orientation" : "landscape", + "idiom" : "ipad", + "extent" : "to-status-bar", + "filename" : "Default-Landscape~ipad.png", + "scale" : "1x" + }, + { + "orientation" : "portrait", + "idiom" : "ipad", + "extent" : "to-status-bar", + "filename" : "Default-Portrait@2x~ipad.png", + "scale" : "2x" + }, + { + "orientation" : "landscape", + "idiom" : "ipad", + "extent" : "to-status-bar", + "filename" : "Default-Landscape@2x~ipad.png", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png new file mode 100644 index 0000000..066c96e Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Landscape@2x~ipad.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Landscape@2x~ipad.png new file mode 100644 index 0000000..71cf7ec Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Landscape@2x~ipad.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Landscape~ipad.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Landscape~ipad.png new file mode 100644 index 0000000..feb5d05 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Landscape~ipad.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Portrait@2x~ipad.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Portrait@2x~ipad.png new file mode 100644 index 0000000..dae22d4 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Portrait@2x~ipad.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Portrait~ipad.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Portrait~ipad.png new file mode 100644 index 0000000..966fba1 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default-Portrait~ipad.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default.png new file mode 100644 index 0000000..0846ca1 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default@2x.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default@2x.png new file mode 100644 index 0000000..c85e912 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/Default@2x.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7-Default-Landscape~ipad.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7-Default-Landscape~ipad.png new file mode 100644 index 0000000..0e11a55 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7-Default-Landscape~ipad.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default-Landscape@2x~ipad.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default-Landscape@2x~ipad.png new file mode 100644 index 0000000..9b496c8 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default-Landscape@2x~ipad.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default-Portrait@2x~ipad.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default-Portrait@2x~ipad.png new file mode 100644 index 0000000..c0debb3 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default-Portrait@2x~ipad.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default-Portrait~ipad.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default-Portrait~ipad.png new file mode 100644 index 0000000..5292969 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default-Portrait~ipad.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default@2x.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default@2x.png new file mode 100644 index 0000000..9ae5d5e Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/iOS7Default@2x.png differ diff --git a/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/ios7Default-568h@2x.png b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/ios7Default-568h@2x.png new file mode 100644 index 0000000..15f7b02 Binary files /dev/null and b/client/ios/Hackpad/Icons/Images.xcassets/LaunchImage.launchimage/ios7Default-568h@2x.png differ diff --git a/client/ios/Hackpad/Icons/back.png b/client/ios/Hackpad/Icons/back.png new file mode 100644 index 0000000..9ff2acc Binary files /dev/null and b/client/ios/Hackpad/Icons/back.png differ diff --git a/client/ios/Hackpad/Icons/back.xcf b/client/ios/Hackpad/Icons/back.xcf new file mode 100644 index 0000000..b132a7a Binary files /dev/null and b/client/ios/Hackpad/Icons/back.xcf differ diff --git a/client/ios/Hackpad/Icons/back@2x.png b/client/ios/Hackpad/Icons/back@2x.png new file mode 100644 index 0000000..22d16f6 Binary files /dev/null and b/client/ios/Hackpad/Icons/back@2x.png differ diff --git a/client/ios/Hackpad/Icons/bluebg.png b/client/ios/Hackpad/Icons/bluebg.png new file mode 100644 index 0000000..87e8e62 Binary files /dev/null and b/client/ios/Hackpad/Icons/bluebg.png differ diff --git a/client/ios/Hackpad/Icons/bold.png b/client/ios/Hackpad/Icons/bold.png new file mode 100644 index 0000000..1c35984 Binary files /dev/null and b/client/ios/Hackpad/Icons/bold.png differ diff --git a/client/ios/Hackpad/Icons/bold@2x.png b/client/ios/Hackpad/Icons/bold@2x.png new file mode 100644 index 0000000..a015f99 Binary files /dev/null and b/client/ios/Hackpad/Icons/bold@2x.png differ diff --git a/client/ios/Hackpad/Icons/bullet.png b/client/ios/Hackpad/Icons/bullet.png new file mode 100644 index 0000000..7fdc275 Binary files /dev/null and b/client/ios/Hackpad/Icons/bullet.png differ diff --git a/client/ios/Hackpad/Icons/bullet@2x.png b/client/ios/Hackpad/Icons/bullet@2x.png new file mode 100644 index 0000000..4b51a94 Binary files /dev/null and b/client/ios/Hackpad/Icons/bullet@2x.png differ diff --git a/client/ios/Hackpad/Icons/buttons.xcf.bz2 b/client/ios/Hackpad/Icons/buttons.xcf.bz2 new file mode 100644 index 0000000..ab0150d Binary files /dev/null and b/client/ios/Hackpad/Icons/buttons.xcf.bz2 differ diff --git a/client/ios/Hackpad/Icons/check-green.png b/client/ios/Hackpad/Icons/check-green.png new file mode 100644 index 0000000..9c0963b Binary files /dev/null and b/client/ios/Hackpad/Icons/check-green.png differ diff --git a/client/ios/Hackpad/Icons/check-green@2x.png b/client/ios/Hackpad/Icons/check-green@2x.png new file mode 100644 index 0000000..2e9fb96 Binary files /dev/null and b/client/ios/Hackpad/Icons/check-green@2x.png differ diff --git a/client/ios/Hackpad/Icons/check.png b/client/ios/Hackpad/Icons/check.png new file mode 100644 index 0000000..92298b1 Binary files /dev/null and b/client/ios/Hackpad/Icons/check.png differ diff --git a/client/ios/Hackpad/Icons/check@2x.png b/client/ios/Hackpad/Icons/check@2x.png new file mode 100644 index 0000000..42ed530 Binary files /dev/null and b/client/ios/Hackpad/Icons/check@2x.png differ diff --git a/client/ios/Hackpad/Icons/clearback.png b/client/ios/Hackpad/Icons/clearback.png new file mode 100644 index 0000000..d47cfe2 Binary files /dev/null and b/client/ios/Hackpad/Icons/clearback.png differ diff --git a/client/ios/Hackpad/Icons/clearback@2x.png b/client/ios/Hackpad/Icons/clearback@2x.png new file mode 100644 index 0000000..f00da4a Binary files /dev/null and b/client/ios/Hackpad/Icons/clearback@2x.png differ diff --git a/client/ios/Hackpad/Icons/clearbacklandscape.png b/client/ios/Hackpad/Icons/clearbacklandscape.png new file mode 100644 index 0000000..f2ee980 Binary files /dev/null and b/client/ios/Hackpad/Icons/clearbacklandscape.png differ diff --git a/client/ios/Hackpad/Icons/clearbacklandscape@2x.png b/client/ios/Hackpad/Icons/clearbacklandscape@2x.png new file mode 100644 index 0000000..d5c0b92 Binary files /dev/null and b/client/ios/Hackpad/Icons/clearbacklandscape@2x.png differ diff --git a/client/ios/Hackpad/Icons/close.png b/client/ios/Hackpad/Icons/close.png new file mode 100644 index 0000000..fd82519 Binary files /dev/null and b/client/ios/Hackpad/Icons/close.png differ diff --git a/client/ios/Hackpad/Icons/close@2x.png b/client/ios/Hackpad/Icons/close@2x.png new file mode 100644 index 0000000..e528526 Binary files /dev/null and b/client/ios/Hackpad/Icons/close@2x.png differ diff --git a/client/ios/Hackpad/Icons/comment.png b/client/ios/Hackpad/Icons/comment.png new file mode 100644 index 0000000..3a1341d Binary files /dev/null and b/client/ios/Hackpad/Icons/comment.png differ diff --git a/client/ios/Hackpad/Icons/comment@2x.png b/client/ios/Hackpad/Icons/comment@2x.png new file mode 100644 index 0000000..ecce279 Binary files /dev/null and b/client/ios/Hackpad/Icons/comment@2x.png differ diff --git a/client/ios/Hackpad/Icons/darkgreenbg.png b/client/ios/Hackpad/Icons/darkgreenbg.png new file mode 100644 index 0000000..410804a Binary files /dev/null and b/client/ios/Hackpad/Icons/darkgreenbg.png differ diff --git a/client/ios/Hackpad/Icons/dot44.png b/client/ios/Hackpad/Icons/dot44.png new file mode 100644 index 0000000..f9ac72f Binary files /dev/null and b/client/ios/Hackpad/Icons/dot44.png differ diff --git a/client/ios/Hackpad/Icons/dot44@2x.png b/client/ios/Hackpad/Icons/dot44@2x.png new file mode 100644 index 0000000..afb7c11 Binary files /dev/null and b/client/ios/Hackpad/Icons/dot44@2x.png differ diff --git a/client/ios/Hackpad/Icons/down-chevron.png b/client/ios/Hackpad/Icons/down-chevron.png new file mode 100644 index 0000000..bcfc7bc Binary files /dev/null and b/client/ios/Hackpad/Icons/down-chevron.png differ diff --git a/client/ios/Hackpad/Icons/down-chevron@2x.png b/client/ios/Hackpad/Icons/down-chevron@2x.png new file mode 100644 index 0000000..e00d532 Binary files /dev/null and b/client/ios/Hackpad/Icons/down-chevron@2x.png differ diff --git a/client/ios/Hackpad/Icons/dropbox.png b/client/ios/Hackpad/Icons/dropbox.png new file mode 100644 index 0000000..5efe507 Binary files /dev/null and b/client/ios/Hackpad/Icons/dropbox.png differ diff --git a/client/ios/Hackpad/Icons/dropbox@2x.png b/client/ios/Hackpad/Icons/dropbox@2x.png new file mode 100644 index 0000000..f8a9bdd Binary files /dev/null and b/client/ios/Hackpad/Icons/dropbox@2x.png differ diff --git a/client/ios/Hackpad/Icons/editorbg.png b/client/ios/Hackpad/Icons/editorbg.png new file mode 100644 index 0000000..1599d0c Binary files /dev/null and b/client/ios/Hackpad/Icons/editorbg.png differ diff --git a/client/ios/Hackpad/Icons/email-button-white.png b/client/ios/Hackpad/Icons/email-button-white.png new file mode 100644 index 0000000..5d0b615 Binary files /dev/null and b/client/ios/Hackpad/Icons/email-button-white.png differ diff --git a/client/ios/Hackpad/Icons/email-button-white@2x.png b/client/ios/Hackpad/Icons/email-button-white@2x.png new file mode 100644 index 0000000..19be548 Binary files /dev/null and b/client/ios/Hackpad/Icons/email-button-white@2x.png differ diff --git a/client/ios/Hackpad/Icons/email-green.png b/client/ios/Hackpad/Icons/email-green.png new file mode 100644 index 0000000..1c1a7f8 Binary files /dev/null and b/client/ios/Hackpad/Icons/email-green.png differ diff --git a/client/ios/Hackpad/Icons/email-green@2x.png b/client/ios/Hackpad/Icons/email-green@2x.png new file mode 100644 index 0000000..59ad772 Binary files /dev/null and b/client/ios/Hackpad/Icons/email-green@2x.png differ diff --git a/client/ios/Hackpad/Icons/facebook44.png b/client/ios/Hackpad/Icons/facebook44.png new file mode 100644 index 0000000..495fecb Binary files /dev/null and b/client/ios/Hackpad/Icons/facebook44.png differ diff --git a/client/ios/Hackpad/Icons/facebook44@2x.png b/client/ios/Hackpad/Icons/facebook44@2x.png new file mode 100644 index 0000000..9f56762 Binary files /dev/null and b/client/ios/Hackpad/Icons/facebook44@2x.png differ diff --git a/client/ios/Hackpad/Icons/follow.png b/client/ios/Hackpad/Icons/follow.png new file mode 100644 index 0000000..516b982 Binary files /dev/null and b/client/ios/Hackpad/Icons/follow.png differ diff --git a/client/ios/Hackpad/Icons/follow@2x.png b/client/ios/Hackpad/Icons/follow@2x.png new file mode 100644 index 0000000..28d6b05 Binary files /dev/null and b/client/ios/Hackpad/Icons/follow@2x.png differ diff --git a/client/ios/Hackpad/Icons/forward.png b/client/ios/Hackpad/Icons/forward.png new file mode 100644 index 0000000..03d2994 Binary files /dev/null and b/client/ios/Hackpad/Icons/forward.png differ diff --git a/client/ios/Hackpad/Icons/forward@2x.png b/client/ios/Hackpad/Icons/forward@2x.png new file mode 100644 index 0000000..3e5212b Binary files /dev/null and b/client/ios/Hackpad/Icons/forward@2x.png differ diff --git a/client/ios/Hackpad/Icons/gear.png b/client/ios/Hackpad/Icons/gear.png new file mode 100644 index 0000000..21e9224 Binary files /dev/null and b/client/ios/Hackpad/Icons/gear.png differ diff --git a/client/ios/Hackpad/Icons/gear@2x.png b/client/ios/Hackpad/Icons/gear@2x.png new file mode 100644 index 0000000..beb1a86 Binary files /dev/null and b/client/ios/Hackpad/Icons/gear@2x.png differ diff --git a/client/ios/Hackpad/Icons/google44.png b/client/ios/Hackpad/Icons/google44.png new file mode 100644 index 0000000..64e4d21 Binary files /dev/null and b/client/ios/Hackpad/Icons/google44.png differ diff --git a/client/ios/Hackpad/Icons/google44@2x.png b/client/ios/Hackpad/Icons/google44@2x.png new file mode 100644 index 0000000..f1b3cea Binary files /dev/null and b/client/ios/Hackpad/Icons/google44@2x.png differ diff --git a/client/ios/Hackpad/Icons/graybg.png b/client/ios/Hackpad/Icons/graybg.png new file mode 100644 index 0000000..bd09859 Binary files /dev/null and b/client/ios/Hackpad/Icons/graybg.png differ diff --git a/client/ios/Hackpad/Icons/groupbg.png b/client/ios/Hackpad/Icons/groupbg.png new file mode 100644 index 0000000..559c4d2 Binary files /dev/null and b/client/ios/Hackpad/Icons/groupbg.png differ diff --git a/client/ios/Hackpad/Icons/header1.png b/client/ios/Hackpad/Icons/header1.png new file mode 100644 index 0000000..52ba5da Binary files /dev/null and b/client/ios/Hackpad/Icons/header1.png differ diff --git a/client/ios/Hackpad/Icons/header1@2x.png b/client/ios/Hackpad/Icons/header1@2x.png new file mode 100644 index 0000000..56c1892 Binary files /dev/null and b/client/ios/Hackpad/Icons/header1@2x.png differ diff --git a/client/ios/Hackpad/Icons/header2.png b/client/ios/Hackpad/Icons/header2.png new file mode 100644 index 0000000..2ce3dd4 Binary files /dev/null and b/client/ios/Hackpad/Icons/header2.png differ diff --git a/client/ios/Hackpad/Icons/header2@2x.png b/client/ios/Hackpad/Icons/header2@2x.png new file mode 100644 index 0000000..f36c3d7 Binary files /dev/null and b/client/ios/Hackpad/Icons/header2@2x.png differ diff --git a/client/ios/Hackpad/Icons/header3.png b/client/ios/Hackpad/Icons/header3.png new file mode 100644 index 0000000..5f3f58b Binary files /dev/null and b/client/ios/Hackpad/Icons/header3.png differ diff --git a/client/ios/Hackpad/Icons/header3@2x.png b/client/ios/Hackpad/Icons/header3@2x.png new file mode 100644 index 0000000..7f6292d Binary files /dev/null and b/client/ios/Hackpad/Icons/header3@2x.png differ diff --git a/client/ios/Hackpad/Icons/icon-1024.png b/client/ios/Hackpad/Icons/icon-1024.png new file mode 100644 index 0000000..40de190 Binary files /dev/null and b/client/ios/Hackpad/Icons/icon-1024.png differ diff --git a/client/ios/Hackpad/Icons/indent.png b/client/ios/Hackpad/Icons/indent.png new file mode 100644 index 0000000..6f118d0 Binary files /dev/null and b/client/ios/Hackpad/Icons/indent.png differ diff --git a/client/ios/Hackpad/Icons/indent@2x.png b/client/ios/Hackpad/Icons/indent@2x.png new file mode 100644 index 0000000..3df1138 Binary files /dev/null and b/client/ios/Hackpad/Icons/indent@2x.png differ diff --git a/client/ios/Hackpad/Icons/insert.png b/client/ios/Hackpad/Icons/insert.png new file mode 100644 index 0000000..24212c0 Binary files /dev/null and b/client/ios/Hackpad/Icons/insert.png differ diff --git a/client/ios/Hackpad/Icons/insert@2x.png b/client/ios/Hackpad/Icons/insert@2x.png new file mode 100644 index 0000000..90dc6b7 Binary files /dev/null and b/client/ios/Hackpad/Icons/insert@2x.png differ diff --git a/client/ios/Hackpad/Icons/italic.png b/client/ios/Hackpad/Icons/italic.png new file mode 100644 index 0000000..708876b Binary files /dev/null and b/client/ios/Hackpad/Icons/italic.png differ diff --git a/client/ios/Hackpad/Icons/italic@2x.png b/client/ios/Hackpad/Icons/italic@2x.png new file mode 100644 index 0000000..6cde2d8 Binary files /dev/null and b/client/ios/Hackpad/Icons/italic@2x.png differ diff --git a/client/ios/Hackpad/Icons/link.png b/client/ios/Hackpad/Icons/link.png new file mode 100644 index 0000000..c21cbc4 Binary files /dev/null and b/client/ios/Hackpad/Icons/link.png differ diff --git a/client/ios/Hackpad/Icons/link@2x.png b/client/ios/Hackpad/Icons/link@2x.png new file mode 100644 index 0000000..c6260c0 Binary files /dev/null and b/client/ios/Hackpad/Icons/link@2x.png differ diff --git a/client/ios/Hackpad/Icons/mention.png b/client/ios/Hackpad/Icons/mention.png new file mode 100644 index 0000000..7dd4262 Binary files /dev/null and b/client/ios/Hackpad/Icons/mention.png differ diff --git a/client/ios/Hackpad/Icons/mention@2x.png b/client/ios/Hackpad/Icons/mention@2x.png new file mode 100644 index 0000000..103d295 Binary files /dev/null and b/client/ios/Hackpad/Icons/mention@2x.png differ diff --git a/client/ios/Hackpad/Icons/menu.png b/client/ios/Hackpad/Icons/menu.png new file mode 100644 index 0000000..37ca134 Binary files /dev/null and b/client/ios/Hackpad/Icons/menu.png differ diff --git a/client/ios/Hackpad/Icons/menu@2x.png b/client/ios/Hackpad/Icons/menu@2x.png new file mode 100644 index 0000000..feca2ad Binary files /dev/null and b/client/ios/Hackpad/Icons/menu@2x.png differ diff --git a/client/ios/Hackpad/Icons/newpad.png b/client/ios/Hackpad/Icons/newpad.png new file mode 100644 index 0000000..d4dc01e Binary files /dev/null and b/client/ios/Hackpad/Icons/newpad.png differ diff --git a/client/ios/Hackpad/Icons/newpad@2x.png b/client/ios/Hackpad/Icons/newpad@2x.png new file mode 100644 index 0000000..c10212d Binary files /dev/null and b/client/ios/Hackpad/Icons/newpad@2x.png differ diff --git a/client/ios/Hackpad/Icons/nophoto.png b/client/ios/Hackpad/Icons/nophoto.png new file mode 100644 index 0000000..e248917 Binary files /dev/null and b/client/ios/Hackpad/Icons/nophoto.png differ diff --git a/client/ios/Hackpad/Icons/number.png b/client/ios/Hackpad/Icons/number.png new file mode 100644 index 0000000..9ccd80b Binary files /dev/null and b/client/ios/Hackpad/Icons/number.png differ diff --git a/client/ios/Hackpad/Icons/number@2x.png b/client/ios/Hackpad/Icons/number@2x.png new file mode 100644 index 0000000..b4c345f Binary files /dev/null and b/client/ios/Hackpad/Icons/number@2x.png differ diff --git a/client/ios/Hackpad/Icons/online.png b/client/ios/Hackpad/Icons/online.png new file mode 100644 index 0000000..1353e58 Binary files /dev/null and b/client/ios/Hackpad/Icons/online.png differ diff --git a/client/ios/Hackpad/Icons/online@2x.png b/client/ios/Hackpad/Icons/online@2x.png new file mode 100644 index 0000000..a937384 Binary files /dev/null and b/client/ios/Hackpad/Icons/online@2x.png differ diff --git a/client/ios/Hackpad/Icons/outdent.png b/client/ios/Hackpad/Icons/outdent.png new file mode 100644 index 0000000..611f59a Binary files /dev/null and b/client/ios/Hackpad/Icons/outdent.png differ diff --git a/client/ios/Hackpad/Icons/outdent@2x.png b/client/ios/Hackpad/Icons/outdent@2x.png new file mode 100644 index 0000000..ccc1ef1 Binary files /dev/null and b/client/ios/Hackpad/Icons/outdent@2x.png differ diff --git a/client/ios/Hackpad/Icons/paragraph.png b/client/ios/Hackpad/Icons/paragraph.png new file mode 100644 index 0000000..89cba31 Binary files /dev/null and b/client/ios/Hackpad/Icons/paragraph.png differ diff --git a/client/ios/Hackpad/Icons/paragraph@2x.png b/client/ios/Hackpad/Icons/paragraph@2x.png new file mode 100644 index 0000000..c6c779f Binary files /dev/null and b/client/ios/Hackpad/Icons/paragraph@2x.png differ diff --git a/client/ios/Hackpad/Icons/password-green.png b/client/ios/Hackpad/Icons/password-green.png new file mode 100644 index 0000000..c867bcb Binary files /dev/null and b/client/ios/Hackpad/Icons/password-green.png differ diff --git a/client/ios/Hackpad/Icons/password-green@2x.png b/client/ios/Hackpad/Icons/password-green@2x.png new file mode 100644 index 0000000..efbfc89 Binary files /dev/null and b/client/ios/Hackpad/Icons/password-green@2x.png differ diff --git a/client/ios/Hackpad/Icons/pencilLove.png b/client/ios/Hackpad/Icons/pencilLove.png new file mode 100644 index 0000000..e5dffbf Binary files /dev/null and b/client/ios/Hackpad/Icons/pencilLove.png differ diff --git a/client/ios/Hackpad/Icons/pencilLove@2x.png b/client/ios/Hackpad/Icons/pencilLove@2x.png new file mode 100644 index 0000000..a3afe92 Binary files /dev/null and b/client/ios/Hackpad/Icons/pencilLove@2x.png differ diff --git a/client/ios/Hackpad/Icons/photo.png b/client/ios/Hackpad/Icons/photo.png new file mode 100644 index 0000000..618b288 Binary files /dev/null and b/client/ios/Hackpad/Icons/photo.png differ diff --git a/client/ios/Hackpad/Icons/photo@2x.png b/client/ios/Hackpad/Icons/photo@2x.png new file mode 100644 index 0000000..e7931bb Binary files /dev/null and b/client/ios/Hackpad/Icons/photo@2x.png differ diff --git a/client/ios/Hackpad/Icons/search.png b/client/ios/Hackpad/Icons/search.png new file mode 100644 index 0000000..1240d83 Binary files /dev/null and b/client/ios/Hackpad/Icons/search.png differ diff --git a/client/ios/Hackpad/Icons/search@2x.png b/client/ios/Hackpad/Icons/search@2x.png new file mode 100644 index 0000000..d30a09a Binary files /dev/null and b/client/ios/Hackpad/Icons/search@2x.png differ diff --git a/client/ios/Hackpad/Icons/separator.png b/client/ios/Hackpad/Icons/separator.png new file mode 100644 index 0000000..0bca66e Binary files /dev/null and b/client/ios/Hackpad/Icons/separator.png differ diff --git a/client/ios/Hackpad/Icons/separator@2x.png b/client/ios/Hackpad/Icons/separator@2x.png new file mode 100644 index 0000000..eabcd4e Binary files /dev/null and b/client/ios/Hackpad/Icons/separator@2x.png differ diff --git a/client/ios/Hackpad/Icons/site-switcher.png b/client/ios/Hackpad/Icons/site-switcher.png new file mode 100644 index 0000000..5c2e9e5 Binary files /dev/null and b/client/ios/Hackpad/Icons/site-switcher.png differ diff --git a/client/ios/Hackpad/Icons/strikethrough.png b/client/ios/Hackpad/Icons/strikethrough.png new file mode 100644 index 0000000..74d1195 Binary files /dev/null and b/client/ios/Hackpad/Icons/strikethrough.png differ diff --git a/client/ios/Hackpad/Icons/strikethrough@2x.png b/client/ios/Hackpad/Icons/strikethrough@2x.png new file mode 100644 index 0000000..0370033 Binary files /dev/null and b/client/ios/Hackpad/Icons/strikethrough@2x.png differ diff --git a/client/ios/Hackpad/Icons/table.png b/client/ios/Hackpad/Icons/table.png new file mode 100644 index 0000000..3d1f614 Binary files /dev/null and b/client/ios/Hackpad/Icons/table.png differ diff --git a/client/ios/Hackpad/Icons/table@2x.png b/client/ios/Hackpad/Icons/table@2x.png new file mode 100644 index 0000000..04f6e87 Binary files /dev/null and b/client/ios/Hackpad/Icons/table@2x.png differ diff --git a/client/ios/Hackpad/Icons/tag.png b/client/ios/Hackpad/Icons/tag.png new file mode 100644 index 0000000..1a94ea8 Binary files /dev/null and b/client/ios/Hackpad/Icons/tag.png differ diff --git a/client/ios/Hackpad/Icons/tag@2x.png b/client/ios/Hackpad/Icons/tag@2x.png new file mode 100644 index 0000000..2506adf Binary files /dev/null and b/client/ios/Hackpad/Icons/tag@2x.png differ diff --git a/client/ios/Hackpad/Icons/textformat.png b/client/ios/Hackpad/Icons/textformat.png new file mode 100644 index 0000000..7d8525b Binary files /dev/null and b/client/ios/Hackpad/Icons/textformat.png differ diff --git a/client/ios/Hackpad/Icons/textformat@2x.png b/client/ios/Hackpad/Icons/textformat@2x.png new file mode 100644 index 0000000..cbaf2d4 Binary files /dev/null and b/client/ios/Hackpad/Icons/textformat@2x.png differ diff --git a/client/ios/Hackpad/Icons/underline.png b/client/ios/Hackpad/Icons/underline.png new file mode 100644 index 0000000..e161e5f Binary files /dev/null and b/client/ios/Hackpad/Icons/underline.png differ diff --git a/client/ios/Hackpad/Icons/underline@2x.png b/client/ios/Hackpad/Icons/underline@2x.png new file mode 100644 index 0000000..2d9c328 Binary files /dev/null and b/client/ios/Hackpad/Icons/underline@2x.png differ diff --git a/client/ios/Hackpad/Icons/up-chevron.png b/client/ios/Hackpad/Icons/up-chevron.png new file mode 100644 index 0000000..0ec0624 Binary files /dev/null and b/client/ios/Hackpad/Icons/up-chevron.png differ diff --git a/client/ios/Hackpad/Icons/up-chevron@2x.png b/client/ios/Hackpad/Icons/up-chevron@2x.png new file mode 100644 index 0000000..9bf826b Binary files /dev/null and b/client/ios/Hackpad/Icons/up-chevron@2x.png differ diff --git a/client/ios/Hackpad/Icons/user-green.png b/client/ios/Hackpad/Icons/user-green.png new file mode 100644 index 0000000..7c8144a Binary files /dev/null and b/client/ios/Hackpad/Icons/user-green.png differ diff --git a/client/ios/Hackpad/Icons/user-green@2x.png b/client/ios/Hackpad/Icons/user-green@2x.png new file mode 100644 index 0000000..f8f3a86 Binary files /dev/null and b/client/ios/Hackpad/Icons/user-green@2x.png differ diff --git a/client/ios/Hackpad/Icons/user.png b/client/ios/Hackpad/Icons/user.png new file mode 100644 index 0000000..91d14c8 Binary files /dev/null and b/client/ios/Hackpad/Icons/user.png differ diff --git a/client/ios/Hackpad/Icons/user@2x.png b/client/ios/Hackpad/Icons/user@2x.png new file mode 100644 index 0000000..eb57862 Binary files /dev/null and b/client/ios/Hackpad/Icons/user@2x.png differ diff --git a/client/ios/Hackpad/Icons/whiteback.png b/client/ios/Hackpad/Icons/whiteback.png new file mode 100644 index 0000000..e67e9e7 Binary files /dev/null and b/client/ios/Hackpad/Icons/whiteback.png differ diff --git a/client/ios/Hackpad/Icons/whiteback@2x.png b/client/ios/Hackpad/Icons/whiteback@2x.png new file mode 100644 index 0000000..e40921b Binary files /dev/null and b/client/ios/Hackpad/Icons/whiteback@2x.png differ diff --git a/client/ios/Hackpad/Icons/whitebacklandscape.png b/client/ios/Hackpad/Icons/whitebacklandscape.png new file mode 100644 index 0000000..5bc6536 Binary files /dev/null and b/client/ios/Hackpad/Icons/whitebacklandscape.png differ diff --git a/client/ios/Hackpad/Icons/whitebacklandscape@2x.png b/client/ios/Hackpad/Icons/whitebacklandscape@2x.png new file mode 100644 index 0000000..4c39984 Binary files /dev/null and b/client/ios/Hackpad/Icons/whitebacklandscape@2x.png differ diff --git a/client/ios/Hackpad/Icons/whitebg.png b/client/ios/Hackpad/Icons/whitebg.png new file mode 100644 index 0000000..536ee93 Binary files /dev/null and b/client/ios/Hackpad/Icons/whitebg.png differ diff --git a/client/ios/Hackpad/Icons/x-red.png b/client/ios/Hackpad/Icons/x-red.png new file mode 100644 index 0000000..3d7652d Binary files /dev/null and b/client/ios/Hackpad/Icons/x-red.png differ diff --git a/client/ios/Hackpad/Icons/x-red@2x.png b/client/ios/Hackpad/Icons/x-red@2x.png new file mode 100644 index 0000000..3296f72 Binary files /dev/null and b/client/ios/Hackpad/Icons/x-red@2x.png differ diff --git a/client/ios/Hackpad/MBProgressHUD/LICENSE b/client/ios/Hackpad/MBProgressHUD/LICENSE new file mode 100644 index 0000000..c51b6b0 --- /dev/null +++ b/client/ios/Hackpad/MBProgressHUD/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2013 Matej Bukovinski + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/client/ios/Hackpad/MBProgressHUD/MBProgressHUD.h b/client/ios/Hackpad/MBProgressHUD/MBProgressHUD.h new file mode 100644 index 0000000..00084f5 --- /dev/null +++ b/client/ios/Hackpad/MBProgressHUD/MBProgressHUD.h @@ -0,0 +1,500 @@ +// +// MBProgressHUD.h +// Version 0.8 +// Created by Matej Bukovinski on 2.4.09. +// + +// This code is distributed under the terms and conditions of the MIT license. + +// Copyright (c) 2013 Matej Bukovinski +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import +#import +#import + +@protocol MBProgressHUDDelegate; + + +typedef enum { + /** Progress is shown using an UIActivityIndicatorView. This is the default. */ + MBProgressHUDModeIndeterminate, + /** Progress is shown using a round, pie-chart like, progress view. */ + MBProgressHUDModeDeterminate, + /** Progress is shown using a horizontal progress bar */ + MBProgressHUDModeDeterminateHorizontalBar, + /** Progress is shown using a ring-shaped progress view. */ + MBProgressHUDModeAnnularDeterminate, + /** Shows a custom view */ + MBProgressHUDModeCustomView, + /** Shows only labels */ + MBProgressHUDModeText +} MBProgressHUDMode; + +typedef enum { + /** Opacity animation */ + MBProgressHUDAnimationFade, + /** Opacity + scale animation */ + MBProgressHUDAnimationZoom, + MBProgressHUDAnimationZoomOut = MBProgressHUDAnimationZoom, + MBProgressHUDAnimationZoomIn +} MBProgressHUDAnimation; + + +#ifndef MB_INSTANCETYPE +#if __has_feature(objc_instancetype) + #define MB_INSTANCETYPE instancetype +#else + #define MB_INSTANCETYPE id +#endif +#endif + +#ifndef MB_STRONG +#if __has_feature(objc_arc) + #define MB_STRONG strong +#else + #define MB_STRONG retain +#endif +#endif + +#ifndef MB_WEAK +#if __has_feature(objc_arc_weak) + #define MB_WEAK weak +#elif __has_feature(objc_arc) + #define MB_WEAK unsafe_unretained +#else + #define MB_WEAK assign +#endif +#endif + +#if NS_BLOCKS_AVAILABLE +typedef void (^MBProgressHUDCompletionBlock)(); +#endif + + +/** + * Displays a simple HUD window containing a progress indicator and two optional labels for short messages. + * + * This is a simple drop-in class for displaying a progress HUD view similar to Apple's private UIProgressHUD class. + * The MBProgressHUD window spans over the entire space given to it by the initWithFrame constructor and catches all + * user input on this region, thereby preventing the user operations on components below the view. The HUD itself is + * drawn centered as a rounded semi-transparent view which resizes depending on the user specified content. + * + * This view supports four modes of operation: + * - MBProgressHUDModeIndeterminate - shows a UIActivityIndicatorView + * - MBProgressHUDModeDeterminate - shows a custom round progress indicator + * - MBProgressHUDModeAnnularDeterminate - shows a custom annular progress indicator + * - MBProgressHUDModeCustomView - shows an arbitrary, user specified view (@see customView) + * + * All three modes can have optional labels assigned: + * - If the labelText property is set and non-empty then a label containing the provided content is placed below the + * indicator view. + * - If also the detailsLabelText property is set then another label is placed below the first label. + */ +@interface MBProgressHUD : UIView + +/** + * Creates a new HUD, adds it to provided view and shows it. The counterpart to this method is hideHUDForView:animated:. + * + * @param view The view that the HUD will be added to + * @param animated If set to YES the HUD will appear using the current animationType. If set to NO the HUD will not use + * animations while appearing. + * @return A reference to the created HUD. + * + * @see hideHUDForView:animated: + * @see animationType + */ ++ (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view animated:(BOOL)animated; + +/** + * Finds the top-most HUD subview and hides it. The counterpart to this method is showHUDAddedTo:animated:. + * + * @param view The view that is going to be searched for a HUD subview. + * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use + * animations while disappearing. + * @return YES if a HUD was found and removed, NO otherwise. + * + * @see showHUDAddedTo:animated: + * @see animationType + */ ++ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated; + +/** + * Finds all the HUD subviews and hides them. + * + * @param view The view that is going to be searched for HUD subviews. + * @param animated If set to YES the HUDs will disappear using the current animationType. If set to NO the HUDs will not use + * animations while disappearing. + * @return the number of HUDs found and removed. + * + * @see hideHUDForView:animated: + * @see animationType + */ ++ (NSUInteger)hideAllHUDsForView:(UIView *)view animated:(BOOL)animated; + +/** + * Finds the top-most HUD subview and returns it. + * + * @param view The view that is going to be searched. + * @return A reference to the last HUD subview discovered. + */ ++ (MB_INSTANCETYPE)HUDForView:(UIView *)view; + +/** + * Finds all HUD subviews and returns them. + * + * @param view The view that is going to be searched. + * @return All found HUD views (array of MBProgressHUD objects). + */ ++ (NSArray *)allHUDsForView:(UIView *)view; + +/** + * A convenience constructor that initializes the HUD with the window's bounds. Calls the designated constructor with + * window.bounds as the parameter. + * + * @param window The window instance that will provide the bounds for the HUD. Should be the same instance as + * the HUD's superview (i.e., the window that the HUD will be added to). + */ +- (id)initWithWindow:(UIWindow *)window; + +/** + * A convenience constructor that initializes the HUD with the view's bounds. Calls the designated constructor with + * view.bounds as the parameter + * + * @param view The view instance that will provide the bounds for the HUD. Should be the same instance as + * the HUD's superview (i.e., the view that the HUD will be added to). + */ +- (id)initWithView:(UIView *)view; + +/** + * Display the HUD. You need to make sure that the main thread completes its run loop soon after this method call so + * the user interface can be updated. Call this method when your task is already set-up to be executed in a new thread + * (e.g., when using something like NSOperation or calling an asynchronous call like NSURLRequest). + * + * @param animated If set to YES the HUD will appear using the current animationType. If set to NO the HUD will not use + * animations while appearing. + * + * @see animationType + */ +- (void)show:(BOOL)animated; + +/** + * Hide the HUD. This still calls the hudWasHidden: delegate. This is the counterpart of the show: method. Use it to + * hide the HUD when your task completes. + * + * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use + * animations while disappearing. + * + * @see animationType + */ +- (void)hide:(BOOL)animated; + +/** + * Hide the HUD after a delay. This still calls the hudWasHidden: delegate. This is the counterpart of the show: method. Use it to + * hide the HUD when your task completes. + * + * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use + * animations while disappearing. + * @param delay Delay in seconds until the HUD is hidden. + * + * @see animationType + */ +- (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay; + +/** + * Shows the HUD while a background task is executing in a new thread, then hides the HUD. + * + * This method also takes care of autorelease pools so your method does not have to be concerned with setting up a + * pool. + * + * @param method The method to be executed while the HUD is shown. This method will be executed in a new thread. + * @param target The object that the target method belongs to. + * @param object An optional object to be passed to the method. + * @param animated If set to YES the HUD will (dis)appear using the current animationType. If set to NO the HUD will not use + * animations while (dis)appearing. + */ +- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated; + +#if NS_BLOCKS_AVAILABLE + +/** + * Shows the HUD while a block is executing on a background queue, then hides the HUD. + * + * @see showAnimated:whileExecutingBlock:onQueue:completionBlock: + */ +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block; + +/** + * Shows the HUD while a block is executing on a background queue, then hides the HUD. + * + * @see showAnimated:whileExecutingBlock:onQueue:completionBlock: + */ +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(MBProgressHUDCompletionBlock)completion; + +/** + * Shows the HUD while a block is executing on the specified dispatch queue, then hides the HUD. + * + * @see showAnimated:whileExecutingBlock:onQueue:completionBlock: + */ +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue; + +/** + * Shows the HUD while a block is executing on the specified dispatch queue, executes completion block on the main queue, and then hides the HUD. + * + * @param animated If set to YES the HUD will (dis)appear using the current animationType. If set to NO the HUD will + * not use animations while (dis)appearing. + * @param block The block to be executed while the HUD is shown. + * @param queue The dispatch queue on which the block should be executed. + * @param completion The block to be executed on completion. + * + * @see completionBlock + */ +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue + completionBlock:(MBProgressHUDCompletionBlock)completion; + +/** + * A block that gets called after the HUD was completely hidden. + */ +@property (copy) MBProgressHUDCompletionBlock completionBlock; + +#endif + +/** + * MBProgressHUD operation mode. The default is MBProgressHUDModeIndeterminate. + * + * @see MBProgressHUDMode + */ +@property (assign) MBProgressHUDMode mode; + +/** + * The animation type that should be used when the HUD is shown and hidden. + * + * @see MBProgressHUDAnimation + */ +@property (assign) MBProgressHUDAnimation animationType; + +/** + * The UIView (e.g., a UIImageView) to be shown when the HUD is in MBProgressHUDModeCustomView. + * For best results use a 37 by 37 pixel view (so the bounds match the built in indicator bounds). + */ +@property (MB_STRONG) UIView *customView; + +/** + * The HUD delegate object. + * + * @see MBProgressHUDDelegate + */ +@property (MB_WEAK) id delegate; + +/** + * An optional short message to be displayed below the activity indicator. The HUD is automatically resized to fit + * the entire text. If the text is too long it will get clipped by displaying "..." at the end. If left unchanged or + * set to @"", then no message is displayed. + */ +@property (copy) NSString *labelText; + +/** + * An optional details message displayed below the labelText message. This message is displayed only if the labelText + * property is also set and is different from an empty string (@""). The details text can span multiple lines. + */ +@property (copy) NSString *detailsLabelText; + +/** + * The opacity of the HUD window. Defaults to 0.8 (80% opacity). + */ +@property (assign) float opacity; + +/** + * The color of the HUD window. Defaults to black. If this property is set, color is set using + * this UIColor and the opacity property is not used. using retain because performing copy on + * UIColor base colors (like [UIColor greenColor]) cause problems with the copyZone. + */ +@property (MB_STRONG) UIColor *color; + +/** + * The x-axis offset of the HUD relative to the centre of the superview. + */ +@property (assign) float xOffset; + +/** + * The y-axis offset of the HUD relative to the centre of the superview. + */ +@property (assign) float yOffset; + +/** + * The amount of space between the HUD edge and the HUD elements (labels, indicators or custom views). + * Defaults to 20.0 + */ +@property (assign) float margin; + +/** + * The corner radius for th HUD + * Defaults to 10.0 + */ +@property (assign) float cornerRadius; + +/** + * Cover the HUD background view with a radial gradient. + */ +@property (assign) BOOL dimBackground; + +/* + * Grace period is the time (in seconds) that the invoked method may be run without + * showing the HUD. If the task finishes before the grace time runs out, the HUD will + * not be shown at all. + * This may be used to prevent HUD display for very short tasks. + * Defaults to 0 (no grace time). + * Grace time functionality is only supported when the task status is known! + * @see taskInProgress + */ +@property (assign) float graceTime; + +/** + * The minimum time (in seconds) that the HUD is shown. + * This avoids the problem of the HUD being shown and than instantly hidden. + * Defaults to 0 (no minimum show time). + */ +@property (assign) float minShowTime; + +/** + * Indicates that the executed operation is in progress. Needed for correct graceTime operation. + * If you don't set a graceTime (different than 0.0) this does nothing. + * This property is automatically set when using showWhileExecuting:onTarget:withObject:animated:. + * When threading is done outside of the HUD (i.e., when the show: and hide: methods are used directly), + * you need to set this property when your task starts and completes in order to have normal graceTime + * functionality. + */ +@property (assign) BOOL taskInProgress; + +/** + * Removes the HUD from its parent view when hidden. + * Defaults to NO. + */ +@property (assign) BOOL removeFromSuperViewOnHide; + +/** + * Font to be used for the main label. Set this property if the default is not adequate. + */ +@property (MB_STRONG) UIFont* labelFont; + +/** + * Color to be used for the main label. Set this property if the default is not adequate. + */ +@property (MB_STRONG) UIColor* labelColor; + +/** + * Font to be used for the details label. Set this property if the default is not adequate. + */ +@property (MB_STRONG) UIFont* detailsLabelFont; + +/** + * Color to be used for the details label. Set this property if the default is not adequate. + */ +@property (MB_STRONG) UIColor* detailsLabelColor; + +/** + * The progress of the progress indicator, from 0.0 to 1.0. Defaults to 0.0. + */ +@property (assign) float progress; + +/** + * The minimum size of the HUD bezel. Defaults to CGSizeZero (no minimum size). + */ +@property (assign) CGSize minSize; + +/** + * Force the HUD dimensions to be equal if possible. + */ +@property (assign, getter = isSquare) BOOL square; + +@end + + +@protocol MBProgressHUDDelegate + +@optional + +/** + * Called after the HUD was fully hidden from the screen. + */ +- (void)hudWasHidden:(MBProgressHUD *)hud; + +@end + + +/** + * A progress view for showing definite progress by filling up a circle (pie chart). + */ +@interface MBRoundProgressView : UIView + +/** + * Progress (0.0 to 1.0) + */ +@property (nonatomic, assign) float progress; + +/** + * Indicator progress color. + * Defaults to white [UIColor whiteColor] + */ +@property (nonatomic, MB_STRONG) UIColor *progressTintColor; + +/** + * Indicator background (non-progress) color. + * Defaults to translucent white (alpha 0.1) + */ +@property (nonatomic, MB_STRONG) UIColor *backgroundTintColor; + +/* + * Display mode - NO = round or YES = annular. Defaults to round. + */ +@property (nonatomic, assign, getter = isAnnular) BOOL annular; + +@end + + +/** + * A flat bar progress view. + */ +@interface MBBarProgressView : UIView + +/** + * Progress (0.0 to 1.0) + */ +@property (nonatomic, assign) float progress; + +/** + * Bar border line color. + * Defaults to white [UIColor whiteColor]. + */ +@property (nonatomic, MB_STRONG) UIColor *lineColor; + +/** + * Bar background color. + * Defaults to clear [UIColor clearColor]; + */ +@property (nonatomic, MB_STRONG) UIColor *progressRemainingColor; + +/** + * Bar progress color. + * Defaults to white [UIColor whiteColor]. + */ +@property (nonatomic, MB_STRONG) UIColor *progressColor; + +@end diff --git a/client/ios/Hackpad/MBProgressHUD/MBProgressHUD.m b/client/ios/Hackpad/MBProgressHUD/MBProgressHUD.m new file mode 100644 index 0000000..fc55e8e --- /dev/null +++ b/client/ios/Hackpad/MBProgressHUD/MBProgressHUD.m @@ -0,0 +1,1018 @@ +// +// MBProgressHUD.m +// Version 0.8 +// Created by Matej Bukovinski on 2.4.09. +// + +#import "MBProgressHUD.h" +#import + + +#if __has_feature(objc_arc) + #define MB_AUTORELEASE(exp) exp + #define MB_RELEASE(exp) exp + #define MB_RETAIN(exp) exp +#else + #define MB_AUTORELEASE(exp) [exp autorelease] + #define MB_RELEASE(exp) [exp release] + #define MB_RETAIN(exp) [exp retain] +#endif + +#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 + #define MBLabelAlignmentCenter NSTextAlignmentCenter +#else + #define MBLabelAlignmentCenter UITextAlignmentCenter +#endif + +#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 + #define MB_TEXTSIZE(text, font) [text length] > 0 ? [text \ + sizeWithAttributes:@{NSFontAttributeName:font}] : CGSizeZero; +#else + #define MB_TEXTSIZE(text, font) [text length] > 0 ? [text sizeWithFont:font] : CGSizeZero; +#endif + +#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 + #define MB_MULTILINE_TEXTSIZE(text, font, maxSize, mode) [text length] > 0 ? [text \ + boundingRectWithSize:maxSize options:(NSStringDrawingUsesLineFragmentOrigin) \ + attributes:@{NSFontAttributeName:font} context:nil].size : CGSizeZero; +#else + #define MB_MULTILINE_TEXTSIZE(text, font, maxSize, mode) [text length] > 0 ? [text \ + sizeWithFont:font constrainedToSize:maxSize lineBreakMode:mode] : CGSizeZero; +#endif + + +static const CGFloat kPadding = 4.f; +static const CGFloat kLabelFontSize = 16.f; +static const CGFloat kDetailsLabelFontSize = 12.f; + + +@interface MBProgressHUD () + +- (void)setupLabels; +- (void)registerForKVO; +- (void)unregisterFromKVO; +- (NSArray *)observableKeypaths; +- (void)registerForNotifications; +- (void)unregisterFromNotifications; +- (void)updateUIForKeypath:(NSString *)keyPath; +- (void)hideUsingAnimation:(BOOL)animated; +- (void)showUsingAnimation:(BOOL)animated; +- (void)done; +- (void)updateIndicators; +- (void)handleGraceTimer:(NSTimer *)theTimer; +- (void)handleMinShowTimer:(NSTimer *)theTimer; +- (void)setTransformForCurrentOrientation:(BOOL)animated; +- (void)cleanUp; +- (void)launchExecution; +- (void)deviceOrientationDidChange:(NSNotification *)notification; +- (void)hideDelayed:(NSNumber *)animated; + +@property (atomic, MB_STRONG) UIView *indicator; +@property (atomic, MB_STRONG) NSTimer *graceTimer; +@property (atomic, MB_STRONG) NSTimer *minShowTimer; +@property (atomic, MB_STRONG) NSDate *showStarted; +@property (atomic, assign) CGSize size; + +@end + + +@implementation MBProgressHUD { + BOOL useAnimation; + SEL methodForExecution; + id targetForExecution; + id objectForExecution; + UILabel *label; + UILabel *detailsLabel; + BOOL isFinished; + CGAffineTransform rotationTransform; +} + +#pragma mark - Properties + +@synthesize animationType; +@synthesize delegate; +@synthesize opacity; +@synthesize color; +@synthesize labelFont; +@synthesize labelColor; +@synthesize detailsLabelFont; +@synthesize detailsLabelColor; +@synthesize indicator; +@synthesize xOffset; +@synthesize yOffset; +@synthesize minSize; +@synthesize square; +@synthesize margin; +@synthesize dimBackground; +@synthesize graceTime; +@synthesize minShowTime; +@synthesize graceTimer; +@synthesize minShowTimer; +@synthesize taskInProgress; +@synthesize removeFromSuperViewOnHide; +@synthesize customView; +@synthesize showStarted; +@synthesize mode; +@synthesize labelText; +@synthesize detailsLabelText; +@synthesize progress; +@synthesize size; +#if NS_BLOCKS_AVAILABLE +@synthesize completionBlock; +#endif + +#pragma mark - Class methods + ++ (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view animated:(BOOL)animated { + MBProgressHUD *hud = [[self alloc] initWithView:view]; + [view addSubview:hud]; + [hud show:animated]; + return MB_AUTORELEASE(hud); +} + ++ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated { + MBProgressHUD *hud = [self HUDForView:view]; + if (hud != nil) { + hud.removeFromSuperViewOnHide = YES; + [hud hide:animated]; + return YES; + } + return NO; +} + ++ (NSUInteger)hideAllHUDsForView:(UIView *)view animated:(BOOL)animated { + NSArray *huds = [MBProgressHUD allHUDsForView:view]; + for (MBProgressHUD *hud in huds) { + hud.removeFromSuperViewOnHide = YES; + [hud hide:animated]; + } + return [huds count]; +} + ++ (MB_INSTANCETYPE)HUDForView:(UIView *)view { + NSEnumerator *subviewsEnum = [view.subviews reverseObjectEnumerator]; + for (UIView *subview in subviewsEnum) { + if ([subview isKindOfClass:self]) { + return (MBProgressHUD *)subview; + } + } + return nil; +} + ++ (NSArray *)allHUDsForView:(UIView *)view { + NSMutableArray *huds = [NSMutableArray array]; + NSArray *subviews = view.subviews; + for (UIView *aView in subviews) { + if ([aView isKindOfClass:self]) { + [huds addObject:aView]; + } + } + return [NSArray arrayWithArray:huds]; +} + +#pragma mark - Lifecycle + +- (id)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + // Set default values for properties + self.animationType = MBProgressHUDAnimationFade; + self.mode = MBProgressHUDModeIndeterminate; + self.labelText = nil; + self.detailsLabelText = nil; + self.opacity = 0.8f; + self.color = nil; + self.labelFont = [UIFont boldSystemFontOfSize:kLabelFontSize]; + self.labelColor = [UIColor whiteColor]; + self.detailsLabelFont = [UIFont boldSystemFontOfSize:kDetailsLabelFontSize]; + self.detailsLabelColor = [UIColor whiteColor]; + self.xOffset = 0.0f; + self.yOffset = 0.0f; + self.dimBackground = NO; + self.margin = 20.0f; + self.cornerRadius = 10.0f; + self.graceTime = 0.0f; + self.minShowTime = 0.0f; + self.removeFromSuperViewOnHide = NO; + self.minSize = CGSizeZero; + self.square = NO; + self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin + | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; + + // Transparent background + self.opaque = NO; + self.backgroundColor = [UIColor clearColor]; + // Make it invisible for now + self.alpha = 0.0f; + + taskInProgress = NO; + rotationTransform = CGAffineTransformIdentity; + + [self setupLabels]; + [self updateIndicators]; + [self registerForKVO]; + [self registerForNotifications]; + } + return self; +} + +- (id)initWithView:(UIView *)view { + NSAssert(view, @"View must not be nil."); + return [self initWithFrame:view.bounds]; +} + +- (id)initWithWindow:(UIWindow *)window { + return [self initWithView:window]; +} + +- (void)dealloc { + [self unregisterFromNotifications]; + [self unregisterFromKVO]; +#if !__has_feature(objc_arc) + [color release]; + [indicator release]; + [label release]; + [detailsLabel release]; + [labelText release]; + [detailsLabelText release]; + [graceTimer release]; + [minShowTimer release]; + [showStarted release]; + [customView release]; +#if NS_BLOCKS_AVAILABLE + [completionBlock release]; +#endif + [super dealloc]; +#endif +} + +#pragma mark - Show & hide + +- (void)show:(BOOL)animated { + useAnimation = animated; + // If the grace time is set postpone the HUD display + if (self.graceTime > 0.0) { + self.graceTimer = [NSTimer scheduledTimerWithTimeInterval:self.graceTime target:self + selector:@selector(handleGraceTimer:) userInfo:nil repeats:NO]; + } + // ... otherwise show the HUD imediately + else { + [self setNeedsDisplay]; + [self showUsingAnimation:useAnimation]; + } +} + +- (void)hide:(BOOL)animated { + useAnimation = animated; + // If the minShow time is set, calculate how long the hud was shown, + // and pospone the hiding operation if necessary + if (self.minShowTime > 0.0 && showStarted) { + NSTimeInterval interv = [[NSDate date] timeIntervalSinceDate:showStarted]; + if (interv < self.minShowTime) { + self.minShowTimer = [NSTimer scheduledTimerWithTimeInterval:(self.minShowTime - interv) target:self + selector:@selector(handleMinShowTimer:) userInfo:nil repeats:NO]; + return; + } + } + // ... otherwise hide the HUD immediately + [self hideUsingAnimation:useAnimation]; +} + +- (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay { + [self performSelector:@selector(hideDelayed:) withObject:[NSNumber numberWithBool:animated] afterDelay:delay]; +} + +- (void)hideDelayed:(NSNumber *)animated { + [self hide:[animated boolValue]]; +} + +#pragma mark - Timer callbacks + +- (void)handleGraceTimer:(NSTimer *)theTimer { + // Show the HUD only if the task is still running + if (taskInProgress) { + [self setNeedsDisplay]; + [self showUsingAnimation:useAnimation]; + } +} + +- (void)handleMinShowTimer:(NSTimer *)theTimer { + [self hideUsingAnimation:useAnimation]; +} + +#pragma mark - View Hierrarchy + +- (void)didMoveToSuperview { + // We need to take care of rotation ourselfs if we're adding the HUD to a window + if ([self.superview isKindOfClass:[UIWindow class]]) { + [self setTransformForCurrentOrientation:NO]; + } +} + +#pragma mark - Internal show & hide operations + +- (void)showUsingAnimation:(BOOL)animated { + if (animated && animationType == MBProgressHUDAnimationZoomIn) { + self.transform = CGAffineTransformConcat(rotationTransform, CGAffineTransformMakeScale(0.5f, 0.5f)); + } else if (animated && animationType == MBProgressHUDAnimationZoomOut) { + self.transform = CGAffineTransformConcat(rotationTransform, CGAffineTransformMakeScale(1.5f, 1.5f)); + } + self.showStarted = [NSDate date]; + // Fade in + if (animated) { + [UIView beginAnimations:nil context:NULL]; + [UIView setAnimationDuration:0.30]; + self.alpha = 1.0f; + if (animationType == MBProgressHUDAnimationZoomIn || animationType == MBProgressHUDAnimationZoomOut) { + self.transform = rotationTransform; + } + [UIView commitAnimations]; + } + else { + self.alpha = 1.0f; + } +} + +- (void)hideUsingAnimation:(BOOL)animated { + // Fade out + if (animated && showStarted) { + [UIView beginAnimations:nil context:NULL]; + [UIView setAnimationDuration:0.30]; + [UIView setAnimationDelegate:self]; + [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)]; + // 0.02 prevents the hud from passing through touches during the animation the hud will get completely hidden + // in the done method + if (animationType == MBProgressHUDAnimationZoomIn) { + self.transform = CGAffineTransformConcat(rotationTransform, CGAffineTransformMakeScale(1.5f, 1.5f)); + } else if (animationType == MBProgressHUDAnimationZoomOut) { + self.transform = CGAffineTransformConcat(rotationTransform, CGAffineTransformMakeScale(0.5f, 0.5f)); + } + + self.alpha = 0.02f; + [UIView commitAnimations]; + } + else { + self.alpha = 0.0f; + [self done]; + } + self.showStarted = nil; +} + +- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void*)context { + [self done]; +} + +- (void)done { + isFinished = YES; + self.alpha = 0.0f; + if (removeFromSuperViewOnHide) { + [self removeFromSuperview]; + } +#if NS_BLOCKS_AVAILABLE + if (self.completionBlock) { + self.completionBlock(); + self.completionBlock = NULL; + } +#endif + if ([delegate respondsToSelector:@selector(hudWasHidden:)]) { + [delegate performSelector:@selector(hudWasHidden:) withObject:self]; + } +} + +#pragma mark - Threading + +- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated { + methodForExecution = method; + targetForExecution = MB_RETAIN(target); + objectForExecution = MB_RETAIN(object); + // Launch execution in new thread + self.taskInProgress = YES; + [NSThread detachNewThreadSelector:@selector(launchExecution) toTarget:self withObject:nil]; + // Show HUD view + [self show:animated]; +} + +#if NS_BLOCKS_AVAILABLE + +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block { + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + [self showAnimated:animated whileExecutingBlock:block onQueue:queue completionBlock:NULL]; +} + +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(void (^)())completion { + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + [self showAnimated:animated whileExecutingBlock:block onQueue:queue completionBlock:completion]; +} + +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue { + [self showAnimated:animated whileExecutingBlock:block onQueue:queue completionBlock:NULL]; +} + +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue + completionBlock:(MBProgressHUDCompletionBlock)completion { + self.taskInProgress = YES; + self.completionBlock = completion; + dispatch_async(queue, ^(void) { + block(); + dispatch_async(dispatch_get_main_queue(), ^(void) { + [self cleanUp]; + }); + }); + [self show:animated]; +} + +#endif + +- (void)launchExecution { + @autoreleasepool { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + // Start executing the requested task + [targetForExecution performSelector:methodForExecution withObject:objectForExecution]; +#pragma clang diagnostic pop + // Task completed, update view in main thread (note: view operations should + // be done only in the main thread) + [self performSelectorOnMainThread:@selector(cleanUp) withObject:nil waitUntilDone:NO]; + } +} + +- (void)cleanUp { + taskInProgress = NO; +#if !__has_feature(objc_arc) + [targetForExecution release]; + [objectForExecution release]; +#else + targetForExecution = nil; + objectForExecution = nil; +#endif + [self hide:useAnimation]; +} + +#pragma mark - UI + +- (void)setupLabels { + label = [[UILabel alloc] initWithFrame:self.bounds]; + label.adjustsFontSizeToFitWidth = NO; + label.textAlignment = MBLabelAlignmentCenter; + label.opaque = NO; + label.backgroundColor = [UIColor clearColor]; + label.textColor = self.labelColor; + label.font = self.labelFont; + label.text = self.labelText; + [self addSubview:label]; + + detailsLabel = [[UILabel alloc] initWithFrame:self.bounds]; + detailsLabel.font = self.detailsLabelFont; + detailsLabel.adjustsFontSizeToFitWidth = NO; + detailsLabel.textAlignment = MBLabelAlignmentCenter; + detailsLabel.opaque = NO; + detailsLabel.backgroundColor = [UIColor clearColor]; + detailsLabel.textColor = self.detailsLabelColor; + detailsLabel.numberOfLines = 0; + detailsLabel.font = self.detailsLabelFont; + detailsLabel.text = self.detailsLabelText; + [self addSubview:detailsLabel]; +} + +- (void)updateIndicators { + + BOOL isActivityIndicator = [indicator isKindOfClass:[UIActivityIndicatorView class]]; + BOOL isRoundIndicator = [indicator isKindOfClass:[MBRoundProgressView class]]; + + if (mode == MBProgressHUDModeIndeterminate && !isActivityIndicator) { + // Update to indeterminate indicator + [indicator removeFromSuperview]; + self.indicator = MB_AUTORELEASE([[UIActivityIndicatorView alloc] + initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]); + [(UIActivityIndicatorView *)indicator startAnimating]; + [self addSubview:indicator]; + } + else if (mode == MBProgressHUDModeDeterminateHorizontalBar) { + // Update to bar determinate indicator + [indicator removeFromSuperview]; + self.indicator = MB_AUTORELEASE([[MBBarProgressView alloc] init]); + [self addSubview:indicator]; + } + else if (mode == MBProgressHUDModeDeterminate || mode == MBProgressHUDModeAnnularDeterminate) { + if (!isRoundIndicator) { + // Update to determinante indicator + [indicator removeFromSuperview]; + self.indicator = MB_AUTORELEASE([[MBRoundProgressView alloc] init]); + [self addSubview:indicator]; + } + if (mode == MBProgressHUDModeAnnularDeterminate) { + [(MBRoundProgressView *)indicator setAnnular:YES]; + } + } + else if (mode == MBProgressHUDModeCustomView && customView != indicator) { + // Update custom view indicator + [indicator removeFromSuperview]; + self.indicator = customView; + [self addSubview:indicator]; + } else if (mode == MBProgressHUDModeText) { + [indicator removeFromSuperview]; + self.indicator = nil; + } +} + +#pragma mark - Layout + +- (void)layoutSubviews { + + // Entirely cover the parent view + UIView *parent = self.superview; + if (parent) { + self.frame = parent.bounds; + } + CGRect bounds = self.bounds; + + // Determine the total widt and height needed + CGFloat maxWidth = bounds.size.width - 4 * margin; + CGSize totalSize = CGSizeZero; + + CGRect indicatorF = indicator.bounds; + indicatorF.size.width = MIN(indicatorF.size.width, maxWidth); + totalSize.width = MAX(totalSize.width, indicatorF.size.width); + totalSize.height += indicatorF.size.height; + + CGSize labelSize = MB_TEXTSIZE(label.text, label.font); + labelSize.width = MIN(labelSize.width, maxWidth); + totalSize.width = MAX(totalSize.width, labelSize.width); + totalSize.height += labelSize.height; + if (labelSize.height > 0.f && indicatorF.size.height > 0.f) { + totalSize.height += kPadding; + } + + CGFloat remainingHeight = bounds.size.height - totalSize.height - kPadding - 4 * margin; + CGSize maxSize = CGSizeMake(maxWidth, remainingHeight); + CGSize detailsLabelSize = MB_MULTILINE_TEXTSIZE(detailsLabel.text, detailsLabel.font, maxSize, detailsLabel.lineBreakMode); + totalSize.width = MAX(totalSize.width, detailsLabelSize.width); + totalSize.height += detailsLabelSize.height; + if (detailsLabelSize.height > 0.f && (indicatorF.size.height > 0.f || labelSize.height > 0.f)) { + totalSize.height += kPadding; + } + + totalSize.width += 2 * margin; + totalSize.height += 2 * margin; + + // Position elements + CGFloat yPos = round(((bounds.size.height - totalSize.height) / 2)) + margin + yOffset; + CGFloat xPos = xOffset; + indicatorF.origin.y = yPos; + indicatorF.origin.x = round((bounds.size.width - indicatorF.size.width) / 2) + xPos; + indicator.frame = indicatorF; + yPos += indicatorF.size.height; + + if (labelSize.height > 0.f && indicatorF.size.height > 0.f) { + yPos += kPadding; + } + CGRect labelF; + labelF.origin.y = yPos; + labelF.origin.x = round((bounds.size.width - labelSize.width) / 2) + xPos; + labelF.size = labelSize; + label.frame = labelF; + yPos += labelF.size.height; + + if (detailsLabelSize.height > 0.f && (indicatorF.size.height > 0.f || labelSize.height > 0.f)) { + yPos += kPadding; + } + CGRect detailsLabelF; + detailsLabelF.origin.y = yPos; + detailsLabelF.origin.x = round((bounds.size.width - detailsLabelSize.width) / 2) + xPos; + detailsLabelF.size = detailsLabelSize; + detailsLabel.frame = detailsLabelF; + + // Enforce minsize and quare rules + if (square) { + CGFloat max = MAX(totalSize.width, totalSize.height); + if (max <= bounds.size.width - 2 * margin) { + totalSize.width = max; + } + if (max <= bounds.size.height - 2 * margin) { + totalSize.height = max; + } + } + if (totalSize.width < minSize.width) { + totalSize.width = minSize.width; + } + if (totalSize.height < minSize.height) { + totalSize.height = minSize.height; + } + + self.size = totalSize; +} + +#pragma mark BG Drawing + +- (void)drawRect:(CGRect)rect { + + CGContextRef context = UIGraphicsGetCurrentContext(); + UIGraphicsPushContext(context); + + if (self.dimBackground) { + //Gradient colours + size_t gradLocationsNum = 2; + CGFloat gradLocations[2] = {0.0f, 1.0f}; + CGFloat gradColors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f}; + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, gradColors, gradLocations, gradLocationsNum); + CGColorSpaceRelease(colorSpace); + //Gradient center + CGPoint gradCenter= CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); + //Gradient radius + float gradRadius = MIN(self.bounds.size.width , self.bounds.size.height) ; + //Gradient draw + CGContextDrawRadialGradient (context, gradient, gradCenter, + 0, gradCenter, gradRadius, + kCGGradientDrawsAfterEndLocation); + CGGradientRelease(gradient); + } + + // Set background rect color + if (self.color) { + CGContextSetFillColorWithColor(context, self.color.CGColor); + } else { + CGContextSetGrayFillColor(context, 0.0f, self.opacity); + } + + + // Center HUD + CGRect allRect = self.bounds; + // Draw rounded HUD backgroud rect + CGRect boxRect = CGRectMake(round((allRect.size.width - size.width) / 2) + self.xOffset, + round((allRect.size.height - size.height) / 2) + self.yOffset, size.width, size.height); + float radius = self.cornerRadius; + CGContextBeginPath(context); + CGContextMoveToPoint(context, CGRectGetMinX(boxRect) + radius, CGRectGetMinY(boxRect)); + CGContextAddArc(context, CGRectGetMaxX(boxRect) - radius, CGRectGetMinY(boxRect) + radius, radius, 3 * (float)M_PI / 2, 0, 0); + CGContextAddArc(context, CGRectGetMaxX(boxRect) - radius, CGRectGetMaxY(boxRect) - radius, radius, 0, (float)M_PI / 2, 0); + CGContextAddArc(context, CGRectGetMinX(boxRect) + radius, CGRectGetMaxY(boxRect) - radius, radius, (float)M_PI / 2, (float)M_PI, 0); + CGContextAddArc(context, CGRectGetMinX(boxRect) + radius, CGRectGetMinY(boxRect) + radius, radius, (float)M_PI, 3 * (float)M_PI / 2, 0); + CGContextClosePath(context); + CGContextFillPath(context); + + UIGraphicsPopContext(); +} + +#pragma mark - KVO + +- (void)registerForKVO { + for (NSString *keyPath in [self observableKeypaths]) { + [self addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionNew context:NULL]; + } +} + +- (void)unregisterFromKVO { + for (NSString *keyPath in [self observableKeypaths]) { + [self removeObserver:self forKeyPath:keyPath]; + } +} + +- (NSArray *)observableKeypaths { + return [NSArray arrayWithObjects:@"mode", @"customView", @"labelText", @"labelFont", @"labelColor", + @"detailsLabelText", @"detailsLabelFont", @"detailsLabelColor", @"progress", nil]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + if (![NSThread isMainThread]) { + [self performSelectorOnMainThread:@selector(updateUIForKeypath:) withObject:keyPath waitUntilDone:NO]; + } else { + [self updateUIForKeypath:keyPath]; + } +} + +- (void)updateUIForKeypath:(NSString *)keyPath { + if ([keyPath isEqualToString:@"mode"] || [keyPath isEqualToString:@"customView"]) { + [self updateIndicators]; + } else if ([keyPath isEqualToString:@"labelText"]) { + label.text = self.labelText; + } else if ([keyPath isEqualToString:@"labelFont"]) { + label.font = self.labelFont; + } else if ([keyPath isEqualToString:@"labelColor"]) { + label.textColor = self.labelColor; + } else if ([keyPath isEqualToString:@"detailsLabelText"]) { + detailsLabel.text = self.detailsLabelText; + } else if ([keyPath isEqualToString:@"detailsLabelFont"]) { + detailsLabel.font = self.detailsLabelFont; + } else if ([keyPath isEqualToString:@"detailsLabelColor"]) { + detailsLabel.textColor = self.detailsLabelColor; + } else if ([keyPath isEqualToString:@"progress"]) { + if ([indicator respondsToSelector:@selector(setProgress:)]) { + [(id)indicator setProgress:progress]; + } + return; + } + [self setNeedsLayout]; + [self setNeedsDisplay]; +} + +#pragma mark - Notifications + +- (void)registerForNotifications { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + [nc addObserver:self selector:@selector(deviceOrientationDidChange:) + name:UIDeviceOrientationDidChangeNotification object:nil]; +} + +- (void)unregisterFromNotifications { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (void)deviceOrientationDidChange:(NSNotification *)notification { + UIView *superview = self.superview; + if (!superview) { + return; + } else if ([superview isKindOfClass:[UIWindow class]]) { + [self setTransformForCurrentOrientation:YES]; + } else { + self.frame = self.superview.bounds; + [self setNeedsDisplay]; + } +} + +- (void)setTransformForCurrentOrientation:(BOOL)animated { + // Stay in sync with the superview + if (self.superview) { + self.bounds = self.superview.bounds; + [self setNeedsDisplay]; + } + + UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; + CGFloat radians = 0; + if (UIInterfaceOrientationIsLandscape(orientation)) { + if (orientation == UIInterfaceOrientationLandscapeLeft) { radians = -(CGFloat)M_PI_2; } + else { radians = (CGFloat)M_PI_2; } + // Window coordinates differ! + self.bounds = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.width); + } else { + if (orientation == UIInterfaceOrientationPortraitUpsideDown) { radians = (CGFloat)M_PI; } + else { radians = 0; } + } + rotationTransform = CGAffineTransformMakeRotation(radians); + + if (animated) { + [UIView beginAnimations:nil context:nil]; + } + [self setTransform:rotationTransform]; + if (animated) { + [UIView commitAnimations]; + } +} + +@end + + +@implementation MBRoundProgressView + +#pragma mark - Lifecycle + +- (id)init { + return [self initWithFrame:CGRectMake(0.f, 0.f, 37.f, 37.f)]; +} + +- (id)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + self.backgroundColor = [UIColor clearColor]; + self.opaque = NO; + _progress = 0.f; + _annular = NO; + _progressTintColor = [[UIColor alloc] initWithWhite:1.f alpha:1.f]; + _backgroundTintColor = [[UIColor alloc] initWithWhite:1.f alpha:.1f]; + [self registerForKVO]; + } + return self; +} + +- (void)dealloc { + [self unregisterFromKVO]; +#if !__has_feature(objc_arc) + [_progressTintColor release]; + [_backgroundTintColor release]; + [super dealloc]; +#endif +} + +#pragma mark - Drawing + +- (void)drawRect:(CGRect)rect { + + CGRect allRect = self.bounds; + CGRect circleRect = CGRectInset(allRect, 2.0f, 2.0f); + CGContextRef context = UIGraphicsGetCurrentContext(); + + if (_annular) { + // Draw background + CGFloat lineWidth = 5.f; + UIBezierPath *processBackgroundPath = [UIBezierPath bezierPath]; + processBackgroundPath.lineWidth = lineWidth; + processBackgroundPath.lineCapStyle = kCGLineCapRound; + CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); + CGFloat radius = (self.bounds.size.width - lineWidth)/2; + CGFloat startAngle = - ((float)M_PI / 2); // 90 degrees + CGFloat endAngle = (2 * (float)M_PI) + startAngle; + [processBackgroundPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; + [_backgroundTintColor set]; + [processBackgroundPath stroke]; + // Draw progress + UIBezierPath *processPath = [UIBezierPath bezierPath]; + processPath.lineCapStyle = kCGLineCapRound; + processPath.lineWidth = lineWidth; + endAngle = (self.progress * 2 * (float)M_PI) + startAngle; + [processPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; + [_progressTintColor set]; + [processPath stroke]; + } else { + // Draw background + [_progressTintColor setStroke]; + [_backgroundTintColor setFill]; + CGContextSetLineWidth(context, 2.0f); + CGContextFillEllipseInRect(context, circleRect); + CGContextStrokeEllipseInRect(context, circleRect); + // Draw progress + CGPoint center = CGPointMake(allRect.size.width / 2, allRect.size.height / 2); + CGFloat radius = (allRect.size.width - 4) / 2; + CGFloat startAngle = - ((float)M_PI / 2); // 90 degrees + CGFloat endAngle = (self.progress * 2 * (float)M_PI) + startAngle; + CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f); // white + CGContextMoveToPoint(context, center.x, center.y); + CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, 0); + CGContextClosePath(context); + CGContextFillPath(context); + } +} + +#pragma mark - KVO + +- (void)registerForKVO { + for (NSString *keyPath in [self observableKeypaths]) { + [self addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionNew context:NULL]; + } +} + +- (void)unregisterFromKVO { + for (NSString *keyPath in [self observableKeypaths]) { + [self removeObserver:self forKeyPath:keyPath]; + } +} + +- (NSArray *)observableKeypaths { + return [NSArray arrayWithObjects:@"progressTintColor", @"backgroundTintColor", @"progress", @"annular", nil]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + [self setNeedsDisplay]; +} + +@end + + +@implementation MBBarProgressView + +#pragma mark - Lifecycle + +- (id)init { + return [self initWithFrame:CGRectMake(.0f, .0f, 120.0f, 20.0f)]; +} + +- (id)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + _progress = 0.f; + _lineColor = [UIColor whiteColor]; + _progressColor = [UIColor whiteColor]; + _progressRemainingColor = [UIColor clearColor]; + self.backgroundColor = [UIColor clearColor]; + self.opaque = NO; + [self registerForKVO]; + } + return self; +} + +- (void)dealloc { + [self unregisterFromKVO]; +#if !__has_feature(objc_arc) + [_lineColor release]; + [_progressColor release]; + [_progressRemainingColor release]; + [super dealloc]; +#endif +} + +#pragma mark - Drawing + +- (void)drawRect:(CGRect)rect { + CGContextRef context = UIGraphicsGetCurrentContext(); + + // setup properties + CGContextSetLineWidth(context, 2); + CGContextSetStrokeColorWithColor(context,[_lineColor CGColor]); + CGContextSetFillColorWithColor(context, [_progressRemainingColor CGColor]); + + // draw line border + float radius = (rect.size.height / 2) - 2; + CGContextMoveToPoint(context, 2, rect.size.height/2); + CGContextAddArcToPoint(context, 2, 2, radius + 2, 2, radius); + CGContextAddLineToPoint(context, rect.size.width - radius - 2, 2); + CGContextAddArcToPoint(context, rect.size.width - 2, 2, rect.size.width - 2, rect.size.height / 2, radius); + CGContextAddArcToPoint(context, rect.size.width - 2, rect.size.height - 2, rect.size.width - radius - 2, rect.size.height - 2, radius); + CGContextAddLineToPoint(context, radius + 2, rect.size.height - 2); + CGContextAddArcToPoint(context, 2, rect.size.height - 2, 2, rect.size.height/2, radius); + CGContextFillPath(context); + + // draw progress background + CGContextMoveToPoint(context, 2, rect.size.height/2); + CGContextAddArcToPoint(context, 2, 2, radius + 2, 2, radius); + CGContextAddLineToPoint(context, rect.size.width - radius - 2, 2); + CGContextAddArcToPoint(context, rect.size.width - 2, 2, rect.size.width - 2, rect.size.height / 2, radius); + CGContextAddArcToPoint(context, rect.size.width - 2, rect.size.height - 2, rect.size.width - radius - 2, rect.size.height - 2, radius); + CGContextAddLineToPoint(context, radius + 2, rect.size.height - 2); + CGContextAddArcToPoint(context, 2, rect.size.height - 2, 2, rect.size.height/2, radius); + CGContextStrokePath(context); + + // setup to draw progress color + CGContextSetFillColorWithColor(context, [_progressColor CGColor]); + radius = radius - 2; + float amount = self.progress * rect.size.width; + + // if progress is in the middle area + if (amount >= radius + 4 && amount <= (rect.size.width - radius - 4)) { + // top + CGContextMoveToPoint(context, 4, rect.size.height/2); + CGContextAddArcToPoint(context, 4, 4, radius + 4, 4, radius); + CGContextAddLineToPoint(context, amount, 4); + CGContextAddLineToPoint(context, amount, radius + 4); + + // bottom + CGContextMoveToPoint(context, 4, rect.size.height/2); + CGContextAddArcToPoint(context, 4, rect.size.height - 4, radius + 4, rect.size.height - 4, radius); + CGContextAddLineToPoint(context, amount, rect.size.height - 4); + CGContextAddLineToPoint(context, amount, radius + 4); + + CGContextFillPath(context); + } + + // progress is in the right arc + else if (amount > radius + 4) { + float x = amount - (rect.size.width - radius - 4); + + // top + CGContextMoveToPoint(context, 4, rect.size.height/2); + CGContextAddArcToPoint(context, 4, 4, radius + 4, 4, radius); + CGContextAddLineToPoint(context, rect.size.width - radius - 4, 4); + float angle = -acos(x/radius); + if (isnan(angle)) angle = 0; + CGContextAddArc(context, rect.size.width - radius - 4, rect.size.height/2, radius, M_PI, angle, 0); + CGContextAddLineToPoint(context, amount, rect.size.height/2); + + // bottom + CGContextMoveToPoint(context, 4, rect.size.height/2); + CGContextAddArcToPoint(context, 4, rect.size.height - 4, radius + 4, rect.size.height - 4, radius); + CGContextAddLineToPoint(context, rect.size.width - radius - 4, rect.size.height - 4); + angle = acos(x/radius); + if (isnan(angle)) angle = 0; + CGContextAddArc(context, rect.size.width - radius - 4, rect.size.height/2, radius, -M_PI, angle, 1); + CGContextAddLineToPoint(context, amount, rect.size.height/2); + + CGContextFillPath(context); + } + + // progress is in the left arc + else if (amount < radius + 4 && amount > 0) { + // top + CGContextMoveToPoint(context, 4, rect.size.height/2); + CGContextAddArcToPoint(context, 4, 4, radius + 4, 4, radius); + CGContextAddLineToPoint(context, radius + 4, rect.size.height/2); + + // bottom + CGContextMoveToPoint(context, 4, rect.size.height/2); + CGContextAddArcToPoint(context, 4, rect.size.height - 4, radius + 4, rect.size.height - 4, radius); + CGContextAddLineToPoint(context, radius + 4, rect.size.height/2); + + CGContextFillPath(context); + } +} + +#pragma mark - KVO + +- (void)registerForKVO { + for (NSString *keyPath in [self observableKeypaths]) { + [self addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionNew context:NULL]; + } +} + +- (void)unregisterFromKVO { + for (NSString *keyPath in [self observableKeypaths]) { + [self removeObserver:self forKeyPath:keyPath]; + } +} + +- (NSArray *)observableKeypaths { + return [NSArray arrayWithObjects:@"lineColor", @"progressRemainingColor", @"progressColor", @"progress", nil]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + [self setNeedsDisplay]; +} + +@end diff --git a/client/ios/Hackpad/NSAttributedString+DDHTML/NSAttributedString+DDHTML.h b/client/ios/Hackpad/NSAttributedString+DDHTML/NSAttributedString+DDHTML.h new file mode 100644 index 0000000..1ba8cd9 --- /dev/null +++ b/client/ios/Hackpad/NSAttributedString+DDHTML/NSAttributedString+DDHTML.h @@ -0,0 +1,39 @@ +// +// NSAttributedString+HTML.m +// +// Created by Derek Bowen +// Copyright (c) 2012, Deloitte Digital +// 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 the 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 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. +// + +#import +#import + +@interface NSAttributedString (DDHTML) + ++ (NSAttributedString *)attributedStringFromHTML:(NSString *)htmlString boldFont:(UIFont *)boldFont; ++ (NSAttributedString *)attributedStringFromHTML:(NSString *)htmlString boldFont:(UIFont *)boldFont regularFont:(UIFont *)regularFont; + +@end diff --git a/client/ios/Hackpad/NSAttributedString+DDHTML/NSAttributedString+DDHTML.m b/client/ios/Hackpad/NSAttributedString+DDHTML/NSAttributedString+DDHTML.m new file mode 100644 index 0000000..5569b7d --- /dev/null +++ b/client/ios/Hackpad/NSAttributedString+DDHTML/NSAttributedString+DDHTML.m @@ -0,0 +1,296 @@ +// +// NSAttributedString+HTML.m +// +// Created by Derek Bowen +// Copyright (c) 2012, Deloitte Digital +// 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 the 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 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. +// + +#import "NSAttributedString+DDHTML.h" +#include + +@implementation NSAttributedString (DDHTML) + ++ (NSAttributedString *)attributedStringFromHTML:(NSString *)htmlString boldFont:(UIFont *)boldFont regularFont:(UIFont *)regularFont +{ + NSUInteger length = [htmlString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + if (length > INT32_MAX) { + return nil; + } + xmlDoc *document = htmlReadMemory([htmlString cStringUsingEncoding:NSUTF8StringEncoding], (int32_t)length, nil, NULL, HTML_PARSE_NOWARNING | HTML_PARSE_NOERROR); + + if (document == NULL) + return nil; + + NSMutableAttributedString *finalAttributedString = [[NSMutableAttributedString alloc] init]; + + xmlNodePtr currentNode = document->children; + while (currentNode != NULL) { + NSAttributedString *childString = [self attributedStringFromNode:currentNode boldFont:boldFont regularFont:regularFont]; + [finalAttributedString appendAttributedString:childString]; + + currentNode = currentNode->next; + } + + return finalAttributedString; +} + ++ (NSAttributedString *)attributedStringFromHTML:(NSString *)htmlString boldFont:(UIFont *)boldFont +{ + return [self.class attributedStringFromHTML:htmlString boldFont:boldFont regularFont:nil]; +} + ++ (NSAttributedString *)attributedStringFromNode:(xmlNodePtr)xmlNode boldFont:(UIFont *)boldFont regularFont:(UIFont *)regularFont +{ + NSMutableAttributedString *nodeAttributedString = [[NSMutableAttributedString alloc] init]; + + if ((xmlNode->type != XML_ENTITY_REF_NODE) && ((xmlNode->type != XML_ELEMENT_NODE) && xmlNode->content != NULL)) { + [nodeAttributedString appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithCString:(const char *)xmlNode->content encoding:NSUTF8StringEncoding]]]; + } + + // Handle children + xmlNodePtr currentNode = xmlNode->children; + while (currentNode != NULL) { + NSAttributedString *childString = [self attributedStringFromNode:currentNode boldFont:boldFont regularFont:regularFont]; + [nodeAttributedString appendAttributedString:childString]; + + currentNode = currentNode->next; + } + + if (xmlNode->type == XML_ELEMENT_NODE) { + + NSRange nodeAttributedStringRange = NSMakeRange(0, nodeAttributedString.length); + + // Build dictionary to store attributes + NSMutableDictionary *attributeDictionary = [NSMutableDictionary dictionary]; + if (xmlNode->properties != NULL) { + xmlAttrPtr attribute = xmlNode->properties; + + while (attribute != NULL) { + NSString *attributeValue = @""; + + if (attribute->children != NULL) { + attributeValue = [NSString stringWithCString:(const char *)attribute->children->content encoding:NSUTF8StringEncoding]; + } + NSString *attributeName = [[NSString stringWithCString:(const char*)attribute->name encoding:NSUTF8StringEncoding] lowercaseString]; + [attributeDictionary setObject:attributeValue forKey:attributeName]; + + attribute = attribute->next; + } + } + + // Bold Tag + if (strncmp("b", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + if (boldFont) { + [nodeAttributedString addAttribute:NSFontAttributeName value:boldFont range:nodeAttributedStringRange]; + } + } + + // Underline Tag + else if (strncmp("u", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + [nodeAttributedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:nodeAttributedStringRange]; + } + + // Stike Tag + else if (strncmp("strike", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + [nodeAttributedString addAttribute:NSStrikethroughStyleAttributeName value:@(YES) range:nodeAttributedStringRange]; + } + + // Stoke Tag + else if (strncmp("stroke", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + UIColor *strokeColor = [UIColor purpleColor]; + NSNumber *strokeWidth = @(1.0); + + if ([attributeDictionary objectForKey:@"color"]) { + strokeColor = [self colorFromHexString:[attributeDictionary objectForKey:@"color"]]; + } + if ([attributeDictionary objectForKey:@"width"]) { + strokeWidth = @(fabs([[attributeDictionary objectForKey:@"width"] doubleValue])); + } + if (![attributeDictionary objectForKey:@"nofill"]) { + strokeWidth = @(-fabs([strokeWidth doubleValue])); + } + + [nodeAttributedString addAttribute:NSStrokeColorAttributeName value:strokeColor range:nodeAttributedStringRange]; + [nodeAttributedString addAttribute:NSStrokeWidthAttributeName value:strokeWidth range:nodeAttributedStringRange]; + } + + // Shadow Tag + else if (strncmp("shadow", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + NSShadow *shadow = [[NSShadow alloc] init]; + shadow.shadowOffset = CGSizeMake(0, 0); + shadow.shadowBlurRadius = 2.0; + shadow.shadowColor = [UIColor blackColor]; + + if ([attributeDictionary objectForKey:@"offset"]) { + shadow.shadowOffset = CGSizeFromString([attributeDictionary objectForKey:@"offset"]); + } + if ([attributeDictionary objectForKey:@"blurradius"]) { + shadow.shadowBlurRadius = [[attributeDictionary objectForKey:@"blurradius"] doubleValue]; + } + if ([attributeDictionary objectForKey:@"color"]) { + shadow.shadowColor = [self colorFromHexString:[attributeDictionary objectForKey:@"color"]]; + } + + [nodeAttributedString addAttribute:NSShadowAttributeName value:shadow range:nodeAttributedStringRange]; + } + + // Font Tag + else if (strncmp("font", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + NSString *fontName = nil; + NSNumber *fontSize = nil; + UIColor *foregroundColor = nil; + UIColor *backgroundColor = nil; + + if ([attributeDictionary objectForKey:@"face"]) { + fontName = [attributeDictionary objectForKey:@"face"]; + } + if ([attributeDictionary objectForKey:@"size"]) { + fontSize = @([[attributeDictionary objectForKey:@"size"] doubleValue]); + } + if ([attributeDictionary objectForKey:@"color"]) { + foregroundColor = [self colorFromHexString:[attributeDictionary objectForKey:@"color"]]; + } + if ([attributeDictionary objectForKey:@"backgroundcolor"]) { + backgroundColor = [self colorFromHexString:[attributeDictionary objectForKey:@"backgroundcolor"]]; + } + + if (fontName == nil && fontSize != nil) { + [nodeAttributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:[fontSize doubleValue]] range:nodeAttributedStringRange]; + } + else if (fontName != nil && fontSize == nil) { + [nodeAttributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:fontName size:12.0] range:nodeAttributedStringRange]; + } + else if (fontName != nil && fontSize != nil) { + [nodeAttributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:fontName size:[fontSize doubleValue]] range:nodeAttributedStringRange]; + } + + if (foregroundColor) { + [nodeAttributedString addAttribute:NSForegroundColorAttributeName value:foregroundColor range:nodeAttributedStringRange]; + } + if (backgroundColor) { + [nodeAttributedString addAttribute:NSBackgroundColorAttributeName value:backgroundColor range:nodeAttributedStringRange]; + } + } + + // Paragraph Tag + else if (strncmp("p", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + + if ([attributeDictionary objectForKey:@"align"]) { + NSString *alignString = [[attributeDictionary objectForKey:@"align"] lowercaseString]; + + if ([alignString isEqualToString:@"left"]) { + paragraphStyle.alignment = NSTextAlignmentLeft; + } + else if ([alignString isEqualToString:@"center"]) { + paragraphStyle.alignment = NSTextAlignmentCenter; + } + else if ([alignString isEqualToString:@"right"]) { + paragraphStyle.alignment = NSTextAlignmentRight; + } + else if ([alignString isEqualToString:@"justify"]) { + paragraphStyle.alignment = NSTextAlignmentJustified; + } + } + if ([attributeDictionary objectForKey:@"linebreakmode"]) { + NSString *lineBreakModeString = [[attributeDictionary objectForKey:@"linebreakmode"] lowercaseString]; + + if ([lineBreakModeString isEqualToString:@"wordwrapping"]) { + paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping; + } + else if ([lineBreakModeString isEqualToString:@"charwrapping"]) { + paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping; + } + else if ([lineBreakModeString isEqualToString:@"clipping"]) { + paragraphStyle.lineBreakMode = NSLineBreakByClipping; + } + else if ([lineBreakModeString isEqualToString:@"truncatinghead"]) { + paragraphStyle.lineBreakMode = NSLineBreakByTruncatingHead; + } + else if ([lineBreakModeString isEqualToString:@"truncatingtail"]) { + paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail; + } + else if ([lineBreakModeString isEqualToString:@"truncatingmiddle"]) { + paragraphStyle.lineBreakMode = NSLineBreakByTruncatingMiddle; + } + } + + if ([attributeDictionary objectForKey:@"firstlineheadindent"]) { + paragraphStyle.firstLineHeadIndent = [[attributeDictionary objectForKey:@"firstlineheadindent"] doubleValue]; + } + if ([attributeDictionary objectForKey:@"headindent"]) { + paragraphStyle.headIndent = [[attributeDictionary objectForKey:@"headindent"] doubleValue]; + } + if ([attributeDictionary objectForKey:@"hyphenationfactor"]) { + paragraphStyle.hyphenationFactor = [[attributeDictionary objectForKey:@"hyphenationfactor"] doubleValue]; + } + if ([attributeDictionary objectForKey:@"lineheightmultiple"]) { + paragraphStyle.lineHeightMultiple = [[attributeDictionary objectForKey:@"lineheightmultiple"] doubleValue]; + } + if ([attributeDictionary objectForKey:@"linespacing"]) { + paragraphStyle.lineSpacing = [[attributeDictionary objectForKey:@"linespacing"] doubleValue]; + } + if ([attributeDictionary objectForKey:@"maximumlineheight"]) { + paragraphStyle.maximumLineHeight = [[attributeDictionary objectForKey:@"maximumlineheight"] doubleValue]; + } + if ([attributeDictionary objectForKey:@"minimumlineheight"]) { + paragraphStyle.minimumLineHeight = [[attributeDictionary objectForKey:@"minimumlineheight"] doubleValue]; + } + if ([attributeDictionary objectForKey:@"paragraphspacing"]) { + paragraphStyle.paragraphSpacing = [[attributeDictionary objectForKey:@"paragraphspacing"] doubleValue]; + } + if ([attributeDictionary objectForKey:@"paragraphspacingbefore"]) { + paragraphStyle.paragraphSpacingBefore = [[attributeDictionary objectForKey:@"paragraphspacingbefore"] doubleValue]; + } + if ([attributeDictionary objectForKey:@"tailindent"]) { + paragraphStyle.tailIndent = [[attributeDictionary objectForKey:@"tailindent"] doubleValue]; + } + + [nodeAttributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:nodeAttributedStringRange]; + } + } + + return nodeAttributedString; +} + ++ (NSAttributedString *)attributedStringFromNode:(xmlNodePtr)xmlNode boldFont:(UIFont *)boldFont +{ + return [self.class attributedStringFromNode:xmlNode boldFont:boldFont regularFont:nil]; +} + ++ (UIColor *)colorFromHexString:(NSString *)hexString +{ + if (hexString == nil) + return nil; + + hexString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""]; + char *p; + NSUInteger hexValue = strtoul([hexString cStringUsingEncoding:NSUTF8StringEncoding], &p, 16); + + return [UIColor colorWithRed:((hexValue & 0xff0000) >> 16) / 255.0 green:((hexValue & 0xff00) >> 8) / 255.0 blue:(hexValue & 0xff) / 255.0 alpha:1.0]; +} + +@end diff --git a/client/ios/Hackpad/OCMock/NSNotificationCenter+OCMAdditions.h b/client/ios/Hackpad/OCMock/NSNotificationCenter+OCMAdditions.h new file mode 100644 index 0000000..ab4832b --- /dev/null +++ b/client/ios/Hackpad/OCMock/NSNotificationCenter+OCMAdditions.h @@ -0,0 +1,15 @@ +//--------------------------------------------------------------------------------------- +// $Id$ +// Copyright (c) 2009 by Mulle Kybernetik. See License file for details. +//--------------------------------------------------------------------------------------- + +#import + +@class OCMockObserver; + + +@interface NSNotificationCenter(OCMAdditions) + +- (void)addMockObserver:(OCMockObserver *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender; + +@end diff --git a/client/ios/Hackpad/OCMock/OCMArg.h b/client/ios/Hackpad/OCMock/OCMArg.h new file mode 100644 index 0000000..fe6321c --- /dev/null +++ b/client/ios/Hackpad/OCMock/OCMArg.h @@ -0,0 +1,35 @@ +//--------------------------------------------------------------------------------------- +// $Id$ +// Copyright (c) 2009-2013 by Mulle Kybernetik. See License file for details. +//--------------------------------------------------------------------------------------- + +#import + +@interface OCMArg : NSObject + +// constraining arguments + ++ (id)any; ++ (SEL)anySelector; ++ (void *)anyPointer; ++ (id)isNil; ++ (id)isNotNil; ++ (id)isNotEqual:(id)value; ++ (id)checkWithSelector:(SEL)selector onObject:(id)anObject; +#if NS_BLOCKS_AVAILABLE ++ (id)checkWithBlock:(BOOL (^)(id obj))block; +#endif + +// manipulating arguments + ++ (id *)setTo:(id)value; ++ (void *)setToValue:(NSValue *)value; + +// internal use only + ++ (id)resolveSpecialValues:(NSValue *)value; + +@end + +#define OCMOCK_ANY [OCMArg any] +#define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(__typeof__(variable))] diff --git a/client/ios/Hackpad/OCMock/OCMConstraint.h b/client/ios/Hackpad/OCMock/OCMConstraint.h new file mode 100644 index 0000000..3ae1264 --- /dev/null +++ b/client/ios/Hackpad/OCMock/OCMConstraint.h @@ -0,0 +1,64 @@ +//--------------------------------------------------------------------------------------- +// $Id$ +// Copyright (c) 2007-2010 by Mulle Kybernetik. See License file for details. +//--------------------------------------------------------------------------------------- + +#import + + +@interface OCMConstraint : NSObject + ++ (id)constraint; +- (BOOL)evaluate:(id)value; + +// if you are looking for any, isNil, etc, they have moved to OCMArg + +// try to use [OCMArg checkWith...] instead of the constraintWith... methods below + ++ (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject; ++ (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue; + + +@end + +@interface OCMAnyConstraint : OCMConstraint +@end + +@interface OCMIsNilConstraint : OCMConstraint +@end + +@interface OCMIsNotNilConstraint : OCMConstraint +@end + +@interface OCMIsNotEqualConstraint : OCMConstraint +{ + @public + id testValue; +} + +@end + +@interface OCMInvocationConstraint : OCMConstraint +{ + @public + NSInvocation *invocation; +} + +@end + +#if NS_BLOCKS_AVAILABLE + +@interface OCMBlockConstraint : OCMConstraint +{ + BOOL (^block)(id); +} + +- (id)initWithConstraintBlock:(BOOL (^)(id))block; + +@end + +#endif + + +#define CONSTRAINT(aSelector) [OCMConstraint constraintWithSelector:aSelector onObject:self] +#define CONSTRAINTV(aSelector, aValue) [OCMConstraint constraintWithSelector:aSelector onObject:self withValue:(aValue)] diff --git a/client/ios/Hackpad/OCMock/OCMock.h b/client/ios/Hackpad/OCMock/OCMock.h new file mode 100644 index 0000000..e18de58 --- /dev/null +++ b/client/ios/Hackpad/OCMock/OCMock.h @@ -0,0 +1,10 @@ +//--------------------------------------------------------------------------------------- +// $Id$ +// Copyright (c) 2004-2008 by Mulle Kybernetik. See License file for details. +//--------------------------------------------------------------------------------------- + +#import +#import +#import +#import +#import diff --git a/client/ios/Hackpad/OCMock/OCMockObject.h b/client/ios/Hackpad/OCMock/OCMockObject.h new file mode 100644 index 0000000..e796705 --- /dev/null +++ b/client/ios/Hackpad/OCMock/OCMockObject.h @@ -0,0 +1,46 @@ +//--------------------------------------------------------------------------------------- +// $Id$ +// Copyright (c) 2004-2008 by Mulle Kybernetik. See License file for details. +//--------------------------------------------------------------------------------------- + +#import + +@interface OCMockObject : NSProxy +{ + BOOL isNice; + BOOL expectationOrderMatters; + NSMutableArray *recorders; + NSMutableArray *expectations; + NSMutableArray *rejections; + NSMutableArray *exceptions; +} + ++ (id)mockForClass:(Class)aClass; ++ (id)mockForProtocol:(Protocol *)aProtocol; ++ (id)partialMockForObject:(NSObject *)anObject; + ++ (id)niceMockForClass:(Class)aClass; ++ (id)niceMockForProtocol:(Protocol *)aProtocol; + ++ (id)observerMock; + +- (id)init; + +- (void)setExpectationOrderMatters:(BOOL)flag; + +- (id)stub; +- (id)expect; +- (id)reject; + +- (void)verify; + +- (void)stopMocking; + +// internal use only + +- (id)getNewRecorder; +- (BOOL)handleInvocation:(NSInvocation *)anInvocation; +- (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation; +- (BOOL)handleSelector:(SEL)sel; + +@end diff --git a/client/ios/Hackpad/OCMock/OCMockRecorder.h b/client/ios/Hackpad/OCMock/OCMockRecorder.h new file mode 100644 index 0000000..0dcd3f2 --- /dev/null +++ b/client/ios/Hackpad/OCMock/OCMockRecorder.h @@ -0,0 +1,38 @@ +//--------------------------------------------------------------------------------------- +// $Id$ +// Copyright (c) 2004-2013 by Mulle Kybernetik. See License file for details. +//--------------------------------------------------------------------------------------- + +#import + +@interface OCMockRecorder : NSProxy +{ + id signatureResolver; + BOOL recordedAsClassMethod; + BOOL ignoreNonObjectArgs; + NSInvocation *recordedInvocation; + NSMutableArray *invocationHandlers; +} + +- (id)initWithSignatureResolver:(id)anObject; + +- (BOOL)matchesSelector:(SEL)sel; +- (BOOL)matchesInvocation:(NSInvocation *)anInvocation; +- (void)releaseInvocation; + +- (id)andReturn:(id)anObject; +- (id)andReturnValue:(NSValue *)aValue; +- (id)andThrow:(NSException *)anException; +- (id)andPost:(NSNotification *)aNotification; +- (id)andCall:(SEL)selector onObject:(id)anObject; +#if NS_BLOCKS_AVAILABLE +- (id)andDo:(void (^)(NSInvocation *))block; +#endif +- (id)andForwardToRealObject; + +- (id)classMethod; +- (id)ignoringNonObjectArgs; + +- (NSArray *)invocationHandlers; + +@end diff --git a/client/ios/Hackpad/OCMock/libOCMock.a b/client/ios/Hackpad/OCMock/libOCMock.a new file mode 100644 index 0000000..3aae913 Binary files /dev/null and b/client/ios/Hackpad/OCMock/libOCMock.a differ diff --git a/client/ios/Hackpad/RNCachingURLProtocol/RNCachingURLProtocol.h b/client/ios/Hackpad/RNCachingURLProtocol/RNCachingURLProtocol.h new file mode 100644 index 0000000..ebf0ab7 --- /dev/null +++ b/client/ios/Hackpad/RNCachingURLProtocol/RNCachingURLProtocol.h @@ -0,0 +1,69 @@ +// +// RNCachingURLProtocol.h +// +// Created by Robert Napier on 1/10/12. +// Copyright (c) 2012 Rob Napier. All rights reserved. +// +// This code is licensed under the MIT License: +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + +// RNCachingURLProtocol is a simple shim for the HTTP protocol (that’s not +// nearly as scary as it sounds). Anytime a URL is download, the response is +// cached to disk. Anytime a URL is requested, if we’re online then things +// proceed normally. If we’re offline, then we retrieve the cached version. +// +// The point of RNCachingURLProtocol is mostly to demonstrate how this is done. +// The current implementation is extremely simple. In particular, it doesn’t +// worry about cleaning up the cache. The assumption is that you’re caching just +// a few simple things, like your “Latest News” page (which was the problem I +// was solving). It caches all HTTP traffic, so without some modifications, it’s +// not appropriate for an app that has a lot of HTTP connections (see +// MKNetworkKit for that). But if you need to cache some URLs and not others, +// that is easy to implement. +// +// You should also look at [AFCache](https://github.com/artifacts/AFCache) for a +// more powerful caching engine that is currently integrating the ideas of +// RNCachingURLProtocol. +// +// A quick rundown of how to use it: +// +// 1. To build, you will need the Reachability code from Apple (included). That requires that you link with +// `SystemConfiguration.framework`. +// +// 2. At some point early in the program (application:didFinishLaunchingWithOptions:), +// call the following: +// +// `[NSURLProtocol registerClass:[RNCachingURLProtocol class]];` +// +// 3. There is no step 3. +// +// For more details see +// [Drop-in offline caching for UIWebView (and NSURLProtocol)](http://robnapier.net/blog/offline-uiwebview-nsurlprotocol-588). + +#import + +@interface RNCachingURLProtocol : NSURLProtocol + +- (NSString *)cachePathForRequest:(NSURLRequest *)aRequest; +- (BOOL) useCache; +- (BOOL) allowNetwork; + +@end diff --git a/client/ios/Hackpad/RNCachingURLProtocol/RNCachingURLProtocol.m b/client/ios/Hackpad/RNCachingURLProtocol/RNCachingURLProtocol.m new file mode 100644 index 0000000..7a5297c --- /dev/null +++ b/client/ios/Hackpad/RNCachingURLProtocol/RNCachingURLProtocol.m @@ -0,0 +1,264 @@ +// +// RNCachingURLProtocol.m +// +// Created by Robert Napier on 1/10/12. +// Copyright (c) 2012 Rob Napier. +// +// This code is licensed under the MIT License: +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + +#import "RNCachingURLProtocol.h" +#import "Reachability.h" + +#define WORKAROUND_MUTABLE_COPY_LEAK 1 + +#if WORKAROUND_MUTABLE_COPY_LEAK +// required to workaround http://openradar.appspot.com/11596316 +@interface NSURLRequest(MutableCopyWorkaround) + +- (id) mutableCopyWorkaround; + +@end +#endif + +@interface RNCachedData : NSObject +@property (nonatomic, readwrite, strong) NSData *data; +@property (nonatomic, readwrite, strong) NSURLResponse *response; +@property (nonatomic, readwrite, strong) NSURLRequest *redirectRequest; +@end + +static NSString *RNCachingURLHeader = @"X-RNCache"; + +@interface RNCachingURLProtocol () // iOS5-only +@property (nonatomic, readwrite, strong) NSURLConnection *connection; +@property (nonatomic, readwrite, strong) NSMutableData *data; +@property (nonatomic, readwrite, strong) NSURLResponse *response; +- (void)appendData:(NSData *)newData; +@end + +@implementation RNCachingURLProtocol +@synthesize connection = connection_; +@synthesize data = data_; +@synthesize response = response_; + + ++ (BOOL)canInitWithRequest:(NSURLRequest *)request +{ + // only handle http requests we haven't marked with our header. + if ([[[request URL] scheme] isEqualToString:@"http"] && + ([request valueForHTTPHeaderField:RNCachingURLHeader] == nil)) { + return YES; + } + return NO; +} + ++ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request +{ + return request; +} + +- (NSString *)cachePathForRequest:(NSURLRequest *)aRequest +{ + // This stores in the Caches directory, which can be deleted when space is low, but we only use it for offline access + NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; + return [cachesPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%lx", + (unsigned long)[[[aRequest URL] absoluteString] hash]]]; +} + +- (void)startLoading +{ + RNCachedData *cache; + if ([self useCache]) { + @try { + cache = [NSKeyedUnarchiver unarchiveObjectWithFile:[self cachePathForRequest:[self request]]]; + } @catch (NSException *e) { } + } + if (!cache && [self allowNetwork]) { + NSMutableURLRequest *connectionRequest = +#if WORKAROUND_MUTABLE_COPY_LEAK + [[self request] mutableCopyWorkaround]; +#else + [[self request] mutableCopy]; +#endif + // we need to mark this request with our header so we know not to handle it in +[NSURLProtocol canInitWithRequest:]. + [connectionRequest setValue:@"" forHTTPHeaderField:RNCachingURLHeader]; + NSURLConnection *connection = [NSURLConnection connectionWithRequest:connectionRequest + delegate:self]; + [self setConnection:connection]; + } + else { + if (cache) { + NSData *data = [cache data]; + NSURLResponse *response = [cache response]; + NSURLRequest *redirectRequest = [cache redirectRequest]; + if (redirectRequest) { + [[self client] URLProtocol:self wasRedirectedToRequest:redirectRequest redirectResponse:response]; + } else { + + [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; // we handle caching ourselves. + [[self client] URLProtocol:self didLoadData:data]; + [[self client] URLProtocolDidFinishLoading:self]; + } + } + else { + [[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCannotConnectToHost userInfo:nil]]; + } + } +} + +- (void)stopLoading +{ + [[self connection] cancel]; +} + +// NSURLConnection delegates (generally we pass these on to our client) + +- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response +{ +// Thanks to Nick Dowell https://gist.github.com/1885821 + if (response != nil) { + NSMutableURLRequest *redirectableRequest = +#if WORKAROUND_MUTABLE_COPY_LEAK + [request mutableCopyWorkaround]; +#else + [request mutableCopy]; +#endif + // We need to remove our header so we know to handle this request and cache it. + // There are 3 requests in flight: the outside request, which we handled, the internal request, + // which we marked with our header, and the redirectableRequest, which we're modifying here. + // The redirectable request will cause a new outside request from the NSURLProtocolClient, which + // must not be marked with our header. + [redirectableRequest setValue:nil forHTTPHeaderField:RNCachingURLHeader]; + + NSString *cachePath = [self cachePathForRequest:[self request]]; + RNCachedData *cache = [RNCachedData new]; + [cache setResponse:response]; + [cache setData:[self data]]; + [cache setRedirectRequest:redirectableRequest]; + [NSKeyedArchiver archiveRootObject:cache toFile:cachePath]; + [[self client] URLProtocol:self wasRedirectedToRequest:redirectableRequest redirectResponse:response]; + return redirectableRequest; + } else { + return request; + } +} + +- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data +{ + [[self client] URLProtocol:self didLoadData:data]; + [self appendData:data]; +} + +- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error +{ + [[self client] URLProtocol:self didFailWithError:error]; + [self setConnection:nil]; + [self setData:nil]; + [self setResponse:nil]; +} + +- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response +{ + [self setResponse:response]; + [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; // We cache ourselves. +} + +- (void)connectionDidFinishLoading:(NSURLConnection *)connection +{ + [[self client] URLProtocolDidFinishLoading:self]; + + NSString *cachePath = [self cachePathForRequest:[self request]]; + RNCachedData *cache = [RNCachedData new]; + [cache setResponse:[self response]]; + [cache setData:[self data]]; + [NSKeyedArchiver archiveRootObject:cache toFile:cachePath]; + + [self setConnection:nil]; + [self setData:nil]; + [self setResponse:nil]; +} + +- (BOOL) useCache +{ + BOOL reachable = (BOOL) [[Reachability reachabilityWithHostName:[[[self request] URL] host]] currentReachabilityStatus] != NotReachable; + return !reachable; +} + +- (BOOL) allowNetwork +{ + return ![self useCache]; +} + +- (void)appendData:(NSData *)newData +{ + if ([self data] == nil) { + [self setData:[newData mutableCopy]]; + } + else { + [[self data] appendData:newData]; + } +} + +@end + +static NSString *const kDataKey = @"data"; +static NSString *const kResponseKey = @"response"; +static NSString *const kRedirectRequestKey = @"redirectRequest"; + +@implementation RNCachedData +@synthesize data = data_; +@synthesize response = response_; +@synthesize redirectRequest = redirectRequest_; + +- (void)encodeWithCoder:(NSCoder *)aCoder +{ + [aCoder encodeObject:[self data] forKey:kDataKey]; + [aCoder encodeObject:[self response] forKey:kResponseKey]; + [aCoder encodeObject:[self redirectRequest] forKey:kRedirectRequestKey]; +} + +- (id)initWithCoder:(NSCoder *)aDecoder +{ + self = [super init]; + if (self != nil) { + [self setData:[aDecoder decodeObjectForKey:kDataKey]]; + [self setResponse:[aDecoder decodeObjectForKey:kResponseKey]]; + [self setRedirectRequest:[aDecoder decodeObjectForKey:kRedirectRequestKey]]; + } + + return self; +} + +@end + +#if WORKAROUND_MUTABLE_COPY_LEAK +@implementation NSURLRequest(MutableCopyWorkaround) + +- (id) mutableCopyWorkaround { + NSMutableURLRequest *mutableURLRequest = [[NSMutableURLRequest alloc] initWithURL:[self URL] + cachePolicy:[self cachePolicy] + timeoutInterval:[self timeoutInterval]]; + [mutableURLRequest setAllHTTPHeaderFields:[self allHTTPHeaderFields]]; + return mutableURLRequest; +} + +@end +#endif diff --git a/client/ios/Hackpad/TestFlight/README.md b/client/ios/Hackpad/TestFlight/README.md new file mode 100644 index 0000000..f0b01fe --- /dev/null +++ b/client/ios/Hackpad/TestFlight/README.md @@ -0,0 +1,235 @@ +## Introduction + +The TestFlight SDK allows you to track how beta testers are testing your application. Out of the box we track simple usage information, such as which tester is using your application, their device model/OS, how long they used the application, and automatic recording of any crashes they encounter. + +The SDK can track more information if you pass it to TestFlight. The Checkpoint API is used to help you track exactly how your testers are using your application. Curious about which users passed level 5 in your game, or posted their high score to Twitter, or found that obscure feature? See "Checkpoint API" down below to see how. + +The SDK also offers a remote logging solution. Find out more about our logging system in the "Remote Logging" section. + +## Requirements + +The TestFlight SDK requires iOS 4.3 or above, the Apple LLVM compiler, and the libz library to run. + +The AdSupport.framework is required for iOS 6.0+ in order to uniquely identify users so we can estimate the number of users your app has (using `ASIdentifierManager`). You may weak link the framework in you app. If your app does not link with the AdSupport.framework, the TestFlight SDK will automatically load it for apps running on iOS 6.0+. + + +## Integration + +1. Add the files to your project: File -> Add Files to " " + 1. Find and select the folder that contains the SDK + 2. Make sure that "Copy items into destination folder (if needed)" is checked + 3. Set Folders to "Create groups for any added folders" + 4. Select all targets that you want to add the SDK to + +2. Verify that libTestFlight.a has been added to the Link Binary With Libraries Build Phase for the targets you want to use the SDK with + 1. Select your Project in the Project Navigator + 2. Select the target you want to enable the SDK for + 3. Select the Build Phases tab + 4. Open the Link Binary With Libraries Phase + 5. If libTestFlight.a is not listed, drag and drop the library from your Project Navigator to the Link Binary With Libraries area + 6. Repeat Steps 2 - 5 until all targets you want to use the SDK with have the SDK linked + +3. Add libz to your Link Binary With Libraries Build Phase + 1. Select your Project in the Project Navigator + 2. Select the target you want to enable the SDK for + 3. Select the Build Phases tab + 4. Open the Link Binary With Libraries Phase + 5. Click the + to add a new library + 6. Find libz.dylib in the list and add it + 7. Repeat Steps 2 - 6 until all targets you want to use the SDK with have libz.dylib + +4. Get your App Token + + 1. If this is a new application, and you have not uploaded it to TestFlight before, first register it here: [https://testflightapp.com/dashboard/applications/create/](). + + Otherwise, if you have previously uploaded your app to TestFlight, go to your list of applications ([http://testflightapp.com/dashboard/applications/]()) and click on the application you are using from the list. + + 2. Click on the "App Token" tab on the left. The App Token for that application will be there. + +5. In your Application Delegate: + + 1. Import TestFlight: `#import "TestFlight.h"` + + 2. Launch TestFlight with your App Token + + In your `-application:didFinishLaunchingWithOptions:` method, call `+[TestFlight takeOff:]` with your App Token. + + -(BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // start of your application:didFinishLaunchingWithOptions + + [TestFlight takeOff:@"Insert your Application Token here"]; + + // The rest of your application:didFinishLaunchingWithOptions method + // ... + } + + 3. To report crashes to you we install our own uncaught exception handler. If you are not currently using an exception handler of your own then all you need to do is go to the next step. If you currently use an Exception Handler, or you use another framework that does please go to the section on advanced exception handling. + + +## Setting the UDID + +For **BETA** apps only: In order for "In App Updates" to work and for user data not to be anonymized, you may provide the device's unique identifier. To send the device identifier call the following method **before** your call to `+[TestFlight takeOff:]` like so: + + [TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]]; + [TestFlight takeOff:@"Insert your Application Token here"]; + +Note: `[[UIDevice currentDevice] uniqueIdentifier]` is deprecated, which means it may be removed from iOS in the future and that it should not be used in production apps. We recommend using it **only** in beta apps. If using it makes you feel uncomfortable, you are not required to include it. + +**Note on iOS 7 and Xcode 5**: In iOS 7, `uniqueIdentifier` no longer returns the device's UDID, so iOS 7 users will show up anonymously on TestFlight. Also, when building with ARC, Xcode 5 will not allow you to call `uniqueIdentifier` because it has been removed in iOS 7 from `UIDevice`'s header. We are working on a workaround for this issue. + +**DO NOT USE THIS IN PRODUCTION APPS**. When it is time to submit to the App Store comment this line out. Apple will probably reject your app if you leave this line in. + + +## Uploading your build + +After you have integrated the SDK into your application you need to upload your build to TestFlight. You can upload your build on our [website](https://testflightapp.com/dashboard/builds/add/), using our [desktop app](https://testflightapp.com/desktop/), or by using our [upload API](https://testflightapp.com/api/doc/). + + +## Basic Features + +### Session Information + +View anonymous information about how often users use your app, how long they use it for, and when they use it. You can see what type of device the user is using, which OS, which language, etc. + +Sessions automatically start at when the app becomes active and end when the app resigns active. Sessions that start shortly after an end continue the session instead of starting a new one. + +NB: Sessions do not start when `takeOff:` is called, `takeOff:` registers callbacks to start sessions when the app is active. + +For **beta** users, you can see who the users are if you are **setting the UDID**, they have a TestFlight account, and their device is registered to TestFlight. (See Setting the UDID for more information). + + +### Crash Reports + +The TestFlight SDK automatically reports all crashes (beta and prod) to TestFlight's website where you can view them. Crash reports are sent **at** crash time. TestFlight will also automatically symbolicate all crashes (if you have uploaded your dSYM). For **beta** apps, on the site, you can see which checkpoints the user passed before the crash and see remote logs that were sent before the crash. For **prod** apps, you can see remote logs that were sent before the crash. + + +### Beta In App Updates + +If a user is using a **beta** version of your app, you are **setting the UDID**, a new beta version is available, and that user has permission to install it; an in app popup will ask them if they would like to install the update. If they tap "Install", the new version is installed from inside the app. + +NB: For this to work, you must increment your build version before uploading. Otherwise the new and old builds will have the same version number and we won't know if the user needs to update or is already using the new version. + +To turn this off set this option before calling `takeOff:` + + [TestFlight setOptions:@{ TFOptionDisableInAppUpdates : @YES }]; + + +## Additional Features + +### Checkpoints + +When a tester does something you care about in your app, you can pass a checkpoint. For example completing a level, adding a todo item, etc. The checkpoint progress is used to provide insight into how your testers are testing your apps. The passed checkpoints are also attached to crashes, which can help when creating steps to replicate. Checkpoints are visible for all beta and prod builds. + + [TestFlight passCheckpoint:@"CHECKPOINT_NAME"]; + +Use `passCheckpoint:` to track when a user performs certain tasks in your application. This can be useful for making sure testers are hitting all parts of your application, as well as tracking which testers are being thorough. + +Checkpoints are meant to tell you if a user visited a place in your app or completed a task. They should not be used for debugging purposes. Instead, use Remote Logging for debugging information (more information below). + +NB: Checkpoints are only recorded during sessions. + + +### Custom Environment Information + +In **beta** builds, if you want to see some extra information about your user, you can add some custom environment information. You must add this information before the session starts (a session starts at `takeOff:`) to see it on TestFlight's website. NB: You can only see this information for **beta** users. + + [TestFlight addCustomEnvironmentInformation:@"info" forKey:@"key"]; + +You may call this method as many times as you would like to add more information. + + +### User Feedback + +In **beta** builds, if you collect feedback from your users, you may pass it back to TestFlight which will associate it with the user's current session. + + [TestFlight submitFeedback:feedback]; + +Once users have submitted feedback from inside of the application you can view it in the feedback area of your build page. + + +### Remote Logging + +Remote Logging allows you to see the logs your app prints out remotely, on TestFlight's website. You can see logs for **beta sessions** and **prod sessions with crashes**. NB: you cannot see the logs for all prod sessions. + +To use it, simply replace all of your `NSLog` calls with `TFLog` calls. An easy way to do this without rewriting all your `NSLog` calls is to add the following macro to your `.pch` file. + + #import "TestFlight.h" + #define NSLog TFLog + +Not only will `TFLog` log remotely to TestFlight, it will also log to the console (viewable in a device's logs) and STDERR (shown while debugging) just like NSLog does, providing a complete replacement. + +For even better information in your remote logs, such as file name and line number, you can use this macro instead: + + #define NSLog(__FORMAT__, ...) TFLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) + +Which will produce output that looks like + + -[MyAppDelegate application:didFinishLaunchingWithOptions:] [Line 45] Launched! + +NB: Logs are only recorded during sessions. + +**Custom Logging** + +If you have your own custom logging, call `TFLog` from your custom logging function. If you do not need `TFLog` to log to the console or STDERR because you handle those yourself, you can turn them off with these calls: + + [TestFlight setOptions:@{ TFOptionLogToConsole : @NO }]; + [TestFlight setOptions:@{ TFOptionLogToSTDERR : @NO }]; + +## Advanced Notes + +### Checkpoint API + +When passing a checkpoint, TestFlight logs the checkpoint synchronously (See Remote Logging for more information). If your app has very high performance needs, you can turn the logging off with the `TFOptionLogOnCheckpoint` option. + + +### Remote Logging + +All logging is done synchronously. Every time the SDK logs, it must write data to a file. This is to ensure log integrity at crash time. Without this, we could not trust logs at crash time. If you have a high performance app, please email support@testflightapp.com for more options. + +### Advanced Session Control + +Continuing sessions: You can adjust the amount of time a user can leave the app for and still continue the same session when they come back by changing the `TFOptionSessionKeepAliveTimeout` option. Change it to 0 to turn the feature off. + +Manual Session Control: If your app is a music player that continues to play music in the background, a navigation app that continues to function in the background, or any app where a user is considered to be "using" the app even while the app is not active you should use Manual Session Control. Please only use manual session control if you know exactly what you are doing. There are many pitfalls which can result in bad session duration and counts. See `TestFlight+ManualSessions.h` for more information and instructions. + +### Advanced Exception/Signal Handling + +An uncaught exception means that your application is in an unknown state and there is not much that you can do but try and exit gracefully. Our SDK does its best to get the data we collect in this situation to you while it is crashing, but it is designed in such a way that the important act of saving the data occurs in as safe way a way as possible before trying to send anything. If you do use uncaught exception or signal handlers, install your handlers before calling `takeOff:`. Our SDK will then call your handler while ours is running. For example: + + /* + My Apps Custom uncaught exception catcher, we do special stuff here, and TestFlight takes care of the rest + */ + void HandleExceptions(NSException *exception) { + NSLog(@"This is where we save the application data during a exception"); + // Save application data on crash + } + /* + My Apps Custom signal catcher, we do special stuff here, and TestFlight takes care of the rest + */ + void SignalHandler(int sig) { + NSLog(@"This is where we save the application data during a signal"); + // Save application data on crash + } + + -(BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // installs HandleExceptions as the Uncaught Exception Handler + NSSetUncaughtExceptionHandler(&HandleExceptions); + // create the signal action structure + struct sigaction newSignalAction; + // initialize the signal action structure + memset(&newSignalAction, 0, sizeof(newSignalAction)); + // set SignalHandler as the handler in the signal action structure + newSignalAction.sa_handler = &SignalHandler; + // set SignalHandler as the handlers for SIGABRT, SIGILL and SIGBUS + sigaction(SIGABRT, &newSignalAction, NULL); + sigaction(SIGILL, &newSignalAction, NULL); + sigaction(SIGBUS, &newSignalAction, NULL); + // Call takeOff after install your own unhandled exception and signal handlers + [TestFlight takeOff:@"Insert your Application Token here"]; + // continue with your application initialization + } + +You do not need to add the above code if your application does not use exception handling already. + diff --git a/client/ios/Hackpad/TestFlight/TestFlight+AsyncLogging.h b/client/ios/Hackpad/TestFlight/TestFlight+AsyncLogging.h new file mode 100644 index 0000000..6393e95 --- /dev/null +++ b/client/ios/Hackpad/TestFlight/TestFlight+AsyncLogging.h @@ -0,0 +1,30 @@ +// +// TestFlight+AsyncLogging.h +// libTestFlight +// +// Created by Jason Gregori on 2/12/13. +// Copyright (c) 2013 TestFlight. All rights reserved. +// + +/* + + When logging, it is important that logs are written synchronously. In the event of a crash, all logs that happened before the crash are gauranteed to be on disk. If they were written asynchronously and a crash occurs, you might lose some very valuable logs that might have helped fixed the crash. + + However, because TFLog waits until writing to disk is complete, it takes a while. If you have a very high preformance app that can't afford to wait for logs, these functions are for you. + + USE THESE, BUT KNOW YOU RISK LOSING SOME LOGS AT CRASH TIME + + */ + +#import "TestFlight.h" + + + +#if __cplusplus +extern "C" { +#endif + void TFLog_async(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); + void TFLogv_async(NSString *format, va_list arg_list); +#if __cplusplus +} +#endif \ No newline at end of file diff --git a/client/ios/Hackpad/TestFlight/TestFlight+ManualSessions.h b/client/ios/Hackpad/TestFlight/TestFlight+ManualSessions.h new file mode 100644 index 0000000..62a392a --- /dev/null +++ b/client/ios/Hackpad/TestFlight/TestFlight+ManualSessions.h @@ -0,0 +1,58 @@ +// +// TestFlight+ManualSessions.h +// libTestFlight +// +// Created by Jason Gregori on 5/16/13. +// Copyright (c) 2013 TestFlight. All rights reserved. +// + +/* + + YOU ARE STRONGLY ADVISED NOT TO USE THESE METHODS unless you know exactly what you are doing. By using these you take on the responsibility of ensuring your session data is reported accurately. + + The way TestFlight normally does sessions is to automatically start them at app launch, app did become active, and app will enter foreground and end them at app will resign active, app did enter background, or app will terminate. + + If your app is a music player that continues to play music in the background, a navigation app that continues to function in the background, or any app where a user is considered to be "using" the app even while the app is not active, this file is for you. + + + Usage + ----- + + 1. Add this file to your project. + + 2. Set the manual sessions option to true **before** calling `takeOff:` + + [TestFlight setOptions:@{ TFOptionManualSessions : @YES }]; + + 3. Use the manually start/end session methods to control you sessions. + + + Pitfalls + -------- + + When using manual sessions in the background, you must always be aware of the fact that iOS may suspend your app at any time without any warning. You must end your session before that happens. If you do not, the session will continue and include all the time the app was suspended in it's duration if the app is brought back from suspension. This will lead to very inaccurate session lengths and counts. + + On app termination: For the most accurate sessions, try to end your session if you know the app is about to terminate. If you do not, the session will still be ended on the next launch, however, it's end time will not be exact. In that case, the end time will be within 30 seconds of the correct time (session information is saved every 30 seconds and when a checkpoint is sent). + + Sessions do not continue across termination if you do not end a session before termination. + + On crashes: Do not worry about ending sessions in the event of a crash. Even manual sessions are automatically ended in the event of a crash. + + Continuing sessions: If a session is started without 30 seconds of the last session ending (and their was no termination between the sessions), the last session will continue instead of a new session starting. This is the case in manual and automatic sessions. You may change the timeout or turn this feature off using the `TFOptionSessionKeepAliveTimeout` option. + + */ + +#import "TestFlight.h" + + + +extern NSString *const TFOptionManualSessions; // Defaults to @NO. Set to @YES before calling `takeOff:` in order to use manual session methods. + + +@interface TestFlight (ManualSessions) + +// these methods are thread safe ++ (void)manuallyStartSession; ++ (void)manuallyEndSession; + +@end diff --git a/client/ios/Hackpad/TestFlight/TestFlight.h b/client/ios/Hackpad/TestFlight/TestFlight.h new file mode 100644 index 0000000..bb1b39c --- /dev/null +++ b/client/ios/Hackpad/TestFlight/TestFlight.h @@ -0,0 +1,122 @@ +// +// TestFlight.h +// libTestFlight +// +// Created by Jonathan Janzen on 06/11/11. +// Copyright 2011 TestFlight. All rights reserved. + +#import +#define TESTFLIGHT_SDK_VERSION @"2.1.3" +#undef TFLog + +#if __cplusplus +extern "C" { +#endif + /* + * Remote Logging + * Note: All Logging is synchronous, see the README for more information. + */ + void TFLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); + void TFLogv(NSString *format, va_list arg_list); + void TFLogPreFormatted(NSString *message); +#if __cplusplus +} +#endif + +/** + * TestFlight object + * All methods are class level + */ +@interface TestFlight : NSObject + +/** + * Add custom environment information + * If you want to track custom information such as a user name from your application you can add it here. + * NB: This information must be added before the session starts, it is recorded only on session start. + * + * @param information A string containing the environment you are storing + * @param key The key to store the information with + */ ++ (void)addCustomEnvironmentInformation:(NSString *)information forKey:(NSString*)key; + + +/** + * Sets up TestFlight's infrastructure. + * + * - Saves App Token + * - Starts automatic session management + * - Installs Crash Handlers + * - Kicks off sending of old session data + * + * @param applicationToken Will be the application token for the current application. + * The token for this application can be retrieved by going to https://testflightapp.com/dashboard/applications/ + * selecting this application from the list then selecting SDK. + */ ++ (void)takeOff:(NSString *)applicationToken; + +/** + * Sets custom options + * + * @param options NSDictionary containing the options you want to set. Available options are described below at "TestFlight Option Keys" + * + */ ++ (void)setOptions:(NSDictionary*)options; + +/** + * Track when a user has passed a checkpoint after the flight has taken off. Eg. passed level 1, posted high score. + * Checkpoints are sent in the background. + * Note: The checkpoint is logged synchronously (See TFLog and TFOptionLogOnCheckpoint for more information). + * + * @param checkpointName The name of the checkpoint, this should be a static string + */ ++ (void)passCheckpoint:(NSString *)checkpointName; + +/** + * Submits custom feedback to the site. Sends the data in feedback to the site. This is to be used as the method to submit + * feedback from custom feedback forms. + * + * @param feedback Your users feedback, method does nothing if feedback is nil + */ ++ (void)submitFeedback:(NSString*)feedback; + +/** + * Sets the Device Identifier. + * + * !! DO NOT CALL IN SUBMITTED APP STORE APP. + * + * !! MUST BE CALLED BEFORE +takeOff: + * + * This method should only be used during testing so that you can identify a testers test data with them. + * If you do not provide the identifier you will still see all session data, with checkpoints + * and logs, but the data will be anonymized. + * + * It is recommended that you only use this method during testing. + * Apple may reject your app if left in a submitted app. + * + * Use: + * Only use this with the Apple device UDID. DO NOT use Open ID or your own identifier. + * [TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]]; + * + * @param deviceIdentifer The current devices device identifier + */ ++ (void)setDeviceIdentifier:(NSString*)deviceIdentifer; + +@end + + +/** + * TestFlight Option Keys + * + * Pass these as keys to the dictionary you pass to +`[TestFlight setOptions:]`. + * The values should be NSNumber BOOLs (`[NSNumber numberWithBool:YES]` or `@YES`) + */ +extern NSString *const TFOptionDisableInAppUpdates; // Defaults to @NO. Setting to @YES, disables the in app update screen shown in BETA apps when there is a new version available on TestFlight. +extern NSString *const TFOptionFlushSecondsInterval; // Defaults to @60. Set to a number. @0 turns off the flush timer. 30 seconds is the minimum flush interval. +extern NSString *const TFOptionLogOnCheckpoint; // Defaults to @YES. Because logging is synchronous, if you have a high preformance app, you might want to turn this off. +extern NSString *const TFOptionLogToConsole; // Defaults to @YES. Prints remote logs to Apple System Log. +extern NSString *const TFOptionLogToSTDERR; // Defaults to @YES. Sends remote logs to STDERR when debugger is attached. +extern NSString *const TFOptionReinstallCrashHandlers; // If set to @YES: Reinstalls crash handlers, to be used if a third party library installs crash handlers overtop of the TestFlight Crash Handlers. +extern NSString *const TFOptionReportCrashes; // Defaults to @YES. If set to @NO, crash handlers are never installed. Must be set **before** calling `takeOff:`. +extern NSString *const TFOptionSendLogOnlyOnCrash; // Defaults to @NO. Setting to @YES stops remote logs from being sent when sessions end. They would only be sent in the event of a crash. +extern NSString *const TFOptionSessionKeepAliveTimeout; // Defaults to @30. This is the amount of time a user can leave the app for and still continue the same session when they come back. If they are away from the app for longer, a new session is created when they come back. Must be a number. Change to @0 to turn off. + diff --git a/client/ios/Hackpad/TestFlight/libTestFlight.a b/client/ios/Hackpad/TestFlight/libTestFlight.a new file mode 100644 index 0000000..5904d8c Binary files /dev/null and b/client/ios/Hackpad/TestFlight/libTestFlight.a differ diff --git a/client/ios/Hackpad/TestFlight/release_notes.md b/client/ios/Hackpad/TestFlight/release_notes.md new file mode 100644 index 0000000..92c6f6c --- /dev/null +++ b/client/ios/Hackpad/TestFlight/release_notes.md @@ -0,0 +1,295 @@ +## 2.1.2 + +- Fix for bug that caused events to not get sent properly when using the `TFOptionSessionKeepAliveTimeout` option +- Fix for bug that caused logs that were sent immediately after start session to sometimes not be sent to server + +## 2.1.1 + +- Create sdk version that removes all access to `ASIdentifierManager` +- Add UIDevice's `identifierForVendor` + +## 2.1 + +- Full support for the iPhone 5s’ ARM64 processor while still supporting down to iOS 4.3 + +## 2.0.2 + +- Fixed a bug where the sdk would cause an app's CPU usage to rise significantly if the device had no internet connection when the app started + +## 2.0.1 + +- Fixed rare `8badf00d` crash in TFNetworkManager that happened when the app was in the background + +## 2.0 - August 12, 2013 + +Improvements + +- ARC +- All public TestFlight methods may be called from any thread or dispatch_queue +- All public TestFlight methods (except for `TFLog` and `takeOff:`) are asynchronous, so there is never a wait on them +- TestFlight never uses more than 1 network connection at a time +- All network traffic is grouped together, sent at once, and transferred in MessagePack. This results in using less bandwidth and less network calls. +- All network traffic if server is not reachable +- Size of SDK reduced by 70% +- New In App Update UI in an alert with landscape support. Should work for all different types of apps. +- Manual Sessions: You can manually control session start and end. See `TestFlight+ManualSessions.h` for more information +- Combining of back to back sessions. If a session starts less than 30 seconds from the last session which ended, the previous session is continued. You may change the time limit (or turn this off) using the `TFOptionSessionKeepAliveTimeout` option key. +- No longer automatically starts a session on `+takeOff:` in order to support new background modes that might launch an app in the background. +- `TFOptionReportCrashes` option to not install crash handlers +- Remove all calls to `dispatch_get_current_queue`, it is deprecated + +Changes + +- Removed all access to mac address +- Added AdSupport.framework requirement (as a replacement for mac address to get accurate user counts) +- Add format attribute to TFLog to show warnings for wrong format specifiers or not using a format string +- Removed Questions +- Removed Feedback View (along with backtrace option) + +Bug Fixes + +- Fixed addrinfo memory leak +- Fixed possible `-[TFAirTrafficController getNumberOrNilFrom:withKey:]` crash when bad data is received. +- CoreTelephony crash work around: this is a workaround of a iOS bug that causes deallocated instances of `CTTelephonyNetworkInfo` to receive notifications which causes crashes. Core Telephony is used to retrieve the device's mobile carrier. +- Fix bug with crash reporting in iOS 7 + + +## 1.2.4 - February 19, 2013 + +- Fixed bug that caused crash reports to sometimes not send immediately (they would be resent later) + +## 1.2.3 - January 8, 2013 + +- Fixed typos in readme +- Fixed bug where logs not sent on crash +- Fixed bug where empty crash files were created (but not sent) +- Cache path to TF's directory so it does not need to be regenerated every time +- Use consts for `setOptions:` +- Updated `setDeviceIdentifier:` comments to make them clearer +- Remove potentially conflicting function name `UIColorFromRGB` +- Fixed crash on bad in app update data + +## 1.2.2 - December 26, 2012 + +- Fix typo in app token error message + +## 1.2.1 - December 26, 2012 + +- The max number of concurrent network connections has been reduced from 4 to 2. + +##1.2 - November 12, 2012 + +* Removed Team Token support. As of version 1.2 takeOff must be called with the Application Token, https://testflightapp.com/dashboard/applications/, choose your application, select SDK, get the Token for this Application. + +##1.2 BETA 3 - October 11, 2012 + +* Added application token support. Application Tokens are currently optional if you do not have one you do not need one + +##1.2 BETA 2 - October 9, 2012 + +* Resolved an instance of close_file being called on a bad file descriptor + +##1.2 BETA 1 - October 1, 2012 + +* Removed support for armv6 +* Exception handler now returns instead of raising a SIGTRAP + +##1.1 - September 13, 2012 + +* armv7s and iOS 6 support +* Updated for general release + +##1.1 BETA 3 - September 12, 2012 + +* armv7s slice added to library +* fixed typo for in application updates, inAppUdates changed to inAppUpdates + +##1.1 BETA 2 - September 6, 2012 + +* Re-enabled armv6 support +* Added option to disable in application updates + +##1.1 BETA 1 - July 13, 2012 + +* Added TFLogv to allow for log customizations. Check the README or online docs for more information. +* Added option attachBacktraceToFeedback, which attaches a backtrace to feedback sent from the SDK. For users who use feedback in more than one location in the application. +* Resolved issue where other exception handlers would not be called during an exception. +* SDK now sends the device language for a session. +* Documentation fixes. +* Stability fixes. + +###1.0 - March 29, 2012 + +* Resolved occurrences of exceptions with the message "No background task exists with identifier 0" + +###1.0 BETA 1 - March 23, 2012 + +* Privacy Updates +* UDID is no longer collected by the SDK. During testing please use `[TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]];` to send the UDID so you can identify your testers. For release do not set `+setDeviceIdentifier`. See Beta Testing and Release Differentiation in the README or online at [https://testflightapp.com/sdk/doc/1.0beta1/](http://testflightapp.com/sdk/doc/1.0beta1/) + +###0.8.3 - February 14, 2012 + +* Rolled previous beta code into release builds +* No longer allow in application updates to occur in applications that were obtained from the app store. + +**Tested compiled library with:** + +* Xcode 4.3 +* Xcode 4.2 +* Xcode 4.1 +* Xcode 3.2.6 + +###0.8.3 BETA 5 - February 10, 2012 + +* Changed logging from asynchronous to synchronous. +* Resolved crash when looking for a log path failed. +* Added submitFeedback to the TestFlight class to allow for custom feedback forms. + +###0.8.3 BETA 4 - January 20, 2012 + +* Resolved an issue that occured when an application was upgraded from 0.8.3 BETA 1 to 0.8.3 BETA 3+ with unsent data from 0.8.3 BETA 1 + +###0.8.3 BETA 3 - January 19, 2012 + +* On crash log files over 64k will not be sent until next launch. + +**Known Issues:** + +* Logging massive amounts of data at the end of a session may prevent the application from launching in time on next launch + +###0.8.3 BETA 2 - January 13, 2012 + +* libz.dylib is now required to be added to your "Link Binary with Libraries" build phase +* Log file compression, The compression is done on an as needed basis rather than before sending +* Changed all outgoing data from JSON to MessagePack +* Added option `logToSTDERR` to disable the `STDERR` logger + +###0.8.3 BETA 1 - December 29, 2011 + +* In rare occurrences old session data that had not been sent to our server may have been discarded or attached to the wrong build. It is now no longer discarded +* Made sending of Session End events more robust +* Network queuing system does better bursting of unsent data +* Log files that are larger than 64K are now sent sometime after the next launch +* Log files that are larger than 16MB are no longer supported and will be replaced with a message indicating the log file was too large +* Fixed crashes while resuming from background + +###0.8.2 - December 20, 2011 + +* Promoted 0.8.2 BETA 4 to stable + +**Known Issues:** + +* Under some circumstances Session End events may not be sent until the next launch. +* With large log files Session End events may take a long time to show up. + +**Tested compiled library with:** + +* Xcode 4.3 +* Xcode 4.2 +* Xcode 4.1 +* Xcode 3.2.6 + +###0.8.2 BETA 4 - December 12, 2011 + +* Prevented "The string argument is NULL" from occuring during finishedHandshake in rare cases +* Resolved issue where data recorded while offline may not be sent + +###0.8.2 BETA 3 - December 8, 2011 + +* Added auto-release pools to background setup and tear down + +###0.8.2 BETA 2 - December 5, 2011 + +* Fixed the "pointer being freed was not allocated" bug + +###0.8.1 - November 18, 2011 + +* Implemented TFLog logging system, see README for more information +* Fixed an issue where Session End events may not be sent until next launch +* Fixed an issue where duplicate events could be sent +* Fixed an issue with Session End events not being sent from some iPod touch models + +**Tested compiled library with:** + +* Xcode 4.2 +* Xcode 4.1 +* Xcode 3.2.6 + +###0.8 - November 8, 2011 + +* Added `SIGTRAP` as a signal type that we catch +* Removed all Objective-c from crash reporting +* Removed the use of non signal safe functions from signal handling +* Created a signal safe way to get symbols from a stack trace +* Changed the keyboardType for Long Answer Questions and Feedback to allow for international character input +* Changed `TESTFLIGHT_SDK_VERSION` string to be an `NSString` +* Changed cache folder from Library/Caches/TestFlight to Library/Caches/com.testflight.testflightsdk +* Fixed issue with saving data when device is offline +* Fixed compability issues with iOS 3 +* Added calling into the rootViewController shouldAutorotateToInterfaceOrientation if a rootViewController is set +* Made the comments in TestFlight.h compatible with Appledoc + +Tested compiled library with: + +* Xcode 4.2 +* Xcode 4.1 +* Xcode 3.2 + +###0.7.2 - September 29, 2011 + +* Changed `TESTFLIGHT_SDK_VERSION` string to be an `NSString` +* Fixed an issue where exiting an application while the SDK is active caused modal views to be dismissed + +###0.7.1 - September 22, 2011 + +* Internal release +* Refactoring + +###0.7 - September 21, 2011 + +* Moved TestFlight images and data to the Library/Caches folder +* Resolved an issue where sometimes the rootViewController could not be found and feedback, questions and upgrade views would not be displayed +* In application upgrade changed to allow skipping until the next version is installed and allows upgrades to be forced +* Fixed a memory leak when launching questions + +###0.6 - September 2, 2011 + +* Renamed base64_encode to testflight_base64_encode to remove a conflict with other third party libraries +* Added ability to reinstall crash handlers when they are overwritten using the setOptions API +* Fixed an issue where crash reports might not get sent under certain circumstances +* Fixed a deadlock when the application is put in the background and then resumed before all information can be sent +* Fixed an issue when attempting to un-install all signal handlers during a signal +* Added support for landscape mode on the iPad to the Questions and Feedback views +* Crash reporting now works in versions of Xcode earlier than 4.2 +* Fixed a memory leak during handshake + +###0.5 - August 19, 2011 + +* Feedback that is not attached to a checkpoint [TestFlight openFeedbackView] +* Usability changes to question views +* Removed pause and resume sessions, replaced with sessions being stopped and started +* Added text auto correction to the Long Answer question type +* Crash reports now send on crash instead of next launch + +###0.4 - August 15, 2011 + +* In Application Feedback with Questions +* In application updates +* Custom Environment Information added +* Networking stack reimplementation +* Exception handling fixes + +###0.3 - June 15, 2011 + +* Removed all mention of JSONKit from the README +* Added support for using both the Bundle Version and the Bundle Short Version string + +###0.2 - June 14, 2011 + +* Removed all categories this allows users to use the SDK without having to set -ObjC and -load_all +* Prefixed JSONKit for use in TestFlight to remove reported issues where some users were already using JSONKit +* Added support for armv6 again + +###0.1 - June 11, 2011 + +* Initial Version diff --git a/client/ios/Hackpad/WebViewJavascriptBridge/WebViewJavascriptBridge.h b/client/ios/Hackpad/WebViewJavascriptBridge/WebViewJavascriptBridge.h new file mode 100644 index 0000000..d2d0544 --- /dev/null +++ b/client/ios/Hackpad/WebViewJavascriptBridge/WebViewJavascriptBridge.h @@ -0,0 +1,42 @@ +// +// WebViewJavascriptBridge.h +// ExampleApp-iOS +// +// Created by Marcus Westin on 6/14/13. +// Copyright (c) 2013 Marcus Westin. All rights reserved. +// + +#import + +#define kCustomProtocolScheme @"wvjbscheme" +#define kQueueHasMessage @"__WVJB_QUEUE_MESSAGE__" + +#if defined __MAC_OS_X_VERSION_MAX_ALLOWED + #import + #define WVJB_PLATFORM_OSX + #define WVJB_WEBVIEW_TYPE WebView + #define WVJB_WEBVIEW_DELEGATE_TYPE NSObject +#elif defined __IPHONE_OS_VERSION_MAX_ALLOWED + #define WVJB_PLATFORM_IOS + #define WVJB_WEBVIEW_TYPE UIWebView + #define WVJB_WEBVIEW_DELEGATE_TYPE NSObject +#endif + +typedef void (^WVJBResponseCallback)(id responseData); +typedef void (^WVJBHandler)(id data, WVJBResponseCallback responseCallback); + +@interface WebViewJavascriptBridge : WVJB_WEBVIEW_DELEGATE_TYPE + ++ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView handler:(WVJBHandler)handler; ++ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)handler; ++ (void)enableLogging; + +- (void)send:(id)message; +- (void)send:(id)message responseCallback:(WVJBResponseCallback)responseCallback; +- (void)registerHandler:(NSString*)handlerName handler:(WVJBHandler)handler; +- (void)callHandler:(NSString*)handlerName; +- (void)callHandler:(NSString*)handlerName data:(id)data; +- (void)callHandler:(NSString*)handlerName data:(id)data responseCallback:(WVJBResponseCallback)responseCallback; +- (void)reset; + +@end diff --git a/client/ios/Hackpad/WebViewJavascriptBridge/WebViewJavascriptBridge.js.txt b/client/ios/Hackpad/WebViewJavascriptBridge/WebViewJavascriptBridge.js.txt new file mode 100644 index 0000000..bbe9f97 --- /dev/null +++ b/client/ios/Hackpad/WebViewJavascriptBridge/WebViewJavascriptBridge.js.txt @@ -0,0 +1,116 @@ +;(function() { + if (window.WebViewJavascriptBridge) { return } + var messagingIframe + var sendMessageQueue = [] + var receiveMessageQueue = [] + var messageHandlers = {} + + var CUSTOM_PROTOCOL_SCHEME = 'wvjbscheme' + var QUEUE_HAS_MESSAGE = '__WVJB_QUEUE_MESSAGE__' + + var responseCallbacks = {} + var uniqueId = 1 + + function _createQueueReadyIframe(doc) { + messagingIframe = doc.createElement('iframe') + messagingIframe.style.display = 'none' + doc.documentElement.appendChild(messagingIframe) + } + + function init(messageHandler) { + if (WebViewJavascriptBridge._messageHandler) { throw new Error('WebViewJavascriptBridge.init called twice') } + WebViewJavascriptBridge._messageHandler = messageHandler + var receivedMessages = receiveMessageQueue + receiveMessageQueue = null + for (var i=0; i 500) { + NSLog(@"WVJB %@: %@ [...]", action, [json substringToIndex:500]); + } else { + NSLog(@"WVJB %@: %@", action, json); + } +} + + + +/* Platform specific internals: OSX + **********************************/ +#if defined WVJB_PLATFORM_OSX + +- (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)messageHandler { + _messageHandler = messageHandler; + _webView = webView; + _webViewDelegate = webViewDelegate; + _messageHandlers = [NSMutableDictionary dictionary]; + + _webView.frameLoadDelegate = self; + _webView.resourceLoadDelegate = self; + _webView.policyDelegate = self; +} + +- (void) _platformSpecificDealloc { + _webView.frameLoadDelegate = nil; + _webView.resourceLoadDelegate = nil; + _webView.policyDelegate = nil; +} + +- (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)frame +{ + if (webView != _webView) { return; } + + if (![[webView stringByEvaluatingJavaScriptFromString:@"typeof WebViewJavascriptBridge == 'object'"] isEqualToString:@"true"]) { + NSString *filePath = [[NSBundle mainBundle] pathForResource:@"WebViewJavascriptBridge.js" ofType:@"txt"]; + NSString *js = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; + [webView stringByEvaluatingJavaScriptFromString:js]; + } + + if (_startupMessageQueue) { + for (id queuedMessage in _startupMessageQueue) { + [self _dispatchMessage:queuedMessage]; + } + _startupMessageQueue = nil; + } + + if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:didFinishLoadForFrame:)]) { + [_webViewDelegate webView:webView didFinishLoadForFrame:frame]; + } +} + +- (void)webView:(WebView *)webView didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { + if (webView != _webView) { return; } + + if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:didFailLoadWithError:forFrame:)]) { + [_webViewDelegate webView:webView didFailLoadWithError:error forFrame:frame]; + } +} + +- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener +{ + if (webView != _webView) { return; } + + NSURL *url = [request URL]; + if ([[url scheme] isEqualToString:kCustomProtocolScheme]) { + if ([[url host] isEqualToString:kQueueHasMessage]) { + [self _flushMessageQueue]; + } else { + NSLog(@"WebViewJavascriptBridge: WARNING: Received unknown WebViewJavascriptBridge command %@://%@", kCustomProtocolScheme, [url path]); + } + [listener ignore]; + } else if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)]) { + [_webViewDelegate webView:webView decidePolicyForNavigationAction:actionInformation request:request frame:frame decisionListener:listener]; + } else { + [listener use]; + } +} + +- (void)webView:(WebView *)webView didCommitLoadForFrame:(WebFrame *)frame { + if (webView != _webView) { return; } + + if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:didCommitLoadForFrame:)]) { + [_webViewDelegate webView:webView didCommitLoadForFrame:frame]; + } +} + +- (NSURLRequest *)webView:(WebView *)webView resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource { + if (webView != _webView) { return request; } + + if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)]) { + return [_webViewDelegate webView:webView resource:identifier willSendRequest:request redirectResponse:redirectResponse fromDataSource:dataSource]; + } + + return request; +} + + + +/* Platform specific internals: OSX + **********************************/ +#elif defined WVJB_PLATFORM_IOS + +- (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(id)webViewDelegate handler:(WVJBHandler)messageHandler { + _messageHandler = messageHandler; + _webView = webView; + _webViewDelegate = webViewDelegate; + _messageHandlers = [NSMutableDictionary dictionary]; + _webView.delegate = self; +} + +- (void) _platformSpecificDealloc { + _webView.delegate = nil; +} + +- (void)webViewDidFinishLoad:(UIWebView *)webView { + if (webView != _webView) { return; } + + _numRequestsLoading--; + + if (_numRequestsLoading == 0 && ![[webView stringByEvaluatingJavaScriptFromString:@"typeof WebViewJavascriptBridge == 'object'"] isEqualToString:@"true"]) { + NSString *filePath = [[NSBundle mainBundle] pathForResource:@"WebViewJavascriptBridge.js" ofType:@"txt"]; + NSString *js = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; + [webView stringByEvaluatingJavaScriptFromString:js]; + } + + if (_startupMessageQueue) { + for (id queuedMessage in _startupMessageQueue) { + [self _dispatchMessage:queuedMessage]; + } + _startupMessageQueue = nil; + } + + __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; + if (strongDelegate && [strongDelegate respondsToSelector:@selector(webViewDidFinishLoad:)]) { + [strongDelegate webViewDidFinishLoad:webView]; + } +} + +- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { + if (webView != _webView) { return; } + + _numRequestsLoading--; + + __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; + if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) { + [strongDelegate webView:webView didFailLoadWithError:error]; + } +} + +- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { + if (webView != _webView) { return YES; } + NSURL *url = [request URL]; + __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; + if ([[url scheme] isEqualToString:kCustomProtocolScheme]) { + if ([[url host] isEqualToString:kQueueHasMessage]) { + [self _flushMessageQueue]; + } else { + NSLog(@"WebViewJavascriptBridge: WARNING: Received unknown WebViewJavascriptBridge command %@://%@", kCustomProtocolScheme, [url path]); + } + return NO; + } else if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) { + return [strongDelegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType]; + } else { + return YES; + } +} + +- (void)webViewDidStartLoad:(UIWebView *)webView { + if (webView != _webView) { return; } + + _numRequestsLoading++; + + __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; + if (strongDelegate && [strongDelegate respondsToSelector:@selector(webViewDidStartLoad:)]) { + [strongDelegate webViewDidStartLoad:webView]; + } +} + +#endif + +@end diff --git a/client/ios/Hackpad/vocaro.com/UIImage+Alpha.h b/client/ios/Hackpad/vocaro.com/UIImage+Alpha.h new file mode 100644 index 0000000..370d978 --- /dev/null +++ b/client/ios/Hackpad/vocaro.com/UIImage+Alpha.h @@ -0,0 +1,11 @@ +// UIImage+Alpha.h +// Created by Trevor Harmon on 9/20/09. +// Free for personal or commercial use, with or without modification. +// No warranty is expressed or implied. + +// Helper methods for adding an alpha layer to an image +@interface UIImage (Alpha) +- (BOOL)hasAlpha; +- (UIImage *)imageWithAlpha; +- (UIImage *)transparentBorderImage:(NSUInteger)borderSize; +@end diff --git a/client/ios/Hackpad/vocaro.com/UIImage+Alpha.m b/client/ios/Hackpad/vocaro.com/UIImage+Alpha.m new file mode 100644 index 0000000..139f27f --- /dev/null +++ b/client/ios/Hackpad/vocaro.com/UIImage+Alpha.m @@ -0,0 +1,122 @@ +// UIImage+Alpha.m +// Created by Trevor Harmon on 9/20/09. +// Free for personal or commercial use, with or without modification. +// No warranty is expressed or implied. + +#import "UIImage+Alpha.h" + +@implementation UIImage (Alpha) + +// Returns true if the image has an alpha layer +- (BOOL)hasAlpha { + CGImageAlphaInfo alpha = CGImageGetAlphaInfo(self.CGImage); + return (alpha == kCGImageAlphaFirst || + alpha == kCGImageAlphaLast || + alpha == kCGImageAlphaPremultipliedFirst || + alpha == kCGImageAlphaPremultipliedLast); +} + +// Returns a copy of the given image, adding an alpha channel if it doesn't already have one +- (UIImage *)imageWithAlpha { + if ([self hasAlpha]) { + return self; + } + + CGImageRef imageRef = self.CGImage; + size_t width = CGImageGetWidth(imageRef); + size_t height = CGImageGetHeight(imageRef); + + // The bitsPerComponent and bitmapInfo values are hard-coded to prevent an "unsupported parameter combination" error + CGContextRef offscreenContext = CGBitmapContextCreate(NULL, + width, + height, + 8, + 0, + CGImageGetColorSpace(imageRef), + kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst); + + // Draw the image into the context and retrieve the new image, which will now have an alpha layer + CGContextDrawImage(offscreenContext, CGRectMake(0, 0, width, height), imageRef); + CGImageRef imageRefWithAlpha = CGBitmapContextCreateImage(offscreenContext); + UIImage *imageWithAlpha = [UIImage imageWithCGImage:imageRefWithAlpha]; + + // Clean up + CGContextRelease(offscreenContext); + CGImageRelease(imageRefWithAlpha); + + return imageWithAlpha; +} + +// Returns a copy of the image with a transparent border of the given size added around its edges. +// If the image has no alpha layer, one will be added to it. +- (UIImage *)transparentBorderImage:(NSUInteger)borderSize { + // If the image does not have an alpha layer, add one + UIImage *image = [self imageWithAlpha]; + + CGRect newRect = CGRectMake(0, 0, image.size.width + borderSize * 2, image.size.height + borderSize * 2); + + // Build a context that's the same dimensions as the new size + CGContextRef bitmap = CGBitmapContextCreate(NULL, + newRect.size.width, + newRect.size.height, + CGImageGetBitsPerComponent(self.CGImage), + 0, + CGImageGetColorSpace(self.CGImage), + CGImageGetBitmapInfo(self.CGImage)); + + // Draw the image in the center of the context, leaving a gap around the edges + CGRect imageLocation = CGRectMake(borderSize, borderSize, image.size.width, image.size.height); + CGContextDrawImage(bitmap, imageLocation, self.CGImage); + CGImageRef borderImageRef = CGBitmapContextCreateImage(bitmap); + + // Create a mask to make the border transparent, and combine it with the image + CGImageRef maskImageRef = [self newBorderMask:borderSize size:newRect.size]; + CGImageRef transparentBorderImageRef = CGImageCreateWithMask(borderImageRef, maskImageRef); + UIImage *transparentBorderImage = [UIImage imageWithCGImage:transparentBorderImageRef]; + + // Clean up + CGContextRelease(bitmap); + CGImageRelease(borderImageRef); + CGImageRelease(maskImageRef); + CGImageRelease(transparentBorderImageRef); + + return transparentBorderImage; +} + +#pragma mark - +#pragma mark Private helper methods + +// Creates a mask that makes the outer edges transparent and everything else opaque +// The size must include the entire mask (opaque part + transparent border) +// The caller is responsible for releasing the returned reference by calling CGImageRelease +- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size { + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); + + // Build a context that's the same dimensions as the new size + CGContextRef maskContext = CGBitmapContextCreate(NULL, + size.width, + size.height, + 8, // 8-bit grayscale + 0, + colorSpace, + kCGBitmapByteOrderDefault | kCGImageAlphaNone); + + // Start with a mask that's entirely transparent + CGContextSetFillColorWithColor(maskContext, [UIColor blackColor].CGColor); + CGContextFillRect(maskContext, CGRectMake(0, 0, size.width, size.height)); + + // Make the inner part (within the border) opaque + CGContextSetFillColorWithColor(maskContext, [UIColor whiteColor].CGColor); + CGContextFillRect(maskContext, CGRectMake(borderSize, borderSize, size.width - borderSize * 2, size.height - borderSize * 2)); + + // Get an image of the context + CGImageRef maskImageRef = CGBitmapContextCreateImage(maskContext); + + // Clean up + CGContextRelease(maskContext); + CGColorSpaceRelease(colorSpace); + + return maskImageRef; +} + +@end diff --git a/client/ios/Hackpad/vocaro.com/UIImage+Resize.h b/client/ios/Hackpad/vocaro.com/UIImage+Resize.h new file mode 100644 index 0000000..f143381 --- /dev/null +++ b/client/ios/Hackpad/vocaro.com/UIImage+Resize.h @@ -0,0 +1,18 @@ +// UIImage+Resize.h +// Created by Trevor Harmon on 8/5/09. +// Free for personal or commercial use, with or without modification. +// No warranty is expressed or implied. + +// Extends the UIImage class to support resizing/cropping +@interface UIImage (Resize) +- (UIImage *)croppedImage:(CGRect)bounds; +- (UIImage *)thumbnailImage:(NSInteger)thumbnailSize + transparentBorder:(NSUInteger)borderSize + cornerRadius:(NSUInteger)cornerRadius + interpolationQuality:(CGInterpolationQuality)quality; +- (UIImage *)resizedImage:(CGSize)newSize + interpolationQuality:(CGInterpolationQuality)quality; +- (UIImage *)resizedImageWithContentMode:(UIViewContentMode)contentMode + bounds:(CGSize)bounds + interpolationQuality:(CGInterpolationQuality)quality; +@end diff --git a/client/ios/Hackpad/vocaro.com/UIImage+Resize.m b/client/ios/Hackpad/vocaro.com/UIImage+Resize.m new file mode 100644 index 0000000..fb220f0 --- /dev/null +++ b/client/ios/Hackpad/vocaro.com/UIImage+Resize.m @@ -0,0 +1,183 @@ +// UIImage+Resize.m +// Created by Trevor Harmon on 8/5/09. +// Free for personal or commercial use, with or without modification. +// No warranty is expressed or implied. + +#import "UIImage+Resize.h" +#import "UIImage+RoundedCorner.h" +#import "UIImage+Alpha.h" + +@implementation UIImage (Resize) + +// Returns a copy of this image that is cropped to the given bounds. +// The bounds will be adjusted using CGRectIntegral. +// This method ignores the image's imageOrientation setting. +- (UIImage *)croppedImage:(CGRect)bounds { + CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], bounds); + UIImage *croppedImage = [UIImage imageWithCGImage:imageRef]; + CGImageRelease(imageRef); + return croppedImage; +} + +// Returns a copy of this image that is squared to the thumbnail size. +// If transparentBorder is non-zero, a transparent border of the given size will be added around the edges of the thumbnail. (Adding a transparent border of at least one pixel in size has the side-effect of antialiasing the edges of the image when rotating it using Core Animation.) +- (UIImage *)thumbnailImage:(NSInteger)thumbnailSize + transparentBorder:(NSUInteger)borderSize + cornerRadius:(NSUInteger)cornerRadius + interpolationQuality:(CGInterpolationQuality)quality { + UIImage *resizedImage = [self resizedImageWithContentMode:UIViewContentModeScaleAspectFill + bounds:CGSizeMake(thumbnailSize, thumbnailSize) + interpolationQuality:quality]; + + // Crop out any part of the image that's larger than the thumbnail size + // The cropped rect must be centered on the resized image + // Round the origin points so that the size isn't altered when CGRectIntegral is later invoked + CGRect cropRect = CGRectMake(round((resizedImage.size.width - thumbnailSize) / 2), + round((resizedImage.size.height - thumbnailSize) / 2), + thumbnailSize, + thumbnailSize); + UIImage *croppedImage = [resizedImage croppedImage:cropRect]; + + UIImage *transparentBorderImage = borderSize ? [croppedImage transparentBorderImage:borderSize] : croppedImage; + + return [transparentBorderImage roundedCornerImage:cornerRadius borderSize:borderSize]; +} + +// Returns a rescaled copy of the image, taking into account its orientation +// The image will be scaled disproportionately if necessary to fit the bounds specified by the parameter +- (UIImage *)resizedImage:(CGSize)newSize interpolationQuality:(CGInterpolationQuality)quality { + BOOL drawTransposed; + + switch (self.imageOrientation) { + case UIImageOrientationLeft: + case UIImageOrientationLeftMirrored: + case UIImageOrientationRight: + case UIImageOrientationRightMirrored: + drawTransposed = YES; + break; + + default: + drawTransposed = NO; + } + + return [self resizedImage:newSize + transform:[self transformForOrientation:newSize] + drawTransposed:drawTransposed + interpolationQuality:quality]; +} + +// Resizes the image according to the given content mode, taking into account the image's orientation +- (UIImage *)resizedImageWithContentMode:(UIViewContentMode)contentMode + bounds:(CGSize)bounds + interpolationQuality:(CGInterpolationQuality)quality { + CGFloat horizontalRatio = bounds.width / self.size.width; + CGFloat verticalRatio = bounds.height / self.size.height; + CGFloat ratio; + + switch (contentMode) { + case UIViewContentModeScaleAspectFill: + ratio = MAX(horizontalRatio, verticalRatio); + break; + + case UIViewContentModeScaleAspectFit: + ratio = MIN(horizontalRatio, verticalRatio); + break; + + default: + [NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %ld", (long)contentMode]; + } + + CGSize newSize = CGSizeMake(self.size.width * ratio, self.size.height * ratio); + + return [self resizedImage:newSize interpolationQuality:quality]; +} + +#pragma mark - +#pragma mark Private helper methods + +// Returns a copy of the image that has been transformed using the given affine transform and scaled to the new size +// The new image's orientation will be UIImageOrientationUp, regardless of the current image's orientation +// If the new size is not integral, it will be rounded up +- (UIImage *)resizedImage:(CGSize)newSize + transform:(CGAffineTransform)transform + drawTransposed:(BOOL)transpose + interpolationQuality:(CGInterpolationQuality)quality { + CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height)); + CGRect transposedRect = CGRectMake(0, 0, newRect.size.height, newRect.size.width); + CGImageRef imageRef = self.CGImage; + + // Build a context that's the same dimensions as the new size + CGContextRef bitmap = CGBitmapContextCreate(NULL, + newRect.size.width, + newRect.size.height, + CGImageGetBitsPerComponent(imageRef), + 0, + CGImageGetColorSpace(imageRef), + CGImageGetBitmapInfo(imageRef)); + + // Rotate and/or flip the image if required by its orientation + CGContextConcatCTM(bitmap, transform); + + // Set the quality level to use when rescaling + CGContextSetInterpolationQuality(bitmap, quality); + + // Draw into the context; this scales the image + CGContextDrawImage(bitmap, transpose ? transposedRect : newRect, imageRef); + + // Get the resized image from the context and a UIImage + CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap); + UIImage *newImage = [UIImage imageWithCGImage:newImageRef]; + + // Clean up + CGContextRelease(bitmap); + CGImageRelease(newImageRef); + + return newImage; +} + +// Returns an affine transform that takes into account the image orientation when drawing a scaled image +- (CGAffineTransform)transformForOrientation:(CGSize)newSize { + CGAffineTransform transform = CGAffineTransformIdentity; + + switch (self.imageOrientation) { + case UIImageOrientationDown: // EXIF = 3 + case UIImageOrientationDownMirrored: // EXIF = 4 + transform = CGAffineTransformTranslate(transform, newSize.width, newSize.height); + transform = CGAffineTransformRotate(transform, M_PI); + break; + + case UIImageOrientationLeft: // EXIF = 6 + case UIImageOrientationLeftMirrored: // EXIF = 5 + transform = CGAffineTransformTranslate(transform, newSize.width, 0); + transform = CGAffineTransformRotate(transform, M_PI_2); + break; + + case UIImageOrientationRight: // EXIF = 8 + case UIImageOrientationRightMirrored: // EXIF = 7 + transform = CGAffineTransformTranslate(transform, 0, newSize.height); + transform = CGAffineTransformRotate(transform, -M_PI_2); + break; + default: + break; + } + + switch (self.imageOrientation) { + case UIImageOrientationUpMirrored: // EXIF = 2 + case UIImageOrientationDownMirrored: // EXIF = 4 + transform = CGAffineTransformTranslate(transform, newSize.width, 0); + transform = CGAffineTransformScale(transform, -1, 1); + break; + + case UIImageOrientationLeftMirrored: // EXIF = 5 + case UIImageOrientationRightMirrored: // EXIF = 7 + transform = CGAffineTransformTranslate(transform, newSize.height, 0); + transform = CGAffineTransformScale(transform, -1, 1); + break; + default: + break; + } + + return transform; +} + +@end diff --git a/client/ios/Hackpad/vocaro.com/UIImage+RoundedCorner.h b/client/ios/Hackpad/vocaro.com/UIImage+RoundedCorner.h new file mode 100644 index 0000000..630ebb3 --- /dev/null +++ b/client/ios/Hackpad/vocaro.com/UIImage+RoundedCorner.h @@ -0,0 +1,9 @@ +// UIImage+RoundedCorner.h +// Created by Trevor Harmon on 9/20/09. +// Free for personal or commercial use, with or without modification. +// No warranty is expressed or implied. + +// Extends the UIImage class to support making rounded corners +@interface UIImage (RoundedCorner) +- (UIImage *)roundedCornerImage:(NSInteger)cornerSize borderSize:(NSInteger)borderSize; +@end diff --git a/client/ios/Hackpad/vocaro.com/UIImage+RoundedCorner.m b/client/ios/Hackpad/vocaro.com/UIImage+RoundedCorner.m new file mode 100644 index 0000000..d611e1a --- /dev/null +++ b/client/ios/Hackpad/vocaro.com/UIImage+RoundedCorner.m @@ -0,0 +1,74 @@ +// UIImage+RoundedCorner.m +// Created by Trevor Harmon on 9/20/09. +// Free for personal or commercial use, with or without modification. +// No warranty is expressed or implied. + +#import "UIImage+RoundedCorner.h" +#import "UIImage+Alpha.h" + +@implementation UIImage (RoundedCorner) + +// Creates a copy of this image with rounded corners +// If borderSize is non-zero, a transparent border of the given size will also be added +// Original author: Björn Sållarp. Used with permission. See: http://blog.sallarp.com/iphone-uiimage-round-corners/ +- (UIImage *)roundedCornerImage:(NSInteger)cornerSize borderSize:(NSInteger)borderSize { + // If the image does not have an alpha layer, add one + UIImage *image = [self imageWithAlpha]; + + // Build a context that's the same dimensions as the new size + CGContextRef context = CGBitmapContextCreate(NULL, + image.size.width, + image.size.height, + CGImageGetBitsPerComponent(image.CGImage), + 0, + CGImageGetColorSpace(image.CGImage), + CGImageGetBitmapInfo(image.CGImage)); + + // Create a clipping path with rounded corners + CGContextBeginPath(context); + [self addRoundedRectToPath:CGRectMake(borderSize, borderSize, image.size.width - borderSize * 2, image.size.height - borderSize * 2) + context:context + ovalWidth:cornerSize + ovalHeight:cornerSize]; + CGContextClosePath(context); + CGContextClip(context); + + // Draw the image to the context; the clipping path will make anything outside the rounded rect transparent + CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage); + + // Create a CGImage from the context + CGImageRef clippedImage = CGBitmapContextCreateImage(context); + CGContextRelease(context); + + // Create a UIImage from the CGImage + UIImage *roundedImage = [UIImage imageWithCGImage:clippedImage]; + CGImageRelease(clippedImage); + + return roundedImage; +} + +#pragma mark - +#pragma mark Private helper methods + +// Adds a rectangular path to the given context and rounds its corners by the given extents +// Original author: Björn Sållarp. Used with permission. See: http://blog.sallarp.com/iphone-uiimage-round-corners/ +- (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight { + if (ovalWidth == 0 || ovalHeight == 0) { + CGContextAddRect(context, rect); + return; + } + CGContextSaveGState(context); + CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect)); + CGContextScaleCTM(context, ovalWidth, ovalHeight); + CGFloat fw = CGRectGetWidth(rect) / ovalWidth; + CGFloat fh = CGRectGetHeight(rect) / ovalHeight; + CGContextMoveToPoint(context, fw, fh/2); + CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1); + CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); + CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); + CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); + CGContextClosePath(context); + CGContextRestoreGState(context); +} + +@end diff --git a/client/osx/.gitignore b/client/osx/.gitignore new file mode 100644 index 0000000..5c69045 --- /dev/null +++ b/client/osx/.gitignore @@ -0,0 +1,23 @@ +# Xcode +build/* +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +!default.xcworkspace +xcuserdata +profile +*.moved-aside +# Finder +.DS_Store +#deploy script +deploy +rakefile*.rb +upload*.sh +*.rb +pkg/ +bin diff --git a/client/osx/ASICacheDelegate.h b/client/osx/ASICacheDelegate.h new file mode 100644 index 0000000..060cda5 --- /dev/null +++ b/client/osx/ASICacheDelegate.h @@ -0,0 +1,103 @@ +// +// ASICacheDelegate.h +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 01/05/2010. +// Copyright 2010 All-Seeing Interactive. All rights reserved. +// + +#import +@class ASIHTTPRequest; + +// Cache policies control the behaviour of a cache and how requests use the cache +// When setting a cache policy, you can use a combination of these values as a bitmask +// For example: [request setCachePolicy:ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy|ASIDoNotWriteToCacheCachePolicy]; +// Note that some of the behaviours below are mutally exclusive - you cannot combine ASIAskServerIfModifiedWhenStaleCachePolicy and ASIAskServerIfModifiedCachePolicy, for example. +typedef enum _ASICachePolicy { + + // The default cache policy. When you set a request to use this, it will use the cache's defaultCachePolicy + // ASIDownloadCache's default cache policy is 'ASIAskServerIfModifiedWhenStaleCachePolicy' + ASIUseDefaultCachePolicy = 0, + + // Tell the request not to read from the cache + ASIDoNotReadFromCacheCachePolicy = 1, + + // The the request not to write to the cache + ASIDoNotWriteToCacheCachePolicy = 2, + + // Ask the server if there is an updated version of this resource (using a conditional GET) ONLY when the cached data is stale + ASIAskServerIfModifiedWhenStaleCachePolicy = 4, + + // Always ask the server if there is an updated version of this resource (using a conditional GET) + ASIAskServerIfModifiedCachePolicy = 8, + + // If cached data exists, use it even if it is stale. This means requests will not talk to the server unless the resource they are requesting is not in the cache + ASIOnlyLoadIfNotCachedCachePolicy = 16, + + // If cached data exists, use it even if it is stale. If cached data does not exist, stop (will not set an error on the request) + ASIDontLoadCachePolicy = 32, + + // Specifies that cached data may be used if the request fails. If cached data is used, the request will succeed without error. Usually used in combination with other options above. + ASIFallbackToCacheIfLoadFailsCachePolicy = 64 +} ASICachePolicy; + +// Cache storage policies control whether cached data persists between application launches (ASICachePermanentlyCacheStoragePolicy) or not (ASICacheForSessionDurationCacheStoragePolicy) +// Calling [ASIHTTPRequest clearSession] will remove any data stored using ASICacheForSessionDurationCacheStoragePolicy +typedef enum _ASICacheStoragePolicy { + ASICacheForSessionDurationCacheStoragePolicy = 0, + ASICachePermanentlyCacheStoragePolicy = 1 +} ASICacheStoragePolicy; + + +@protocol ASICacheDelegate + +@required + +// Should return the cache policy that will be used when requests have their cache policy set to ASIUseDefaultCachePolicy +- (ASICachePolicy)defaultCachePolicy; + +// Returns the date a cached response should expire on. Pass a non-zero max age to specify a custom date. +- (NSDate *)expiryDateForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge; + +// Updates cached response headers with a new expiry date. Pass a non-zero max age to specify a custom date. +- (void)updateExpiryForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge; + +// Looks at the request's cache policy and any cached headers to determine if the cache data is still valid +- (BOOL)canUseCachedDataForRequest:(ASIHTTPRequest *)request; + +// Removes cached data for a particular request +- (void)removeCachedDataForRequest:(ASIHTTPRequest *)request; + +// Should return YES if the cache considers its cached response current for the request +// Should return NO is the data is not cached, or (for example) if the cached headers state the request should have expired +- (BOOL)isCachedDataCurrentForRequest:(ASIHTTPRequest *)request; + +// Should store the response for the passed request in the cache +// When a non-zero maxAge is passed, it should be used as the expiry time for the cached response +- (void)storeResponseForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge; + +// Removes cached data for a particular url +- (void)removeCachedDataForURL:(NSURL *)url; + +// Should return an NSDictionary of cached headers for the passed URL, if it is stored in the cache +- (NSDictionary *)cachedResponseHeadersForURL:(NSURL *)url; + +// Should return the cached body of a response for the passed URL, if it is stored in the cache +- (NSData *)cachedResponseDataForURL:(NSURL *)url; + +// Returns a path to the cached response data, if it exists +- (NSString *)pathToCachedResponseDataForURL:(NSURL *)url; + +// Returns a path to the cached response headers, if they url +- (NSString *)pathToCachedResponseHeadersForURL:(NSURL *)url; + +// Returns the location to use to store cached response headers for a particular request +- (NSString *)pathToStoreCachedResponseHeadersForRequest:(ASIHTTPRequest *)request; + +// Returns the location to use to store a cached response body for a particular request +- (NSString *)pathToStoreCachedResponseDataForRequest:(ASIHTTPRequest *)request; + +// Clear cached data stored for the passed storage policy +- (void)clearCachedResponsesForStoragePolicy:(ASICacheStoragePolicy)cachePolicy; + +@end diff --git a/client/osx/ASIDataCompressor.h b/client/osx/ASIDataCompressor.h new file mode 100644 index 0000000..ae0e441 --- /dev/null +++ b/client/osx/ASIDataCompressor.h @@ -0,0 +1,42 @@ +// +// ASIDataCompressor.h +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 17/08/2010. +// Copyright 2010 All-Seeing Interactive. All rights reserved. +// + +// This is a helper class used by ASIHTTPRequest to handle deflating (compressing) data in memory and on disk +// You may also find it helpful if you need to deflate data and files yourself - see the class methods below +// Most of the zlib stuff is based on the sample code by Mark Adler available at http://zlib.net + +#import +#import + +@interface ASIDataCompressor : NSObject { + BOOL streamReady; + z_stream zStream; +} + +// Convenience constructor will call setupStream for you ++ (id)compressor; + +// Compress the passed chunk of data +// Passing YES for shouldFinish will finalize the deflated data - you must pass YES when you are on the last chunk of data +- (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err shouldFinish:(BOOL)shouldFinish; + +// Convenience method - pass it some data, and you'll get deflated data back ++ (NSData *)compressData:(NSData*)uncompressedData error:(NSError **)err; + +// Convenience method - pass it a file containing the data to compress in sourcePath, and it will write deflated data to destinationPath ++ (BOOL)compressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err; + +// Sets up zlib to handle the inflating. You only need to call this yourself if you aren't using the convenience constructor 'compressor' +- (NSError *)setupStream; + +// Tells zlib to clean up. You need to call this if you need to cancel deflating part way through +// If deflating finishes or fails, this method will be called automatically +- (NSError *)closeStream; + +@property (assign, readonly) BOOL streamReady; +@end diff --git a/client/osx/ASIDataCompressor.m b/client/osx/ASIDataCompressor.m new file mode 100644 index 0000000..1e9fd8d --- /dev/null +++ b/client/osx/ASIDataCompressor.m @@ -0,0 +1,219 @@ +// +// ASIDataCompressor.m +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 17/08/2010. +// Copyright 2010 All-Seeing Interactive. All rights reserved. +// + +#import "ASIDataCompressor.h" +#import "ASIHTTPRequest.h" + +#define DATA_CHUNK_SIZE 262144 // Deal with gzipped data in 256KB chunks +#define COMPRESSION_AMOUNT Z_DEFAULT_COMPRESSION + +@interface ASIDataCompressor () ++ (NSError *)deflateErrorWithCode:(int)code; +@end + +@implementation ASIDataCompressor + ++ (id)compressor +{ + ASIDataCompressor *compressor = [[[self alloc] init] autorelease]; + [compressor setupStream]; + return compressor; +} + +- (void)dealloc +{ + if (streamReady) { + [self closeStream]; + } + [super dealloc]; +} + +- (NSError *)setupStream +{ + if (streamReady) { + return nil; + } + // Setup the inflate stream + zStream.zalloc = Z_NULL; + zStream.zfree = Z_NULL; + zStream.opaque = Z_NULL; + zStream.avail_in = 0; + zStream.next_in = 0; + int status = deflateInit2(&zStream, COMPRESSION_AMOUNT, Z_DEFLATED, (15+16), 8, Z_DEFAULT_STRATEGY); + if (status != Z_OK) { + return [[self class] deflateErrorWithCode:status]; + } + streamReady = YES; + return nil; +} + +- (NSError *)closeStream +{ + if (!streamReady) { + return nil; + } + // Close the deflate stream + streamReady = NO; + int status = deflateEnd(&zStream); + if (status != Z_OK) { + return [[self class] deflateErrorWithCode:status]; + } + return nil; +} + +- (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err shouldFinish:(BOOL)shouldFinish +{ + if (length == 0) return nil; + + NSUInteger halfLength = length/2; + + // We'll take a guess that the compressed data will fit in half the size of the original (ie the max to compress at once is half DATA_CHUNK_SIZE), if not, we'll increase it below + NSMutableData *outputData = [NSMutableData dataWithLength:length/2]; + + int status; + + zStream.next_in = bytes; + zStream.avail_in = (unsigned int)length; + zStream.avail_out = 0; + + NSInteger bytesProcessedAlready = zStream.total_out; + while (zStream.avail_out == 0) { + + if (zStream.total_out-bytesProcessedAlready >= [outputData length]) { + [outputData increaseLengthBy:halfLength]; + } + + zStream.next_out = [outputData mutableBytes] + zStream.total_out-bytesProcessedAlready; + zStream.avail_out = (unsigned int)([outputData length] - (zStream.total_out-bytesProcessedAlready)); + status = deflate(&zStream, shouldFinish ? Z_FINISH : Z_NO_FLUSH); + + if (status == Z_STREAM_END) { + break; + } else if (status != Z_OK) { + if (err) { + *err = [[self class] deflateErrorWithCode:status]; + } + return NO; + } + } + + // Set real length + [outputData setLength: zStream.total_out-bytesProcessedAlready]; + return outputData; +} + + ++ (NSData *)compressData:(NSData*)uncompressedData error:(NSError **)err +{ + NSError *theError = nil; + NSData *outputData = [[ASIDataCompressor compressor] compressBytes:(Bytef *)[uncompressedData bytes] length:[uncompressedData length] error:&theError shouldFinish:YES]; + if (theError) { + if (err) { + *err = theError; + } + return nil; + } + return outputData; +} + + + ++ (BOOL)compressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err +{ + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; + + // Create an empty file at the destination path + if (![fileManager createFileAtPath:destinationPath contents:[NSData data] attributes:nil]) { + if (err) { + *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed because we were to create a file at %@",sourcePath,destinationPath],NSLocalizedDescriptionKey,nil]]; + } + return NO; + } + + // Ensure the source file exists + if (![fileManager fileExistsAtPath:sourcePath]) { + if (err) { + *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed the file does not exist",sourcePath],NSLocalizedDescriptionKey,nil]]; + } + return NO; + } + + UInt8 inputData[DATA_CHUNK_SIZE]; + NSData *outputData; + NSInteger readLength; + NSError *theError = nil; + + ASIDataCompressor *compressor = [ASIDataCompressor compressor]; + + NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:sourcePath]; + [inputStream open]; + NSOutputStream *outputStream = [NSOutputStream outputStreamToFileAtPath:destinationPath append:NO]; + [outputStream open]; + + while ([compressor streamReady]) { + + // Read some data from the file + readLength = [inputStream read:inputData maxLength:DATA_CHUNK_SIZE]; + + // Make sure nothing went wrong + if ([inputStream streamStatus] == NSStreamEventErrorOccurred) { + if (err) { + *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed because we were unable to read from the source data file",sourcePath],NSLocalizedDescriptionKey,[inputStream streamError],NSUnderlyingErrorKey,nil]]; + } + [compressor closeStream]; + return NO; + } + // Have we reached the end of the input data? + if (!readLength) { + break; + } + + // Attempt to deflate the chunk of data + outputData = [compressor compressBytes:inputData length:readLength error:&theError shouldFinish:readLength < DATA_CHUNK_SIZE ]; + if (theError) { + if (err) { + *err = theError; + } + [compressor closeStream]; + return NO; + } + + // Write the deflated data out to the destination file + [outputStream write:[outputData bytes] maxLength:[outputData length]]; + + // Make sure nothing went wrong + if ([inputStream streamStatus] == NSStreamEventErrorOccurred) { + if (err) { + *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed because we were unable to write to the destination data file at &@",sourcePath,destinationPath],NSLocalizedDescriptionKey,[outputStream streamError],NSUnderlyingErrorKey,nil]]; + } + [compressor closeStream]; + return NO; + } + + } + [inputStream close]; + [outputStream close]; + + NSError *error = [compressor closeStream]; + if (error) { + if (err) { + *err = error; + } + return NO; + } + + return YES; +} + ++ (NSError *)deflateErrorWithCode:(int)code +{ + return [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of data failed with code %hi",code],NSLocalizedDescriptionKey,nil]]; +} + +@synthesize streamReady; +@end diff --git a/client/osx/ASIDataDecompressor.h b/client/osx/ASIDataDecompressor.h new file mode 100644 index 0000000..8be8f9b --- /dev/null +++ b/client/osx/ASIDataDecompressor.h @@ -0,0 +1,41 @@ +// +// ASIDataDecompressor.h +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 17/08/2010. +// Copyright 2010 All-Seeing Interactive. All rights reserved. +// + +// This is a helper class used by ASIHTTPRequest to handle inflating (decompressing) data in memory and on disk +// You may also find it helpful if you need to inflate data and files yourself - see the class methods below +// Most of the zlib stuff is based on the sample code by Mark Adler available at http://zlib.net + +#import +#import + +@interface ASIDataDecompressor : NSObject { + BOOL streamReady; + z_stream zStream; +} + +// Convenience constructor will call setupStream for you ++ (id)decompressor; + +// Uncompress the passed chunk of data +- (NSData *)uncompressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err; + +// Convenience method - pass it some deflated data, and you'll get inflated data back ++ (NSData *)uncompressData:(NSData*)compressedData error:(NSError **)err; + +// Convenience method - pass it a file containing deflated data in sourcePath, and it will write inflated data to destinationPath ++ (BOOL)uncompressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err; + +// Sets up zlib to handle the inflating. You only need to call this yourself if you aren't using the convenience constructor 'decompressor' +- (NSError *)setupStream; + +// Tells zlib to clean up. You need to call this if you need to cancel inflating part way through +// If inflating finishes or fails, this method will be called automatically +- (NSError *)closeStream; + +@property (assign, readonly) BOOL streamReady; +@end diff --git a/client/osx/ASIDataDecompressor.m b/client/osx/ASIDataDecompressor.m new file mode 100644 index 0000000..61cfeb7 --- /dev/null +++ b/client/osx/ASIDataDecompressor.m @@ -0,0 +1,218 @@ +// +// ASIDataDecompressor.m +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 17/08/2010. +// Copyright 2010 All-Seeing Interactive. All rights reserved. +// + +#import "ASIDataDecompressor.h" +#import "ASIHTTPRequest.h" + +#define DATA_CHUNK_SIZE 262144 // Deal with gzipped data in 256KB chunks + +@interface ASIDataDecompressor () ++ (NSError *)inflateErrorWithCode:(int)code; +@end; + +@implementation ASIDataDecompressor + ++ (id)decompressor +{ + ASIDataDecompressor *decompressor = [[[self alloc] init] autorelease]; + [decompressor setupStream]; + return decompressor; +} + +- (void)dealloc +{ + if (streamReady) { + [self closeStream]; + } + [super dealloc]; +} + +- (NSError *)setupStream +{ + if (streamReady) { + return nil; + } + // Setup the inflate stream + zStream.zalloc = Z_NULL; + zStream.zfree = Z_NULL; + zStream.opaque = Z_NULL; + zStream.avail_in = 0; + zStream.next_in = 0; + int status = inflateInit2(&zStream, (15+32)); + if (status != Z_OK) { + return [[self class] inflateErrorWithCode:status]; + } + streamReady = YES; + return nil; +} + +- (NSError *)closeStream +{ + if (!streamReady) { + return nil; + } + // Close the inflate stream + streamReady = NO; + int status = inflateEnd(&zStream); + if (status != Z_OK) { + return [[self class] inflateErrorWithCode:status]; + } + return nil; +} + +- (NSData *)uncompressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err +{ + if (length == 0) return nil; + + NSUInteger halfLength = length/2; + NSMutableData *outputData = [NSMutableData dataWithLength:length+halfLength]; + + int status; + + zStream.next_in = bytes; + zStream.avail_in = (unsigned int)length; + zStream.avail_out = 0; + + NSInteger bytesProcessedAlready = zStream.total_out; + while (zStream.avail_in != 0) { + + if (zStream.total_out-bytesProcessedAlready >= [outputData length]) { + [outputData increaseLengthBy:halfLength]; + } + + zStream.next_out = [outputData mutableBytes] + zStream.total_out-bytesProcessedAlready; + zStream.avail_out = (unsigned int)([outputData length] - (zStream.total_out-bytesProcessedAlready)); + + status = inflate(&zStream, Z_NO_FLUSH); + + if (status == Z_STREAM_END) { + break; + } else if (status != Z_OK) { + if (err) { + *err = [[self class] inflateErrorWithCode:status]; + } + return nil; + } + } + + // Set real length + [outputData setLength: zStream.total_out-bytesProcessedAlready]; + return outputData; +} + + ++ (NSData *)uncompressData:(NSData*)compressedData error:(NSError **)err +{ + NSError *theError = nil; + NSData *outputData = [[ASIDataDecompressor decompressor] uncompressBytes:(Bytef *)[compressedData bytes] length:[compressedData length] error:&theError]; + if (theError) { + if (err) { + *err = theError; + } + return nil; + } + return outputData; +} + ++ (BOOL)uncompressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err +{ + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; + + // Create an empty file at the destination path + if (![fileManager createFileAtPath:destinationPath contents:[NSData data] attributes:nil]) { + if (err) { + *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed because we were to create a file at %@",sourcePath,destinationPath],NSLocalizedDescriptionKey,nil]]; + } + return NO; + } + + // Ensure the source file exists + if (![fileManager fileExistsAtPath:sourcePath]) { + if (err) { + *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed the file does not exist",sourcePath],NSLocalizedDescriptionKey,nil]]; + } + return NO; + } + + UInt8 inputData[DATA_CHUNK_SIZE]; + NSData *outputData; + NSInteger readLength; + NSError *theError = nil; + + + ASIDataDecompressor *decompressor = [ASIDataDecompressor decompressor]; + + NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:sourcePath]; + [inputStream open]; + NSOutputStream *outputStream = [NSOutputStream outputStreamToFileAtPath:destinationPath append:NO]; + [outputStream open]; + + while ([decompressor streamReady]) { + + // Read some data from the file + readLength = [inputStream read:inputData maxLength:DATA_CHUNK_SIZE]; + + // Make sure nothing went wrong + if ([inputStream streamStatus] == NSStreamEventErrorOccurred) { + if (err) { + *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed because we were unable to read from the source data file",sourcePath],NSLocalizedDescriptionKey,[inputStream streamError],NSUnderlyingErrorKey,nil]]; + } + [decompressor closeStream]; + return NO; + } + // Have we reached the end of the input data? + if (!readLength) { + break; + } + + // Attempt to inflate the chunk of data + outputData = [decompressor uncompressBytes:inputData length:readLength error:&theError]; + if (theError) { + if (err) { + *err = theError; + } + [decompressor closeStream]; + return NO; + } + + // Write the inflated data out to the destination file + [outputStream write:[outputData bytes] maxLength:[outputData length]]; + + // Make sure nothing went wrong + if ([inputStream streamStatus] == NSStreamEventErrorOccurred) { + if (err) { + *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed because we were unable to write to the destination data file at &@",sourcePath,destinationPath],NSLocalizedDescriptionKey,[outputStream streamError],NSUnderlyingErrorKey,nil]]; + } + [decompressor closeStream]; + return NO; + } + + } + + [inputStream close]; + [outputStream close]; + + NSError *error = [decompressor closeStream]; + if (error) { + if (err) { + *err = error; + } + return NO; + } + + return YES; +} + + ++ (NSError *)inflateErrorWithCode:(int)code +{ + return [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of data failed with code %hi",code],NSLocalizedDescriptionKey,nil]]; +} + +@synthesize streamReady; +@end diff --git a/client/osx/ASIDownloadCache.h b/client/osx/ASIDownloadCache.h new file mode 100644 index 0000000..a2df908 --- /dev/null +++ b/client/osx/ASIDownloadCache.h @@ -0,0 +1,46 @@ +// +// ASIDownloadCache.h +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 01/05/2010. +// Copyright 2010 All-Seeing Interactive. All rights reserved. +// + +#import +#import "ASICacheDelegate.h" + +@interface ASIDownloadCache : NSObject { + + // The default cache policy for this cache + // Requests that store data in the cache will use this cache policy if their cache policy is set to ASIUseDefaultCachePolicy + // Defaults to ASIAskServerIfModifiedWhenStaleCachePolicy + ASICachePolicy defaultCachePolicy; + + // The directory in which cached data will be stored + // Defaults to a directory called 'ASIHTTPRequestCache' in the temporary directory + NSString *storagePath; + + // Mediates access to the cache + NSRecursiveLock *accessLock; + + // When YES, the cache will look for cache-control / pragma: no-cache headers, and won't reuse store responses if it finds them + BOOL shouldRespectCacheControlHeaders; +} + +// Returns a static instance of an ASIDownloadCache +// In most circumstances, it will make sense to use this as a global cache, rather than creating your own cache +// To make ASIHTTPRequests use it automatically, use [ASIHTTPRequest setDefaultCache:[ASIDownloadCache sharedCache]]; ++ (id)sharedCache; + +// A helper function that determines if the server has requested data should not be cached by looking at the request's response headers ++ (BOOL)serverAllowsResponseCachingForRequest:(ASIHTTPRequest *)request; + +// A list of file extensions that we know won't be readable by a webview when accessed locally +// If we're asking for a path to cache a particular url and it has one of these extensions, we change it to '.html' ++ (NSArray *)fileExtensionsToHandleAsHTML; + +@property (assign, nonatomic) ASICachePolicy defaultCachePolicy; +@property (retain, nonatomic) NSString *storagePath; +@property (retain) NSRecursiveLock *accessLock; +@property (assign) BOOL shouldRespectCacheControlHeaders; +@end diff --git a/client/osx/ASIDownloadCache.m b/client/osx/ASIDownloadCache.m new file mode 100644 index 0000000..93da36f --- /dev/null +++ b/client/osx/ASIDownloadCache.m @@ -0,0 +1,514 @@ +// +// ASIDownloadCache.m +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 01/05/2010. +// Copyright 2010 All-Seeing Interactive. All rights reserved. +// + +#import "ASIDownloadCache.h" +#import "ASIHTTPRequest.h" +#import + +static ASIDownloadCache *sharedCache = nil; + +static NSString *sessionCacheFolder = @"SessionStore"; +static NSString *permanentCacheFolder = @"PermanentStore"; +static NSArray *fileExtensionsToHandleAsHTML = nil; + +@interface ASIDownloadCache () ++ (NSString *)keyForURL:(NSURL *)url; +- (NSString *)pathToFile:(NSString *)file; +@end + +@implementation ASIDownloadCache + ++ (void)initialize +{ + if (self == [ASIDownloadCache class]) { + // Obviously this is not an exhaustive list, but hopefully these are the most commonly used and this will 'just work' for the widest range of people + // I imagine many web developers probably use url rewriting anyway + fileExtensionsToHandleAsHTML = [[NSArray alloc] initWithObjects:@"asp",@"aspx",@"jsp",@"php",@"rb",@"py",@"pl",@"cgi", nil]; + } +} + +- (id)init +{ + self = [super init]; + [self setShouldRespectCacheControlHeaders:YES]; + [self setDefaultCachePolicy:ASIUseDefaultCachePolicy]; + [self setAccessLock:[[[NSRecursiveLock alloc] init] autorelease]]; + return self; +} + ++ (id)sharedCache +{ + if (!sharedCache) { + @synchronized(self) { + if (!sharedCache) { + sharedCache = [[self alloc] init]; + [sharedCache setStoragePath:[[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"ASIHTTPRequestCache"]]; + } + } + } + return sharedCache; +} + +- (void)dealloc +{ + [storagePath release]; + [accessLock release]; + [super dealloc]; +} + +- (NSString *)storagePath +{ + [[self accessLock] lock]; + NSString *p = [[storagePath retain] autorelease]; + [[self accessLock] unlock]; + return p; +} + + +- (void)setStoragePath:(NSString *)path +{ + [[self accessLock] lock]; + [self clearCachedResponsesForStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy]; + [storagePath release]; + storagePath = [path retain]; + + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; + + BOOL isDirectory = NO; + NSArray *directories = [NSArray arrayWithObjects:path,[path stringByAppendingPathComponent:sessionCacheFolder],[path stringByAppendingPathComponent:permanentCacheFolder],nil]; + for (NSString *directory in directories) { + BOOL exists = [fileManager fileExistsAtPath:directory isDirectory:&isDirectory]; + if (exists && !isDirectory) { + [[self accessLock] unlock]; + [NSException raise:@"FileExistsAtCachePath" format:@"Cannot create a directory for the cache at '%@', because a file already exists",directory]; + } else if (!exists) { + [fileManager createDirectoryAtPath:directory withIntermediateDirectories:NO attributes:nil error:nil]; + if (![fileManager fileExistsAtPath:directory]) { + [[self accessLock] unlock]; + [NSException raise:@"FailedToCreateCacheDirectory" format:@"Failed to create a directory for the cache at '%@'",directory]; + } + } + } + [self clearCachedResponsesForStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy]; + [[self accessLock] unlock]; +} + +- (void)updateExpiryForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge +{ + NSString *headerPath = [self pathToStoreCachedResponseHeadersForRequest:request]; + NSMutableDictionary *cachedHeaders = [NSMutableDictionary dictionaryWithContentsOfFile:headerPath]; + if (!cachedHeaders) { + return; + } + NSDate *expires = [self expiryDateForRequest:request maxAge:maxAge]; + if (!expires) { + return; + } + [cachedHeaders setObject:[NSNumber numberWithDouble:[expires timeIntervalSince1970]] forKey:@"X-ASIHTTPRequest-Expires"]; + [cachedHeaders writeToFile:headerPath atomically:NO]; +} + +- (NSDate *)expiryDateForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge +{ + return [ASIHTTPRequest expiryDateForRequest:request maxAge:maxAge]; +} + +- (void)storeResponseForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge +{ + [[self accessLock] lock]; + + if ([request error] || ![request responseHeaders] || ([request cachePolicy] & ASIDoNotWriteToCacheCachePolicy)) { + [[self accessLock] unlock]; + return; + } + + // We only cache 200/OK or redirect reponses (redirect responses are cached so the cache works better with no internet connection) + int responseCode = [request responseStatusCode]; + if (responseCode != 200 && responseCode != 301 && responseCode != 302 && responseCode != 303 && responseCode != 307) { + [[self accessLock] unlock]; + return; + } + + if ([self shouldRespectCacheControlHeaders] && ![[self class] serverAllowsResponseCachingForRequest:request]) { + [[self accessLock] unlock]; + return; + } + + NSString *headerPath = [self pathToStoreCachedResponseHeadersForRequest:request]; + NSString *dataPath = [self pathToStoreCachedResponseDataForRequest:request]; + + NSMutableDictionary *responseHeaders = [NSMutableDictionary dictionaryWithDictionary:[request responseHeaders]]; + if ([request isResponseCompressed]) { + [responseHeaders removeObjectForKey:@"Content-Encoding"]; + } + + // Create a special 'X-ASIHTTPRequest-Expires' header + // This is what we use for deciding if cached data is current, rather than parsing the expires / max-age headers individually each time + // We store this as a timestamp to make reading it easier as NSDateFormatter is quite expensive + + NSDate *expires = [self expiryDateForRequest:request maxAge:maxAge]; + if (expires) { + [responseHeaders setObject:[NSNumber numberWithDouble:[expires timeIntervalSince1970]] forKey:@"X-ASIHTTPRequest-Expires"]; + } + + // Store the response code in a custom header so we can reuse it later + + // We'll change 304/Not Modified to 200/OK because this is likely to be us updating the cached headers with a conditional GET + int statusCode = [request responseStatusCode]; + if (statusCode == 304) { + statusCode = 200; + } + [responseHeaders setObject:[NSNumber numberWithInt:statusCode] forKey:@"X-ASIHTTPRequest-Response-Status-Code"]; + + [responseHeaders writeToFile:headerPath atomically:NO]; + + if ([request responseData]) { + [[request responseData] writeToFile:dataPath atomically:NO]; + } else if ([request downloadDestinationPath] && ![[request downloadDestinationPath] isEqualToString:dataPath]) { + NSError *error = nil; + NSFileManager* manager = [[NSFileManager alloc] init]; + if ([manager fileExistsAtPath:dataPath]) { + [manager removeItemAtPath:dataPath error:&error]; + } + [manager copyItemAtPath:[request downloadDestinationPath] toPath:dataPath error:&error]; + [manager release]; + } + [[self accessLock] unlock]; +} + +- (NSDictionary *)cachedResponseHeadersForURL:(NSURL *)url +{ + NSString *path = [self pathToCachedResponseHeadersForURL:url]; + if (path) { + return [NSDictionary dictionaryWithContentsOfFile:path]; + } + return nil; +} + +- (NSData *)cachedResponseDataForURL:(NSURL *)url +{ + NSString *path = [self pathToCachedResponseDataForURL:url]; + if (path) { + return [NSData dataWithContentsOfFile:path]; + } + return nil; +} + +- (NSString *)pathToCachedResponseDataForURL:(NSURL *)url +{ + // Grab the file extension, if there is one. We do this so we can save the cached response with the same file extension - this is important if you want to display locally cached data in a web view + NSString *extension = [[url path] pathExtension]; + + // If the url doesn't have an extension, we'll add one so a webview can read it when locally cached + // If the url has the extension of a common web scripting language, we'll change the extension on the cached path to html for the same reason + if (![extension length] || [[[self class] fileExtensionsToHandleAsHTML] containsObject:[extension lowercaseString]]) { + extension = @"html"; + } + return [self pathToFile:[[[self class] keyForURL:url] stringByAppendingPathExtension:extension]]; +} + ++ (NSArray *)fileExtensionsToHandleAsHTML +{ + return fileExtensionsToHandleAsHTML; +} + + +- (NSString *)pathToCachedResponseHeadersForURL:(NSURL *)url +{ + return [self pathToFile:[[[self class] keyForURL:url] stringByAppendingPathExtension:@"cachedheaders"]]; +} + +- (NSString *)pathToFile:(NSString *)file +{ + [[self accessLock] lock]; + if (![self storagePath]) { + [[self accessLock] unlock]; + return nil; + } + + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; + + // Look in the session store + NSString *dataPath = [[[self storagePath] stringByAppendingPathComponent:sessionCacheFolder] stringByAppendingPathComponent:file]; + if ([fileManager fileExistsAtPath:dataPath]) { + [[self accessLock] unlock]; + return dataPath; + } + // Look in the permanent store + dataPath = [[[self storagePath] stringByAppendingPathComponent:permanentCacheFolder] stringByAppendingPathComponent:file]; + if ([fileManager fileExistsAtPath:dataPath]) { + [[self accessLock] unlock]; + return dataPath; + } + [[self accessLock] unlock]; + return nil; +} + + +- (NSString *)pathToStoreCachedResponseDataForRequest:(ASIHTTPRequest *)request +{ + [[self accessLock] lock]; + if (![self storagePath]) { + [[self accessLock] unlock]; + return nil; + } + + NSString *path = [[self storagePath] stringByAppendingPathComponent:([request cacheStoragePolicy] == ASICacheForSessionDurationCacheStoragePolicy ? sessionCacheFolder : permanentCacheFolder)]; + + // Grab the file extension, if there is one. We do this so we can save the cached response with the same file extension - this is important if you want to display locally cached data in a web view + NSString *extension = [[[request url] path] pathExtension]; + + // If the url doesn't have an extension, we'll add one so a webview can read it when locally cached + // If the url has the extension of a common web scripting language, we'll change the extension on the cached path to html for the same reason + if (![extension length] || [[[self class] fileExtensionsToHandleAsHTML] containsObject:[extension lowercaseString]]) { + extension = @"html"; + } + path = [path stringByAppendingPathComponent:[[[self class] keyForURL:[request url]] stringByAppendingPathExtension:extension]]; + [[self accessLock] unlock]; + return path; +} + +- (NSString *)pathToStoreCachedResponseHeadersForRequest:(ASIHTTPRequest *)request +{ + [[self accessLock] lock]; + if (![self storagePath]) { + [[self accessLock] unlock]; + return nil; + } + NSString *path = [[self storagePath] stringByAppendingPathComponent:([request cacheStoragePolicy] == ASICacheForSessionDurationCacheStoragePolicy ? sessionCacheFolder : permanentCacheFolder)]; + path = [path stringByAppendingPathComponent:[[[self class] keyForURL:[request url]] stringByAppendingPathExtension:@"cachedheaders"]]; + [[self accessLock] unlock]; + return path; +} + +- (void)removeCachedDataForURL:(NSURL *)url +{ + [[self accessLock] lock]; + if (![self storagePath]) { + [[self accessLock] unlock]; + return; + } + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; + + NSString *path = [self pathToCachedResponseHeadersForURL:url]; + if (path) { + [fileManager removeItemAtPath:path error:NULL]; + } + + path = [self pathToCachedResponseDataForURL:url]; + if (path) { + [fileManager removeItemAtPath:path error:NULL]; + } + [[self accessLock] unlock]; +} + +- (void)removeCachedDataForRequest:(ASIHTTPRequest *)request +{ + [self removeCachedDataForURL:[request url]]; +} + +- (BOOL)isCachedDataCurrentForRequest:(ASIHTTPRequest *)request +{ + [[self accessLock] lock]; + if (![self storagePath]) { + [[self accessLock] unlock]; + return NO; + } + NSDictionary *cachedHeaders = [self cachedResponseHeadersForURL:[request url]]; + if (!cachedHeaders) { + [[self accessLock] unlock]; + return NO; + } + NSString *dataPath = [self pathToCachedResponseDataForURL:[request url]]; + if (!dataPath) { + [[self accessLock] unlock]; + return NO; + } + + // New content is not different + if ([request responseStatusCode] == 304) { + [[self accessLock] unlock]; + return YES; + } + + // If we already have response headers for this request, check to see if the new content is different + // We check [request complete] so that we don't end up comparing response headers from a redirection with these + if ([request responseHeaders] && [request complete]) { + + // If the Etag or Last-Modified date are different from the one we have, we'll have to fetch this resource again + NSArray *headersToCompare = [NSArray arrayWithObjects:@"Etag",@"Last-Modified",nil]; + for (NSString *header in headersToCompare) { + if (![[[request responseHeaders] objectForKey:header] isEqualToString:[cachedHeaders objectForKey:header]]) { + [[self accessLock] unlock]; + return NO; + } + } + } + + if ([self shouldRespectCacheControlHeaders]) { + + // Look for X-ASIHTTPRequest-Expires header to see if the content is out of date + NSNumber *expires = [cachedHeaders objectForKey:@"X-ASIHTTPRequest-Expires"]; + if (expires) { + if ([[NSDate dateWithTimeIntervalSince1970:[expires doubleValue]] timeIntervalSinceNow] >= 0) { + [[self accessLock] unlock]; + return YES; + } + } + + // No explicit expiration time sent by the server + [[self accessLock] unlock]; + return NO; + } + + + [[self accessLock] unlock]; + return YES; +} + +- (ASICachePolicy)defaultCachePolicy +{ + [[self accessLock] lock]; + ASICachePolicy cp = defaultCachePolicy; + [[self accessLock] unlock]; + return cp; +} + + +- (void)setDefaultCachePolicy:(ASICachePolicy)cachePolicy +{ + [[self accessLock] lock]; + if (!cachePolicy) { + defaultCachePolicy = ASIAskServerIfModifiedWhenStaleCachePolicy; + } else { + defaultCachePolicy = cachePolicy; + } + [[self accessLock] unlock]; +} + +- (void)clearCachedResponsesForStoragePolicy:(ASICacheStoragePolicy)storagePolicy +{ + [[self accessLock] lock]; + if (![self storagePath]) { + [[self accessLock] unlock]; + return; + } + NSString *path = [[self storagePath] stringByAppendingPathComponent:(storagePolicy == ASICacheForSessionDurationCacheStoragePolicy ? sessionCacheFolder : permanentCacheFolder)]; + + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; + + BOOL isDirectory = NO; + BOOL exists = [fileManager fileExistsAtPath:path isDirectory:&isDirectory]; + if (!exists || !isDirectory) { + [[self accessLock] unlock]; + return; + } + NSError *error = nil; + NSArray *cacheFiles = [fileManager contentsOfDirectoryAtPath:path error:&error]; + if (error) { + [[self accessLock] unlock]; + [NSException raise:@"FailedToTraverseCacheDirectory" format:@"Listing cache directory failed at path '%@'",path]; + } + for (NSString *file in cacheFiles) { + [fileManager removeItemAtPath:[path stringByAppendingPathComponent:file] error:&error]; + if (error) { + [[self accessLock] unlock]; + [NSException raise:@"FailedToRemoveCacheFile" format:@"Failed to remove cached data at path '%@'",path]; + } + } + [[self accessLock] unlock]; +} + ++ (BOOL)serverAllowsResponseCachingForRequest:(ASIHTTPRequest *)request +{ + NSString *cacheControl = [[[request responseHeaders] objectForKey:@"Cache-Control"] lowercaseString]; + if (cacheControl) { + if ([cacheControl isEqualToString:@"no-cache"] || [cacheControl isEqualToString:@"no-store"]) { + return NO; + } + } + NSString *pragma = [[[request responseHeaders] objectForKey:@"Pragma"] lowercaseString]; + if (pragma) { + if ([pragma isEqualToString:@"no-cache"]) { + return NO; + } + } + return YES; +} + ++ (NSString *)keyForURL:(NSURL *)url +{ + NSString *urlString = [url absoluteString]; + if ([urlString length] == 0) { + return nil; + } + + // Strip trailing slashes so http://allseeing-i.com/ASIHTTPRequest/ is cached the same as http://allseeing-i.com/ASIHTTPRequest + if ([[urlString substringFromIndex:[urlString length]-1] isEqualToString:@"/"]) { + urlString = [urlString substringToIndex:[urlString length]-1]; + } + + // Borrowed from: http://stackoverflow.com/questions/652300/using-md5-hash-on-a-string-in-cocoa + const char *cStr = [urlString UTF8String]; + unsigned char result[16]; + CC_MD5(cStr, (CC_LONG)strlen(cStr), result); + return [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7],result[8], result[9], result[10], result[11],result[12], result[13], result[14], result[15]]; +} + +- (BOOL)canUseCachedDataForRequest:(ASIHTTPRequest *)request +{ + // Ensure the request is allowed to read from the cache + if ([request cachePolicy] & ASIDoNotReadFromCacheCachePolicy) { + return NO; + + // If we don't want to load the request whatever happens, always pretend we have cached data even if we don't + } else if ([request cachePolicy] & ASIDontLoadCachePolicy) { + return YES; + } + + NSDictionary *headers = [self cachedResponseHeadersForURL:[request url]]; + if (!headers) { + return NO; + } + NSString *dataPath = [self pathToCachedResponseDataForURL:[request url]]; + if (!dataPath) { + return NO; + } + + // If we get here, we have cached data + + // If we have cached data, we can use it + if ([request cachePolicy] & ASIOnlyLoadIfNotCachedCachePolicy) { + return YES; + + // If we want to fallback to the cache after an error + } else if ([request complete] && [request cachePolicy] & ASIFallbackToCacheIfLoadFailsCachePolicy) { + return YES; + + // If we have cached data that is current, we can use it + } else if ([request cachePolicy] & ASIAskServerIfModifiedWhenStaleCachePolicy) { + if ([self isCachedDataCurrentForRequest:request]) { + return YES; + } + + // If we've got headers from a conditional GET and the cached data is still current, we can use it + } else if ([request cachePolicy] & ASIAskServerIfModifiedCachePolicy) { + if (![request responseHeaders]) { + return NO; + } else if ([self isCachedDataCurrentForRequest:request]) { + return YES; + } + } + return NO; +} + +@synthesize storagePath; +@synthesize defaultCachePolicy; +@synthesize accessLock; +@synthesize shouldRespectCacheControlHeaders; +@end diff --git a/client/osx/ASIFormDataRequest.h b/client/osx/ASIFormDataRequest.h new file mode 100644 index 0000000..670995f --- /dev/null +++ b/client/osx/ASIFormDataRequest.h @@ -0,0 +1,76 @@ +// +// ASIFormDataRequest.h +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 07/11/2008. +// Copyright 2008-2009 All-Seeing Interactive. All rights reserved. +// + +#import +#import "ASIHTTPRequest.h" +#import "ASIHTTPRequestConfig.h" + +typedef enum _ASIPostFormat { + ASIMultipartFormDataPostFormat = 0, + ASIURLEncodedPostFormat = 1 + +} ASIPostFormat; + +@interface ASIFormDataRequest : ASIHTTPRequest { + + // Parameters that will be POSTed to the url + NSMutableArray *postData; + + // Files that will be POSTed to the url + NSMutableArray *fileData; + + ASIPostFormat postFormat; + + NSStringEncoding stringEncoding; + +#if DEBUG_FORM_DATA_REQUEST + // Will store a string version of the request body that will be printed to the console when ASIHTTPREQUEST_DEBUG is set in GCC_PREPROCESSOR_DEFINITIONS + NSString *debugBodyString; +#endif + +} + +#pragma mark utilities +- (NSString*)encodeURL:(NSString *)string; + +#pragma mark setup request + +// Add a POST variable to the request +- (void)addPostValue:(id )value forKey:(NSString *)key; + +// Set a POST variable for this request, clearing any others with the same key +- (void)setPostValue:(id )value forKey:(NSString *)key; + +// Add the contents of a local file to the request +- (void)addFile:(NSString *)filePath forKey:(NSString *)key; + +// Same as above, but you can specify the content-type and file name +- (void)addFile:(NSString *)filePath withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key; + +// Add the contents of a local file to the request, clearing any others with the same key +- (void)setFile:(NSString *)filePath forKey:(NSString *)key; + +// Same as above, but you can specify the content-type and file name +- (void)setFile:(NSString *)filePath withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key; + +// Add the contents of an NSData object to the request +- (void)addData:(NSData *)data forKey:(NSString *)key; + +// Same as above, but you can specify the content-type and file name +- (void)addData:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key; + +// Add the contents of an NSData object to the request, clearing any others with the same key +- (void)setData:(NSData *)data forKey:(NSString *)key; + +// Same as above, but you can specify the content-type and file name +- (void)setData:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key; + + +@property (assign) ASIPostFormat postFormat; +@property (assign) NSStringEncoding stringEncoding; +@end diff --git a/client/osx/ASIFormDataRequest.m b/client/osx/ASIFormDataRequest.m new file mode 100644 index 0000000..e13ab0a --- /dev/null +++ b/client/osx/ASIFormDataRequest.m @@ -0,0 +1,361 @@ +// +// ASIFormDataRequest.m +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 07/11/2008. +// Copyright 2008-2009 All-Seeing Interactive. All rights reserved. +// + +#import "ASIFormDataRequest.h" + + +// Private stuff +@interface ASIFormDataRequest () +- (void)buildMultipartFormDataPostBody; +- (void)buildURLEncodedPostBody; +- (void)appendPostString:(NSString *)string; + +@property (retain) NSMutableArray *postData; +@property (retain) NSMutableArray *fileData; + +#if DEBUG_FORM_DATA_REQUEST +- (void)addToDebugBody:(NSString *)string; +@property (retain, nonatomic) NSString *debugBodyString; +#endif + +@end + +@implementation ASIFormDataRequest + +#pragma mark utilities +- (NSString*)encodeURL:(NSString *)string +{ + NSString *newString = [NSMakeCollectable(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding([self stringEncoding]))) autorelease]; + if (newString) { + return newString; + } + return @""; +} + +#pragma mark init / dealloc + ++ (id)requestWithURL:(NSURL *)newURL +{ + return [[[self alloc] initWithURL:newURL] autorelease]; +} + +- (id)initWithURL:(NSURL *)newURL +{ + self = [super initWithURL:newURL]; + [self setPostFormat:ASIURLEncodedPostFormat]; + [self setStringEncoding:NSUTF8StringEncoding]; + return self; +} + +- (void)dealloc +{ +#if DEBUG_FORM_DATA_REQUEST + [debugBodyString release]; +#endif + + [postData release]; + [fileData release]; + [super dealloc]; +} + +#pragma mark setup request + +- (void)addPostValue:(id )value forKey:(NSString *)key +{ + if (!key) { + return; + } + if (![self postData]) { + [self setPostData:[NSMutableArray array]]; + } + NSMutableDictionary *keyValuePair = [NSMutableDictionary dictionaryWithCapacity:2]; + [keyValuePair setValue:key forKey:@"key"]; + [keyValuePair setValue:[value description] forKey:@"value"]; + [[self postData] addObject:keyValuePair]; +} + +- (void)setPostValue:(id )value forKey:(NSString *)key +{ + // Remove any existing value + NSUInteger i; + for (i=0; i<[[self postData] count]; i++) { + NSDictionary *val = [[self postData] objectAtIndex:i]; + if ([[val objectForKey:@"key"] isEqualToString:key]) { + [[self postData] removeObjectAtIndex:i]; + i--; + } + } + [self addPostValue:value forKey:key]; +} + + +- (void)addFile:(NSString *)filePath forKey:(NSString *)key +{ + [self addFile:filePath withFileName:nil andContentType:nil forKey:key]; +} + +- (void)addFile:(NSString *)filePath withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key +{ + BOOL isDirectory = NO; + BOOL fileExists = [[[[NSFileManager alloc] init] autorelease] fileExistsAtPath:filePath isDirectory:&isDirectory]; + if (!fileExists || isDirectory) { + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileBuildingRequestType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"No file exists at %@",filePath],NSLocalizedDescriptionKey,nil]]]; + } + + // If the caller didn't specify a custom file name, we'll use the file name of the file we were passed + if (!fileName) { + fileName = [filePath lastPathComponent]; + } + + // If we were given the path to a file, and the user didn't specify a mime type, we can detect it from the file extension + if (!contentType) { + contentType = [ASIHTTPRequest mimeTypeForFileAtPath:filePath]; + } + [self addData:filePath withFileName:fileName andContentType:contentType forKey:key]; +} + +- (void)setFile:(NSString *)filePath forKey:(NSString *)key +{ + [self setFile:filePath withFileName:nil andContentType:nil forKey:key]; +} + +- (void)setFile:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key +{ + // Remove any existing value + NSUInteger i; + for (i=0; i<[[self fileData] count]; i++) { + NSDictionary *val = [[self fileData] objectAtIndex:i]; + if ([[val objectForKey:@"key"] isEqualToString:key]) { + [[self fileData] removeObjectAtIndex:i]; + i--; + } + } + [self addFile:data withFileName:fileName andContentType:contentType forKey:key]; +} + +- (void)addData:(NSData *)data forKey:(NSString *)key +{ + [self addData:data withFileName:@"file" andContentType:nil forKey:key]; +} + +- (void)addData:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key +{ + if (![self fileData]) { + [self setFileData:[NSMutableArray array]]; + } + if (!contentType) { + contentType = @"application/octet-stream"; + } + + NSMutableDictionary *fileInfo = [NSMutableDictionary dictionaryWithCapacity:4]; + [fileInfo setValue:key forKey:@"key"]; + [fileInfo setValue:fileName forKey:@"fileName"]; + [fileInfo setValue:contentType forKey:@"contentType"]; + [fileInfo setValue:data forKey:@"data"]; + + [[self fileData] addObject:fileInfo]; +} + +- (void)setData:(NSData *)data forKey:(NSString *)key +{ + [self setData:data withFileName:@"file" andContentType:nil forKey:key]; +} + +- (void)setData:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key +{ + // Remove any existing value + NSUInteger i; + for (i=0; i<[[self fileData] count]; i++) { + NSDictionary *val = [[self fileData] objectAtIndex:i]; + if ([[val objectForKey:@"key"] isEqualToString:key]) { + [[self fileData] removeObjectAtIndex:i]; + i--; + } + } + [self addData:data withFileName:fileName andContentType:contentType forKey:key]; +} + +- (void)buildPostBody +{ + if ([self haveBuiltPostBody]) { + return; + } + +#if DEBUG_FORM_DATA_REQUEST + [self setDebugBodyString:@""]; +#endif + + if (![self postData] && ![self fileData]) { + [super buildPostBody]; + return; + } + if ([[self fileData] count] > 0) { + [self setShouldStreamPostDataFromDisk:YES]; + } + + if ([self postFormat] == ASIURLEncodedPostFormat) { + [self buildURLEncodedPostBody]; + } else { + [self buildMultipartFormDataPostBody]; + } + + [super buildPostBody]; + +#if DEBUG_FORM_DATA_REQUEST + NSLog(@"%@",[self debugBodyString]); + [self setDebugBodyString:nil]; +#endif +} + + +- (void)buildMultipartFormDataPostBody +{ +#if DEBUG_FORM_DATA_REQUEST + [self addToDebugBody:@"\r\n==== Building a multipart/form-data body ====\r\n"]; +#endif + + NSString *charset = (NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding([self stringEncoding])); + + // We don't bother to check if post data contains the boundary, since it's pretty unlikely that it does. + CFUUIDRef uuid = CFUUIDCreate(nil); + NSString *uuidString = [(NSString*)CFUUIDCreateString(nil, uuid) autorelease]; + CFRelease(uuid); + NSString *stringBoundary = [NSString stringWithFormat:@"0xKhTmLbOuNdArY-%@",uuidString]; + + [self addRequestHeader:@"Content-Type" value:[NSString stringWithFormat:@"multipart/form-data; charset=%@; boundary=%@", charset, stringBoundary]]; + + [self appendPostString:[NSString stringWithFormat:@"--%@\r\n",stringBoundary]]; + + // Adds post data + NSString *endItemBoundary = [NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary]; + NSUInteger i=0; + for (NSDictionary *val in [self postData]) { + [self appendPostString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",[val objectForKey:@"key"]]]; + [self appendPostString:[val objectForKey:@"value"]]; + i++; + if (i != [[self postData] count] || [[self fileData] count] > 0) { //Only add the boundary if this is not the last item in the post body + [self appendPostString:endItemBoundary]; + } + } + + // Adds files to upload + i=0; + for (NSDictionary *val in [self fileData]) { + + [self appendPostString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", [val objectForKey:@"key"], [val objectForKey:@"fileName"]]]; + [self appendPostString:[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", [val objectForKey:@"contentType"]]]; + + id data = [val objectForKey:@"data"]; + if ([data isKindOfClass:[NSString class]]) { + [self appendPostDataFromFile:data]; + } else { + [self appendPostData:data]; + } + i++; + // Only add the boundary if this is not the last item in the post body + if (i != [[self fileData] count]) { + [self appendPostString:endItemBoundary]; + } + } + + [self appendPostString:[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary]]; + +#if DEBUG_FORM_DATA_REQUEST + [self addToDebugBody:@"==== End of multipart/form-data body ====\r\n"]; +#endif +} + +- (void)buildURLEncodedPostBody +{ + + // We can't post binary data using application/x-www-form-urlencoded + if ([[self fileData] count] > 0) { + [self setPostFormat:ASIMultipartFormDataPostFormat]; + [self buildMultipartFormDataPostBody]; + return; + } + +#if DEBUG_FORM_DATA_REQUEST + [self addToDebugBody:@"\r\n==== Building an application/x-www-form-urlencoded body ====\r\n"]; +#endif + + + NSString *charset = (NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding([self stringEncoding])); + + [self addRequestHeader:@"Content-Type" value:[NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@",charset]]; + + + NSUInteger i=0; + NSUInteger count = [[self postData] count]-1; + for (NSDictionary *val in [self postData]) { + NSString *data = [NSString stringWithFormat:@"%@=%@%@", [self encodeURL:[val objectForKey:@"key"]], [self encodeURL:[val objectForKey:@"value"]],(i +#if TARGET_OS_IPHONE + #import + #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 + #import // Necessary for background task support + #endif +#endif + +#import +#import "ASIHTTPRequestConfig.h" +#import "ASIHTTPRequestDelegate.h" +#import "ASIProgressDelegate.h" +#import "ASICacheDelegate.h" + +@class ASIDataDecompressor; + +extern NSString *ASIHTTPRequestVersion; + +// Make targeting different platforms more reliable +// See: http://www.blumtnwerx.com/blog/2009/06/cross-sdk-code-hygiene-in-xcode/ +#ifndef __IPHONE_3_2 + #define __IPHONE_3_2 30200 +#endif +#ifndef __IPHONE_4_0 + #define __IPHONE_4_0 40000 +#endif +#ifndef __MAC_10_5 + #define __MAC_10_5 1050 +#endif +#ifndef __MAC_10_6 + #define __MAC_10_6 1060 +#endif + +typedef enum _ASIAuthenticationState { + ASINoAuthenticationNeededYet = 0, + ASIHTTPAuthenticationNeeded = 1, + ASIProxyAuthenticationNeeded = 2 +} ASIAuthenticationState; + +typedef enum _ASINetworkErrorType { + ASIConnectionFailureErrorType = 1, + ASIRequestTimedOutErrorType = 2, + ASIAuthenticationErrorType = 3, + ASIRequestCancelledErrorType = 4, + ASIUnableToCreateRequestErrorType = 5, + ASIInternalErrorWhileBuildingRequestType = 6, + ASIInternalErrorWhileApplyingCredentialsType = 7, + ASIFileManagementError = 8, + ASITooMuchRedirectionErrorType = 9, + ASIUnhandledExceptionError = 10, + ASICompressionError = 11 + +} ASINetworkErrorType; + + +// The error domain that all errors generated by ASIHTTPRequest use +extern NSString* const NetworkRequestErrorDomain; + +// You can use this number to throttle upload and download bandwidth in iPhone OS apps send or receive a large amount of data +// This may help apps that might otherwise be rejected for inclusion into the app store for using excessive bandwidth +// This number is not official, as far as I know there is no officially documented bandwidth limit +extern unsigned long const ASIWWANBandwidthThrottleAmount; + +#if NS_BLOCKS_AVAILABLE +typedef void (^ASIBasicBlock)(void); +typedef void (^ASIHeadersBlock)(NSDictionary *responseHeaders); +typedef void (^ASISizeBlock)(long long size); +typedef void (^ASIProgressBlock)(unsigned long long size, unsigned long long total); +typedef void (^ASIDataBlock)(NSData *data); +#endif + +@interface ASIHTTPRequest : NSOperation { + + // The url for this operation, should include GET params in the query string where appropriate + NSURL *url; + + // Will always contain the original url used for making the request (the value of url can change when a request is redirected) + NSURL *originalURL; + + // Temporarily stores the url we are about to redirect to. Will be nil again when we do redirect + NSURL *redirectURL; + + // The delegate - will be notified of various changes in state via the ASIHTTPRequestDelegate protocol + id delegate; + + // Another delegate that is also notified of request status changes and progress updates + // Generally, you won't use this directly, but ASINetworkQueue sets itself as the queue so it can proxy updates to its own delegates + // NOTE: WILL BE RETAINED BY THE REQUEST + id queue; + + // HTTP method to use (eg: GET / POST / PUT / DELETE / HEAD etc). Defaults to GET + NSString *requestMethod; + + // Request body - only used when the whole body is stored in memory (shouldStreamPostDataFromDisk is false) + NSMutableData *postBody; + + // gzipped request body used when shouldCompressRequestBody is YES + NSData *compressedPostBody; + + // When true, post body will be streamed from a file on disk, rather than loaded into memory at once (useful for large uploads) + // Automatically set to true in ASIFormDataRequests when using setFile:forKey: + BOOL shouldStreamPostDataFromDisk; + + // Path to file used to store post body (when shouldStreamPostDataFromDisk is true) + // You can set this yourself - useful if you want to PUT a file from local disk + NSString *postBodyFilePath; + + // Path to a temporary file used to store a deflated post body (when shouldCompressPostBody is YES) + NSString *compressedPostBodyFilePath; + + // Set to true when ASIHTTPRequest automatically created a temporary file containing the request body (when true, the file at postBodyFilePath will be deleted at the end of the request) + BOOL didCreateTemporaryPostDataFile; + + // Used when writing to the post body when shouldStreamPostDataFromDisk is true (via appendPostData: or appendPostDataFromFile:) + NSOutputStream *postBodyWriteStream; + + // Used for reading from the post body when sending the request + NSInputStream *postBodyReadStream; + + // Dictionary for custom HTTP request headers + NSMutableDictionary *requestHeaders; + + // Set to YES when the request header dictionary has been populated, used to prevent this happening more than once + BOOL haveBuiltRequestHeaders; + + // Will be populated with HTTP response headers from the server + NSDictionary *responseHeaders; + + // Can be used to manually insert cookie headers to a request, but it's more likely that sessionCookies will do this for you + NSMutableArray *requestCookies; + + // Will be populated with cookies + NSArray *responseCookies; + + // If use useCookiePersistence is true, network requests will present valid cookies from previous requests + BOOL useCookiePersistence; + + // If useKeychainPersistence is true, network requests will attempt to read credentials from the keychain, and will save them in the keychain when they are successfully presented + BOOL useKeychainPersistence; + + // If useSessionPersistence is true, network requests will save credentials and reuse for the duration of the session (until clearSession is called) + BOOL useSessionPersistence; + + // If allowCompressedResponse is true, requests will inform the server they can accept compressed data, and will automatically decompress gzipped responses. Default is true. + BOOL allowCompressedResponse; + + // If shouldCompressRequestBody is true, the request body will be gzipped. Default is false. + // You will probably need to enable this feature on your webserver to make this work. Tested with apache only. + BOOL shouldCompressRequestBody; + + // When downloadDestinationPath is set, the result of this request will be downloaded to the file at this location + // If downloadDestinationPath is not set, download data will be stored in memory + NSString *downloadDestinationPath; + + // The location that files will be downloaded to. Once a download is complete, files will be decompressed (if necessary) and moved to downloadDestinationPath + NSString *temporaryFileDownloadPath; + + // If the response is gzipped and shouldWaitToInflateCompressedResponses is NO, a file will be created at this path containing the inflated response as it comes in + NSString *temporaryUncompressedDataDownloadPath; + + // Used for writing data to a file when downloadDestinationPath is set + NSOutputStream *fileDownloadOutputStream; + + NSOutputStream *inflatedFileDownloadOutputStream; + + // When the request fails or completes successfully, complete will be true + BOOL complete; + + // external "finished" indicator, subject of KVO notifications; updates after 'complete' + BOOL finished; + + // True if our 'cancel' selector has been called + BOOL cancelled; + + // If an error occurs, error will contain an NSError + // If error code is = ASIConnectionFailureErrorType (1, Connection failure occurred) - inspect [[error userInfo] objectForKey:NSUnderlyingErrorKey] for more information + NSError *error; + + // Username and password used for authentication + NSString *username; + NSString *password; + + // User-Agent for this request + NSString *userAgent; + + // Domain used for NTLM authentication + NSString *domain; + + // Username and password used for proxy authentication + NSString *proxyUsername; + NSString *proxyPassword; + + // Domain used for NTLM proxy authentication + NSString *proxyDomain; + + // Delegate for displaying upload progress (usually an NSProgressIndicator, but you can supply a different object and handle this yourself) + id uploadProgressDelegate; + + // Delegate for displaying download progress (usually an NSProgressIndicator, but you can supply a different object and handle this yourself) + id downloadProgressDelegate; + + // Whether we've seen the headers of the response yet + BOOL haveExaminedHeaders; + + // Data we receive will be stored here. Data may be compressed unless allowCompressedResponse is false - you should use [request responseData] instead in most cases + NSMutableData *rawResponseData; + + // Used for sending and receiving data + CFHTTPMessageRef request; + NSInputStream *readStream; + + // Used for authentication + CFHTTPAuthenticationRef requestAuthentication; + NSDictionary *requestCredentials; + + // Used during NTLM authentication + int authenticationRetryCount; + + // Authentication scheme (Basic, Digest, NTLM) + // If you are using Basic authentication and want to force ASIHTTPRequest to send an authorization header without waiting for a 401, you must set this to (NSString *)kCFHTTPAuthenticationSchemeBasic + NSString *authenticationScheme; + + // Realm for authentication when credentials are required + NSString *authenticationRealm; + + // When YES, ASIHTTPRequest will present a dialog allowing users to enter credentials when no-matching credentials were found for a server that requires authentication + // The dialog will not be shown if your delegate responds to authenticationNeededForRequest: + // Default is NO. + BOOL shouldPresentAuthenticationDialog; + + // When YES, ASIHTTPRequest will present a dialog allowing users to enter credentials when no-matching credentials were found for a proxy server that requires authentication + // The dialog will not be shown if your delegate responds to proxyAuthenticationNeededForRequest: + // Default is YES (basically, because most people won't want the hassle of adding support for authenticating proxies to their apps) + BOOL shouldPresentProxyAuthenticationDialog; + + // Used for proxy authentication + CFHTTPAuthenticationRef proxyAuthentication; + NSDictionary *proxyCredentials; + + // Used during authentication with an NTLM proxy + int proxyAuthenticationRetryCount; + + // Authentication scheme for the proxy (Basic, Digest, NTLM) + NSString *proxyAuthenticationScheme; + + // Realm for proxy authentication when credentials are required + NSString *proxyAuthenticationRealm; + + // HTTP status code, eg: 200 = OK, 404 = Not found etc + int responseStatusCode; + + // Description of the HTTP status code + NSString *responseStatusMessage; + + // Size of the response + unsigned long long contentLength; + + // Size of the partially downloaded content + unsigned long long partialDownloadSize; + + // Size of the POST payload + unsigned long long postLength; + + // The total amount of downloaded data + unsigned long long totalBytesRead; + + // The total amount of uploaded data + unsigned long long totalBytesSent; + + // Last amount of data read (used for incrementing progress) + unsigned long long lastBytesRead; + + // Last amount of data sent (used for incrementing progress) + unsigned long long lastBytesSent; + + // This lock prevents the operation from being cancelled at an inopportune moment + NSRecursiveLock *cancelledLock; + + // Called on the delegate (if implemented) when the request starts. Default is requestStarted: + SEL didStartSelector; + + // Called on the delegate (if implemented) when the request receives response headers. Default is request:didReceiveResponseHeaders: + SEL didReceiveResponseHeadersSelector; + + // Called on the delegate (if implemented) when the request receives a Location header and shouldRedirect is YES + // The delegate can then change the url if needed, and can restart the request by calling [request redirectToURL:], or simply cancel it + SEL willRedirectSelector; + + // Called on the delegate (if implemented) when the request completes successfully. Default is requestFinished: + SEL didFinishSelector; + + // Called on the delegate (if implemented) when the request fails. Default is requestFailed: + SEL didFailSelector; + + // Called on the delegate (if implemented) when the request receives data. Default is request:didReceiveData: + // If you set this and implement the method in your delegate, you must handle the data yourself - ASIHTTPRequest will not populate responseData or write the data to downloadDestinationPath + SEL didReceiveDataSelector; + + // Used for recording when something last happened during the request, we will compare this value with the current date to time out requests when appropriate + NSDate *lastActivityTime; + + // Number of seconds to wait before timing out - default is 10 + NSTimeInterval timeOutSeconds; + + // Will be YES when a HEAD request will handle the content-length before this request starts + BOOL shouldResetUploadProgress; + BOOL shouldResetDownloadProgress; + + // Used by HEAD requests when showAccurateProgress is YES to preset the content-length for this request + ASIHTTPRequest *mainRequest; + + // When NO, this request will only update the progress indicator when it completes + // When YES, this request will update the progress indicator according to how much data it has received so far + // The default for requests is YES + // Also see the comments in ASINetworkQueue.h + BOOL showAccurateProgress; + + // Used to ensure the progress indicator is only incremented once when showAccurateProgress = NO + BOOL updatedProgress; + + // Prevents the body of the post being built more than once (largely for subclasses) + BOOL haveBuiltPostBody; + + // Used internally, may reflect the size of the internal buffer used by CFNetwork + // POST / PUT operations with body sizes greater than uploadBufferSize will not timeout unless more than uploadBufferSize bytes have been sent + // Likely to be 32KB on iPhone 3.0, 128KB on Mac OS X Leopard and iPhone 2.2.x + unsigned long long uploadBufferSize; + + // Text encoding for responses that do not send a Content-Type with a charset value. Defaults to NSISOLatin1StringEncoding + NSStringEncoding defaultResponseEncoding; + + // The text encoding of the response, will be defaultResponseEncoding if the server didn't specify. Can't be set. + NSStringEncoding responseEncoding; + + // Tells ASIHTTPRequest not to delete partial downloads, and allows it to use an existing file to resume a download. Defaults to NO. + BOOL allowResumeForFileDownloads; + + // Custom user information associated with the request (not sent to the server) + NSDictionary *userInfo; + NSInteger tag; + + // Use HTTP 1.0 rather than 1.1 (defaults to false) + BOOL useHTTPVersionOne; + + // When YES, requests will automatically redirect when they get a HTTP 30x header (defaults to YES) + BOOL shouldRedirect; + + // Used internally to tell the main loop we need to stop and retry with a new url + BOOL needsRedirect; + + // Incremented every time this request redirects. When it reaches 5, we give up + int redirectCount; + + // When NO, requests will not check the secure certificate is valid (use for self-signed certificates during development, DO NOT USE IN PRODUCTION) Default is YES + BOOL validatesSecureCertificate; + + // If not nil and the URL scheme is https, CFNetwork configured to supply a client certificate + SecIdentityRef clientCertificateIdentity; + NSArray *clientCertificates; + + // Details on the proxy to use - you could set these yourself, but it's probably best to let ASIHTTPRequest detect the system proxy settings + NSString *proxyHost; + int proxyPort; + + // ASIHTTPRequest will assume kCFProxyTypeHTTP if the proxy type could not be automatically determined + // Set to kCFProxyTypeSOCKS if you are manually configuring a SOCKS proxy + NSString *proxyType; + + // URL for a PAC (Proxy Auto Configuration) file. If you want to set this yourself, it's probably best if you use a local file + NSURL *PACurl; + + // See ASIAuthenticationState values above. 0 == default == No authentication needed yet + ASIAuthenticationState authenticationNeeded; + + // When YES, ASIHTTPRequests will present credentials from the session store for requests to the same server before being asked for them + // This avoids an extra round trip for requests after authentication has succeeded, which is much for efficient for authenticated requests with large bodies, or on slower connections + // Set to NO to only present credentials when explicitly asked for them + // This only affects credentials stored in the session cache when useSessionPersistence is YES. Credentials from the keychain are never presented unless the server asks for them + // Default is YES + // For requests using Basic authentication, set authenticationScheme to (NSString *)kCFHTTPAuthenticationSchemeBasic, and credentials can be sent on the very first request when shouldPresentCredentialsBeforeChallenge is YES + BOOL shouldPresentCredentialsBeforeChallenge; + + // YES when the request hasn't finished yet. Will still be YES even if the request isn't doing anything (eg it's waiting for delegate authentication). READ-ONLY + BOOL inProgress; + + // Used internally to track whether the stream is scheduled on the run loop or not + // Bandwidth throttling can unschedule the stream to slow things down while a request is in progress + BOOL readStreamIsScheduled; + + // Set to allow a request to automatically retry itself on timeout + // Default is zero - timeout will stop the request + int numberOfTimesToRetryOnTimeout; + + // The number of times this request has retried (when numberOfTimesToRetryOnTimeout > 0) + int retryCount; + + // Temporarily set to YES when a closed connection forces a retry (internally, this stops ASIHTTPRequest cleaning up a temporary post body) + BOOL willRetryRequest; + + // When YES, requests will keep the connection to the server alive for a while to allow subsequent requests to re-use it for a substantial speed-boost + // Persistent connections will not be used if the server explicitly closes the connection + // Default is YES + BOOL shouldAttemptPersistentConnection; + + // Number of seconds to keep an inactive persistent connection open on the client side + // Default is 60 + // If we get a keep-alive header, this is this value is replaced with how long the server told us to keep the connection around + // A future date is created from this and used for expiring the connection, this is stored in connectionInfo's expires value + NSTimeInterval persistentConnectionTimeoutSeconds; + + // Set to yes when an appropriate keep-alive header is found + BOOL connectionCanBeReused; + + // Stores information about the persistent connection that is currently in use. + // It may contain: + // * The id we set for a particular connection, incremented every time we want to specify that we need a new connection + // * The date that connection should expire + // * A host, port and scheme for the connection. These are used to determine whether that connection can be reused by a subsequent request (all must match the new request) + // * An id for the request that is currently using the connection. This is used for determining if a connection is available or not (we store a number rather than a reference to the request so we don't need to hang onto a request until the connection expires) + // * A reference to the stream that is currently using the connection. This is necessary because we need to keep the old stream open until we've opened a new one. + // The stream will be closed + released either when another request comes to use the connection, or when the timer fires to tell the connection to expire + NSMutableDictionary *connectionInfo; + + // When set to YES, 301 and 302 automatic redirects will use the original method and and body, according to the HTTP 1.1 standard + // Default is NO (to follow the behaviour of most browsers) + BOOL shouldUseRFC2616RedirectBehaviour; + + // Used internally to record when a request has finished downloading data + BOOL downloadComplete; + + // An ID that uniquely identifies this request - primarily used for debugging persistent connections + NSNumber *requestID; + + // Will be ASIHTTPRequestRunLoopMode for synchronous requests, NSDefaultRunLoopMode for all other requests + NSString *runLoopMode; + + // This timer checks up on the request every 0.25 seconds, and updates progress + NSTimer *statusTimer; + + // The download cache that will be used for this request (use [ASIHTTPRequest setDefaultCache:cache] to configure a default cache + id downloadCache; + + // The cache policy that will be used for this request - See ASICacheDelegate.h for possible values + ASICachePolicy cachePolicy; + + // The cache storage policy that will be used for this request - See ASICacheDelegate.h for possible values + ASICacheStoragePolicy cacheStoragePolicy; + + // Will be true when the response was pulled from the cache rather than downloaded + BOOL didUseCachedResponse; + + // Set secondsToCache to use a custom time interval for expiring the response when it is stored in a cache + NSTimeInterval secondsToCache; + + #if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 + BOOL shouldContinueWhenAppEntersBackground; + UIBackgroundTaskIdentifier backgroundTask; + #endif + + // When downloading a gzipped response, the request will use this helper object to inflate the response + ASIDataDecompressor *dataDecompressor; + + // Controls how responses with a gzipped encoding are inflated (decompressed) + // When set to YES (This is the default): + // * gzipped responses for requests without a downloadDestinationPath will be inflated only when [request responseData] / [request responseString] is called + // * gzipped responses for requests with a downloadDestinationPath set will be inflated only when the request completes + // + // When set to NO + // All requests will inflate the response as it comes in + // * If the request has no downloadDestinationPath set, the raw (compressed) response is discarded and rawResponseData will contain the decompressed response + // * If the request has a downloadDestinationPath, the raw response will be stored in temporaryFileDownloadPath as normal, the inflated response will be stored in temporaryUncompressedDataDownloadPath + // Once the request completes successfully, the contents of temporaryUncompressedDataDownloadPath are moved into downloadDestinationPath + // + // Setting this to NO may be especially useful for users using ASIHTTPRequest in conjunction with a streaming parser, as it will allow partial gzipped responses to be inflated and passed on to the parser while the request is still running + BOOL shouldWaitToInflateCompressedResponses; + + // Will be YES if this is a request created behind the scenes to download a PAC file - these requests do not attempt to configure their own proxies + BOOL isPACFileRequest; + + // Used for downloading PAC files from http / https webservers + ASIHTTPRequest *PACFileRequest; + + // Used for asynchronously reading PAC files from file:// URLs + NSInputStream *PACFileReadStream; + + // Used for storing PAC data from file URLs as it is downloaded + NSMutableData *PACFileData; + + // Set to YES in startSynchronous. Currently used by proxy detection to download PAC files synchronously when appropriate + BOOL isSynchronous; + + #if NS_BLOCKS_AVAILABLE + //block to execute when request starts + ASIBasicBlock startedBlock; + + //block to execute when headers are received + ASIHeadersBlock headersReceivedBlock; + + //block to execute when request completes successfully + ASIBasicBlock completionBlock; + + //block to execute when request fails + ASIBasicBlock failureBlock; + + //block for when bytes are received + ASIProgressBlock bytesReceivedBlock; + + //block for when bytes are sent + ASIProgressBlock bytesSentBlock; + + //block for when download size is incremented + ASISizeBlock downloadSizeIncrementedBlock; + + //block for when upload size is incremented + ASISizeBlock uploadSizeIncrementedBlock; + + //block for handling raw bytes received + ASIDataBlock dataReceivedBlock; + + //block for handling authentication + ASIBasicBlock authenticationNeededBlock; + + //block for handling proxy authentication + ASIBasicBlock proxyAuthenticationNeededBlock; + + //block for handling redirections, if you want to + ASIBasicBlock requestRedirectedBlock; + #endif +} + +#pragma mark init / dealloc + +// Should be an HTTP or HTTPS url, may include username and password if appropriate +- (id)initWithURL:(NSURL *)newURL; + +// Convenience constructor ++ (id)requestWithURL:(NSURL *)newURL; + ++ (id)requestWithURL:(NSURL *)newURL usingCache:(id )cache; ++ (id)requestWithURL:(NSURL *)newURL usingCache:(id )cache andCachePolicy:(ASICachePolicy)policy; + +#if NS_BLOCKS_AVAILABLE +- (void)setStartedBlock:(ASIBasicBlock)aStartedBlock; +- (void)setHeadersReceivedBlock:(ASIHeadersBlock)aReceivedBlock; +- (void)setCompletionBlock:(ASIBasicBlock)aCompletionBlock; +- (void)setFailedBlock:(ASIBasicBlock)aFailedBlock; +- (void)setBytesReceivedBlock:(ASIProgressBlock)aBytesReceivedBlock; +- (void)setBytesSentBlock:(ASIProgressBlock)aBytesSentBlock; +- (void)setDownloadSizeIncrementedBlock:(ASISizeBlock) aDownloadSizeIncrementedBlock; +- (void)setUploadSizeIncrementedBlock:(ASISizeBlock) anUploadSizeIncrementedBlock; +- (void)setDataReceivedBlock:(ASIDataBlock)aReceivedBlock; +- (void)setAuthenticationNeededBlock:(ASIBasicBlock)anAuthenticationBlock; +- (void)setProxyAuthenticationNeededBlock:(ASIBasicBlock)aProxyAuthenticationBlock; +- (void)setRequestRedirectedBlock:(ASIBasicBlock)aRedirectBlock; +#endif + +#pragma mark setup request + +// Add a custom header to the request +- (void)addRequestHeader:(NSString *)header value:(NSString *)value; + +// Called during buildRequestHeaders and after a redirect to create a cookie header from request cookies and the global store +- (void)applyCookieHeader; + +// Populate the request headers dictionary. Called before a request is started, or by a HEAD request that needs to borrow them +- (void)buildRequestHeaders; + +// Used to apply authorization header to a request before it is sent (when shouldPresentCredentialsBeforeChallenge is YES) +- (void)applyAuthorizationHeader; + + +// Create the post body +- (void)buildPostBody; + +// Called to add data to the post body. Will append to postBody when shouldStreamPostDataFromDisk is false, or write to postBodyWriteStream when true +- (void)appendPostData:(NSData *)data; +- (void)appendPostDataFromFile:(NSString *)file; + +#pragma mark get information about this request + +// Returns the contents of the result as an NSString (not appropriate for binary data - used responseData instead) +- (NSString *)responseString; + +// Response data, automatically uncompressed where appropriate +- (NSData *)responseData; + +// Returns true if the response was gzip compressed +- (BOOL)isResponseCompressed; + +#pragma mark running a request + + +// Run a request synchronously, and return control when the request completes or fails +- (void)startSynchronous; + +// Run request in the background +- (void)startAsynchronous; + +// Clears all delegates and blocks, then cancels the request +- (void)clearDelegatesAndCancel; + +#pragma mark HEAD request + +// Used by ASINetworkQueue to create a HEAD request appropriate for this request with the same headers (though you can use it yourself) +- (ASIHTTPRequest *)HEADRequest; + +#pragma mark upload/download progress + +// Called approximately every 0.25 seconds to update the progress delegates +- (void)updateProgressIndicators; + +// Updates upload progress (notifies the queue and/or uploadProgressDelegate of this request) +- (void)updateUploadProgress; + +// Updates download progress (notifies the queue and/or uploadProgressDelegate of this request) +- (void)updateDownloadProgress; + +// Called when authorisation is needed, as we only find out we don't have permission to something when the upload is complete +- (void)removeUploadProgressSoFar; + +// Called when we get a content-length header and shouldResetDownloadProgress is true +- (void)incrementDownloadSizeBy:(long long)length; + +// Called when a request starts and shouldResetUploadProgress is true +// Also called (with a negative length) to remove the size of the underlying buffer used for uploading +- (void)incrementUploadSizeBy:(long long)length; + +// Helper method for interacting with progress indicators to abstract the details of different APIS (NSProgressIndicator and UIProgressView) ++ (void)updateProgressIndicator:(id *)indicator withProgress:(unsigned long long)progress ofTotal:(unsigned long long)total; + +// Helper method used for performing invocations on the main thread (used for progress) ++ (void)performSelector:(SEL)selector onTarget:(id *)target withObject:(id)object amount:(void *)amount callerToRetain:(id)caller; + +#pragma mark talking to delegates + +// Called when a request starts, lets the delegate know via didStartSelector +- (void)requestStarted; + +// Called when a request receives response headers, lets the delegate know via didReceiveResponseHeadersSelector +- (void)requestReceivedResponseHeaders:(NSDictionary *)newHeaders; + +// Called when a request completes successfully, lets the delegate know via didFinishSelector +- (void)requestFinished; + +// Called when a request fails, and lets the delegate know via didFailSelector +- (void)failWithError:(NSError *)theError; + +// Called to retry our request when our persistent connection is closed +// Returns YES if we haven't already retried, and connection will be restarted +// Otherwise, returns NO, and nothing will happen +- (BOOL)retryUsingNewConnection; + +// Can be called by delegates from inside their willRedirectSelector implementations to restart the request with a new url +- (void)redirectToURL:(NSURL *)newURL; + +#pragma mark parsing HTTP response headers + +// Reads the response headers to find the content length, encoding, cookies for the session +// Also initiates request redirection when shouldRedirect is true +// And works out if HTTP auth is required +- (void)readResponseHeaders; + +// Attempts to set the correct encoding by looking at the Content-Type header, if this is one +- (void)parseStringEncodingFromHeaders; + ++ (void)parseMimeType:(NSString **)mimeType andResponseEncoding:(NSStringEncoding *)stringEncoding fromContentType:(NSString *)contentType; + +#pragma mark http authentication stuff + +// Apply credentials to this request +- (BOOL)applyCredentials:(NSDictionary *)newCredentials; +- (BOOL)applyProxyCredentials:(NSDictionary *)newCredentials; + +// Attempt to obtain credentials for this request from the URL, username and password or keychain +- (NSMutableDictionary *)findCredentials; +- (NSMutableDictionary *)findProxyCredentials; + +// Unlock (unpause) the request thread so it can resume the request +// Should be called by delegates when they have populated the authentication information after an authentication challenge +- (void)retryUsingSuppliedCredentials; + +// Should be called by delegates when they wish to cancel authentication and stop +- (void)cancelAuthentication; + +// Apply authentication information and resume the request after an authentication challenge +- (void)attemptToApplyCredentialsAndResume; +- (void)attemptToApplyProxyCredentialsAndResume; + +// Attempt to show the built-in authentication dialog, returns YES if credentials were supplied, NO if user cancelled dialog / dialog is disabled / running on main thread +// Currently only used on iPhone OS +- (BOOL)showProxyAuthenticationDialog; +- (BOOL)showAuthenticationDialog; + +// Construct a basic authentication header from the username and password supplied, and add it to the request headers +// Used when shouldPresentCredentialsBeforeChallenge is YES +- (void)addBasicAuthenticationHeaderWithUsername:(NSString *)theUsername andPassword:(NSString *)thePassword; + +#pragma mark stream status handlers + +// CFnetwork event handlers +- (void)handleNetworkEvent:(CFStreamEventType)type; +- (void)handleBytesAvailable; +- (void)handleStreamComplete; +- (void)handleStreamError; + +#pragma mark cleanup + +// Cleans up and lets the queue know this operation is finished. +// Appears in this header for subclassing only, do not call this method from outside your request! +- (void)markAsFinished; + +// Cleans up temporary files. There's normally no reason to call these yourself, they are called automatically when a request completes or fails + +// Clean up the temporary file used to store the downloaded data when it comes in (if downloadDestinationPath is set) +- (BOOL)removeTemporaryDownloadFile; + +// Clean up the temporary file used to store data that is inflated (decompressed) as it comes in +- (BOOL)removeTemporaryUncompressedDownloadFile; + +// Clean up the temporary file used to store the request body (when shouldStreamPostDataFromDisk is YES) +- (BOOL)removeTemporaryUploadFile; + +// Clean up the temporary file used to store a deflated (compressed) request body when shouldStreamPostDataFromDisk is YES +- (BOOL)removeTemporaryCompressedUploadFile; + +// Remove a file on disk, returning NO and populating the passed error pointer if it fails ++ (BOOL)removeFileAtPath:(NSString *)path error:(NSError **)err; + +#pragma mark persistent connections + +// Get the ID of the connection this request used (only really useful in tests and debugging) +- (NSNumber *)connectionID; + +// Called automatically when a request is started to clean up any persistent connections that have expired ++ (void)expirePersistentConnections; + +#pragma mark default time out + ++ (NSTimeInterval)defaultTimeOutSeconds; ++ (void)setDefaultTimeOutSeconds:(NSTimeInterval)newTimeOutSeconds; + +#pragma mark client certificate + +- (void)setClientCertificateIdentity:(SecIdentityRef)anIdentity; + +#pragma mark session credentials + ++ (NSMutableArray *)sessionProxyCredentialsStore; ++ (NSMutableArray *)sessionCredentialsStore; + ++ (void)storeProxyAuthenticationCredentialsInSessionStore:(NSDictionary *)credentials; ++ (void)storeAuthenticationCredentialsInSessionStore:(NSDictionary *)credentials; + ++ (void)removeProxyAuthenticationCredentialsFromSessionStore:(NSDictionary *)credentials; ++ (void)removeAuthenticationCredentialsFromSessionStore:(NSDictionary *)credentials; + +- (NSDictionary *)findSessionProxyAuthenticationCredentials; +- (NSDictionary *)findSessionAuthenticationCredentials; + +#pragma mark keychain storage + +// Save credentials for this request to the keychain +- (void)saveCredentialsToKeychain:(NSDictionary *)newCredentials; + +// Save credentials to the keychain ++ (void)saveCredentials:(NSURLCredential *)credentials forHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm; ++ (void)saveCredentials:(NSURLCredential *)credentials forProxy:(NSString *)host port:(int)port realm:(NSString *)realm; + +// Return credentials from the keychain ++ (NSURLCredential *)savedCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm; ++ (NSURLCredential *)savedCredentialsForProxy:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm; + +// Remove credentials from the keychain ++ (void)removeCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm; ++ (void)removeCredentialsForProxy:(NSString *)host port:(int)port realm:(NSString *)realm; + +// We keep track of any cookies we accept, so that we can remove them from the persistent store later ++ (void)setSessionCookies:(NSMutableArray *)newSessionCookies; ++ (NSMutableArray *)sessionCookies; + +// Adds a cookie to our list of cookies we've accepted, checking first for an old version of the same cookie and removing that ++ (void)addSessionCookie:(NSHTTPCookie *)newCookie; + +// Dump all session data (authentication and cookies) ++ (void)clearSession; + +#pragma mark get user agent + +// Will be used as a user agent if requests do not specify a custom user agent +// Is only used when you have specified a Bundle Display Name (CFDisplayBundleName) or Bundle Name (CFBundleName) in your plist ++ (NSString *)defaultUserAgentString; ++ (void)setDefaultUserAgentString:(NSString *)agent; + +#pragma mark mime-type detection + +// Return the mime type for a file ++ (NSString *)mimeTypeForFileAtPath:(NSString *)path; + +#pragma mark bandwidth measurement / throttling + +// The maximum number of bytes ALL requests can send / receive in a second +// This is a rough figure. The actual amount used will be slightly more, this does not include HTTP headers ++ (unsigned long)maxBandwidthPerSecond; ++ (void)setMaxBandwidthPerSecond:(unsigned long)bytes; + +// Get a rough average (for the last 5 seconds) of how much bandwidth is being used, in bytes ++ (unsigned long)averageBandwidthUsedPerSecond; + +- (void)performThrottling; + +// Will return YES is bandwidth throttling is currently in use ++ (BOOL)isBandwidthThrottled; + +// Used internally to record bandwidth use, and by ASIInputStreams when uploading. It's probably best if you don't mess with this. ++ (void)incrementBandwidthUsedInLastSecond:(unsigned long)bytes; + +// On iPhone, ASIHTTPRequest can automatically turn throttling on and off as the connection type changes between WWAN and WiFi + +#if TARGET_OS_IPHONE +// Set to YES to automatically turn on throttling when WWAN is connected, and automatically turn it off when it isn't ++ (void)setShouldThrottleBandwidthForWWAN:(BOOL)throttle; + +// Turns on throttling automatically when WWAN is connected using a custom limit, and turns it off automatically when it isn't ++ (void)throttleBandwidthForWWANUsingLimit:(unsigned long)limit; + +#pragma mark reachability + +// Returns YES when an iPhone OS device is connected via WWAN, false when connected via WIFI or not connected ++ (BOOL)isNetworkReachableViaWWAN; + +#endif + +#pragma mark queue + +// Returns the shared queue ++ (NSOperationQueue *)sharedQueue; + +#pragma mark cache + ++ (void)setDefaultCache:(id )cache; ++ (id )defaultCache; + +// Returns the maximum amount of data we can read as part of the current measurement period, and sleeps this thread if our allowance is used up ++ (unsigned long)maxUploadReadLength; + +#pragma mark network activity + ++ (BOOL)isNetworkInUse; + ++ (void)setShouldUpdateNetworkActivityIndicator:(BOOL)shouldUpdate; + +// Shows the network activity spinner thing on iOS. You may wish to override this to do something else in Mac projects ++ (void)showNetworkActivityIndicator; + +// Hides the network activity spinner thing on iOS ++ (void)hideNetworkActivityIndicator; + +#pragma mark miscellany + +// Used for generating Authorization header when using basic authentication when shouldPresentCredentialsBeforeChallenge is true +// And also by ASIS3Request ++ (NSString *)base64forData:(NSData *)theData; + +// Returns the expiration date for the request. +// Calculated from the Expires response header property, unless maxAge is non-zero or +// there exists a non-zero max-age property in the Cache-Control response header. ++ (NSDate *)expiryDateForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge; + +// Returns a date from a string in RFC1123 format ++ (NSDate *)dateFromRFC1123String:(NSString *)string; + + +// Used for detecting multitasking support at runtime (for backgrounding requests) +#if TARGET_OS_IPHONE ++ (BOOL)isMultitaskingSupported; +#endif + +#pragma mark threading behaviour + +// In the default implementation, all requests run in a single background thread +// Advanced users only: Override this method in a subclass for a different threading behaviour +// Eg: return [NSThread mainThread] to run all requests in the main thread +// Alternatively, you can create a thread on demand, or manage a pool of threads +// Threads returned by this method will need to run the runloop in default mode (eg CFRunLoopRun()) +// Requests will stop the runloop when they complete +// If you have multiple requests sharing the thread you'll need to restart the runloop when this happens ++ (NSThread *)threadForRequest:(ASIHTTPRequest *)request; + + +#pragma mark === + +@property (retain) NSString *username; +@property (retain) NSString *password; +@property (retain) NSString *userAgent; +@property (retain) NSString *domain; + +@property (retain) NSString *proxyUsername; +@property (retain) NSString *proxyPassword; +@property (retain) NSString *proxyDomain; + +@property (retain) NSString *proxyHost; +@property (assign) int proxyPort; +@property (retain) NSString *proxyType; + +@property (retain,setter=setURL:, nonatomic) NSURL *url; +@property (retain) NSURL *originalURL; +@property (assign, nonatomic) id delegate; +@property (retain, nonatomic) id queue; +@property (assign, nonatomic) id uploadProgressDelegate; +@property (assign, nonatomic) id downloadProgressDelegate; +@property (assign) BOOL useKeychainPersistence; +@property (assign) BOOL useSessionPersistence; +@property (retain) NSString *downloadDestinationPath; +@property (retain) NSString *temporaryFileDownloadPath; +@property (retain) NSString *temporaryUncompressedDataDownloadPath; +@property (assign) SEL didStartSelector; +@property (assign) SEL didReceiveResponseHeadersSelector; +@property (assign) SEL willRedirectSelector; +@property (assign) SEL didFinishSelector; +@property (assign) SEL didFailSelector; +@property (assign) SEL didReceiveDataSelector; +@property (retain,readonly) NSString *authenticationRealm; +@property (retain,readonly) NSString *proxyAuthenticationRealm; +@property (retain) NSError *error; +@property (assign,readonly) BOOL complete; +@property (retain) NSDictionary *responseHeaders; +@property (retain) NSMutableDictionary *requestHeaders; +@property (retain) NSMutableArray *requestCookies; +@property (retain,readonly) NSArray *responseCookies; +@property (assign) BOOL useCookiePersistence; +@property (retain) NSDictionary *requestCredentials; +@property (retain) NSDictionary *proxyCredentials; +@property (assign,readonly) int responseStatusCode; +@property (retain,readonly) NSString *responseStatusMessage; +@property (retain) NSMutableData *rawResponseData; +@property (assign) NSTimeInterval timeOutSeconds; +@property (retain, nonatomic) NSString *requestMethod; +@property (retain) NSMutableData *postBody; +@property (assign) unsigned long long contentLength; +@property (assign) unsigned long long postLength; +@property (assign) BOOL shouldResetDownloadProgress; +@property (assign) BOOL shouldResetUploadProgress; +@property (assign) ASIHTTPRequest *mainRequest; +@property (assign) BOOL showAccurateProgress; +@property (assign) unsigned long long totalBytesRead; +@property (assign) unsigned long long totalBytesSent; +@property (assign) NSStringEncoding defaultResponseEncoding; +@property (assign) NSStringEncoding responseEncoding; +@property (assign) BOOL allowCompressedResponse; +@property (assign) BOOL allowResumeForFileDownloads; +@property (retain) NSDictionary *userInfo; +@property (assign) NSInteger tag; +@property (retain) NSString *postBodyFilePath; +@property (assign) BOOL shouldStreamPostDataFromDisk; +@property (assign) BOOL didCreateTemporaryPostDataFile; +@property (assign) BOOL useHTTPVersionOne; +@property (assign, readonly) unsigned long long partialDownloadSize; +@property (assign) BOOL shouldRedirect; +@property (assign) BOOL validatesSecureCertificate; +@property (assign) BOOL shouldCompressRequestBody; +@property (retain) NSURL *PACurl; +@property (retain) NSString *authenticationScheme; +@property (retain) NSString *proxyAuthenticationScheme; +@property (assign) BOOL shouldPresentAuthenticationDialog; +@property (assign) BOOL shouldPresentProxyAuthenticationDialog; +@property (assign, readonly) ASIAuthenticationState authenticationNeeded; +@property (assign) BOOL shouldPresentCredentialsBeforeChallenge; +@property (assign, readonly) int authenticationRetryCount; +@property (assign, readonly) int proxyAuthenticationRetryCount; +@property (assign) BOOL haveBuiltRequestHeaders; +@property (assign, nonatomic) BOOL haveBuiltPostBody; +@property (assign, readonly) BOOL inProgress; +@property (assign) int numberOfTimesToRetryOnTimeout; +@property (assign, readonly) int retryCount; +@property (assign) BOOL shouldAttemptPersistentConnection; +@property (assign) NSTimeInterval persistentConnectionTimeoutSeconds; +@property (assign) BOOL shouldUseRFC2616RedirectBehaviour; +@property (assign, readonly) BOOL connectionCanBeReused; +@property (retain, readonly) NSNumber *requestID; +@property (assign) id downloadCache; +@property (assign) ASICachePolicy cachePolicy; +@property (assign) ASICacheStoragePolicy cacheStoragePolicy; +@property (assign, readonly) BOOL didUseCachedResponse; +@property (assign) NSTimeInterval secondsToCache; +@property (retain) NSArray *clientCertificates; +#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 +@property (assign) BOOL shouldContinueWhenAppEntersBackground; +#endif +@property (retain) ASIDataDecompressor *dataDecompressor; +@property (assign) BOOL shouldWaitToInflateCompressedResponses; + +@end diff --git a/client/osx/ASIHTTPRequest.m b/client/osx/ASIHTTPRequest.m new file mode 100644 index 0000000..b88abba --- /dev/null +++ b/client/osx/ASIHTTPRequest.m @@ -0,0 +1,5107 @@ +// +// ASIHTTPRequest.m +// +// Created by Ben Copsey on 04/10/2007. +// Copyright 2007-2011 All-Seeing Interactive. All rights reserved. +// +// A guide to the main features is available at: +// http://allseeing-i.com/ASIHTTPRequest +// +// Portions are based on the ImageClient example from Apple: +// See: http://developer.apple.com/samplecode/ImageClient/listing37.html + +#import "ASIHTTPRequest.h" + +#if TARGET_OS_IPHONE +#import "Reachability.h" +#import "ASIAuthenticationDialog.h" +#import +#else +#import +#endif +#import "ASIInputStream.h" +#import "ASIDataDecompressor.h" +#import "ASIDataCompressor.h" + +// Automatically set on build +NSString *ASIHTTPRequestVersion = @"v1.8.1-33 2011-08-20"; + +static NSString *defaultUserAgent = nil; + +NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; + +static NSString *ASIHTTPRequestRunLoopMode = @"ASIHTTPRequestRunLoopMode"; + +static const CFOptionFlags kNetworkEvents = kCFStreamEventHasBytesAvailable | kCFStreamEventEndEncountered | kCFStreamEventErrorOccurred; + +// In memory caches of credentials, used on when useSessionPersistence is YES +static NSMutableArray *sessionCredentialsStore = nil; +static NSMutableArray *sessionProxyCredentialsStore = nil; + +// This lock mediates access to session credentials +static NSRecursiveLock *sessionCredentialsLock = nil; + +// We keep track of cookies we have received here so we can remove them from the sharedHTTPCookieStorage later +static NSMutableArray *sessionCookies = nil; + +// The number of times we will allow requests to redirect before we fail with a redirection error +const int RedirectionLimit = 5; + +// The default number of seconds to use for a timeout +static NSTimeInterval defaultTimeOutSeconds = 10; + +static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventType type, void *clientCallBackInfo) { + [((ASIHTTPRequest*)clientCallBackInfo) handleNetworkEvent: type]; +} + +// This lock prevents the operation from being cancelled while it is trying to update the progress, and vice versa +static NSRecursiveLock *progressLock; + +static NSError *ASIRequestCancelledError; +static NSError *ASIRequestTimedOutError; +static NSError *ASIAuthenticationError; +static NSError *ASIUnableToCreateRequestError; +static NSError *ASITooMuchRedirectionError; + +static NSMutableArray *bandwidthUsageTracker = nil; +static unsigned long averageBandwidthUsedPerSecond = 0; + +// These are used for queuing persistent connections on the same connection + +// Incremented every time we specify we want a new connection +static unsigned int nextConnectionNumberToCreate = 0; + +// An array of connectionInfo dictionaries. +// When attempting a persistent connection, we look here to try to find an existing connection to the same server that is currently not in use +static NSMutableArray *persistentConnectionsPool = nil; + +// Mediates access to the persistent connections pool +static NSRecursiveLock *connectionsLock = nil; + +// Each request gets a new id, we store this rather than a ref to the request itself in the connectionInfo dictionary. +// We do this so we don't have to keep the request around while we wait for the connection to expire +static unsigned int nextRequestID = 0; + +// Records how much bandwidth all requests combined have used in the last second +static unsigned long bandwidthUsedInLastSecond = 0; + +// A date one second in the future from the time it was created +static NSDate *bandwidthMeasurementDate = nil; + +// Since throttling variables are shared among all requests, we'll use a lock to mediate access +static NSLock *bandwidthThrottlingLock = nil; + +// the maximum number of bytes that can be transmitted in one second +static unsigned long maxBandwidthPerSecond = 0; + +// A default figure for throttling bandwidth on mobile devices +unsigned long const ASIWWANBandwidthThrottleAmount = 14800; + +#if TARGET_OS_IPHONE +// YES when bandwidth throttling is active +// This flag does not denote whether throttling is turned on - rather whether it is currently in use +// It will be set to NO when throttling was turned on with setShouldThrottleBandwidthForWWAN, but a WI-FI connection is active +static BOOL isBandwidthThrottled = NO; + +// When YES, bandwidth will be automatically throttled when using WWAN (3G/Edge/GPRS) +// Wifi will not be throttled +static BOOL shouldThrottleBandwithForWWANOnly = NO; +#endif + +// Mediates access to the session cookies so requests +static NSRecursiveLock *sessionCookiesLock = nil; + +// This lock ensures delegates only receive one notification that authentication is required at once +// When using ASIAuthenticationDialogs, it also ensures only one dialog is shown at once +// If a request can't acquire the lock immediately, it means a dialog is being shown or a delegate is handling the authentication challenge +// Once it gets the lock, it will try to look for existing credentials again rather than showing the dialog / notifying the delegate +// This is so it can make use of any credentials supplied for the other request, if they are appropriate +static NSRecursiveLock *delegateAuthenticationLock = nil; + +// When throttling bandwidth, Set to a date in future that we will allow all requests to wake up and reschedule their streams +static NSDate *throttleWakeUpTime = nil; + +static id defaultCache = nil; + +// Used for tracking when requests are using the network +static unsigned int runningRequestCount = 0; + +// You can use [ASIHTTPRequest setShouldUpdateNetworkActivityIndicator:NO] if you want to manage it yourself +// Alternatively, override showNetworkActivityIndicator / hideNetworkActivityIndicator +// By default this does nothing on Mac OS X, but again override the above methods for a different behaviour +static BOOL shouldUpdateNetworkActivityIndicator = YES; + +// The thread all requests will run on +// Hangs around forever, but will be blocked unless there are requests underway +static NSThread *networkThread = nil; + +static NSOperationQueue *sharedQueue = nil; + +// Private stuff +@interface ASIHTTPRequest () + +- (void)cancelLoad; + +- (void)destroyReadStream; +- (void)scheduleReadStream; +- (void)unscheduleReadStream; + +- (BOOL)willAskDelegateForCredentials; +- (BOOL)willAskDelegateForProxyCredentials; +- (void)askDelegateForProxyCredentials; +- (void)askDelegateForCredentials; +- (void)failAuthentication; + ++ (void)measureBandwidthUsage; ++ (void)recordBandwidthUsage; + +- (void)startRequest; +- (void)updateStatus:(NSTimer *)timer; +- (void)checkRequestStatus; +- (void)reportFailure; +- (void)reportFinished; +- (void)markAsFinished; +- (void)performRedirect; +- (BOOL)shouldTimeOut; +- (BOOL)willRedirect; +- (BOOL)willAskDelegateToConfirmRedirect; + ++ (void)performInvocation:(NSInvocation *)invocation onTarget:(id *)target releasingObject:(id)objectToRelease; ++ (void)hideNetworkActivityIndicatorAfterDelay; ++ (void)hideNetworkActivityIndicatorIfNeeeded; ++ (void)runRequests; + +// Handling Proxy autodetection and PAC file downloads +- (BOOL)configureProxies; +- (void)fetchPACFile; +- (void)finishedDownloadingPACFile:(ASIHTTPRequest *)theRequest; +- (void)runPACScript:(NSString *)script; +- (void)timeOutPACRead; + +- (void)useDataFromCache; + +// Called to update the size of a partial download when starting a request, or retrying after a timeout +- (void)updatePartialDownloadSize; + +#if TARGET_OS_IPHONE ++ (void)registerForNetworkReachabilityNotifications; ++ (void)unsubscribeFromNetworkReachabilityNotifications; +// Called when the status of the network changes ++ (void)reachabilityChanged:(NSNotification *)note; +#endif + +#if NS_BLOCKS_AVAILABLE +- (void)performBlockOnMainThread:(ASIBasicBlock)block; +- (void)releaseBlocksOnMainThread; ++ (void)releaseBlocks:(NSArray *)blocks; +- (void)callBlock:(ASIBasicBlock)block; +#endif + + + + + +@property (assign) BOOL complete; +@property (retain) NSArray *responseCookies; +@property (assign) int responseStatusCode; +@property (retain, nonatomic) NSDate *lastActivityTime; + +@property (assign) unsigned long long partialDownloadSize; +@property (assign, nonatomic) unsigned long long uploadBufferSize; +@property (retain, nonatomic) NSOutputStream *postBodyWriteStream; +@property (retain, nonatomic) NSInputStream *postBodyReadStream; +@property (assign, nonatomic) unsigned long long lastBytesRead; +@property (assign, nonatomic) unsigned long long lastBytesSent; +@property (retain) NSRecursiveLock *cancelledLock; +@property (retain, nonatomic) NSOutputStream *fileDownloadOutputStream; +@property (retain, nonatomic) NSOutputStream *inflatedFileDownloadOutputStream; +@property (assign) int authenticationRetryCount; +@property (assign) int proxyAuthenticationRetryCount; +@property (assign, nonatomic) BOOL updatedProgress; +@property (assign, nonatomic) BOOL needsRedirect; +@property (assign, nonatomic) int redirectCount; +@property (retain, nonatomic) NSData *compressedPostBody; +@property (retain, nonatomic) NSString *compressedPostBodyFilePath; +@property (retain) NSString *authenticationRealm; +@property (retain) NSString *proxyAuthenticationRealm; +@property (retain) NSString *responseStatusMessage; +@property (assign) BOOL inProgress; +@property (assign) int retryCount; +@property (assign) BOOL willRetryRequest; +@property (assign) BOOL connectionCanBeReused; +@property (retain, nonatomic) NSMutableDictionary *connectionInfo; +@property (retain, nonatomic) NSInputStream *readStream; +@property (assign) ASIAuthenticationState authenticationNeeded; +@property (assign, nonatomic) BOOL readStreamIsScheduled; +@property (assign, nonatomic) BOOL downloadComplete; +@property (retain) NSNumber *requestID; +@property (assign, nonatomic) NSString *runLoopMode; +@property (retain, nonatomic) NSTimer *statusTimer; +@property (assign) BOOL didUseCachedResponse; +@property (retain, nonatomic) NSURL *redirectURL; + +@property (assign, nonatomic) BOOL isPACFileRequest; +@property (retain, nonatomic) ASIHTTPRequest *PACFileRequest; +@property (retain, nonatomic) NSInputStream *PACFileReadStream; +@property (retain, nonatomic) NSMutableData *PACFileData; + +@property (assign, nonatomic, setter=setSynchronous:) BOOL isSynchronous; +@end + + +@implementation ASIHTTPRequest + +#pragma mark init / dealloc + ++ (void)initialize +{ + if (self == [ASIHTTPRequest class]) { + persistentConnectionsPool = [[NSMutableArray alloc] init]; + connectionsLock = [[NSRecursiveLock alloc] init]; + progressLock = [[NSRecursiveLock alloc] init]; + bandwidthThrottlingLock = [[NSLock alloc] init]; + sessionCookiesLock = [[NSRecursiveLock alloc] init]; + sessionCredentialsLock = [[NSRecursiveLock alloc] init]; + delegateAuthenticationLock = [[NSRecursiveLock alloc] init]; + bandwidthUsageTracker = [[NSMutableArray alloc] initWithCapacity:5]; + ASIRequestTimedOutError = [[NSError alloc] initWithDomain:NetworkRequestErrorDomain code:ASIRequestTimedOutErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"The request timed out",NSLocalizedDescriptionKey,nil]]; + ASIAuthenticationError = [[NSError alloc] initWithDomain:NetworkRequestErrorDomain code:ASIAuthenticationErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Authentication needed",NSLocalizedDescriptionKey,nil]]; + ASIRequestCancelledError = [[NSError alloc] initWithDomain:NetworkRequestErrorDomain code:ASIRequestCancelledErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"The request was cancelled",NSLocalizedDescriptionKey,nil]]; + ASIUnableToCreateRequestError = [[NSError alloc] initWithDomain:NetworkRequestErrorDomain code:ASIUnableToCreateRequestErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Unable to create request (bad url?)",NSLocalizedDescriptionKey,nil]]; + ASITooMuchRedirectionError = [[NSError alloc] initWithDomain:NetworkRequestErrorDomain code:ASITooMuchRedirectionErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"The request failed because it redirected too many times",NSLocalizedDescriptionKey,nil]]; + sharedQueue = [[NSOperationQueue alloc] init]; + [sharedQueue setMaxConcurrentOperationCount:4]; + + } +} + + +- (id)initWithURL:(NSURL *)newURL +{ + self = [self init]; + [self setRequestMethod:@"GET"]; + + [self setRunLoopMode:NSDefaultRunLoopMode]; + [self setShouldAttemptPersistentConnection:YES]; + [self setPersistentConnectionTimeoutSeconds:60.0]; + [self setShouldPresentCredentialsBeforeChallenge:YES]; + [self setShouldRedirect:YES]; + [self setShowAccurateProgress:YES]; + [self setShouldResetDownloadProgress:YES]; + [self setShouldResetUploadProgress:YES]; + [self setAllowCompressedResponse:YES]; + [self setShouldWaitToInflateCompressedResponses:YES]; + [self setDefaultResponseEncoding:NSISOLatin1StringEncoding]; + [self setShouldPresentProxyAuthenticationDialog:YES]; + + [self setTimeOutSeconds:[ASIHTTPRequest defaultTimeOutSeconds]]; + [self setUseSessionPersistence:YES]; + [self setUseCookiePersistence:YES]; + [self setValidatesSecureCertificate:YES]; + [self setRequestCookies:[[[NSMutableArray alloc] init] autorelease]]; + [self setDidStartSelector:@selector(requestStarted:)]; + [self setDidReceiveResponseHeadersSelector:@selector(request:didReceiveResponseHeaders:)]; + [self setWillRedirectSelector:@selector(request:willRedirectToURL:)]; + [self setDidFinishSelector:@selector(requestFinished:)]; + [self setDidFailSelector:@selector(requestFailed:)]; + [self setDidReceiveDataSelector:@selector(request:didReceiveData:)]; + [self setURL:newURL]; + [self setCancelledLock:[[[NSRecursiveLock alloc] init] autorelease]]; + [self setDownloadCache:[[self class] defaultCache]]; + return self; +} + ++ (id)requestWithURL:(NSURL *)newURL +{ + return [[[self alloc] initWithURL:newURL] autorelease]; +} + ++ (id)requestWithURL:(NSURL *)newURL usingCache:(id )cache +{ + return [self requestWithURL:newURL usingCache:cache andCachePolicy:ASIUseDefaultCachePolicy]; +} + ++ (id)requestWithURL:(NSURL *)newURL usingCache:(id )cache andCachePolicy:(ASICachePolicy)policy +{ + ASIHTTPRequest *request = [[[self alloc] initWithURL:newURL] autorelease]; + [request setDownloadCache:cache]; + [request setCachePolicy:policy]; + return request; +} + +- (void)dealloc +{ + [self setAuthenticationNeeded:ASINoAuthenticationNeededYet]; + if (requestAuthentication) { + CFRelease(requestAuthentication); + } + if (proxyAuthentication) { + CFRelease(proxyAuthentication); + } + if (request) { + CFRelease(request); + } + if (clientCertificateIdentity) { + CFRelease(clientCertificateIdentity); + } + [self cancelLoad]; + [redirectURL release]; + [statusTimer invalidate]; + [statusTimer release]; + [queue release]; + [userInfo release]; + [postBody release]; + [compressedPostBody release]; + [error release]; + [requestHeaders release]; + [requestCookies release]; + [downloadDestinationPath release]; + [temporaryFileDownloadPath release]; + [temporaryUncompressedDataDownloadPath release]; + [fileDownloadOutputStream release]; + [inflatedFileDownloadOutputStream release]; + [username release]; + [password release]; + [domain release]; + [authenticationRealm release]; + [authenticationScheme release]; + [requestCredentials release]; + [proxyHost release]; + [proxyType release]; + [proxyUsername release]; + [proxyPassword release]; + [proxyDomain release]; + [proxyAuthenticationRealm release]; + [proxyAuthenticationScheme release]; + [proxyCredentials release]; + [url release]; + [originalURL release]; + [lastActivityTime release]; + [responseCookies release]; + [rawResponseData release]; + [responseHeaders release]; + [requestMethod release]; + [cancelledLock release]; + [postBodyFilePath release]; + [compressedPostBodyFilePath release]; + [postBodyWriteStream release]; + [postBodyReadStream release]; + [PACurl release]; + [clientCertificates release]; + [responseStatusMessage release]; + [connectionInfo release]; + [requestID release]; + [dataDecompressor release]; + [userAgent release]; + + #if NS_BLOCKS_AVAILABLE + [self releaseBlocksOnMainThread]; + #endif + + [super dealloc]; +} + +#if NS_BLOCKS_AVAILABLE +- (void)releaseBlocksOnMainThread +{ + NSMutableArray *blocks = [NSMutableArray array]; + if (completionBlock) { + [blocks addObject:completionBlock]; + [completionBlock release]; + completionBlock = nil; + } + if (failureBlock) { + [blocks addObject:failureBlock]; + [failureBlock release]; + failureBlock = nil; + } + if (startedBlock) { + [blocks addObject:startedBlock]; + [startedBlock release]; + startedBlock = nil; + } + if (headersReceivedBlock) { + [blocks addObject:headersReceivedBlock]; + [headersReceivedBlock release]; + headersReceivedBlock = nil; + } + if (bytesReceivedBlock) { + [blocks addObject:bytesReceivedBlock]; + [bytesReceivedBlock release]; + bytesReceivedBlock = nil; + } + if (bytesSentBlock) { + [blocks addObject:bytesSentBlock]; + [bytesSentBlock release]; + bytesSentBlock = nil; + } + if (downloadSizeIncrementedBlock) { + [blocks addObject:downloadSizeIncrementedBlock]; + [downloadSizeIncrementedBlock release]; + downloadSizeIncrementedBlock = nil; + } + if (uploadSizeIncrementedBlock) { + [blocks addObject:uploadSizeIncrementedBlock]; + [uploadSizeIncrementedBlock release]; + uploadSizeIncrementedBlock = nil; + } + if (dataReceivedBlock) { + [blocks addObject:dataReceivedBlock]; + [dataReceivedBlock release]; + dataReceivedBlock = nil; + } + if (proxyAuthenticationNeededBlock) { + [blocks addObject:proxyAuthenticationNeededBlock]; + [proxyAuthenticationNeededBlock release]; + proxyAuthenticationNeededBlock = nil; + } + if (authenticationNeededBlock) { + [blocks addObject:authenticationNeededBlock]; + [authenticationNeededBlock release]; + authenticationNeededBlock = nil; + } + [[self class] performSelectorOnMainThread:@selector(releaseBlocks:) withObject:blocks waitUntilDone:[NSThread isMainThread]]; +} +// Always called on main thread ++ (void)releaseBlocks:(NSArray *)blocks +{ + // Blocks will be released when this method exits +} +#endif + + +#pragma mark setup request + +- (void)addRequestHeader:(NSString *)header value:(NSString *)value +{ + if (!requestHeaders) { + [self setRequestHeaders:[NSMutableDictionary dictionaryWithCapacity:1]]; + } + [requestHeaders setObject:value forKey:header]; +} + +// This function will be called either just before a request starts, or when postLength is needed, whichever comes first +// postLength must be set by the time this function is complete +- (void)buildPostBody +{ + + if ([self haveBuiltPostBody]) { + return; + } + + // Are we submitting the request body from a file on disk + if ([self postBodyFilePath]) { + + // If we were writing to the post body via appendPostData or appendPostDataFromFile, close the write stream + if ([self postBodyWriteStream]) { + [[self postBodyWriteStream] close]; + [self setPostBodyWriteStream:nil]; + } + + + NSString *path; + if ([self shouldCompressRequestBody]) { + if (![self compressedPostBodyFilePath]) { + [self setCompressedPostBodyFilePath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]]; + + NSError *err = nil; + if (![ASIDataCompressor compressDataFromFile:[self postBodyFilePath] toFile:[self compressedPostBodyFilePath] error:&err]) { + [self failWithError:err]; + return; + } + } + path = [self compressedPostBodyFilePath]; + } else { + path = [self postBodyFilePath]; + } + NSError *err = nil; + [self setPostLength:[[[[[NSFileManager alloc] init] autorelease] attributesOfItemAtPath:path error:&err] fileSize]]; + if (err) { + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to get attributes for file at path '%@'",path],NSLocalizedDescriptionKey,error,NSUnderlyingErrorKey,nil]]]; + return; + } + + // Otherwise, we have an in-memory request body + } else { + if ([self shouldCompressRequestBody]) { + NSError *err = nil; + NSData *compressedBody = [ASIDataCompressor compressData:[self postBody] error:&err]; + if (err) { + [self failWithError:err]; + return; + } + [self setCompressedPostBody:compressedBody]; + [self setPostLength:[[self compressedPostBody] length]]; + } else { + [self setPostLength:[[self postBody] length]]; + } + } + + if ([self postLength] > 0) { + if ([requestMethod isEqualToString:@"GET"] || [requestMethod isEqualToString:@"DELETE"] || [requestMethod isEqualToString:@"HEAD"]) { + [self setRequestMethod:@"POST"]; + } + [self addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%llu",[self postLength]]]; + } + [self setHaveBuiltPostBody:YES]; + +} + +// Sets up storage for the post body +- (void)setupPostBody +{ + if ([self shouldStreamPostDataFromDisk]) { + if (![self postBodyFilePath]) { + [self setPostBodyFilePath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]]; + [self setDidCreateTemporaryPostDataFile:YES]; + } + if (![self postBodyWriteStream]) { + [self setPostBodyWriteStream:[[[NSOutputStream alloc] initToFileAtPath:[self postBodyFilePath] append:NO] autorelease]]; + [[self postBodyWriteStream] open]; + } + } else { + if (![self postBody]) { + [self setPostBody:[[[NSMutableData alloc] init] autorelease]]; + } + } +} + +- (void)appendPostData:(NSData *)data +{ + [self setupPostBody]; + if ([data length] == 0) { + return; + } + if ([self shouldStreamPostDataFromDisk]) { + [[self postBodyWriteStream] write:[data bytes] maxLength:[data length]]; + } else { + [[self postBody] appendData:data]; + } +} + +- (void)appendPostDataFromFile:(NSString *)file +{ + [self setupPostBody]; + NSInputStream *stream = [[[NSInputStream alloc] initWithFileAtPath:file] autorelease]; + [stream open]; + NSUInteger bytesRead; + while ([stream hasBytesAvailable]) { + + unsigned char buffer[1024*256]; + bytesRead = [stream read:buffer maxLength:sizeof(buffer)]; + if (bytesRead == 0) { + break; + } + if ([self shouldStreamPostDataFromDisk]) { + [[self postBodyWriteStream] write:buffer maxLength:bytesRead]; + } else { + [[self postBody] appendData:[NSData dataWithBytes:buffer length:bytesRead]]; + } + } + [stream close]; +} + +- (NSString *)requestMethod +{ + [[self cancelledLock] lock]; + NSString *m = requestMethod; + [[self cancelledLock] unlock]; + return m; +} + +- (void)setRequestMethod:(NSString *)newRequestMethod +{ + [[self cancelledLock] lock]; + if (requestMethod != newRequestMethod) { + [requestMethod release]; + requestMethod = [newRequestMethod retain]; + if ([requestMethod isEqualToString:@"POST"] || [requestMethod isEqualToString:@"PUT"] || [postBody length] || postBodyFilePath) { + [self setShouldAttemptPersistentConnection:NO]; + } + } + [[self cancelledLock] unlock]; +} + +- (NSURL *)url +{ + [[self cancelledLock] lock]; + NSURL *u = url; + [[self cancelledLock] unlock]; + return u; +} + + +- (void)setURL:(NSURL *)newURL +{ + [[self cancelledLock] lock]; + if ([newURL isEqual:[self url]]) { + [[self cancelledLock] unlock]; + return; + } + [url release]; + url = [newURL retain]; + if (requestAuthentication) { + CFRelease(requestAuthentication); + requestAuthentication = NULL; + } + if (proxyAuthentication) { + CFRelease(proxyAuthentication); + proxyAuthentication = NULL; + } + if (request) { + CFRelease(request); + request = NULL; + } + [self setRedirectURL:nil]; + [[self cancelledLock] unlock]; +} + +- (id)delegate +{ + [[self cancelledLock] lock]; + id d = delegate; + [[self cancelledLock] unlock]; + return d; +} + +- (void)setDelegate:(id)newDelegate +{ + [[self cancelledLock] lock]; + delegate = newDelegate; + [[self cancelledLock] unlock]; +} + +- (id)queue +{ + [[self cancelledLock] lock]; + id q = queue; + [[self cancelledLock] unlock]; + return q; +} + + +- (void)setQueue:(id)newQueue +{ + [[self cancelledLock] lock]; + if (newQueue != queue) { + [queue release]; + queue = [newQueue retain]; + } + [[self cancelledLock] unlock]; +} + +#pragma mark get information about this request + +// cancel the request - this must be run on the same thread as the request is running on +- (void)cancelOnRequestThread +{ + #if DEBUG_REQUEST_STATUS + NSLog(@"[STATUS] Request cancelled: %@",self); + #endif + + [[self cancelledLock] lock]; + + if ([self isCancelled] || [self complete]) { + [[self cancelledLock] unlock]; + return; + } + [self failWithError:ASIRequestCancelledError]; + [self setComplete:YES]; + [self cancelLoad]; + + CFRetain(self); + [self willChangeValueForKey:@"isCancelled"]; + cancelled = YES; + [self didChangeValueForKey:@"isCancelled"]; + + [[self cancelledLock] unlock]; + CFRelease(self); +} + +- (void)cancel +{ + [self performSelector:@selector(cancelOnRequestThread) onThread:[[self class] threadForRequest:self] withObject:nil waitUntilDone:NO]; +} + +- (void)clearDelegatesAndCancel +{ + [[self cancelledLock] lock]; + + // Clear delegates + [self setDelegate:nil]; + [self setQueue:nil]; + [self setDownloadProgressDelegate:nil]; + [self setUploadProgressDelegate:nil]; + + #if NS_BLOCKS_AVAILABLE + // Clear blocks + [self releaseBlocksOnMainThread]; + #endif + + [[self cancelledLock] unlock]; + [self cancel]; +} + + +- (BOOL)isCancelled +{ + BOOL result; + + [[self cancelledLock] lock]; + result = cancelled; + [[self cancelledLock] unlock]; + + return result; +} + +// Call this method to get the received data as an NSString. Don't use for binary data! +- (NSString *)responseString +{ + NSData *data = [self responseData]; + if (!data) { + return nil; + } + + return [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:[self responseEncoding]] autorelease]; +} + +- (BOOL)isResponseCompressed +{ + NSString *encoding = [[self responseHeaders] objectForKey:@"Content-Encoding"]; + return encoding && [encoding rangeOfString:@"gzip"].location != NSNotFound; +} + +- (NSData *)responseData +{ + if ([self isResponseCompressed] && [self shouldWaitToInflateCompressedResponses]) { + return [ASIDataDecompressor uncompressData:[self rawResponseData] error:NULL]; + } else { + return [self rawResponseData]; + } + return nil; +} + +#pragma mark running a request + +- (void)startSynchronous +{ +#if DEBUG_REQUEST_STATUS || DEBUG_THROTTLING + NSLog(@"[STATUS] Starting synchronous request %@",self); +#endif + [self setSynchronous:YES]; + [self setRunLoopMode:ASIHTTPRequestRunLoopMode]; + [self setInProgress:YES]; + + if (![self isCancelled] && ![self complete]) { + [self main]; + while (!complete) { + [[NSRunLoop currentRunLoop] runMode:[self runLoopMode] beforeDate:[NSDate distantFuture]]; + } + } + + [self setInProgress:NO]; +} + +- (void)start +{ + [self setInProgress:YES]; + [self performSelector:@selector(main) onThread:[[self class] threadForRequest:self] withObject:nil waitUntilDone:NO]; +} + +- (void)startAsynchronous +{ +#if DEBUG_REQUEST_STATUS || DEBUG_THROTTLING + NSLog(@"[STATUS] Starting asynchronous request %@",self); +#endif + [sharedQueue addOperation:self]; +} + +#pragma mark concurrency + +- (BOOL)isConcurrent +{ + return YES; +} + +- (BOOL)isFinished +{ + return finished; +} + +- (BOOL)isExecuting { + return [self inProgress]; +} + +#pragma mark request logic + +// Create the request +- (void)main +{ + @try { + + [[self cancelledLock] lock]; + + #if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 + if ([ASIHTTPRequest isMultitaskingSupported] && [self shouldContinueWhenAppEntersBackground]) { + backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ + // Synchronize the cleanup call on the main thread in case + // the task actually finishes at around the same time. + dispatch_async(dispatch_get_main_queue(), ^{ + if (backgroundTask != UIBackgroundTaskInvalid) + { + [[UIApplication sharedApplication] endBackgroundTask:backgroundTask]; + backgroundTask = UIBackgroundTaskInvalid; + [self cancel]; + } + }); + }]; + } + #endif + + + // A HEAD request generated by an ASINetworkQueue may have set the error already. If so, we should not proceed. + if ([self error]) { + [self setComplete:YES]; + [self markAsFinished]; + return; + } + + [self setComplete:NO]; + [self setDidUseCachedResponse:NO]; + + if (![self url]) { + [self failWithError:ASIUnableToCreateRequestError]; + return; + } + + // Must call before we create the request so that the request method can be set if needs be + if (![self mainRequest]) { + [self buildPostBody]; + } + + if (![[self requestMethod] isEqualToString:@"GET"]) { + [self setDownloadCache:nil]; + } + + + // If we're redirecting, we'll already have a CFHTTPMessageRef + if (request) { + CFRelease(request); + } + + // Create a new HTTP request. + request = CFHTTPMessageCreateRequest(kCFAllocatorDefault, (CFStringRef)[self requestMethod], (CFURLRef)[self url], [self useHTTPVersionOne] ? kCFHTTPVersion1_0 : kCFHTTPVersion1_1); + if (!request) { + [self failWithError:ASIUnableToCreateRequestError]; + return; + } + + //If this is a HEAD request generated by an ASINetworkQueue, we need to let the main request generate its headers first so we can use them + if ([self mainRequest]) { + [[self mainRequest] buildRequestHeaders]; + } + + // Even if this is a HEAD request with a mainRequest, we still need to call to give subclasses a chance to add their own to HEAD requests (ASIS3Request does this) + [self buildRequestHeaders]; + + if ([self downloadCache]) { + + // If this request should use the default policy, set its policy to the download cache's default policy + if (![self cachePolicy]) { + [self setCachePolicy:[[self downloadCache] defaultCachePolicy]]; + } + + // If have have cached data that is valid for this request, use that and stop + if ([[self downloadCache] canUseCachedDataForRequest:self]) { + [self useDataFromCache]; + return; + } + + // If cached data is stale, or we have been told to ask the server if it has been modified anyway, we need to add headers for a conditional GET + if ([self cachePolicy] & (ASIAskServerIfModifiedWhenStaleCachePolicy|ASIAskServerIfModifiedCachePolicy)) { + + NSDictionary *cachedHeaders = [[self downloadCache] cachedResponseHeadersForURL:[self url]]; + if (cachedHeaders) { + NSString *etag = [cachedHeaders objectForKey:@"Etag"]; + if (etag) { + [[self requestHeaders] setObject:etag forKey:@"If-None-Match"]; + } + NSString *lastModified = [cachedHeaders objectForKey:@"Last-Modified"]; + if (lastModified) { + [[self requestHeaders] setObject:lastModified forKey:@"If-Modified-Since"]; + } + } + } + } + + [self applyAuthorizationHeader]; + + + NSString *header; + for (header in [self requestHeaders]) { + CFHTTPMessageSetHeaderFieldValue(request, (CFStringRef)header, (CFStringRef)[[self requestHeaders] objectForKey:header]); + } + + // If we immediately have access to proxy settings, start the request + // Otherwise, we'll start downloading the proxy PAC file, and call startRequest once that process is complete + if ([self configureProxies]) { + [self startRequest]; + } + + } @catch (NSException *exception) { + NSError *underlyingError = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIUnhandledExceptionError userInfo:[exception userInfo]]; + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIUnhandledExceptionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[exception name],NSLocalizedDescriptionKey,[exception reason],NSLocalizedFailureReasonErrorKey,underlyingError,NSUnderlyingErrorKey,nil]]]; + + } @finally { + [[self cancelledLock] unlock]; + } +} + +- (void)applyAuthorizationHeader +{ + // Do we want to send credentials before we are asked for them? + if (![self shouldPresentCredentialsBeforeChallenge]) { + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ will not send credentials to the server until it asks for them",self); + #endif + return; + } + + NSDictionary *credentials = nil; + + // Do we already have an auth header? + if (![[self requestHeaders] objectForKey:@"Authorization"]) { + + // If we have basic authentication explicitly set and a username and password set on the request, add a basic auth header + if ([self username] && [self password] && [[self authenticationScheme] isEqualToString:(NSString *)kCFHTTPAuthenticationSchemeBasic]) { + [self addBasicAuthenticationHeaderWithUsername:[self username] andPassword:[self password]]; + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ has a username and password set, and was manually configured to use BASIC. Will send credentials without waiting for an authentication challenge",self); + #endif + + } else { + + // See if we have any cached credentials we can use in the session store + if ([self useSessionPersistence]) { + credentials = [self findSessionAuthenticationCredentials]; + + if (credentials) { + + // When the Authentication key is set, the credentials were stored after an authentication challenge, so we can let CFNetwork apply them + // (credentials for Digest and NTLM will always be stored like this) + if ([credentials objectForKey:@"Authentication"]) { + + // If we've already talked to this server and have valid credentials, let's apply them to the request + if (CFHTTPMessageApplyCredentialDictionary(request, (CFHTTPAuthenticationRef)[credentials objectForKey:@"Authentication"], (CFDictionaryRef)[credentials objectForKey:@"Credentials"], NULL)) { + [self setAuthenticationScheme:[credentials objectForKey:@"AuthenticationScheme"]]; + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ found cached credentials (%@), will reuse without waiting for an authentication challenge",self,[credentials objectForKey:@"AuthenticationScheme"]); + #endif + } else { + [[self class] removeAuthenticationCredentialsFromSessionStore:[credentials objectForKey:@"Credentials"]]; + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Failed to apply cached credentials to request %@. These will be removed from the session store, and this request will wait for an authentication challenge",self); + #endif + } + + // If the Authentication key is not set, these credentials were stored after a username and password set on a previous request passed basic authentication + // When this happens, we'll need to create the Authorization header ourselves + } else { + NSDictionary *usernameAndPassword = [credentials objectForKey:@"Credentials"]; + [self addBasicAuthenticationHeaderWithUsername:[usernameAndPassword objectForKey:(NSString *)kCFHTTPAuthenticationUsername] andPassword:[usernameAndPassword objectForKey:(NSString *)kCFHTTPAuthenticationPassword]]; + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ found cached BASIC credentials from a previous request. Will send credentials without waiting for an authentication challenge",self); + #endif + } + } + } + } + } + + // Apply proxy authentication credentials + if ([self useSessionPersistence]) { + credentials = [self findSessionProxyAuthenticationCredentials]; + if (credentials) { + if (!CFHTTPMessageApplyCredentialDictionary(request, (CFHTTPAuthenticationRef)[credentials objectForKey:@"Authentication"], (CFDictionaryRef)[credentials objectForKey:@"Credentials"], NULL)) { + [[self class] removeProxyAuthenticationCredentialsFromSessionStore:[credentials objectForKey:@"Credentials"]]; + } + } + } +} + +- (void)applyCookieHeader +{ + // Add cookies from the persistent (mac os global) store + if ([self useCookiePersistence]) { + NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[[self url] absoluteURL]]; + if (cookies) { + [[self requestCookies] addObjectsFromArray:cookies]; + } + } + + // Apply request cookies + NSArray *cookies; + if ([self mainRequest]) { + cookies = [[self mainRequest] requestCookies]; + } else { + cookies = [self requestCookies]; + } + if ([cookies count] > 0) { + NSHTTPCookie *cookie; + NSString *cookieHeader = nil; + for (cookie in cookies) { + if (!cookieHeader) { + cookieHeader = [NSString stringWithFormat: @"%@=%@",[cookie name],[cookie value]]; + } else { + cookieHeader = [NSString stringWithFormat: @"%@; %@=%@",cookieHeader,[cookie name],[cookie value]]; + } + } + if (cookieHeader) { + [self addRequestHeader:@"Cookie" value:cookieHeader]; + } + } +} + +- (void)buildRequestHeaders +{ + if ([self haveBuiltRequestHeaders]) { + return; + } + [self setHaveBuiltRequestHeaders:YES]; + + if ([self mainRequest]) { + for (NSString *header in [[self mainRequest] requestHeaders]) { + [self addRequestHeader:header value:[[[self mainRequest] requestHeaders] valueForKey:header]]; + } + return; + } + + [self applyCookieHeader]; + + // Build and set the user agent string if the request does not already have a custom user agent specified + if (![[self requestHeaders] objectForKey:@"User-Agent"]) { + NSString *userAgentString = [self userAgent]; + if (!userAgentString) { + userAgentString = [ASIHTTPRequest defaultUserAgentString]; + } + if (userAgentString) { + [self addRequestHeader:@"User-Agent" value:userAgentString]; + } + } + + + // Accept a compressed response + if ([self allowCompressedResponse]) { + [self addRequestHeader:@"Accept-Encoding" value:@"gzip"]; + } + + // Configure a compressed request body + if ([self shouldCompressRequestBody]) { + [self addRequestHeader:@"Content-Encoding" value:@"gzip"]; + } + + // Should this request resume an existing download? + [self updatePartialDownloadSize]; + if ([self partialDownloadSize]) { + [self addRequestHeader:@"Range" value:[NSString stringWithFormat:@"bytes=%llu-",[self partialDownloadSize]]]; + } +} + +- (void)updatePartialDownloadSize +{ + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; + + if ([self allowResumeForFileDownloads] && [self downloadDestinationPath] && [self temporaryFileDownloadPath] && [fileManager fileExistsAtPath:[self temporaryFileDownloadPath]]) { + NSError *err = nil; + [self setPartialDownloadSize:[[fileManager attributesOfItemAtPath:[self temporaryFileDownloadPath] error:&err] fileSize]]; + if (err) { + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to get attributes for file at path '%@'",[self temporaryFileDownloadPath]],NSLocalizedDescriptionKey,error,NSUnderlyingErrorKey,nil]]]; + return; + } + } +} + +- (void)startRequest +{ + if ([self isCancelled]) { + return; + } + + [self performSelectorOnMainThread:@selector(requestStarted) withObject:nil waitUntilDone:[NSThread isMainThread]]; + + [self setDownloadComplete:NO]; + [self setComplete:NO]; + [self setTotalBytesRead:0]; + [self setLastBytesRead:0]; + + if ([self redirectCount] == 0) { + [self setOriginalURL:[self url]]; + } + + // If we're retrying a request, let's remove any progress we made + if ([self lastBytesSent] > 0) { + [self removeUploadProgressSoFar]; + } + + [self setLastBytesSent:0]; + [self setContentLength:0]; + [self setResponseHeaders:nil]; + if (![self downloadDestinationPath]) { + [self setRawResponseData:[[[NSMutableData alloc] init] autorelease]]; + } + + + // + // Create the stream for the request + // + + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; + + [self setReadStreamIsScheduled:NO]; + + // Do we need to stream the request body from disk + if ([self shouldStreamPostDataFromDisk] && [self postBodyFilePath] && [fileManager fileExistsAtPath:[self postBodyFilePath]]) { + + // Are we gzipping the request body? + if ([self compressedPostBodyFilePath] && [fileManager fileExistsAtPath:[self compressedPostBodyFilePath]]) { + [self setPostBodyReadStream:[ASIInputStream inputStreamWithFileAtPath:[self compressedPostBodyFilePath] request:self]]; + } else { + [self setPostBodyReadStream:[ASIInputStream inputStreamWithFileAtPath:[self postBodyFilePath] request:self]]; + } + [self setReadStream:[NSMakeCollectable(CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, request,(CFReadStreamRef)[self postBodyReadStream])) autorelease]]; + } else { + + // If we have a request body, we'll stream it from memory using our custom stream, so that we can measure bandwidth use and it can be bandwidth-throttled if necessary + if ([self postBody] && [[self postBody] length] > 0) { + if ([self shouldCompressRequestBody] && [self compressedPostBody]) { + [self setPostBodyReadStream:[ASIInputStream inputStreamWithData:[self compressedPostBody] request:self]]; + } else if ([self postBody]) { + [self setPostBodyReadStream:[ASIInputStream inputStreamWithData:[self postBody] request:self]]; + } + [self setReadStream:[NSMakeCollectable(CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, request,(CFReadStreamRef)[self postBodyReadStream])) autorelease]]; + + } else { + [self setReadStream:[NSMakeCollectable(CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, request)) autorelease]]; + } + } + + if (![self readStream]) { + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileBuildingRequestType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Unable to create read stream",NSLocalizedDescriptionKey,nil]]]; + return; + } + + + + + // + // Handle SSL certificate settings + // + + if([[[[self url] scheme] lowercaseString] isEqualToString:@"https"]) { + + NSMutableDictionary *sslProperties = [NSMutableDictionary dictionaryWithCapacity:1]; + + // Tell CFNetwork not to validate SSL certificates + if (![self validatesSecureCertificate]) { + [sslProperties setObject:(NSString *)kCFBooleanFalse forKey:(NSString *)kCFStreamSSLValidatesCertificateChain]; + } + + // Tell CFNetwork to use a client certificate + if (clientCertificateIdentity) { + + NSMutableArray *certificates = [NSMutableArray arrayWithCapacity:[clientCertificates count]+1]; + + // The first object in the array is our SecIdentityRef + [certificates addObject:(id)clientCertificateIdentity]; + + // If we've added any additional certificates, add them too + for (id cert in clientCertificates) { + [certificates addObject:cert]; + } + [sslProperties setObject:certificates forKey:(NSString *)kCFStreamSSLCertificates]; + } + + CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertySSLSettings, sslProperties); + } + + // + // Handle proxy settings + // + + if ([self proxyHost] && [self proxyPort]) { + NSString *hostKey; + NSString *portKey; + + if (![self proxyType]) { + [self setProxyType:(NSString *)kCFProxyTypeHTTP]; + } + + if ([[self proxyType] isEqualToString:(NSString *)kCFProxyTypeSOCKS]) { + hostKey = (NSString *)kCFStreamPropertySOCKSProxyHost; + portKey = (NSString *)kCFStreamPropertySOCKSProxyPort; + } else { + hostKey = (NSString *)kCFStreamPropertyHTTPProxyHost; + portKey = (NSString *)kCFStreamPropertyHTTPProxyPort; + if ([[[[self url] scheme] lowercaseString] isEqualToString:@"https"]) { + hostKey = (NSString *)kCFStreamPropertyHTTPSProxyHost; + portKey = (NSString *)kCFStreamPropertyHTTPSProxyPort; + } + } + NSMutableDictionary *proxyToUse = [NSMutableDictionary dictionaryWithObjectsAndKeys:[self proxyHost],hostKey,[NSNumber numberWithInt:[self proxyPort]],portKey,nil]; + + if ([[self proxyType] isEqualToString:(NSString *)kCFProxyTypeSOCKS]) { + CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertySOCKSProxy, proxyToUse); + } else { + CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPProxy, proxyToUse); + } + } + + + // + // Handle persistent connections + // + + [ASIHTTPRequest expirePersistentConnections]; + + [connectionsLock lock]; + + + if (![[self url] host] || ![[self url] scheme]) { + [self setConnectionInfo:nil]; + [self setShouldAttemptPersistentConnection:NO]; + } + + // Will store the old stream that was using this connection (if there was one) so we can clean it up once we've opened our own stream + NSInputStream *oldStream = nil; + + // Use a persistent connection if possible + if ([self shouldAttemptPersistentConnection]) { + + + // If we are redirecting, we will re-use the current connection only if we are connecting to the same server + if ([self connectionInfo]) { + + if (![[[self connectionInfo] objectForKey:@"host"] isEqualToString:[[self url] host]] || ![[[self connectionInfo] objectForKey:@"scheme"] isEqualToString:[[self url] scheme]] || [(NSNumber *)[[self connectionInfo] objectForKey:@"port"] intValue] != [[[self url] port] intValue]) { + [self setConnectionInfo:nil]; + + // Check if we should have expired this connection + } else if ([[[self connectionInfo] objectForKey:@"expires"] timeIntervalSinceNow] < 0) { + #if DEBUG_PERSISTENT_CONNECTIONS + NSLog(@"[CONNECTION] Not re-using connection #%i because it has expired",[[[self connectionInfo] objectForKey:@"id"] intValue]); + #endif + [persistentConnectionsPool removeObject:[self connectionInfo]]; + [self setConnectionInfo:nil]; + + } else if ([[self connectionInfo] objectForKey:@"request"] != nil) { + //Some other request reused this connection already - we'll have to create a new one + #if DEBUG_PERSISTENT_CONNECTIONS + NSLog(@"%@ - Not re-using connection #%i for request #%i because it is already used by request #%i",self,[[[self connectionInfo] objectForKey:@"id"] intValue],[[self requestID] intValue],[[[self connectionInfo] objectForKey:@"request"] intValue]); + #endif + [self setConnectionInfo:nil]; + } + } + + + + if (![self connectionInfo] && [[self url] host] && [[self url] scheme]) { // We must have a proper url with a host and scheme, or this will explode + + // Look for a connection to the same server in the pool + for (NSMutableDictionary *existingConnection in persistentConnectionsPool) { + if (![existingConnection objectForKey:@"request"] && [[existingConnection objectForKey:@"host"] isEqualToString:[[self url] host]] && [[existingConnection objectForKey:@"scheme"] isEqualToString:[[self url] scheme]] && [(NSNumber *)[existingConnection objectForKey:@"port"] intValue] == [[[self url] port] intValue]) { + [self setConnectionInfo:existingConnection]; + } + } + } + + if ([[self connectionInfo] objectForKey:@"stream"]) { + oldStream = [[[self connectionInfo] objectForKey:@"stream"] retain]; + + } + + // No free connection was found in the pool matching the server/scheme/port we're connecting to, we'll need to create a new one + if (![self connectionInfo]) { + [self setConnectionInfo:[NSMutableDictionary dictionary]]; + nextConnectionNumberToCreate++; + [[self connectionInfo] setObject:[NSNumber numberWithInt:nextConnectionNumberToCreate] forKey:@"id"]; + [[self connectionInfo] setObject:[[self url] host] forKey:@"host"]; + [[self connectionInfo] setObject:[NSNumber numberWithInt:[[[self url] port] intValue]] forKey:@"port"]; + [[self connectionInfo] setObject:[[self url] scheme] forKey:@"scheme"]; + [persistentConnectionsPool addObject:[self connectionInfo]]; + } + + // If we are retrying this request, it will already have a requestID + if (![self requestID]) { + nextRequestID++; + [self setRequestID:[NSNumber numberWithUnsignedInt:nextRequestID]]; + } + [[self connectionInfo] setObject:[self requestID] forKey:@"request"]; + [[self connectionInfo] setObject:[self readStream] forKey:@"stream"]; + CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue); + + #if DEBUG_PERSISTENT_CONNECTIONS + NSLog(@"[CONNECTION] Request #%@ will use connection #%i",[self requestID],[[[self connectionInfo] objectForKey:@"id"] intValue]); + #endif + + + // Tag the stream with an id that tells it which connection to use behind the scenes + // See http://lists.apple.com/archives/macnetworkprog/2008/Dec/msg00001.html for details on this approach + + CFReadStreamSetProperty((CFReadStreamRef)[self readStream], CFSTR("ASIStreamID"), [[self connectionInfo] objectForKey:@"id"]); + + } else { + #if DEBUG_PERSISTENT_CONNECTIONS + NSLog(@"[CONNECTION] Request %@ will not use a persistent connection",self); + #endif + } + + [connectionsLock unlock]; + + // Schedule the stream + if (![self readStreamIsScheduled] && (!throttleWakeUpTime || [throttleWakeUpTime timeIntervalSinceDate:[NSDate date]] < 0)) { + [self scheduleReadStream]; + } + + BOOL streamSuccessfullyOpened = NO; + + + // Start the HTTP connection + CFStreamClientContext ctxt = {0, self, NULL, NULL, NULL}; + if (CFReadStreamSetClient((CFReadStreamRef)[self readStream], kNetworkEvents, ReadStreamClientCallBack, &ctxt)) { + if (CFReadStreamOpen((CFReadStreamRef)[self readStream])) { + streamSuccessfullyOpened = YES; + } + } + + // Here, we'll close the stream that was previously using this connection, if there was one + // We've kept it open until now (when we've just opened a new stream) so that the new stream can make use of the old connection + // http://lists.apple.com/archives/Macnetworkprog/2006/Mar/msg00119.html + if (oldStream) { + [oldStream close]; + [oldStream release]; + oldStream = nil; + } + + if (!streamSuccessfullyOpened) { + [self setConnectionCanBeReused:NO]; + [self destroyReadStream]; + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileBuildingRequestType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Unable to start HTTP connection",NSLocalizedDescriptionKey,nil]]]; + return; + } + + if (![self mainRequest]) { + if ([self shouldResetUploadProgress]) { + if ([self showAccurateProgress]) { + [self incrementUploadSizeBy:[self postLength]]; + } else { + [self incrementUploadSizeBy:1]; + } + [ASIHTTPRequest updateProgressIndicator:&uploadProgressDelegate withProgress:0 ofTotal:1]; + } + if ([self shouldResetDownloadProgress] && ![self partialDownloadSize]) { + [ASIHTTPRequest updateProgressIndicator:&downloadProgressDelegate withProgress:0 ofTotal:1]; + } + } + + + // Record when the request started, so we can timeout if nothing happens + [self setLastActivityTime:[NSDate date]]; + [self setStatusTimer:[NSTimer timerWithTimeInterval:0.25 target:self selector:@selector(updateStatus:) userInfo:nil repeats:YES]]; + [[NSRunLoop currentRunLoop] addTimer:[self statusTimer] forMode:[self runLoopMode]]; +} + +- (void)setStatusTimer:(NSTimer *)timer +{ + CFRetain(self); + // We must invalidate the old timer here, not before we've created and scheduled a new timer + // This is because the timer may be the only thing retaining an asynchronous request + if (statusTimer && timer != statusTimer) { + [statusTimer invalidate]; + [statusTimer release]; + } + statusTimer = [timer retain]; + CFRelease(self); +} + +// This gets fired every 1/4 of a second to update the progress and work out if we need to timeout +- (void)updateStatus:(NSTimer*)timer +{ + [self checkRequestStatus]; + if (![self inProgress]) { + [self setStatusTimer:nil]; + } +} + +- (void)performRedirect +{ + [self setURL:[self redirectURL]]; + [self setComplete:YES]; + [self setNeedsRedirect:NO]; + [self setRedirectCount:[self redirectCount]+1]; + + if ([self redirectCount] > RedirectionLimit) { + // Some naughty / badly coded website is trying to force us into a redirection loop. This is not cool. + [self failWithError:ASITooMuchRedirectionError]; + [self setComplete:YES]; + } else { + // Go all the way back to the beginning and build the request again, so that we can apply any new cookies + [self main]; + } +} + +// Called by delegate to resume loading with a new url after the delegate received request:willRedirectToURL: +- (void)redirectToURL:(NSURL *)newURL +{ + [self setRedirectURL:newURL]; + [self performSelector:@selector(performRedirect) onThread:[[self class] threadForRequest:self] withObject:nil waitUntilDone:NO]; +} + +- (BOOL)shouldTimeOut +{ + NSTimeInterval secondsSinceLastActivity = [[NSDate date] timeIntervalSinceDate:lastActivityTime]; + // See if we need to timeout + if ([self readStream] && [self readStreamIsScheduled] && [self lastActivityTime] && [self timeOutSeconds] > 0 && secondsSinceLastActivity > [self timeOutSeconds]) { + + // We have no body, or we've sent more than the upload buffer size,so we can safely time out here + if ([self postLength] == 0 || ([self uploadBufferSize] > 0 && [self totalBytesSent] > [self uploadBufferSize])) { + return YES; + + // ***Black magic warning*** + // We have a body, but we've taken longer than timeOutSeconds to upload the first small chunk of data + // Since there's no reliable way to track upload progress for the first 32KB (iPhone) or 128KB (Mac) with CFNetwork, we'll be slightly more forgiving on the timeout, as there's a strong chance our connection is just very slow. + } else if (secondsSinceLastActivity > [self timeOutSeconds]*1.5) { + return YES; + } + } + return NO; +} + +- (void)checkRequestStatus +{ + // We won't let the request cancel while we're updating progress / checking for a timeout + [[self cancelledLock] lock]; + // See if our NSOperationQueue told us to cancel + if ([self isCancelled] || [self complete]) { + [[self cancelledLock] unlock]; + return; + } + + [self performThrottling]; + + if ([self shouldTimeOut]) { + // Do we need to auto-retry this request? + if ([self numberOfTimesToRetryOnTimeout] > [self retryCount]) { + + // If we are resuming a download, we may need to update the Range header to take account of data we've just downloaded + [self updatePartialDownloadSize]; + if ([self partialDownloadSize]) { + CFHTTPMessageSetHeaderFieldValue(request, (CFStringRef)@"Range", (CFStringRef)[NSString stringWithFormat:@"bytes=%llu-",[self partialDownloadSize]]); + } + [self setRetryCount:[self retryCount]+1]; + [self unscheduleReadStream]; + [[self cancelledLock] unlock]; + [self startRequest]; + return; + } + [self failWithError:ASIRequestTimedOutError]; + [self cancelLoad]; + [self setComplete:YES]; + [[self cancelledLock] unlock]; + return; + } + + // readStream will be null if we aren't currently running (perhaps we're waiting for a delegate to supply credentials) + if ([self readStream]) { + + // If we have a post body + if ([self postLength]) { + + [self setLastBytesSent:totalBytesSent]; + + // Find out how much data we've uploaded so far + [self setTotalBytesSent:[[NSMakeCollectable(CFReadStreamCopyProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPRequestBytesWrittenCount)) autorelease] unsignedLongLongValue]]; + if (totalBytesSent > lastBytesSent) { + + // We've uploaded more data, reset the timeout + [self setLastActivityTime:[NSDate date]]; + [ASIHTTPRequest incrementBandwidthUsedInLastSecond:(unsigned long)(totalBytesSent-lastBytesSent)]; + + #if DEBUG_REQUEST_STATUS + if ([self totalBytesSent] == [self postLength]) { + NSLog(@"[STATUS] Request %@ finished uploading data",self); + } + #endif + } + } + + [self updateProgressIndicators]; + + } + + [[self cancelledLock] unlock]; +} + + +// Cancel loading and clean up. DO NOT USE THIS TO CANCEL REQUESTS - use [request cancel] instead +- (void)cancelLoad +{ + // If we're in the middle of downloading a PAC file, let's stop that first + if (PACFileReadStream) { + [PACFileReadStream setDelegate:nil]; + [PACFileReadStream close]; + [self setPACFileReadStream:nil]; + [self setPACFileData:nil]; + } else if (PACFileRequest) { + [PACFileRequest setDelegate:nil]; + [PACFileRequest cancel]; + [self setPACFileRequest:nil]; + } + + [self destroyReadStream]; + + [[self postBodyReadStream] close]; + [self setPostBodyReadStream:nil]; + + if ([self rawResponseData]) { + if (![self complete]) { + [self setRawResponseData:nil]; + } + // If we were downloading to a file + } else if ([self temporaryFileDownloadPath]) { + [[self fileDownloadOutputStream] close]; + [self setFileDownloadOutputStream:nil]; + + [[self inflatedFileDownloadOutputStream] close]; + [self setInflatedFileDownloadOutputStream:nil]; + + // If we haven't said we might want to resume, let's remove the temporary file too + if (![self complete]) { + if (![self allowResumeForFileDownloads]) { + [self removeTemporaryDownloadFile]; + } + [self removeTemporaryUncompressedDownloadFile]; + } + } + + // Clean up any temporary file used to store request body for streaming + if (![self authenticationNeeded] && ![self willRetryRequest] && [self didCreateTemporaryPostDataFile]) { + [self removeTemporaryUploadFile]; + [self removeTemporaryCompressedUploadFile]; + [self setDidCreateTemporaryPostDataFile:NO]; + } +} + +#pragma mark HEAD request + +// Used by ASINetworkQueue to create a HEAD request appropriate for this request with the same headers (though you can use it yourself) +- (ASIHTTPRequest *)HEADRequest +{ + ASIHTTPRequest *headRequest = [[self class] requestWithURL:[self url]]; + + // Copy the properties that make sense for a HEAD request + [headRequest setRequestHeaders:[[[self requestHeaders] mutableCopy] autorelease]]; + [headRequest setRequestCookies:[[[self requestCookies] mutableCopy] autorelease]]; + [headRequest setUseCookiePersistence:[self useCookiePersistence]]; + [headRequest setUseKeychainPersistence:[self useKeychainPersistence]]; + [headRequest setUseSessionPersistence:[self useSessionPersistence]]; + [headRequest setAllowCompressedResponse:[self allowCompressedResponse]]; + [headRequest setUsername:[self username]]; + [headRequest setPassword:[self password]]; + [headRequest setDomain:[self domain]]; + [headRequest setProxyUsername:[self proxyUsername]]; + [headRequest setProxyPassword:[self proxyPassword]]; + [headRequest setProxyDomain:[self proxyDomain]]; + [headRequest setProxyHost:[self proxyHost]]; + [headRequest setProxyPort:[self proxyPort]]; + [headRequest setProxyType:[self proxyType]]; + [headRequest setShouldPresentAuthenticationDialog:[self shouldPresentAuthenticationDialog]]; + [headRequest setShouldPresentProxyAuthenticationDialog:[self shouldPresentProxyAuthenticationDialog]]; + [headRequest setTimeOutSeconds:[self timeOutSeconds]]; + [headRequest setUseHTTPVersionOne:[self useHTTPVersionOne]]; + [headRequest setValidatesSecureCertificate:[self validatesSecureCertificate]]; + [headRequest setClientCertificateIdentity:clientCertificateIdentity]; + [headRequest setClientCertificates:[[clientCertificates copy] autorelease]]; + [headRequest setPACurl:[self PACurl]]; + [headRequest setShouldPresentCredentialsBeforeChallenge:[self shouldPresentCredentialsBeforeChallenge]]; + [headRequest setNumberOfTimesToRetryOnTimeout:[self numberOfTimesToRetryOnTimeout]]; + [headRequest setShouldUseRFC2616RedirectBehaviour:[self shouldUseRFC2616RedirectBehaviour]]; + [headRequest setShouldAttemptPersistentConnection:[self shouldAttemptPersistentConnection]]; + [headRequest setPersistentConnectionTimeoutSeconds:[self persistentConnectionTimeoutSeconds]]; + + [headRequest setMainRequest:self]; + [headRequest setRequestMethod:@"HEAD"]; + return headRequest; +} + + +#pragma mark upload/download progress + + +- (void)updateProgressIndicators +{ + //Only update progress if this isn't a HEAD request used to preset the content-length + if (![self mainRequest]) { + if ([self showAccurateProgress] || ([self complete] && ![self updatedProgress])) { + [self updateUploadProgress]; + [self updateDownloadProgress]; + } + } +} + +- (id)uploadProgressDelegate +{ + [[self cancelledLock] lock]; + id d = [[uploadProgressDelegate retain] autorelease]; + [[self cancelledLock] unlock]; + return d; +} + +- (void)setUploadProgressDelegate:(id)newDelegate +{ + [[self cancelledLock] lock]; + uploadProgressDelegate = newDelegate; + + #if !TARGET_OS_IPHONE + // If the uploadProgressDelegate is an NSProgressIndicator, we set its MaxValue to 1.0 so we can update it as if it were a UIProgressView + double max = 1.0; + [ASIHTTPRequest performSelector:@selector(setMaxValue:) onTarget:&uploadProgressDelegate withObject:nil amount:&max callerToRetain:nil]; + #endif + [[self cancelledLock] unlock]; +} + +- (id)downloadProgressDelegate +{ + [[self cancelledLock] lock]; + id d = [[downloadProgressDelegate retain] autorelease]; + [[self cancelledLock] unlock]; + return d; +} + +- (void)setDownloadProgressDelegate:(id)newDelegate +{ + [[self cancelledLock] lock]; + downloadProgressDelegate = newDelegate; + + #if !TARGET_OS_IPHONE + // If the downloadProgressDelegate is an NSProgressIndicator, we set its MaxValue to 1.0 so we can update it as if it were a UIProgressView + double max = 1.0; + [ASIHTTPRequest performSelector:@selector(setMaxValue:) onTarget:&downloadProgressDelegate withObject:nil amount:&max callerToRetain:nil]; + #endif + [[self cancelledLock] unlock]; +} + + +- (void)updateDownloadProgress +{ + // We won't update download progress until we've examined the headers, since we might need to authenticate + if (![self responseHeaders] || [self needsRedirect] || !([self contentLength] || [self complete])) { + return; + } + + unsigned long long bytesReadSoFar = [self totalBytesRead]+[self partialDownloadSize]; + unsigned long long value = 0; + + if ([self showAccurateProgress] && [self contentLength]) { + value = bytesReadSoFar-[self lastBytesRead]; + if (value == 0) { + return; + } + } else { + value = 1; + [self setUpdatedProgress:YES]; + } + if (!value) { + return; + } + + [ASIHTTPRequest performSelector:@selector(request:didReceiveBytes:) onTarget:&queue withObject:self amount:&value callerToRetain:self]; + [ASIHTTPRequest performSelector:@selector(request:didReceiveBytes:) onTarget:&downloadProgressDelegate withObject:self amount:&value callerToRetain:self]; + + [ASIHTTPRequest updateProgressIndicator:&downloadProgressDelegate withProgress:[self totalBytesRead]+[self partialDownloadSize] ofTotal:[self contentLength]+[self partialDownloadSize]]; + + #if NS_BLOCKS_AVAILABLE + if (bytesReceivedBlock) { + unsigned long long totalSize = [self contentLength] + [self partialDownloadSize]; + [self performBlockOnMainThread:^{ if (bytesReceivedBlock) { bytesReceivedBlock(value, totalSize); }}]; + } + #endif + [self setLastBytesRead:bytesReadSoFar]; +} + +- (void)updateUploadProgress +{ + if ([self isCancelled] || [self totalBytesSent] == 0) { + return; + } + + // If this is the first time we've written to the buffer, totalBytesSent will be the size of the buffer (currently seems to be 128KB on both Leopard and iPhone 2.2.1, 32KB on iPhone 3.0) + // If request body is less than the buffer size, totalBytesSent will be the total size of the request body + // We will remove this from any progress display, as kCFStreamPropertyHTTPRequestBytesWrittenCount does not tell us how much data has actually be written + if ([self uploadBufferSize] == 0 && [self totalBytesSent] != [self postLength]) { + [self setUploadBufferSize:[self totalBytesSent]]; + [self incrementUploadSizeBy:-[self uploadBufferSize]]; + } + + unsigned long long value = 0; + + if ([self showAccurateProgress]) { + if ([self totalBytesSent] == [self postLength] || [self lastBytesSent] > 0) { + value = [self totalBytesSent]-[self lastBytesSent]; + } else { + return; + } + } else { + value = 1; + [self setUpdatedProgress:YES]; + } + + if (!value) { + return; + } + + [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:&queue withObject:self amount:&value callerToRetain:self]; + [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:&uploadProgressDelegate withObject:self amount:&value callerToRetain:self]; + [ASIHTTPRequest updateProgressIndicator:&uploadProgressDelegate withProgress:[self totalBytesSent]-[self uploadBufferSize] ofTotal:[self postLength]-[self uploadBufferSize]]; + + #if NS_BLOCKS_AVAILABLE + if(bytesSentBlock){ + unsigned long long totalSize = [self postLength]; + [self performBlockOnMainThread:^{ if (bytesSentBlock) { bytesSentBlock(value, totalSize); }}]; + } + #endif +} + + +- (void)incrementDownloadSizeBy:(long long)length +{ + [ASIHTTPRequest performSelector:@selector(request:incrementDownloadSizeBy:) onTarget:&queue withObject:self amount:&length callerToRetain:self]; + [ASIHTTPRequest performSelector:@selector(request:incrementDownloadSizeBy:) onTarget:&downloadProgressDelegate withObject:self amount:&length callerToRetain:self]; + + #if NS_BLOCKS_AVAILABLE + if(downloadSizeIncrementedBlock){ + [self performBlockOnMainThread:^{ if (downloadSizeIncrementedBlock) { downloadSizeIncrementedBlock(length); }}]; + } + #endif +} + +- (void)incrementUploadSizeBy:(long long)length +{ + [ASIHTTPRequest performSelector:@selector(request:incrementUploadSizeBy:) onTarget:&queue withObject:self amount:&length callerToRetain:self]; + [ASIHTTPRequest performSelector:@selector(request:incrementUploadSizeBy:) onTarget:&uploadProgressDelegate withObject:self amount:&length callerToRetain:self]; + + #if NS_BLOCKS_AVAILABLE + if(uploadSizeIncrementedBlock) { + [self performBlockOnMainThread:^{ if (uploadSizeIncrementedBlock) { uploadSizeIncrementedBlock(length); }}]; + } + #endif +} + + +-(void)removeUploadProgressSoFar +{ + long long progressToRemove = -[self totalBytesSent]; + [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:&queue withObject:self amount:&progressToRemove callerToRetain:self]; + [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:&uploadProgressDelegate withObject:self amount:&progressToRemove callerToRetain:self]; + [ASIHTTPRequest updateProgressIndicator:&uploadProgressDelegate withProgress:0 ofTotal:[self postLength]]; + + #if NS_BLOCKS_AVAILABLE + if(bytesSentBlock){ + unsigned long long totalSize = [self postLength]; + [self performBlockOnMainThread:^{ if (bytesSentBlock) { bytesSentBlock(progressToRemove, totalSize); }}]; + } + #endif +} + +#if NS_BLOCKS_AVAILABLE +- (void)performBlockOnMainThread:(ASIBasicBlock)block +{ + [self performSelectorOnMainThread:@selector(callBlock:) withObject:[[block copy] autorelease] waitUntilDone:[NSThread isMainThread]]; +} + +- (void)callBlock:(ASIBasicBlock)block +{ + block(); +} +#endif + + ++ (void)performSelector:(SEL)selector onTarget:(id *)target withObject:(id)object amount:(void *)amount callerToRetain:(id)callerToRetain +{ + if ([*target respondsToSelector:selector]) { + NSMethodSignature *signature = nil; + signature = [*target methodSignatureForSelector:selector]; + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; + + [invocation setSelector:selector]; + + int argumentNumber = 2; + + // If we got an object parameter, we pass a pointer to the object pointer + if (object) { + [invocation setArgument:&object atIndex:argumentNumber]; + argumentNumber++; + } + + // For the amount we'll just pass the pointer directly so NSInvocation will call the method using the number itself rather than a pointer to it + if (amount) { + [invocation setArgument:amount atIndex:argumentNumber]; + } + + SEL callback = @selector(performInvocation:onTarget:releasingObject:); + NSMethodSignature *cbSignature = [ASIHTTPRequest methodSignatureForSelector:callback]; + NSInvocation *cbInvocation = [NSInvocation invocationWithMethodSignature:cbSignature]; + [cbInvocation setSelector:callback]; + [cbInvocation setTarget:self]; + [cbInvocation setArgument:&invocation atIndex:2]; + [cbInvocation setArgument:&target atIndex:3]; + if (callerToRetain) { + [cbInvocation setArgument:&callerToRetain atIndex:4]; + } + + CFRetain(invocation); + + // Used to pass in a request that we must retain until after the call + // We're using CFRetain rather than [callerToRetain retain] so things to avoid earthquakes when using garbage collection + if (callerToRetain) { + CFRetain(callerToRetain); + } + [cbInvocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:[NSThread isMainThread]]; + } +} + ++ (void)performInvocation:(NSInvocation *)invocation onTarget:(id *)target releasingObject:(id)objectToRelease +{ + if (*target && [*target respondsToSelector:[invocation selector]]) { + [invocation invokeWithTarget:*target]; + } + CFRelease(invocation); + if (objectToRelease) { + CFRelease(objectToRelease); + } +} + + ++ (void)updateProgressIndicator:(id *)indicator withProgress:(unsigned long long)progress ofTotal:(unsigned long long)total +{ + #if TARGET_OS_IPHONE + // Cocoa Touch: UIProgressView + SEL selector = @selector(setProgress:); + float progressAmount = (float)((progress*1.0)/(total*1.0)); + + #else + // Cocoa: NSProgressIndicator + double progressAmount = progressAmount = (progress*1.0)/(total*1.0); + SEL selector = @selector(setDoubleValue:); + #endif + + if (![*indicator respondsToSelector:selector]) { + return; + } + + [progressLock lock]; + [ASIHTTPRequest performSelector:selector onTarget:indicator withObject:nil amount:&progressAmount callerToRetain:nil]; + [progressLock unlock]; +} + + +#pragma mark talking to delegates / calling blocks + +/* ALWAYS CALLED ON MAIN THREAD! */ +- (void)requestStarted +{ + if ([self error] || [self mainRequest]) { + return; + } + if (delegate && [delegate respondsToSelector:didStartSelector]) { + [delegate performSelector:didStartSelector withObject:self]; + } + #if NS_BLOCKS_AVAILABLE + if(startedBlock){ + startedBlock(); + } + #endif + if (queue && [queue respondsToSelector:@selector(requestStarted:)]) { + [queue performSelector:@selector(requestStarted:) withObject:self]; + } +} + +/* ALWAYS CALLED ON MAIN THREAD! */ +- (void)requestRedirected +{ + if ([self error] || [self mainRequest]) { + return; + } + + if([[self delegate] respondsToSelector:@selector(requestRedirected:)]){ + [[self delegate] performSelector:@selector(requestRedirected:) withObject:self]; + } + + #if NS_BLOCKS_AVAILABLE + if(requestRedirectedBlock){ + requestRedirectedBlock(); + } + #endif +} + + +/* ALWAYS CALLED ON MAIN THREAD! */ +- (void)requestReceivedResponseHeaders:(NSMutableDictionary *)newResponseHeaders +{ + if ([self error] || [self mainRequest]) { + return; + } + + if (delegate && [delegate respondsToSelector:didReceiveResponseHeadersSelector]) { + [delegate performSelector:didReceiveResponseHeadersSelector withObject:self withObject:newResponseHeaders]; + } + + #if NS_BLOCKS_AVAILABLE + if(headersReceivedBlock){ + headersReceivedBlock(newResponseHeaders); + } + #endif + + if (queue && [queue respondsToSelector:@selector(request:didReceiveResponseHeaders:)]) { + [queue performSelector:@selector(request:didReceiveResponseHeaders:) withObject:self withObject:newResponseHeaders]; + } +} + +/* ALWAYS CALLED ON MAIN THREAD! */ +- (void)requestWillRedirectToURL:(NSURL *)newURL +{ + if ([self error] || [self mainRequest]) { + return; + } + if (delegate && [delegate respondsToSelector:willRedirectSelector]) { + [delegate performSelector:willRedirectSelector withObject:self withObject:newURL]; + } + if (queue && [queue respondsToSelector:@selector(request:willRedirectToURL:)]) { + [queue performSelector:@selector(request:willRedirectToURL:) withObject:self withObject:newURL]; + } +} + +// Subclasses might override this method to process the result in the same thread +// If you do this, don't forget to call [super requestFinished] to let the queue / delegate know we're done +- (void)requestFinished +{ +#if DEBUG_REQUEST_STATUS || DEBUG_THROTTLING + NSLog(@"[STATUS] Request finished: %@",self); +#endif + if ([self error] || [self mainRequest]) { + return; + } + if ([self isPACFileRequest]) { + [self reportFinished]; + } else { + [self performSelectorOnMainThread:@selector(reportFinished) withObject:nil waitUntilDone:[NSThread isMainThread]]; + } +} + +/* ALWAYS CALLED ON MAIN THREAD! */ +- (void)reportFinished +{ + if (delegate && [delegate respondsToSelector:didFinishSelector]) { + [delegate performSelector:didFinishSelector withObject:self]; + } + + #if NS_BLOCKS_AVAILABLE + if(completionBlock){ + completionBlock(); + } + #endif + + if (queue && [queue respondsToSelector:@selector(requestFinished:)]) { + [queue performSelector:@selector(requestFinished:) withObject:self]; + } +} + +/* ALWAYS CALLED ON MAIN THREAD! */ +- (void)reportFailure +{ + if (delegate && [delegate respondsToSelector:didFailSelector]) { + [delegate performSelector:didFailSelector withObject:self]; + } + + #if NS_BLOCKS_AVAILABLE + if(failureBlock){ + failureBlock(); + } + #endif + + if (queue && [queue respondsToSelector:@selector(requestFailed:)]) { + [queue performSelector:@selector(requestFailed:) withObject:self]; + } +} + +/* ALWAYS CALLED ON MAIN THREAD! */ +- (void)passOnReceivedData:(NSData *)data +{ + if (delegate && [delegate respondsToSelector:didReceiveDataSelector]) { + [delegate performSelector:didReceiveDataSelector withObject:self withObject:data]; + } + + #if NS_BLOCKS_AVAILABLE + if (dataReceivedBlock) { + dataReceivedBlock(data); + } + #endif +} + +// Subclasses might override this method to perform error handling in the same thread +// If you do this, don't forget to call [super failWithError:] to let the queue / delegate know we're done +- (void)failWithError:(NSError *)theError +{ +#if DEBUG_REQUEST_STATUS || DEBUG_THROTTLING + NSLog(@"[STATUS] Request %@: %@",self,(theError == ASIRequestCancelledError ? @"Cancelled" : @"Failed")); +#endif + [self setComplete:YES]; + + // Invalidate the current connection so subsequent requests don't attempt to reuse it + if (theError && [theError code] != ASIAuthenticationErrorType && [theError code] != ASITooMuchRedirectionErrorType) { + [connectionsLock lock]; + #if DEBUG_PERSISTENT_CONNECTIONS + NSLog(@"[CONNECTION] Request #%@ failed and will invalidate connection #%@",[self requestID],[[self connectionInfo] objectForKey:@"id"]); + #endif + [[self connectionInfo] removeObjectForKey:@"request"]; + [persistentConnectionsPool removeObject:[self connectionInfo]]; + [connectionsLock unlock]; + [self destroyReadStream]; + } + if ([self connectionCanBeReused]) { + [[self connectionInfo] setObject:[NSDate dateWithTimeIntervalSinceNow:[self persistentConnectionTimeoutSeconds]] forKey:@"expires"]; + } + + if ([self isCancelled] || [self error]) { + return; + } + + // If we have cached data, use it and ignore the error when using ASIFallbackToCacheIfLoadFailsCachePolicy + if ([self downloadCache] && ([self cachePolicy] & ASIFallbackToCacheIfLoadFailsCachePolicy)) { + if ([[self downloadCache] canUseCachedDataForRequest:self]) { + [self useDataFromCache]; + return; + } + } + + + [self setError:theError]; + + ASIHTTPRequest *failedRequest = self; + + // If this is a HEAD request created by an ASINetworkQueue or compatible queue delegate, make the main request fail + if ([self mainRequest]) { + failedRequest = [self mainRequest]; + [failedRequest setError:theError]; + } + + if ([self isPACFileRequest]) { + [failedRequest reportFailure]; + } else { + [failedRequest performSelectorOnMainThread:@selector(reportFailure) withObject:nil waitUntilDone:[NSThread isMainThread]]; + } + + if (!inProgress) + { + // if we're not in progress, we can't notify the queue we've finished (doing so can cause a crash later on) + // "markAsFinished" will be at the start of main() when we are started + return; + } + [self markAsFinished]; +} + +#pragma mark parsing HTTP response headers + +- (void)readResponseHeaders +{ + [self setAuthenticationNeeded:ASINoAuthenticationNeededYet]; + + CFHTTPMessageRef message = (CFHTTPMessageRef)CFReadStreamCopyProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPResponseHeader); + if (!message) { + return; + } + + // Make sure we've received all the headers + if (!CFHTTPMessageIsHeaderComplete(message)) { + CFRelease(message); + return; + } + + #if DEBUG_REQUEST_STATUS + if ([self totalBytesSent] == [self postLength]) { + NSLog(@"[STATUS] Request %@ received response headers",self); + } + #endif + + [self setResponseHeaders:[NSMakeCollectable(CFHTTPMessageCopyAllHeaderFields(message)) autorelease]]; + [self setResponseStatusCode:(int)CFHTTPMessageGetResponseStatusCode(message)]; + [self setResponseStatusMessage:[NSMakeCollectable(CFHTTPMessageCopyResponseStatusLine(message)) autorelease]]; + + if ([self downloadCache] && ([[self downloadCache] canUseCachedDataForRequest:self])) { + + // Update the expiry date + [[self downloadCache] updateExpiryForRequest:self maxAge:[self secondsToCache]]; + + // Read the response from the cache + [self useDataFromCache]; + + CFRelease(message); + return; + } + + // Is the server response a challenge for credentials? + if ([self responseStatusCode] == 401) { + [self setAuthenticationNeeded:ASIHTTPAuthenticationNeeded]; + } else if ([self responseStatusCode] == 407) { + [self setAuthenticationNeeded:ASIProxyAuthenticationNeeded]; + } else { + #if DEBUG_HTTP_AUTHENTICATION + if ([self authenticationScheme]) { + NSLog(@"[AUTH] Request %@ has passed %@ authentication",self,[self authenticationScheme]); + } + #endif + } + + // Authentication succeeded, or no authentication was required + if (![self authenticationNeeded]) { + + // Did we get here without an authentication challenge? (which can happen when shouldPresentCredentialsBeforeChallenge is YES and basic auth was successful) + if (!requestAuthentication && [[self authenticationScheme] isEqualToString:(NSString *)kCFHTTPAuthenticationSchemeBasic] && [self username] && [self password] && [self useSessionPersistence]) { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ passed BASIC authentication, and will save credentials in the session store for future use",self); + #endif + + NSMutableDictionary *newCredentials = [NSMutableDictionary dictionaryWithCapacity:2]; + [newCredentials setObject:[self username] forKey:(NSString *)kCFHTTPAuthenticationUsername]; + [newCredentials setObject:[self password] forKey:(NSString *)kCFHTTPAuthenticationPassword]; + + // Store the credentials in the session + NSMutableDictionary *sessionCredentials = [NSMutableDictionary dictionary]; + [sessionCredentials setObject:newCredentials forKey:@"Credentials"]; + [sessionCredentials setObject:[self url] forKey:@"URL"]; + [sessionCredentials setObject:(NSString *)kCFHTTPAuthenticationSchemeBasic forKey:@"AuthenticationScheme"]; + [[self class] storeAuthenticationCredentialsInSessionStore:sessionCredentials]; + } + } + + // Read response textEncoding + [self parseStringEncodingFromHeaders]; + + // Handle cookies + NSArray *newCookies = [NSHTTPCookie cookiesWithResponseHeaderFields:[self responseHeaders] forURL:[self url]]; + [self setResponseCookies:newCookies]; + + if ([self useCookiePersistence]) { + + // Store cookies in global persistent store + [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:newCookies forURL:[self url] mainDocumentURL:nil]; + + // We also keep any cookies in the sessionCookies array, so that we have a reference to them if we need to remove them later + NSHTTPCookie *cookie; + for (cookie in newCookies) { + [ASIHTTPRequest addSessionCookie:cookie]; + } + } + + // Do we need to redirect? + if (![self willRedirect]) { + // See if we got a Content-length header + NSString *cLength = [responseHeaders valueForKey:@"Content-Length"]; + ASIHTTPRequest *theRequest = self; + if ([self mainRequest]) { + theRequest = [self mainRequest]; + } + + if (cLength) { + unsigned long long length = strtoull([cLength UTF8String], NULL, 0); + + // Workaround for Apache HEAD requests for dynamically generated content returning the wrong Content-Length when using gzip + if ([self mainRequest] && [self allowCompressedResponse] && length == 20 && [self showAccurateProgress] && [self shouldResetDownloadProgress]) { + [[self mainRequest] setShowAccurateProgress:NO]; + [[self mainRequest] incrementDownloadSizeBy:1]; + + } else { + [theRequest setContentLength:length]; + if ([self showAccurateProgress] && [self shouldResetDownloadProgress]) { + [theRequest incrementDownloadSizeBy:[theRequest contentLength]+[theRequest partialDownloadSize]]; + } + } + + } else if ([self showAccurateProgress] && [self shouldResetDownloadProgress]) { + [theRequest setShowAccurateProgress:NO]; + [theRequest incrementDownloadSizeBy:1]; + } + } + + // Handle connection persistence + if ([self shouldAttemptPersistentConnection]) { + + NSString *connectionHeader = [[[self responseHeaders] objectForKey:@"Connection"] lowercaseString]; + + NSString *httpVersion = [NSMakeCollectable(CFHTTPMessageCopyVersion(message)) autorelease]; + + // Don't re-use the connection if the server is HTTP 1.0 and didn't send Connection: Keep-Alive + if (![httpVersion isEqualToString:(NSString *)kCFHTTPVersion1_0] || [connectionHeader isEqualToString:@"keep-alive"]) { + + // See if server explicitly told us to close the connection + if (![connectionHeader isEqualToString:@"close"]) { + + NSString *keepAliveHeader = [[self responseHeaders] objectForKey:@"Keep-Alive"]; + + // If we got a keep alive header, we'll reuse the connection for as long as the server tells us + if (keepAliveHeader) { + int timeout = 0; + int max = 0; + NSScanner *scanner = [NSScanner scannerWithString:keepAliveHeader]; + [scanner scanString:@"timeout=" intoString:NULL]; + [scanner scanInt:&timeout]; + [scanner scanUpToString:@"max=" intoString:NULL]; + [scanner scanString:@"max=" intoString:NULL]; + [scanner scanInt:&max]; + if (max > 5) { + [self setConnectionCanBeReused:YES]; + [self setPersistentConnectionTimeoutSeconds:timeout]; + #if DEBUG_PERSISTENT_CONNECTIONS + NSLog(@"[CONNECTION] Got a keep-alive header, will keep this connection open for %f seconds", [self persistentConnectionTimeoutSeconds]); + #endif + } + + // Otherwise, we'll assume we can keep this connection open + } else { + [self setConnectionCanBeReused:YES]; + #if DEBUG_PERSISTENT_CONNECTIONS + NSLog(@"[CONNECTION] Got no keep-alive header, will keep this connection open for %f seconds", [self persistentConnectionTimeoutSeconds]); + #endif + } + } + } + } + + CFRelease(message); + [self performSelectorOnMainThread:@selector(requestReceivedResponseHeaders:) withObject:[[[self responseHeaders] copy] autorelease] waitUntilDone:[NSThread isMainThread]]; +} + +- (BOOL)willRedirect +{ + // Do we need to redirect? + if (![self shouldRedirect] || ![responseHeaders valueForKey:@"Location"]) { + return NO; + } + + // Note that ASIHTTPRequest does not currently support 305 Use Proxy + int responseCode = [self responseStatusCode]; + if (responseCode != 301 && responseCode != 302 && responseCode != 303 && responseCode != 307) { + return NO; + } + + [self performSelectorOnMainThread:@selector(requestRedirected) withObject:nil waitUntilDone:[NSThread isMainThread]]; + + // By default, we redirect 301 and 302 response codes as GET requests + // According to RFC 2616 this is wrong, but this is what most browsers do, so it's probably what you're expecting to happen + // See also: + // http://allseeing-i.lighthouseapp.com/projects/27881/tickets/27-302-redirection-issue + + if (responseCode != 307 && (![self shouldUseRFC2616RedirectBehaviour] || responseCode == 303)) { + [self setRequestMethod:@"GET"]; + [self setPostBody:nil]; + [self setPostLength:0]; + + // Perhaps there are other headers we should be preserving, but it's hard to know what we need to keep and what to throw away. + NSString *userAgentHeader = [[self requestHeaders] objectForKey:@"User-Agent"]; + NSString *acceptHeader = [[self requestHeaders] objectForKey:@"Accept"]; + [self setRequestHeaders:nil]; + if (userAgentHeader) { + [self addRequestHeader:@"User-Agent" value:userAgentHeader]; + } + if (acceptHeader) { + [self addRequestHeader:@"Accept" value:acceptHeader]; + } + [self setHaveBuiltRequestHeaders:NO]; + + } else { + // Force rebuild the cookie header incase we got some new cookies from this request + // All other request headers will remain as they are for 301 / 302 redirects + [self applyCookieHeader]; + } + + // Force the redirected request to rebuild the request headers (if not a 303, it will re-use old ones, and add any new ones) + [self setRedirectURL:[[NSURL URLWithString:[responseHeaders valueForKey:@"Location"] relativeToURL:[self url]] absoluteURL]]; + [self setNeedsRedirect:YES]; + + // Clear the request cookies + // This means manually added cookies will not be added to the redirect request - only those stored in the global persistent store + // But, this is probably the safest option - we might be redirecting to a different domain + [self setRequestCookies:[NSMutableArray array]]; + + #if DEBUG_REQUEST_STATUS + NSLog(@"[STATUS] Request will redirect (code: %i): %@",responseCode,self); + #endif + + return YES; +} + +- (void)parseStringEncodingFromHeaders +{ + // Handle response text encoding + NSStringEncoding charset = 0; + NSString *mimeType = nil; + [[self class] parseMimeType:&mimeType andResponseEncoding:&charset fromContentType:[[self responseHeaders] valueForKey:@"Content-Type"]]; + if (charset != 0) { + [self setResponseEncoding:charset]; + } else { + [self setResponseEncoding:[self defaultResponseEncoding]]; + } +} + +#pragma mark http authentication + +- (void)saveProxyCredentialsToKeychain:(NSDictionary *)newCredentials +{ + NSURLCredential *authenticationCredentials = [NSURLCredential credentialWithUser:[newCredentials objectForKey:(NSString *)kCFHTTPAuthenticationUsername] password:[newCredentials objectForKey:(NSString *)kCFHTTPAuthenticationPassword] persistence:NSURLCredentialPersistencePermanent]; + if (authenticationCredentials) { + [ASIHTTPRequest saveCredentials:authenticationCredentials forProxy:[self proxyHost] port:[self proxyPort] realm:[self proxyAuthenticationRealm]]; + } +} + + +- (void)saveCredentialsToKeychain:(NSDictionary *)newCredentials +{ + NSURLCredential *authenticationCredentials = [NSURLCredential credentialWithUser:[newCredentials objectForKey:(NSString *)kCFHTTPAuthenticationUsername] password:[newCredentials objectForKey:(NSString *)kCFHTTPAuthenticationPassword] persistence:NSURLCredentialPersistencePermanent]; + + if (authenticationCredentials) { + [ASIHTTPRequest saveCredentials:authenticationCredentials forHost:[[self url] host] port:[[[self url] port] intValue] protocol:[[self url] scheme] realm:[self authenticationRealm]]; + } +} + +- (BOOL)applyProxyCredentials:(NSDictionary *)newCredentials +{ + [self setProxyAuthenticationRetryCount:[self proxyAuthenticationRetryCount]+1]; + + if (newCredentials && proxyAuthentication && request) { + + // Apply whatever credentials we've built up to the old request + if (CFHTTPMessageApplyCredentialDictionary(request, proxyAuthentication, (CFMutableDictionaryRef)newCredentials, NULL)) { + + //If we have credentials and they're ok, let's save them to the keychain + if (useKeychainPersistence) { + [self saveProxyCredentialsToKeychain:newCredentials]; + } + if (useSessionPersistence) { + NSMutableDictionary *sessionProxyCredentials = [NSMutableDictionary dictionary]; + [sessionProxyCredentials setObject:(id)proxyAuthentication forKey:@"Authentication"]; + [sessionProxyCredentials setObject:newCredentials forKey:@"Credentials"]; + [sessionProxyCredentials setObject:[self proxyHost] forKey:@"Host"]; + [sessionProxyCredentials setObject:[NSNumber numberWithInt:[self proxyPort]] forKey:@"Port"]; + [sessionProxyCredentials setObject:[self proxyAuthenticationScheme] forKey:@"AuthenticationScheme"]; + [[self class] storeProxyAuthenticationCredentialsInSessionStore:sessionProxyCredentials]; + } + [self setProxyCredentials:newCredentials]; + return YES; + } else { + [[self class] removeProxyAuthenticationCredentialsFromSessionStore:newCredentials]; + } + } + return NO; +} + +- (BOOL)applyCredentials:(NSDictionary *)newCredentials +{ + [self setAuthenticationRetryCount:[self authenticationRetryCount]+1]; + + if (newCredentials && requestAuthentication && request) { + // Apply whatever credentials we've built up to the old request + if (CFHTTPMessageApplyCredentialDictionary(request, requestAuthentication, (CFMutableDictionaryRef)newCredentials, NULL)) { + + //If we have credentials and they're ok, let's save them to the keychain + if (useKeychainPersistence) { + [self saveCredentialsToKeychain:newCredentials]; + } + if (useSessionPersistence) { + + NSMutableDictionary *sessionCredentials = [NSMutableDictionary dictionary]; + [sessionCredentials setObject:(id)requestAuthentication forKey:@"Authentication"]; + [sessionCredentials setObject:newCredentials forKey:@"Credentials"]; + [sessionCredentials setObject:[self url] forKey:@"URL"]; + [sessionCredentials setObject:[self authenticationScheme] forKey:@"AuthenticationScheme"]; + if ([self authenticationRealm]) { + [sessionCredentials setObject:[self authenticationRealm] forKey:@"AuthenticationRealm"]; + } + [[self class] storeAuthenticationCredentialsInSessionStore:sessionCredentials]; + + } + [self setRequestCredentials:newCredentials]; + return YES; + } else { + [[self class] removeAuthenticationCredentialsFromSessionStore:newCredentials]; + } + } + return NO; +} + +- (NSMutableDictionary *)findProxyCredentials +{ + NSMutableDictionary *newCredentials = [[[NSMutableDictionary alloc] init] autorelease]; + + NSString *user = nil; + NSString *pass = nil; + + ASIHTTPRequest *theRequest = [self mainRequest]; + // If this is a HEAD request generated by an ASINetworkQueue, we'll try to use the details from the main request + if ([theRequest proxyUsername] && [theRequest proxyPassword]) { + user = [theRequest proxyUsername]; + pass = [theRequest proxyPassword]; + + // Let's try to use the ones set in this object + } else if ([self proxyUsername] && [self proxyPassword]) { + user = [self proxyUsername]; + pass = [self proxyPassword]; + } + + // When we connect to a website using NTLM via a proxy, we will use the main credentials + if ((!user || !pass) && [self proxyAuthenticationScheme] == (NSString *)kCFHTTPAuthenticationSchemeNTLM) { + user = [self username]; + pass = [self password]; + } + + + + // Ok, that didn't work, let's try the keychain + // For authenticating proxies, we'll look in the keychain regardless of the value of useKeychainPersistence + if ((!user || !pass)) { + NSURLCredential *authenticationCredentials = [ASIHTTPRequest savedCredentialsForProxy:[self proxyHost] port:[self proxyPort] protocol:[[self url] scheme] realm:[self proxyAuthenticationRealm]]; + if (authenticationCredentials) { + user = [authenticationCredentials user]; + pass = [authenticationCredentials password]; + } + + } + + // Handle NTLM, which requires a domain to be set too + if (CFHTTPAuthenticationRequiresAccountDomain(proxyAuthentication)) { + + NSString *ntlmDomain = [self proxyDomain]; + + // If we have no domain yet + if (!ntlmDomain || [ntlmDomain length] == 0) { + + // Let's try to extract it from the username + NSArray* ntlmComponents = [user componentsSeparatedByString:@"\\"]; + if ([ntlmComponents count] == 2) { + ntlmDomain = [ntlmComponents objectAtIndex:0]; + user = [ntlmComponents objectAtIndex:1]; + + // If we are connecting to a website using NTLM, but we are connecting via a proxy, the string we need may be in the domain property + } else { + ntlmDomain = [self domain]; + } + if (!ntlmDomain) { + ntlmDomain = @""; + } + } + [newCredentials setObject:ntlmDomain forKey:(NSString *)kCFHTTPAuthenticationAccountDomain]; + } + + + // If we have a username and password, let's apply them to the request and continue + if (user && pass) { + [newCredentials setObject:user forKey:(NSString *)kCFHTTPAuthenticationUsername]; + [newCredentials setObject:pass forKey:(NSString *)kCFHTTPAuthenticationPassword]; + return newCredentials; + } + return nil; +} + + +- (NSMutableDictionary *)findCredentials +{ + NSMutableDictionary *newCredentials = [[[NSMutableDictionary alloc] init] autorelease]; + + // First, let's look at the url to see if the username and password were included + NSString *user = [[self url] user]; + NSString *pass = [[self url] password]; + + if (user && pass) { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ will use credentials set on its url",self); + #endif + + } else { + + // If this is a HEAD request generated by an ASINetworkQueue, we'll try to use the details from the main request + if ([self mainRequest] && [[self mainRequest] username] && [[self mainRequest] password]) { + user = [[self mainRequest] username]; + pass = [[self mainRequest] password]; + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ will use credentials from its parent request",self); + #endif + + // Let's try to use the ones set in this object + } else if ([self username] && [self password]) { + user = [self username]; + pass = [self password]; + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ will use username and password properties as credentials",self); + #endif + } + } + + // Ok, that didn't work, let's try the keychain + if ((!user || !pass) && useKeychainPersistence) { + NSURLCredential *authenticationCredentials = [ASIHTTPRequest savedCredentialsForHost:[[self url] host] port:[[[self url] port] intValue] protocol:[[self url] scheme] realm:[self authenticationRealm]]; + if (authenticationCredentials) { + user = [authenticationCredentials user]; + pass = [authenticationCredentials password]; + #if DEBUG_HTTP_AUTHENTICATION + if (user && pass) { + NSLog(@"[AUTH] Request %@ will use credentials from the keychain",self); + } + #endif + } + } + + // Handle NTLM, which requires a domain to be set too + if (CFHTTPAuthenticationRequiresAccountDomain(requestAuthentication)) { + + NSString *ntlmDomain = [self domain]; + + // If we have no domain yet, let's try to extract it from the username + if (!ntlmDomain || [ntlmDomain length] == 0) { + ntlmDomain = @""; + NSArray* ntlmComponents = [user componentsSeparatedByString:@"\\"]; + if ([ntlmComponents count] == 2) { + ntlmDomain = [ntlmComponents objectAtIndex:0]; + user = [ntlmComponents objectAtIndex:1]; + } + } + [newCredentials setObject:ntlmDomain forKey:(NSString *)kCFHTTPAuthenticationAccountDomain]; + } + + // If we have a username and password, let's apply them to the request and continue + if (user && pass) { + [newCredentials setObject:user forKey:(NSString *)kCFHTTPAuthenticationUsername]; + [newCredentials setObject:pass forKey:(NSString *)kCFHTTPAuthenticationPassword]; + return newCredentials; + } + return nil; +} + +// Called by delegate or authentication dialog to resume loading once authentication info has been populated +- (void)retryUsingSuppliedCredentials +{ + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ received credentials from its delegate or an ASIAuthenticationDialog, will retry",self); + #endif + //If the url was changed by the delegate, our CFHTTPMessageRef will be NULL and we'll go back to the start + if (!request) { + [self performSelector:@selector(main) onThread:[[self class] threadForRequest:self] withObject:nil waitUntilDone:NO]; + return; + } + [self performSelector:@selector(attemptToApplyCredentialsAndResume) onThread:[[self class] threadForRequest:self] withObject:nil waitUntilDone:NO]; +} + +// Called by delegate or authentication dialog to cancel authentication +- (void)cancelAuthentication +{ + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ had authentication cancelled by its delegate or an ASIAuthenticationDialog",self); + #endif + [self performSelector:@selector(failAuthentication) onThread:[[self class] threadForRequest:self] withObject:nil waitUntilDone:NO]; +} + +- (void)failAuthentication +{ + [self failWithError:ASIAuthenticationError]; +} + +- (BOOL)showProxyAuthenticationDialog +{ + if ([self isSynchronous]) { + return NO; + } + + // Mac authentication dialog coming soon! + #if TARGET_OS_IPHONE + if ([self shouldPresentProxyAuthenticationDialog]) { + [ASIAuthenticationDialog performSelectorOnMainThread:@selector(presentAuthenticationDialogForRequest:) withObject:self waitUntilDone:[NSThread isMainThread]]; + return YES; + } + return NO; + #else + return NO; + #endif +} + + +- (BOOL)willAskDelegateForProxyCredentials +{ + if ([self isSynchronous]) { + return NO; + } + + // If we have a delegate, we'll see if it can handle proxyAuthenticationNeededForRequest:. + // Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate + id authenticationDelegate = [self delegate]; + if (!authenticationDelegate) { + authenticationDelegate = [self queue]; + } + + BOOL delegateOrBlockWillHandleAuthentication = NO; + + if ([authenticationDelegate respondsToSelector:@selector(proxyAuthenticationNeededForRequest:)]) { + delegateOrBlockWillHandleAuthentication = YES; + } + + #if NS_BLOCKS_AVAILABLE + if(proxyAuthenticationNeededBlock){ + delegateOrBlockWillHandleAuthentication = YES; + } + #endif + + if (delegateOrBlockWillHandleAuthentication) { + [self performSelectorOnMainThread:@selector(askDelegateForProxyCredentials) withObject:nil waitUntilDone:NO]; + } + + return delegateOrBlockWillHandleAuthentication; +} + +/* ALWAYS CALLED ON MAIN THREAD! */ +- (void)askDelegateForProxyCredentials +{ + id authenticationDelegate = [self delegate]; + if (!authenticationDelegate) { + authenticationDelegate = [self queue]; + } + if ([authenticationDelegate respondsToSelector:@selector(proxyAuthenticationNeededForRequest:)]) { + [authenticationDelegate performSelector:@selector(proxyAuthenticationNeededForRequest:) withObject:self]; + return; + } + #if NS_BLOCKS_AVAILABLE + if(proxyAuthenticationNeededBlock){ + proxyAuthenticationNeededBlock(); + } + #endif +} + + +- (BOOL)willAskDelegateForCredentials +{ + if ([self isSynchronous]) { + return NO; + } + + // If we have a delegate, we'll see if it can handle proxyAuthenticationNeededForRequest:. + // Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate + id authenticationDelegate = [self delegate]; + if (!authenticationDelegate) { + authenticationDelegate = [self queue]; + } + + BOOL delegateOrBlockWillHandleAuthentication = NO; + + if ([authenticationDelegate respondsToSelector:@selector(authenticationNeededForRequest:)]) { + delegateOrBlockWillHandleAuthentication = YES; + } + + #if NS_BLOCKS_AVAILABLE + if (authenticationNeededBlock) { + delegateOrBlockWillHandleAuthentication = YES; + } + #endif + + if (delegateOrBlockWillHandleAuthentication) { + [self performSelectorOnMainThread:@selector(askDelegateForCredentials) withObject:nil waitUntilDone:NO]; + } + return delegateOrBlockWillHandleAuthentication; +} + +/* ALWAYS CALLED ON MAIN THREAD! */ +- (void)askDelegateForCredentials +{ + id authenticationDelegate = [self delegate]; + if (!authenticationDelegate) { + authenticationDelegate = [self queue]; + } + + if ([authenticationDelegate respondsToSelector:@selector(authenticationNeededForRequest:)]) { + [authenticationDelegate performSelector:@selector(authenticationNeededForRequest:) withObject:self]; + return; + } + + #if NS_BLOCKS_AVAILABLE + if (authenticationNeededBlock) { + authenticationNeededBlock(); + } + #endif +} + +- (void)attemptToApplyProxyCredentialsAndResume +{ + + if ([self error] || [self isCancelled]) { + return; + } + + // Read authentication data + if (!proxyAuthentication) { + CFHTTPMessageRef responseHeader = (CFHTTPMessageRef) CFReadStreamCopyProperty((CFReadStreamRef)[self readStream],kCFStreamPropertyHTTPResponseHeader); + proxyAuthentication = CFHTTPAuthenticationCreateFromResponse(NULL, responseHeader); + CFRelease(responseHeader); + [self setProxyAuthenticationScheme:[NSMakeCollectable(CFHTTPAuthenticationCopyMethod(proxyAuthentication)) autorelease]]; + } + + // If we haven't got a CFHTTPAuthenticationRef by now, something is badly wrong, so we'll have to give up + if (!proxyAuthentication) { + [self cancelLoad]; + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileApplyingCredentialsType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Failed to get authentication object from response headers",NSLocalizedDescriptionKey,nil]]]; + return; + } + + // Get the authentication realm + [self setProxyAuthenticationRealm:nil]; + if (!CFHTTPAuthenticationRequiresAccountDomain(proxyAuthentication)) { + [self setProxyAuthenticationRealm:[NSMakeCollectable(CFHTTPAuthenticationCopyRealm(proxyAuthentication)) autorelease]]; + } + + // See if authentication is valid + CFStreamError err; + if (!CFHTTPAuthenticationIsValid(proxyAuthentication, &err)) { + + CFRelease(proxyAuthentication); + proxyAuthentication = NULL; + + // check for bad credentials, so we can give the delegate a chance to replace them + if (err.domain == kCFStreamErrorDomainHTTP && (err.error == kCFStreamErrorHTTPAuthenticationBadUserName || err.error == kCFStreamErrorHTTPAuthenticationBadPassword)) { + + // Prevent more than one request from asking for credentials at once + [delegateAuthenticationLock lock]; + + // We know the credentials we just presented are bad, we should remove them from the session store too + [[self class] removeProxyAuthenticationCredentialsFromSessionStore:proxyCredentials]; + [self setProxyCredentials:nil]; + + + // If the user cancelled authentication via a dialog presented by another request, our queue may have cancelled us + if ([self error] || [self isCancelled]) { + [delegateAuthenticationLock unlock]; + return; + } + + + // Now we've acquired the lock, it may be that the session contains credentials we can re-use for this request + if ([self useSessionPersistence]) { + NSDictionary *credentials = [self findSessionProxyAuthenticationCredentials]; + if (credentials && [self applyProxyCredentials:[credentials objectForKey:@"Credentials"]]) { + [delegateAuthenticationLock unlock]; + [self startRequest]; + return; + } + } + + [self setLastActivityTime:nil]; + + if ([self willAskDelegateForProxyCredentials]) { + [self attemptToApplyProxyCredentialsAndResume]; + [delegateAuthenticationLock unlock]; + return; + } + if ([self showProxyAuthenticationDialog]) { + [self attemptToApplyProxyCredentialsAndResume]; + [delegateAuthenticationLock unlock]; + return; + } + [delegateAuthenticationLock unlock]; + } + [self cancelLoad]; + [self failWithError:ASIAuthenticationError]; + return; + } + + [self cancelLoad]; + + if (proxyCredentials) { + + // We use startRequest rather than starting all over again in load request because NTLM requires we reuse the request + if ((([self proxyAuthenticationScheme] != (NSString *)kCFHTTPAuthenticationSchemeNTLM) || [self proxyAuthenticationRetryCount] < 2) && [self applyProxyCredentials:proxyCredentials]) { + [self startRequest]; + + // We've failed NTLM authentication twice, we should assume our credentials are wrong + } else if ([self proxyAuthenticationScheme] == (NSString *)kCFHTTPAuthenticationSchemeNTLM && [self proxyAuthenticationRetryCount] == 2) { + [self failWithError:ASIAuthenticationError]; + + // Something went wrong, we'll have to give up + } else { + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileApplyingCredentialsType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Failed to apply proxy credentials to request",NSLocalizedDescriptionKey,nil]]]; + } + + // Are a user name & password needed? + } else if (CFHTTPAuthenticationRequiresUserNameAndPassword(proxyAuthentication)) { + + // Prevent more than one request from asking for credentials at once + [delegateAuthenticationLock lock]; + + // If the user cancelled authentication via a dialog presented by another request, our queue may have cancelled us + if ([self error] || [self isCancelled]) { + [delegateAuthenticationLock unlock]; + return; + } + + // Now we've acquired the lock, it may be that the session contains credentials we can re-use for this request + if ([self useSessionPersistence]) { + NSDictionary *credentials = [self findSessionProxyAuthenticationCredentials]; + if (credentials && [self applyProxyCredentials:[credentials objectForKey:@"Credentials"]]) { + [delegateAuthenticationLock unlock]; + [self startRequest]; + return; + } + } + + NSMutableDictionary *newCredentials = [self findProxyCredentials]; + + //If we have some credentials to use let's apply them to the request and continue + if (newCredentials) { + + if ([self applyProxyCredentials:newCredentials]) { + [delegateAuthenticationLock unlock]; + [self startRequest]; + } else { + [delegateAuthenticationLock unlock]; + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileApplyingCredentialsType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Failed to apply proxy credentials to request",NSLocalizedDescriptionKey,nil]]]; + } + + return; + } + + if ([self willAskDelegateForProxyCredentials]) { + [delegateAuthenticationLock unlock]; + return; + } + + if ([self showProxyAuthenticationDialog]) { + [delegateAuthenticationLock unlock]; + return; + } + [delegateAuthenticationLock unlock]; + + // The delegate isn't interested and we aren't showing the authentication dialog, we'll have to give up + [self failWithError:ASIAuthenticationError]; + return; + } + +} + +- (BOOL)showAuthenticationDialog +{ + if ([self isSynchronous]) { + return NO; + } + // Mac authentication dialog coming soon! + #if TARGET_OS_IPHONE + if ([self shouldPresentAuthenticationDialog]) { + [ASIAuthenticationDialog performSelectorOnMainThread:@selector(presentAuthenticationDialogForRequest:) withObject:self waitUntilDone:[NSThread isMainThread]]; + return YES; + } + return NO; + #else + return NO; + #endif +} + +- (void)attemptToApplyCredentialsAndResume +{ + if ([self error] || [self isCancelled]) { + return; + } + + // Do we actually need to authenticate with a proxy? + if ([self authenticationNeeded] == ASIProxyAuthenticationNeeded) { + [self attemptToApplyProxyCredentialsAndResume]; + return; + } + + // Read authentication data + if (!requestAuthentication) { + CFHTTPMessageRef responseHeader = (CFHTTPMessageRef) CFReadStreamCopyProperty((CFReadStreamRef)[self readStream],kCFStreamPropertyHTTPResponseHeader); + requestAuthentication = CFHTTPAuthenticationCreateFromResponse(NULL, responseHeader); + CFRelease(responseHeader); + [self setAuthenticationScheme:[NSMakeCollectable(CFHTTPAuthenticationCopyMethod(requestAuthentication)) autorelease]]; + } + + if (!requestAuthentication) { + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ failed to read authentication information from response headers",self); + #endif + + [self cancelLoad]; + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileApplyingCredentialsType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Failed to get authentication object from response headers",NSLocalizedDescriptionKey,nil]]]; + return; + } + + // Get the authentication realm + [self setAuthenticationRealm:nil]; + if (!CFHTTPAuthenticationRequiresAccountDomain(requestAuthentication)) { + [self setAuthenticationRealm:[NSMakeCollectable(CFHTTPAuthenticationCopyRealm(requestAuthentication)) autorelease]]; + } + + #if DEBUG_HTTP_AUTHENTICATION + NSString *realm = [self authenticationRealm]; + if (realm) { + realm = [NSString stringWithFormat:@" (Realm: %@)",realm]; + } else { + realm = @""; + } + if ([self authenticationScheme] != (NSString *)kCFHTTPAuthenticationSchemeNTLM || [self authenticationRetryCount] == 0) { + NSLog(@"[AUTH] Request %@ received 401 challenge and must authenticate using %@%@",self,[self authenticationScheme],realm); + } else { + NSLog(@"[AUTH] Request %@ NTLM handshake step %i",self,[self authenticationRetryCount]+1); + } + #endif + + // See if authentication is valid + CFStreamError err; + if (!CFHTTPAuthenticationIsValid(requestAuthentication, &err)) { + + CFRelease(requestAuthentication); + requestAuthentication = NULL; + + // check for bad credentials, so we can give the delegate a chance to replace them + if (err.domain == kCFStreamErrorDomainHTTP && (err.error == kCFStreamErrorHTTPAuthenticationBadUserName || err.error == kCFStreamErrorHTTPAuthenticationBadPassword)) { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ had bad credentials, will remove them from the session store if they are cached",self); + #endif + + // Prevent more than one request from asking for credentials at once + [delegateAuthenticationLock lock]; + + // We know the credentials we just presented are bad, we should remove them from the session store too + [[self class] removeAuthenticationCredentialsFromSessionStore:requestCredentials]; + [self setRequestCredentials:nil]; + + // If the user cancelled authentication via a dialog presented by another request, our queue may have cancelled us + if ([self error] || [self isCancelled]) { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ failed or was cancelled while waiting to access credentials",self); + #endif + + [delegateAuthenticationLock unlock]; + return; + } + + // Now we've acquired the lock, it may be that the session contains credentials we can re-use for this request + if ([self useSessionPersistence]) { + NSDictionary *credentials = [self findSessionAuthenticationCredentials]; + if (credentials && [self applyCredentials:[credentials objectForKey:@"Credentials"]]) { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ will reuse cached credentials from the session (%@)",self,[credentials objectForKey:@"AuthenticationScheme"]); + #endif + + [delegateAuthenticationLock unlock]; + [self startRequest]; + return; + } + } + + [self setLastActivityTime:nil]; + + if ([self willAskDelegateForCredentials]) { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ will ask its delegate for credentials to use",self); + #endif + + [delegateAuthenticationLock unlock]; + return; + } + if ([self showAuthenticationDialog]) { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ will ask ASIAuthenticationDialog for credentials",self); + #endif + + [delegateAuthenticationLock unlock]; + return; + } + [delegateAuthenticationLock unlock]; + } + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ has no credentials to present and must give up",self); + #endif + + [self cancelLoad]; + [self failWithError:ASIAuthenticationError]; + return; + } + + [self cancelLoad]; + + if (requestCredentials) { + + if ((([self authenticationScheme] != (NSString *)kCFHTTPAuthenticationSchemeNTLM) || [self authenticationRetryCount] < 2) && [self applyCredentials:requestCredentials]) { + [self startRequest]; + + // We've failed NTLM authentication twice, we should assume our credentials are wrong + } else if ([self authenticationScheme] == (NSString *)kCFHTTPAuthenticationSchemeNTLM && [self authenticationRetryCount ] == 2) { + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ has failed NTLM authentication",self); + #endif + + [self failWithError:ASIAuthenticationError]; + + } else { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ had credentials and they were not marked as bad, but we got a 401 all the same.",self); + #endif + + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileApplyingCredentialsType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Failed to apply credentials to request",NSLocalizedDescriptionKey,nil]]]; + } + + // Are a user name & password needed? + } else if (CFHTTPAuthenticationRequiresUserNameAndPassword(requestAuthentication)) { + + // Prevent more than one request from asking for credentials at once + [delegateAuthenticationLock lock]; + + // If the user cancelled authentication via a dialog presented by another request, our queue may have cancelled us + if ([self error] || [self isCancelled]) { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ failed or was cancelled while waiting to access credentials",self); + #endif + + [delegateAuthenticationLock unlock]; + return; + } + + // Now we've acquired the lock, it may be that the session contains credentials we can re-use for this request + if ([self useSessionPersistence]) { + NSDictionary *credentials = [self findSessionAuthenticationCredentials]; + if (credentials && [self applyCredentials:[credentials objectForKey:@"Credentials"]]) { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ will reuse cached credentials from the session (%@)",self,[credentials objectForKey:@"AuthenticationScheme"]); + #endif + + [delegateAuthenticationLock unlock]; + [self startRequest]; + return; + } + } + + + NSMutableDictionary *newCredentials = [self findCredentials]; + + //If we have some credentials to use let's apply them to the request and continue + if (newCredentials) { + + if ([self applyCredentials:newCredentials]) { + [delegateAuthenticationLock unlock]; + [self startRequest]; + } else { + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ failed to apply credentials",self); + #endif + [delegateAuthenticationLock unlock]; + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileApplyingCredentialsType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Failed to apply credentials to request",NSLocalizedDescriptionKey,nil]]]; + } + return; + } + if ([self willAskDelegateForCredentials]) { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ will ask its delegate for credentials to use",self); + #endif + + [delegateAuthenticationLock unlock]; + return; + } + if ([self showAuthenticationDialog]) { + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ will ask ASIAuthenticationDialog for credentials",self); + #endif + + [delegateAuthenticationLock unlock]; + return; + } + + #if DEBUG_HTTP_AUTHENTICATION + NSLog(@"[AUTH] Request %@ has no credentials to present and must give up",self); + #endif + [delegateAuthenticationLock unlock]; + [self failWithError:ASIAuthenticationError]; + return; + } + +} + +- (void)addBasicAuthenticationHeaderWithUsername:(NSString *)theUsername andPassword:(NSString *)thePassword +{ + [self addRequestHeader:@"Authorization" value:[NSString stringWithFormat:@"Basic %@",[ASIHTTPRequest base64forData:[[NSString stringWithFormat:@"%@:%@",theUsername,thePassword] dataUsingEncoding:NSUTF8StringEncoding]]]]; + [self setAuthenticationScheme:(NSString *)kCFHTTPAuthenticationSchemeBasic]; + +} + + +#pragma mark stream status handlers + +- (void)handleNetworkEvent:(CFStreamEventType)type +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + [[self cancelledLock] lock]; + + if ([self complete] || [self isCancelled]) { + [[self cancelledLock] unlock]; + [pool drain]; + return; + } + + CFRetain(self); + + // Dispatch the stream events. + switch (type) { + case kCFStreamEventHasBytesAvailable: + [self handleBytesAvailable]; + break; + + case kCFStreamEventEndEncountered: + [self handleStreamComplete]; + break; + + case kCFStreamEventErrorOccurred: + [self handleStreamError]; + break; + + default: + break; + } + + [self performThrottling]; + + [[self cancelledLock] unlock]; + + if ([self downloadComplete] && [self needsRedirect]) { + if (![self willAskDelegateToConfirmRedirect]) { + [self performRedirect]; + } + } else if ([self downloadComplete] && [self authenticationNeeded]) { + [self attemptToApplyCredentialsAndResume]; + } + + CFRelease(self); + [pool drain]; +} + +- (BOOL)willAskDelegateToConfirmRedirect +{ + // We must lock to ensure delegate / queue aren't changed while we check them + [[self cancelledLock] lock]; + + // Here we perform an initial check to see if either the delegate or the queue wants to be asked about the redirect, because if not we should redirect straight away + // We will check again on the main thread later + BOOL needToAskDelegateAboutRedirect = (([self delegate] && [[self delegate] respondsToSelector:[self willRedirectSelector]]) || ([self queue] && [[self queue] respondsToSelector:@selector(request:willRedirectToURL:)])); + + [[self cancelledLock] unlock]; + + // Either the delegate or the queue's delegate is interested in being told when we are about to redirect + if (needToAskDelegateAboutRedirect) { + NSURL *newURL = [[[self redirectURL] copy] autorelease]; + [self setRedirectURL:nil]; + [self performSelectorOnMainThread:@selector(requestWillRedirectToURL:) withObject:newURL waitUntilDone:[NSThread isMainThread]]; + return true; + } + return false; +} + +- (void)handleBytesAvailable +{ + if (![self responseHeaders]) { + [self readResponseHeaders]; + } + + // If we've cancelled the load part way through (for example, after deciding to use a cached version) + if ([self complete]) { + return; + } + + // In certain (presumably very rare) circumstances, handleBytesAvailable seems to be called when there isn't actually any data available + // We'll check that there is actually data available to prevent blocking on CFReadStreamRead() + // So far, I've only seen this in the stress tests, so it might never happen in real-world situations. + if (!CFReadStreamHasBytesAvailable((CFReadStreamRef)[self readStream])) { + return; + } + + long long bufferSize = 16384; + if (contentLength > 262144) { + bufferSize = 262144; + } else if (contentLength > 65536) { + bufferSize = 65536; + } + + // Reduce the buffer size if we're receiving data too quickly when bandwidth throttling is active + // This just augments the throttling done in measureBandwidthUsage to reduce the amount we go over the limit + + if ([[self class] isBandwidthThrottled]) { + [bandwidthThrottlingLock lock]; + if (maxBandwidthPerSecond > 0) { + long long maxiumumSize = (long long)maxBandwidthPerSecond-(long long)bandwidthUsedInLastSecond; + if (maxiumumSize < 0) { + // We aren't supposed to read any more data right now, but we'll read a single byte anyway so the CFNetwork's buffer isn't full + bufferSize = 1; + } else if (maxiumumSize/4 < bufferSize) { + // We were going to fetch more data that we should be allowed, so we'll reduce the size of our read + bufferSize = maxiumumSize/4; + } + } + if (bufferSize < 1) { + bufferSize = 1; + } + [bandwidthThrottlingLock unlock]; + } + + + UInt8 buffer[bufferSize]; + NSInteger bytesRead = [[self readStream] read:buffer maxLength:sizeof(buffer)]; + + // Less than zero is an error + if (bytesRead < 0) { + [self handleStreamError]; + + // If zero bytes were read, wait for the EOF to come. + } else if (bytesRead) { + + // If we are inflating the response on the fly + NSData *inflatedData = nil; + if ([self isResponseCompressed] && ![self shouldWaitToInflateCompressedResponses]) { + if (![self dataDecompressor]) { + [self setDataDecompressor:[ASIDataDecompressor decompressor]]; + } + NSError *err = nil; + inflatedData = [[self dataDecompressor] uncompressBytes:buffer length:bytesRead error:&err]; + if (err) { + [self failWithError:err]; + return; + } + } + + [self setTotalBytesRead:[self totalBytesRead]+bytesRead]; + [self setLastActivityTime:[NSDate date]]; + + // For bandwidth measurement / throttling + [ASIHTTPRequest incrementBandwidthUsedInLastSecond:bytesRead]; + + // If we need to redirect, and have automatic redirect on, and might be resuming a download, let's do nothing with the content + if ([self needsRedirect] && [self shouldRedirect] && [self allowResumeForFileDownloads]) { + return; + } + + BOOL dataWillBeHandledExternally = NO; + if ([[self delegate] respondsToSelector:[self didReceiveDataSelector]]) { + dataWillBeHandledExternally = YES; + } + #if NS_BLOCKS_AVAILABLE + if (dataReceivedBlock) { + dataWillBeHandledExternally = YES; + } + #endif + // Does the delegate want to handle the data manually? + if (dataWillBeHandledExternally) { + + NSData *data = nil; + if ([self isResponseCompressed] && ![self shouldWaitToInflateCompressedResponses]) { + data = inflatedData; + } else { + data = [NSData dataWithBytes:buffer length:bytesRead]; + } + [self performSelectorOnMainThread:@selector(passOnReceivedData:) withObject:data waitUntilDone:[NSThread isMainThread]]; + + // Are we downloading to a file? + } else if ([self downloadDestinationPath]) { + BOOL append = NO; + if (![self fileDownloadOutputStream]) { + if (![self temporaryFileDownloadPath]) { + [self setTemporaryFileDownloadPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]]; + } else if ([self allowResumeForFileDownloads] && [[self requestHeaders] objectForKey:@"Range"]) { + if ([[self responseHeaders] objectForKey:@"Content-Range"]) { + append = YES; + } else { + [self incrementDownloadSizeBy:-[self partialDownloadSize]]; + [self setPartialDownloadSize:0]; + } + } + + [self setFileDownloadOutputStream:[[[NSOutputStream alloc] initToFileAtPath:[self temporaryFileDownloadPath] append:append] autorelease]]; + [[self fileDownloadOutputStream] open]; + + } + [[self fileDownloadOutputStream] write:buffer maxLength:bytesRead]; + + if ([self isResponseCompressed] && ![self shouldWaitToInflateCompressedResponses]) { + + if (![self inflatedFileDownloadOutputStream]) { + if (![self temporaryUncompressedDataDownloadPath]) { + [self setTemporaryUncompressedDataDownloadPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]]; + } + + [self setInflatedFileDownloadOutputStream:[[[NSOutputStream alloc] initToFileAtPath:[self temporaryUncompressedDataDownloadPath] append:append] autorelease]]; + [[self inflatedFileDownloadOutputStream] open]; + } + + [[self inflatedFileDownloadOutputStream] write:[inflatedData bytes] maxLength:[inflatedData length]]; + } + + + //Otherwise, let's add the data to our in-memory store + } else { + if ([self isResponseCompressed] && ![self shouldWaitToInflateCompressedResponses]) { + [rawResponseData appendData:inflatedData]; + } else { + [rawResponseData appendBytes:buffer length:bytesRead]; + } + } + } +} + +- (void)handleStreamComplete +{ + +#if DEBUG_REQUEST_STATUS + NSLog(@"[STATUS] Request %@ finished downloading data (%qu bytes)",self, [self totalBytesRead]); +#endif + [self setStatusTimer:nil]; + [self setDownloadComplete:YES]; + + if (![self responseHeaders]) { + [self readResponseHeaders]; + } + + [progressLock lock]; + // Find out how much data we've uploaded so far + [self setLastBytesSent:totalBytesSent]; + [self setTotalBytesSent:[[NSMakeCollectable(CFReadStreamCopyProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPRequestBytesWrittenCount)) autorelease] unsignedLongLongValue]]; + [self setComplete:YES]; + if (![self contentLength]) { + [self setContentLength:[self totalBytesRead]]; + } + [self updateProgressIndicators]; + + + [[self postBodyReadStream] close]; + [self setPostBodyReadStream:nil]; + + [self setDataDecompressor:nil]; + + NSError *fileError = nil; + + // Delete up the request body temporary file, if it exists + if ([self didCreateTemporaryPostDataFile] && ![self authenticationNeeded]) { + [self removeTemporaryUploadFile]; + [self removeTemporaryCompressedUploadFile]; + } + + // Close the output stream as we're done writing to the file + if ([self temporaryFileDownloadPath]) { + + [[self fileDownloadOutputStream] close]; + [self setFileDownloadOutputStream:nil]; + + [[self inflatedFileDownloadOutputStream] close]; + [self setInflatedFileDownloadOutputStream:nil]; + + // If we are going to redirect and we are resuming, let's ignore this download + if ([self shouldRedirect] && [self needsRedirect] && [self allowResumeForFileDownloads]) { + + } else if ([self isResponseCompressed]) { + + // Decompress the file directly to the destination path + if ([self shouldWaitToInflateCompressedResponses]) { + [ASIDataDecompressor uncompressDataFromFile:[self temporaryFileDownloadPath] toFile:[self downloadDestinationPath] error:&fileError]; + + // Response should already have been inflated, move the temporary file to the destination path + } else { + NSError *moveError = nil; + [[[[NSFileManager alloc] init] autorelease] moveItemAtPath:[self temporaryUncompressedDataDownloadPath] toPath:[self downloadDestinationPath] error:&moveError]; + if (moveError) { + fileError = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to move file from '%@' to '%@'",[self temporaryFileDownloadPath],[self downloadDestinationPath]],NSLocalizedDescriptionKey,moveError,NSUnderlyingErrorKey,nil]]; + } + [self setTemporaryUncompressedDataDownloadPath:nil]; + + } + [self removeTemporaryDownloadFile]; + + } else { + + //Remove any file at the destination path + NSError *moveError = nil; + if (![[self class] removeFileAtPath:[self downloadDestinationPath] error:&moveError]) { + fileError = moveError; + + } + + //Move the temporary file to the destination path + if (!fileError) { + [[[[NSFileManager alloc] init] autorelease] moveItemAtPath:[self temporaryFileDownloadPath] toPath:[self downloadDestinationPath] error:&moveError]; + if (moveError) { + fileError = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to move file from '%@' to '%@'",[self temporaryFileDownloadPath],[self downloadDestinationPath]],NSLocalizedDescriptionKey,moveError,NSUnderlyingErrorKey,nil]]; + } + [self setTemporaryFileDownloadPath:nil]; + } + + } + } + + // Save to the cache + if ([self downloadCache] && ![self didUseCachedResponse]) { + [[self downloadCache] storeResponseForRequest:self maxAge:[self secondsToCache]]; + } + + [progressLock unlock]; + + + [connectionsLock lock]; + if (![self connectionCanBeReused]) { + [self unscheduleReadStream]; + } + #if DEBUG_PERSISTENT_CONNECTIONS + if ([self requestID]) { + NSLog(@"[CONNECTION] Request #%@ finished using connection #%@",[self requestID], [[self connectionInfo] objectForKey:@"id"]); + } + #endif + [[self connectionInfo] removeObjectForKey:@"request"]; + [[self connectionInfo] setObject:[NSDate dateWithTimeIntervalSinceNow:[self persistentConnectionTimeoutSeconds]] forKey:@"expires"]; + [connectionsLock unlock]; + + if (![self authenticationNeeded]) { + [self destroyReadStream]; + } + + + if (![self needsRedirect] && ![self authenticationNeeded] && ![self didUseCachedResponse]) { + + if (fileError) { + [self failWithError:fileError]; + } else { + [self requestFinished]; + } + + [self markAsFinished]; + + // If request has asked delegate or ASIAuthenticationDialog for credentials + } else if ([self authenticationNeeded]) { + CFRunLoopStop(CFRunLoopGetCurrent()); + } + +} + +- (void)markAsFinished +{ + // Autoreleased requests may well be dealloced here otherwise + CFRetain(self); + + // dealloc won't be called when running with GC, so we'll clean these up now + if (request) { + CFRelease(request); + request = nil; + } + if (requestAuthentication) { + CFRelease(requestAuthentication); + requestAuthentication = nil; + } + if (proxyAuthentication) { + CFRelease(proxyAuthentication); + proxyAuthentication = nil; + } + + BOOL wasInProgress = inProgress; + BOOL wasFinished = finished; + + if (!wasFinished) + [self willChangeValueForKey:@"isFinished"]; + if (wasInProgress) + [self willChangeValueForKey:@"isExecuting"]; + + [self setInProgress:NO]; + finished = YES; + + if (wasInProgress) + [self didChangeValueForKey:@"isExecuting"]; + if (!wasFinished) + [self didChangeValueForKey:@"isFinished"]; + + CFRunLoopStop(CFRunLoopGetCurrent()); + + #if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 + if ([ASIHTTPRequest isMultitaskingSupported] && [self shouldContinueWhenAppEntersBackground]) { + dispatch_async(dispatch_get_main_queue(), ^{ + if (backgroundTask != UIBackgroundTaskInvalid) { + [[UIApplication sharedApplication] endBackgroundTask:backgroundTask]; + backgroundTask = UIBackgroundTaskInvalid; + } + }); + } + #endif + CFRelease(self); +} + +- (void)useDataFromCache +{ + NSDictionary *headers = [[self downloadCache] cachedResponseHeadersForURL:[self url]]; + NSString *dataPath = [[self downloadCache] pathToCachedResponseDataForURL:[self url]]; + + ASIHTTPRequest *theRequest = self; + if ([self mainRequest]) { + theRequest = [self mainRequest]; + } + + if (headers && dataPath) { + + [self setResponseStatusCode:[[headers objectForKey:@"X-ASIHTTPRequest-Response-Status-Code"] intValue]]; + [self setDidUseCachedResponse:YES]; + [theRequest setResponseHeaders:headers]; + + if ([theRequest downloadDestinationPath]) { + [theRequest setDownloadDestinationPath:dataPath]; + } else { + [theRequest setRawResponseData:[NSMutableData dataWithData:[[self downloadCache] cachedResponseDataForURL:[self url]]]]; + } + [theRequest setContentLength:[[[self responseHeaders] objectForKey:@"Content-Length"] longLongValue]]; + [theRequest setTotalBytesRead:[self contentLength]]; + + [theRequest parseStringEncodingFromHeaders]; + + [theRequest setResponseCookies:[NSHTTPCookie cookiesWithResponseHeaderFields:headers forURL:[self url]]]; + + // See if we need to redirect + if ([self willRedirect]) { + if (![self willAskDelegateToConfirmRedirect]) { + [self performRedirect]; + } + return; + } + } + + [theRequest setComplete:YES]; + [theRequest setDownloadComplete:YES]; + + // If we're pulling data from the cache without contacting the server at all, we won't have set originalURL yet + if ([self redirectCount] == 0) { + [theRequest setOriginalURL:[theRequest url]]; + } + + [theRequest updateProgressIndicators]; + [theRequest requestFinished]; + [theRequest markAsFinished]; + if ([self mainRequest]) { + [self markAsFinished]; + } +} + +- (BOOL)retryUsingNewConnection +{ + if ([self retryCount] == 0) { + + [self setWillRetryRequest:YES]; + [self cancelLoad]; + [self setWillRetryRequest:NO]; + + #if DEBUG_PERSISTENT_CONNECTIONS + NSLog(@"[CONNECTION] Request attempted to use connection #%@, but it has been closed - will retry with a new connection", [[self connectionInfo] objectForKey:@"id"]); + #endif + [connectionsLock lock]; + [[self connectionInfo] removeObjectForKey:@"request"]; + [persistentConnectionsPool removeObject:[self connectionInfo]]; + [self setConnectionInfo:nil]; + [connectionsLock unlock]; + [self setRetryCount:[self retryCount]+1]; + [self startRequest]; + return YES; + } + #if DEBUG_PERSISTENT_CONNECTIONS + NSLog(@"[CONNECTION] Request attempted to use connection #%@, but it has been closed - we have already retried with a new connection, so we must give up", [[self connectionInfo] objectForKey:@"id"]); + #endif + return NO; +} + +- (void)handleStreamError + +{ + NSError *underlyingError = [NSMakeCollectable(CFReadStreamCopyError((CFReadStreamRef)[self readStream])) autorelease]; + + if (![self error]) { // We may already have handled this error + + // First, check for a 'socket not connected', 'broken pipe' or 'connection lost' error + // This may occur when we've attempted to reuse a connection that should have been closed + // If we get this, we need to retry the request + // We'll only do this once - if it happens again on retry, we'll give up + // -1005 = kCFURLErrorNetworkConnectionLost - this doesn't seem to be declared on Mac OS 10.5 + if (([[underlyingError domain] isEqualToString:NSPOSIXErrorDomain] && ([underlyingError code] == ENOTCONN || [underlyingError code] == EPIPE)) + || ([[underlyingError domain] isEqualToString:(NSString *)kCFErrorDomainCFNetwork] && [underlyingError code] == -1005)) { + if ([self retryUsingNewConnection]) { + return; + } + } + + NSString *reason = @"A connection failure occurred"; + + // We'll use a custom error message for SSL errors, but you should always check underlying error if you want more details + // For some reason SecureTransport.h doesn't seem to be available on iphone, so error codes hard-coded + // Also, iPhone seems to handle errors differently from Mac OS X - a self-signed certificate returns a different error code on each platform, so we'll just provide a general error + if ([[underlyingError domain] isEqualToString:NSOSStatusErrorDomain]) { + if ([underlyingError code] <= -9800 && [underlyingError code] >= -9818) { + reason = [NSString stringWithFormat:@"%@: SSL problem (Possible causes may include a bad/expired/self-signed certificate, clock set to wrong date)",reason]; + } + } + [self cancelLoad]; + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIConnectionFailureErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:reason,NSLocalizedDescriptionKey,underlyingError,NSUnderlyingErrorKey,nil]]]; + } else { + [self cancelLoad]; + } + [self checkRequestStatus]; +} + +#pragma mark managing the read stream + +- (void)destroyReadStream +{ + if ([self readStream]) { + [self unscheduleReadStream]; + if (![self connectionCanBeReused]) { + [[self readStream] removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]]; + [[self readStream] close]; + } + [self setReadStream:nil]; + } +} + +- (void)scheduleReadStream +{ + if ([self readStream] && ![self readStreamIsScheduled]) { + + [connectionsLock lock]; + runningRequestCount++; + if (shouldUpdateNetworkActivityIndicator) { + [[self class] showNetworkActivityIndicator]; + } + [connectionsLock unlock]; + + // Reset the timeout + [self setLastActivityTime:[NSDate date]]; + CFStreamClientContext ctxt = {0, self, NULL, NULL, NULL}; + CFReadStreamSetClient((CFReadStreamRef)[self readStream], kNetworkEvents, ReadStreamClientCallBack, &ctxt); + [[self readStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]]; + [self setReadStreamIsScheduled:YES]; + } +} + + +- (void)unscheduleReadStream +{ + if ([self readStream] && [self readStreamIsScheduled]) { + + [connectionsLock lock]; + runningRequestCount--; + if (shouldUpdateNetworkActivityIndicator && runningRequestCount == 0) { + // This call will wait half a second before turning off the indicator + // This can prevent flicker when you have a single request finish and then immediately start another request + // We run this on the main thread because we have no guarantee this thread will have a runloop in 0.5 seconds time + // We don't bother the cancel this call if we start a new request, because we'll check if requests are running before we hide it + [[self class] performSelectorOnMainThread:@selector(hideNetworkActivityIndicatorAfterDelay) withObject:nil waitUntilDone:[NSThread isMainThread]]; + } + [connectionsLock unlock]; + + CFReadStreamSetClient((CFReadStreamRef)[self readStream], kCFStreamEventNone, NULL, NULL); + [[self readStream] removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]]; + [self setReadStreamIsScheduled:NO]; + } +} + +#pragma mark cleanup + +- (BOOL)removeTemporaryDownloadFile +{ + NSError *err = nil; + if ([self temporaryFileDownloadPath]) { + if (![[self class] removeFileAtPath:[self temporaryFileDownloadPath] error:&err]) { + [self failWithError:err]; + } + [self setTemporaryFileDownloadPath:nil]; + } + return (!err); +} + +- (BOOL)removeTemporaryUncompressedDownloadFile +{ + NSError *err = nil; + if ([self temporaryUncompressedDataDownloadPath]) { + if (![[self class] removeFileAtPath:[self temporaryUncompressedDataDownloadPath] error:&err]) { + [self failWithError:err]; + } + [self setTemporaryUncompressedDataDownloadPath:nil]; + } + return (!err); +} + +- (BOOL)removeTemporaryUploadFile +{ + NSError *err = nil; + if ([self postBodyFilePath]) { + if (![[self class] removeFileAtPath:[self postBodyFilePath] error:&err]) { + [self failWithError:err]; + } + [self setPostBodyFilePath:nil]; + } + return (!err); +} + +- (BOOL)removeTemporaryCompressedUploadFile +{ + NSError *err = nil; + if ([self compressedPostBodyFilePath]) { + if (![[self class] removeFileAtPath:[self compressedPostBodyFilePath] error:&err]) { + [self failWithError:err]; + } + [self setCompressedPostBodyFilePath:nil]; + } + return (!err); +} + ++ (BOOL)removeFileAtPath:(NSString *)path error:(NSError **)err +{ + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; + + if ([fileManager fileExistsAtPath:path]) { + NSError *removeError = nil; + [fileManager removeItemAtPath:path error:&removeError]; + if (removeError) { + if (err) { + *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to delete file at path '%@'",path],NSLocalizedDescriptionKey,removeError,NSUnderlyingErrorKey,nil]]; + } + return NO; + } + } + return YES; +} + +#pragma mark Proxies + +- (BOOL)configureProxies +{ + // Have details of the proxy been set on this request + if (![self isPACFileRequest] && (![self proxyHost] && ![self proxyPort])) { + + // If not, we need to figure out what they'll be + NSArray *proxies = nil; + + // Have we been given a proxy auto config file? + if ([self PACurl]) { + + // If yes, we'll need to fetch the PAC file asynchronously, so we stop this request to wait until we have the proxy details. + [self fetchPACFile]; + return NO; + + // Detect proxy settings and apply them + } else { + +#if TARGET_OS_IPHONE + NSDictionary *proxySettings = [NSMakeCollectable(CFNetworkCopySystemProxySettings()) autorelease]; +#else + NSDictionary *proxySettings = [NSMakeCollectable(SCDynamicStoreCopyProxies(NULL)) autorelease]; +#endif + + proxies = [NSMakeCollectable(CFNetworkCopyProxiesForURL((CFURLRef)[self url], (CFDictionaryRef)proxySettings)) autorelease]; + + // Now check to see if the proxy settings contained a PAC url, we need to run the script to get the real list of proxies if so + NSDictionary *settings = [proxies objectAtIndex:0]; + if ([settings objectForKey:(NSString *)kCFProxyAutoConfigurationURLKey]) { + [self setPACurl:[settings objectForKey:(NSString *)kCFProxyAutoConfigurationURLKey]]; + [self fetchPACFile]; + return NO; + } + } + + if (!proxies) { + [self setReadStream:nil]; + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileBuildingRequestType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Unable to obtain information on proxy servers needed for request",NSLocalizedDescriptionKey,nil]]]; + return NO; + } + // I don't really understand why the dictionary returned by CFNetworkCopyProxiesForURL uses different key names from CFNetworkCopySystemProxySettings/SCDynamicStoreCopyProxies + // and why its key names are documented while those we actually need to use don't seem to be (passing the kCF* keys doesn't seem to work) + if ([proxies count] > 0) { + NSDictionary *settings = [proxies objectAtIndex:0]; + [self setProxyHost:[settings objectForKey:(NSString *)kCFProxyHostNameKey]]; + [self setProxyPort:[[settings objectForKey:(NSString *)kCFProxyPortNumberKey] intValue]]; + [self setProxyType:[settings objectForKey:(NSString *)kCFProxyTypeKey]]; + } + } + return YES; +} + + + +// Attempts to download a PAC (Proxy Auto-Configuration) file +// PAC files at file://, http:// and https:// addresses are supported +- (void)fetchPACFile +{ + // For file:// urls, we'll use an async NSInputStream (ASIHTTPRequest does not support file:// urls) + if ([[self PACurl] isFileURL]) { + NSInputStream *stream = [[[NSInputStream alloc] initWithFileAtPath:[[self PACurl] path]] autorelease]; + [self setPACFileReadStream:stream]; + [stream setDelegate:(id)self]; + [stream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]]; + [stream open]; + // If it takes more than timeOutSeconds to read the PAC, we'll just give up and assume no proxies + // We won't bother to handle cases where the first part of the PAC is read within timeOutSeconds, but the whole thing takes longer + // Either our PAC file is in easy reach, or it's going to slow things down to the point that it's probably better requests fail + [self performSelector:@selector(timeOutPACRead) withObject:nil afterDelay:[self timeOutSeconds]]; + return; + } + + NSString *scheme = [[[self PACurl] scheme] lowercaseString]; + if (![scheme isEqualToString:@"http"] && ![scheme isEqualToString:@"https"]) { + // Don't know how to read data from this URL, we'll have to give up + // We'll simply assume no proxies, and start the request as normal + [self startRequest]; + return; + } + + // Create an ASIHTTPRequest to fetch the PAC file + ASIHTTPRequest *PACRequest = [ASIHTTPRequest requestWithURL:[self PACurl]]; + + // Will prevent this request attempting to configure proxy settings for itself + [PACRequest setIsPACFileRequest:YES]; + + [PACRequest setTimeOutSeconds:[self timeOutSeconds]]; + + // If we're a synchronous request, we'll download the PAC file synchronously + if ([self isSynchronous]) { + [PACRequest startSynchronous]; + if (![PACRequest error] && [PACRequest responseString]) { + [self runPACScript:[PACRequest responseString]]; + } + [self startRequest]; + return; + } + + [self setPACFileRequest:PACRequest]; + + // Force this request to run before others in the shared queue + [PACRequest setQueuePriority:NSOperationQueuePriorityHigh]; + + // We'll treat failure to download the PAC file the same as success - if we were unable to fetch a PAC file, we proceed as if we have no proxy server and let this request fail itself if necessary + [PACRequest setDelegate:self]; + [PACRequest setDidFinishSelector:@selector(finishedDownloadingPACFile:)]; + [PACRequest setDidFailSelector:@selector(finishedDownloadingPACFile:)]; + [PACRequest startAsynchronous]; + + // Temporarily increase the number of operations in the shared queue to give our request a chance to run + [connectionsLock lock]; + [sharedQueue setMaxConcurrentOperationCount:[sharedQueue maxConcurrentOperationCount]+1]; + [connectionsLock unlock]; +} + +// Called as we read the PAC file from a file:// url +- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode +{ + if (![self PACFileReadStream]) { + return; + } + if (eventCode == NSStreamEventHasBytesAvailable) { + + if (![self PACFileData]) { + [self setPACFileData:[NSMutableData data]]; + } + // If your PAC file is larger than 16KB, you're just being cruel. + uint8_t buf[16384]; + NSInteger len = [(NSInputStream *)stream read:buf maxLength:16384]; + if (len) { + [[self PACFileData] appendBytes:(const void *)buf length:len]; + } + + } else if (eventCode == NSStreamEventErrorOccurred || eventCode == NSStreamEventEndEncountered) { + + [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(timeOutPACRead) object:nil]; + + [stream close]; + [stream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]]; + [self setPACFileReadStream:nil]; + + if (eventCode == NSStreamEventEndEncountered) { + // It sounds as though we have no idea what encoding a PAC file will use + static NSStringEncoding encodingsToTry[2] = {NSUTF8StringEncoding,NSISOLatin1StringEncoding}; + NSUInteger i; + for (i=0; i<2; i++) { + NSString *pacScript = [[[NSString alloc] initWithBytes:[[self PACFileData] bytes] length:[[self PACFileData] length] encoding:encodingsToTry[i]] autorelease]; + if (pacScript) { + [self runPACScript:pacScript]; + break; + } + } + } + [self setPACFileData:nil]; + [self startRequest]; + } +} + +// Called if it takes longer than timeOutSeconds to read the whole PAC file (when reading from a file:// url) +- (void)timeOutPACRead +{ + [self stream:[self PACFileReadStream] handleEvent:NSStreamEventErrorOccurred]; +} + +// Runs the downloaded PAC script +- (void)runPACScript:(NSString *)script +{ + if (script) { + // From: http://developer.apple.com/samplecode/CFProxySupportTool/listing1.html + // Work around . This dummy call to + // CFNetworkCopyProxiesForURL initialise some state within CFNetwork + // that is required by CFNetworkCopyProxiesForAutoConfigurationScript. + CFRelease(CFNetworkCopyProxiesForURL((CFURLRef)[self url], NULL)); + + // Obtain the list of proxies by running the autoconfiguration script + CFErrorRef err = NULL; + NSArray *proxies = [NSMakeCollectable(CFNetworkCopyProxiesForAutoConfigurationScript((CFStringRef)script,(CFURLRef)[self url], &err)) autorelease]; + if (!err && [proxies count] > 0) { + NSDictionary *settings = [proxies objectAtIndex:0]; + [self setProxyHost:[settings objectForKey:(NSString *)kCFProxyHostNameKey]]; + [self setProxyPort:[[settings objectForKey:(NSString *)kCFProxyPortNumberKey] intValue]]; + [self setProxyType:[settings objectForKey:(NSString *)kCFProxyTypeKey]]; + } + } +} + +// Called if we successfully downloaded a PAC file from a webserver +- (void)finishedDownloadingPACFile:(ASIHTTPRequest *)theRequest +{ + if (![theRequest error] && [theRequest responseString]) { + [self runPACScript:[theRequest responseString]]; + } + + // Set the shared queue's maxConcurrentOperationCount back to normal + [connectionsLock lock]; + [sharedQueue setMaxConcurrentOperationCount:[sharedQueue maxConcurrentOperationCount]-1]; + [connectionsLock unlock]; + + // We no longer need our PAC file request + [self setPACFileRequest:nil]; + + // Start the request + [self startRequest]; +} + + +#pragma mark persistent connections + +- (NSNumber *)connectionID +{ + return [[self connectionInfo] objectForKey:@"id"]; +} + ++ (void)expirePersistentConnections +{ + [connectionsLock lock]; + NSUInteger i; + for (i=0; i<[persistentConnectionsPool count]; i++) { + NSDictionary *existingConnection = [persistentConnectionsPool objectAtIndex:i]; + if (![existingConnection objectForKey:@"request"] && [[existingConnection objectForKey:@"expires"] timeIntervalSinceNow] <= 0) { +#if DEBUG_PERSISTENT_CONNECTIONS + NSLog(@"[CONNECTION] Closing connection #%i because it has expired",[[existingConnection objectForKey:@"id"] intValue]); +#endif + NSInputStream *stream = [existingConnection objectForKey:@"stream"]; + if (stream) { + [stream close]; + } + [persistentConnectionsPool removeObject:existingConnection]; + i--; + } + } + [connectionsLock unlock]; +} + +#pragma mark NSCopying +- (id)copyWithZone:(NSZone *)zone +{ + // Don't forget - this will return a retained copy! + ASIHTTPRequest *newRequest = [[[self class] alloc] initWithURL:[self url]]; + [newRequest setDelegate:[self delegate]]; + [newRequest setRequestMethod:[self requestMethod]]; + [newRequest setPostBody:[self postBody]]; + [newRequest setShouldStreamPostDataFromDisk:[self shouldStreamPostDataFromDisk]]; + [newRequest setPostBodyFilePath:[self postBodyFilePath]]; + [newRequest setRequestHeaders:[[[self requestHeaders] mutableCopyWithZone:zone] autorelease]]; + [newRequest setRequestCookies:[[[self requestCookies] mutableCopyWithZone:zone] autorelease]]; + [newRequest setUseCookiePersistence:[self useCookiePersistence]]; + [newRequest setUseKeychainPersistence:[self useKeychainPersistence]]; + [newRequest setUseSessionPersistence:[self useSessionPersistence]]; + [newRequest setAllowCompressedResponse:[self allowCompressedResponse]]; + [newRequest setDownloadDestinationPath:[self downloadDestinationPath]]; + [newRequest setTemporaryFileDownloadPath:[self temporaryFileDownloadPath]]; + [newRequest setUsername:[self username]]; + [newRequest setPassword:[self password]]; + [newRequest setDomain:[self domain]]; + [newRequest setProxyUsername:[self proxyUsername]]; + [newRequest setProxyPassword:[self proxyPassword]]; + [newRequest setProxyDomain:[self proxyDomain]]; + [newRequest setProxyHost:[self proxyHost]]; + [newRequest setProxyPort:[self proxyPort]]; + [newRequest setProxyType:[self proxyType]]; + [newRequest setUploadProgressDelegate:[self uploadProgressDelegate]]; + [newRequest setDownloadProgressDelegate:[self downloadProgressDelegate]]; + [newRequest setShouldPresentAuthenticationDialog:[self shouldPresentAuthenticationDialog]]; + [newRequest setShouldPresentProxyAuthenticationDialog:[self shouldPresentProxyAuthenticationDialog]]; + [newRequest setPostLength:[self postLength]]; + [newRequest setHaveBuiltPostBody:[self haveBuiltPostBody]]; + [newRequest setDidStartSelector:[self didStartSelector]]; + [newRequest setDidFinishSelector:[self didFinishSelector]]; + [newRequest setDidFailSelector:[self didFailSelector]]; + [newRequest setTimeOutSeconds:[self timeOutSeconds]]; + [newRequest setShouldResetDownloadProgress:[self shouldResetDownloadProgress]]; + [newRequest setShouldResetUploadProgress:[self shouldResetUploadProgress]]; + [newRequest setShowAccurateProgress:[self showAccurateProgress]]; + [newRequest setDefaultResponseEncoding:[self defaultResponseEncoding]]; + [newRequest setAllowResumeForFileDownloads:[self allowResumeForFileDownloads]]; + [newRequest setUserInfo:[[[self userInfo] copyWithZone:zone] autorelease]]; + [newRequest setTag:[self tag]]; + [newRequest setUseHTTPVersionOne:[self useHTTPVersionOne]]; + [newRequest setShouldRedirect:[self shouldRedirect]]; + [newRequest setValidatesSecureCertificate:[self validatesSecureCertificate]]; + [newRequest setClientCertificateIdentity:clientCertificateIdentity]; + [newRequest setClientCertificates:[[clientCertificates copy] autorelease]]; + [newRequest setPACurl:[self PACurl]]; + [newRequest setShouldPresentCredentialsBeforeChallenge:[self shouldPresentCredentialsBeforeChallenge]]; + [newRequest setNumberOfTimesToRetryOnTimeout:[self numberOfTimesToRetryOnTimeout]]; + [newRequest setShouldUseRFC2616RedirectBehaviour:[self shouldUseRFC2616RedirectBehaviour]]; + [newRequest setShouldAttemptPersistentConnection:[self shouldAttemptPersistentConnection]]; + [newRequest setPersistentConnectionTimeoutSeconds:[self persistentConnectionTimeoutSeconds]]; + [newRequest setAuthenticationScheme:[self authenticationScheme]]; + return newRequest; +} + +#pragma mark default time out + ++ (NSTimeInterval)defaultTimeOutSeconds +{ + return defaultTimeOutSeconds; +} + ++ (void)setDefaultTimeOutSeconds:(NSTimeInterval)newTimeOutSeconds +{ + defaultTimeOutSeconds = newTimeOutSeconds; +} + + +#pragma mark client certificate + +- (void)setClientCertificateIdentity:(SecIdentityRef)anIdentity { + if(clientCertificateIdentity) { + CFRelease(clientCertificateIdentity); + } + + clientCertificateIdentity = anIdentity; + + if (clientCertificateIdentity) { + CFRetain(clientCertificateIdentity); + } +} + + +#pragma mark session credentials + ++ (NSMutableArray *)sessionProxyCredentialsStore +{ + [sessionCredentialsLock lock]; + if (!sessionProxyCredentialsStore) { + sessionProxyCredentialsStore = [[NSMutableArray alloc] init]; + } + [sessionCredentialsLock unlock]; + return sessionProxyCredentialsStore; +} + ++ (NSMutableArray *)sessionCredentialsStore +{ + [sessionCredentialsLock lock]; + if (!sessionCredentialsStore) { + sessionCredentialsStore = [[NSMutableArray alloc] init]; + } + [sessionCredentialsLock unlock]; + return sessionCredentialsStore; +} + ++ (void)storeProxyAuthenticationCredentialsInSessionStore:(NSDictionary *)credentials +{ + [sessionCredentialsLock lock]; + [self removeProxyAuthenticationCredentialsFromSessionStore:[credentials objectForKey:@"Credentials"]]; + [[[self class] sessionProxyCredentialsStore] addObject:credentials]; + [sessionCredentialsLock unlock]; +} + ++ (void)storeAuthenticationCredentialsInSessionStore:(NSDictionary *)credentials +{ + [sessionCredentialsLock lock]; + [self removeAuthenticationCredentialsFromSessionStore:[credentials objectForKey:@"Credentials"]]; + [[[self class] sessionCredentialsStore] addObject:credentials]; + [sessionCredentialsLock unlock]; +} + ++ (void)removeProxyAuthenticationCredentialsFromSessionStore:(NSDictionary *)credentials +{ + [sessionCredentialsLock lock]; + NSMutableArray *sessionCredentialsList = [[self class] sessionProxyCredentialsStore]; + NSUInteger i; + for (i=0; i<[sessionCredentialsList count]; i++) { + NSDictionary *theCredentials = [sessionCredentialsList objectAtIndex:i]; + if ([theCredentials objectForKey:@"Credentials"] == credentials) { + [sessionCredentialsList removeObjectAtIndex:i]; + [sessionCredentialsLock unlock]; + return; + } + } + [sessionCredentialsLock unlock]; +} + ++ (void)removeAuthenticationCredentialsFromSessionStore:(NSDictionary *)credentials +{ + [sessionCredentialsLock lock]; + NSMutableArray *sessionCredentialsList = [[self class] sessionCredentialsStore]; + NSUInteger i; + for (i=0; i<[sessionCredentialsList count]; i++) { + NSDictionary *theCredentials = [sessionCredentialsList objectAtIndex:i]; + if ([theCredentials objectForKey:@"Credentials"] == credentials) { + [sessionCredentialsList removeObjectAtIndex:i]; + [sessionCredentialsLock unlock]; + return; + } + } + [sessionCredentialsLock unlock]; +} + +- (NSDictionary *)findSessionProxyAuthenticationCredentials +{ + [sessionCredentialsLock lock]; + NSMutableArray *sessionCredentialsList = [[self class] sessionProxyCredentialsStore]; + for (NSDictionary *theCredentials in sessionCredentialsList) { + if ([[theCredentials objectForKey:@"Host"] isEqualToString:[self proxyHost]] && [[theCredentials objectForKey:@"Port"] intValue] == [self proxyPort]) { + [sessionCredentialsLock unlock]; + return theCredentials; + } + } + [sessionCredentialsLock unlock]; + return nil; +} + + +- (NSDictionary *)findSessionAuthenticationCredentials +{ + [sessionCredentialsLock lock]; + NSMutableArray *sessionCredentialsList = [[self class] sessionCredentialsStore]; + NSURL *requestURL = [self url]; + + BOOL haveFoundExactMatch; + NSDictionary *closeMatch = nil; + + // Loop through all the cached credentials we have, looking for the best match for this request + for (NSDictionary *theCredentials in sessionCredentialsList) { + + haveFoundExactMatch = NO; + NSURL *cachedCredentialsURL = [theCredentials objectForKey:@"URL"]; + + // Find an exact match (same url) + if ([cachedCredentialsURL isEqual:[self url]]) { + haveFoundExactMatch = YES; + + // This is not an exact match for the url, and we already have a close match we can use + } else if (closeMatch) { + continue; + + // Find a close match (same host, scheme and port) + } else if ([[cachedCredentialsURL host] isEqualToString:[requestURL host]] && ([cachedCredentialsURL port] == [requestURL port] || ([requestURL port] && [[cachedCredentialsURL port] isEqualToNumber:[requestURL port]])) && [[cachedCredentialsURL scheme] isEqualToString:[requestURL scheme]]) { + } else { + continue; + } + + // Just a sanity check to ensure we never choose credentials from a different realm. Can't really do more than that, as either this request or the stored credentials may not have a realm when the other does + if ([self authenticationRealm] && ([theCredentials objectForKey:@"AuthenticationRealm"] && ![[theCredentials objectForKey:@"AuthenticationRealm"] isEqualToString:[self authenticationRealm]])) { + continue; + } + + // If we have a username and password set on the request, check that they are the same as the cached ones + if ([self username] && [self password]) { + NSDictionary *usernameAndPassword = [theCredentials objectForKey:@"Credentials"]; + NSString *storedUsername = [usernameAndPassword objectForKey:(NSString *)kCFHTTPAuthenticationUsername]; + NSString *storedPassword = [usernameAndPassword objectForKey:(NSString *)kCFHTTPAuthenticationPassword]; + if (![storedUsername isEqualToString:[self username]] || ![storedPassword isEqualToString:[self password]]) { + continue; + } + } + + // If we have an exact match for the url, use those credentials + if (haveFoundExactMatch) { + [sessionCredentialsLock unlock]; + return theCredentials; + } + + // We have no exact match, let's remember that we have a good match for this server, and we'll use it at the end if we don't find an exact match + closeMatch = theCredentials; + } + [sessionCredentialsLock unlock]; + + // Return credentials that matched on host, port and scheme, or nil if we didn't find any + return closeMatch; +} + +#pragma mark keychain storage + ++ (void)saveCredentials:(NSURLCredential *)credentials forHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm +{ + NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithHost:host port:port protocol:protocol realm:realm authenticationMethod:NSURLAuthenticationMethodDefault] autorelease]; + [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credentials forProtectionSpace:protectionSpace]; +} + ++ (void)saveCredentials:(NSURLCredential *)credentials forProxy:(NSString *)host port:(int)port realm:(NSString *)realm +{ + NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithProxyHost:host port:port type:NSURLProtectionSpaceHTTPProxy realm:realm authenticationMethod:NSURLAuthenticationMethodDefault] autorelease]; + [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credentials forProtectionSpace:protectionSpace]; +} + ++ (NSURLCredential *)savedCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm +{ + NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithHost:host port:port protocol:protocol realm:realm authenticationMethod:NSURLAuthenticationMethodDefault] autorelease]; + return [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:protectionSpace]; +} + ++ (NSURLCredential *)savedCredentialsForProxy:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm +{ + NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithProxyHost:host port:port type:NSURLProtectionSpaceHTTPProxy realm:realm authenticationMethod:NSURLAuthenticationMethodDefault] autorelease]; + return [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:protectionSpace]; +} + ++ (void)removeCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm +{ + NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithHost:host port:port protocol:protocol realm:realm authenticationMethod:NSURLAuthenticationMethodDefault] autorelease]; + NSURLCredential *credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:protectionSpace]; + if (credential) { + [[NSURLCredentialStorage sharedCredentialStorage] removeCredential:credential forProtectionSpace:protectionSpace]; + } +} + ++ (void)removeCredentialsForProxy:(NSString *)host port:(int)port realm:(NSString *)realm +{ + NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithProxyHost:host port:port type:NSURLProtectionSpaceHTTPProxy realm:realm authenticationMethod:NSURLAuthenticationMethodDefault] autorelease]; + NSURLCredential *credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:protectionSpace]; + if (credential) { + [[NSURLCredentialStorage sharedCredentialStorage] removeCredential:credential forProtectionSpace:protectionSpace]; + } +} + ++ (NSMutableArray *)sessionCookies +{ + [sessionCookiesLock lock]; + if (!sessionCookies) { + [ASIHTTPRequest setSessionCookies:[NSMutableArray array]]; + } + NSMutableArray *cookies = [[sessionCookies retain] autorelease]; + [sessionCookiesLock unlock]; + return cookies; +} + ++ (void)setSessionCookies:(NSMutableArray *)newSessionCookies +{ + [sessionCookiesLock lock]; + // Remove existing cookies from the persistent store + for (NSHTTPCookie *cookie in sessionCookies) { + [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; + } + [sessionCookies release]; + sessionCookies = [newSessionCookies retain]; + [sessionCookiesLock unlock]; +} + ++ (void)addSessionCookie:(NSHTTPCookie *)newCookie +{ + [sessionCookiesLock lock]; + NSHTTPCookie *cookie; + NSUInteger i; + NSUInteger max = [[ASIHTTPRequest sessionCookies] count]; + for (i=0; i 0) { + if ([self readStreamIsScheduled]) { + [self unscheduleReadStream]; + #if DEBUG_THROTTLING + NSLog(@"[THROTTLING] Sleeping request %@ until after %@",self,throttleWakeUpTime); + #endif + } + } else { + if (![self readStreamIsScheduled]) { + [self scheduleReadStream]; + #if DEBUG_THROTTLING + NSLog(@"[THROTTLING] Waking up request %@",self); + #endif + } + } + } + [bandwidthThrottlingLock unlock]; + + // Bandwidth throttling must have been turned off since we last looked, let's re-schedule the stream + } else if (![self readStreamIsScheduled]) { + [self scheduleReadStream]; + } +} + ++ (BOOL)isBandwidthThrottled +{ +#if TARGET_OS_IPHONE + [bandwidthThrottlingLock lock]; + + BOOL throttle = isBandwidthThrottled || (!shouldThrottleBandwithForWWANOnly && (maxBandwidthPerSecond > 0)); + [bandwidthThrottlingLock unlock]; + return throttle; +#else + [bandwidthThrottlingLock lock]; + BOOL throttle = (maxBandwidthPerSecond > 0); + [bandwidthThrottlingLock unlock]; + return throttle; +#endif +} + ++ (unsigned long)maxBandwidthPerSecond +{ + [bandwidthThrottlingLock lock]; + unsigned long amount = maxBandwidthPerSecond; + [bandwidthThrottlingLock unlock]; + return amount; +} + ++ (void)setMaxBandwidthPerSecond:(unsigned long)bytes +{ + [bandwidthThrottlingLock lock]; + maxBandwidthPerSecond = bytes; + [bandwidthThrottlingLock unlock]; +} + ++ (void)incrementBandwidthUsedInLastSecond:(unsigned long)bytes +{ + [bandwidthThrottlingLock lock]; + bandwidthUsedInLastSecond += bytes; + [bandwidthThrottlingLock unlock]; +} + ++ (void)recordBandwidthUsage +{ + if (bandwidthUsedInLastSecond == 0) { + [bandwidthUsageTracker removeAllObjects]; + } else { + NSTimeInterval interval = [bandwidthMeasurementDate timeIntervalSinceNow]; + while ((interval < 0 || [bandwidthUsageTracker count] > 5) && [bandwidthUsageTracker count] > 0) { + [bandwidthUsageTracker removeObjectAtIndex:0]; + interval++; + } + } + #if DEBUG_THROTTLING + NSLog(@"[THROTTLING] ===Used: %u bytes of bandwidth in last measurement period===",bandwidthUsedInLastSecond); + #endif + [bandwidthUsageTracker addObject:[NSNumber numberWithUnsignedLong:bandwidthUsedInLastSecond]]; + [bandwidthMeasurementDate release]; + bandwidthMeasurementDate = [[NSDate dateWithTimeIntervalSinceNow:1] retain]; + bandwidthUsedInLastSecond = 0; + + NSUInteger measurements = [bandwidthUsageTracker count]; + unsigned long totalBytes = 0; + for (NSNumber *bytes in bandwidthUsageTracker) { + totalBytes += [bytes unsignedLongValue]; + } + averageBandwidthUsedPerSecond = totalBytes/measurements; +} + ++ (unsigned long)averageBandwidthUsedPerSecond +{ + [bandwidthThrottlingLock lock]; + unsigned long amount = averageBandwidthUsedPerSecond; + [bandwidthThrottlingLock unlock]; + return amount; +} + ++ (void)measureBandwidthUsage +{ + // Other requests may have to wait for this lock if we're sleeping, but this is fine, since in that case we already know they shouldn't be sending or receiving data + [bandwidthThrottlingLock lock]; + + if (!bandwidthMeasurementDate || [bandwidthMeasurementDate timeIntervalSinceNow] < -0) { + [ASIHTTPRequest recordBandwidthUsage]; + } + + // Are we performing bandwidth throttling? + if ( + #if TARGET_OS_IPHONE + isBandwidthThrottled || (!shouldThrottleBandwithForWWANOnly && (maxBandwidthPerSecond)) + #else + maxBandwidthPerSecond + #endif + ) { + // How much data can we still send or receive this second? + long long bytesRemaining = (long long)maxBandwidthPerSecond - (long long)bandwidthUsedInLastSecond; + + // Have we used up our allowance? + if (bytesRemaining < 0) { + + // Yes, put this request to sleep until a second is up, with extra added punishment sleeping time for being very naughty (we have used more bandwidth than we were allowed) + double extraSleepyTime = (-bytesRemaining/(maxBandwidthPerSecond*1.0)); + [throttleWakeUpTime release]; + throttleWakeUpTime = [[NSDate alloc] initWithTimeInterval:extraSleepyTime sinceDate:bandwidthMeasurementDate]; + } + } + [bandwidthThrottlingLock unlock]; +} + ++ (unsigned long)maxUploadReadLength +{ + [bandwidthThrottlingLock lock]; + + // We'll split our bandwidth allowance into 4 (which is the default for an ASINetworkQueue's max concurrent operations count) to give all running requests a fighting chance of reading data this cycle + long long toRead = maxBandwidthPerSecond/4; + if (maxBandwidthPerSecond > 0 && (bandwidthUsedInLastSecond + toRead > maxBandwidthPerSecond)) { + toRead = (long long)maxBandwidthPerSecond-(long long)bandwidthUsedInLastSecond; + if (toRead < 0) { + toRead = 0; + } + } + + if (toRead == 0 || !bandwidthMeasurementDate || [bandwidthMeasurementDate timeIntervalSinceNow] < -0) { + [throttleWakeUpTime release]; + throttleWakeUpTime = [bandwidthMeasurementDate retain]; + } + [bandwidthThrottlingLock unlock]; + return (unsigned long)toRead; +} + + +#if TARGET_OS_IPHONE ++ (void)setShouldThrottleBandwidthForWWAN:(BOOL)throttle +{ + if (throttle) { + [ASIHTTPRequest throttleBandwidthForWWANUsingLimit:ASIWWANBandwidthThrottleAmount]; + } else { + [ASIHTTPRequest unsubscribeFromNetworkReachabilityNotifications]; + [ASIHTTPRequest setMaxBandwidthPerSecond:0]; + [bandwidthThrottlingLock lock]; + isBandwidthThrottled = NO; + shouldThrottleBandwithForWWANOnly = NO; + [bandwidthThrottlingLock unlock]; + } +} + ++ (void)throttleBandwidthForWWANUsingLimit:(unsigned long)limit +{ + [bandwidthThrottlingLock lock]; + shouldThrottleBandwithForWWANOnly = YES; + maxBandwidthPerSecond = limit; + [ASIHTTPRequest registerForNetworkReachabilityNotifications]; + [bandwidthThrottlingLock unlock]; + [ASIHTTPRequest reachabilityChanged:nil]; +} + +#pragma mark reachability + ++ (void)registerForNetworkReachabilityNotifications +{ + [[Reachability reachabilityForInternetConnection] startNotifier]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil]; +} + + ++ (void)unsubscribeFromNetworkReachabilityNotifications +{ + [[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil]; +} + ++ (BOOL)isNetworkReachableViaWWAN +{ + return ([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] == ReachableViaWWAN); +} + ++ (void)reachabilityChanged:(NSNotification *)note +{ + [bandwidthThrottlingLock lock]; + isBandwidthThrottled = [ASIHTTPRequest isNetworkReachableViaWWAN]; + [bandwidthThrottlingLock unlock]; +} +#endif + +#pragma mark queue + +// Returns the shared queue ++ (NSOperationQueue *)sharedQueue +{ + return [[sharedQueue retain] autorelease]; +} + +#pragma mark cache + ++ (void)setDefaultCache:(id )cache +{ + @synchronized (self) { + [cache retain]; + [defaultCache release]; + defaultCache = cache; + } +} + ++ (id )defaultCache +{ + @synchronized(self) { + return [[defaultCache retain] autorelease]; + } + return nil; +} + + +#pragma mark network activity + ++ (BOOL)isNetworkInUse +{ + [connectionsLock lock]; + BOOL inUse = (runningRequestCount > 0); + [connectionsLock unlock]; + return inUse; +} + ++ (void)setShouldUpdateNetworkActivityIndicator:(BOOL)shouldUpdate +{ + [connectionsLock lock]; + shouldUpdateNetworkActivityIndicator = shouldUpdate; + [connectionsLock unlock]; +} + ++ (void)showNetworkActivityIndicator +{ +#if TARGET_OS_IPHONE + [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; +#endif +} + ++ (void)hideNetworkActivityIndicator +{ +#if TARGET_OS_IPHONE + [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; +#endif +} + + +/* Always called on main thread */ ++ (void)hideNetworkActivityIndicatorAfterDelay +{ + [self performSelector:@selector(hideNetworkActivityIndicatorIfNeeeded) withObject:nil afterDelay:0.5]; +} + ++ (void)hideNetworkActivityIndicatorIfNeeeded +{ + [connectionsLock lock]; + if (runningRequestCount == 0) { + [self hideNetworkActivityIndicator]; + } + [connectionsLock unlock]; +} + + +#pragma mark threading behaviour + +// In the default implementation, all requests run in a single background thread +// Advanced users only: Override this method in a subclass for a different threading behaviour +// Eg: return [NSThread mainThread] to run all requests in the main thread +// Alternatively, you can create a thread on demand, or manage a pool of threads +// Threads returned by this method will need to run the runloop in default mode (eg CFRunLoopRun()) +// Requests will stop the runloop when they complete +// If you have multiple requests sharing the thread or you want to re-use the thread, you'll need to restart the runloop ++ (NSThread *)threadForRequest:(ASIHTTPRequest *)request +{ + if (networkThread == nil) { + @synchronized(self) { + if (networkThread == nil) { + networkThread = [[NSThread alloc] initWithTarget:self selector:@selector(runRequests) object:nil]; + [networkThread start]; + } + } + } + return networkThread; +} + ++ (void)runRequests +{ + // Should keep the runloop from exiting + CFRunLoopSourceContext context = {0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + CFRunLoopSourceRef source = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &context); + CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode); + + BOOL runAlways = YES; // Introduced to cheat Static Analyzer + while (runAlways) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + CFRunLoopRun(); + [pool drain]; + } + + // Should never be called, but anyway + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode); + CFRelease(source); +} + +#pragma mark miscellany + +#if TARGET_OS_IPHONE ++ (BOOL)isMultitaskingSupported +{ + BOOL multiTaskingSupported = NO; + if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) { + multiTaskingSupported = [(id)[UIDevice currentDevice] isMultitaskingSupported]; + } + return multiTaskingSupported; +} +#endif + +// From: http://www.cocoadev.com/index.pl?BaseSixtyFour + ++ (NSString*)base64forData:(NSData*)theData { + + const uint8_t* input = (const uint8_t*)[theData bytes]; + NSInteger length = [theData length]; + + static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + + NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4]; + uint8_t* output = (uint8_t*)data.mutableBytes; + + NSInteger i,i2; + for (i=0; i < length; i += 3) { + NSInteger value = 0; + for (i2=0; i2<3; i2++) { + value <<= 8; + if (i+i2 < length) { + value |= (0xFF & input[i+i2]); + } + } + + NSInteger theIndex = (i / 3) * 4; + output[theIndex + 0] = table[(value >> 18) & 0x3F]; + output[theIndex + 1] = table[(value >> 12) & 0x3F]; + output[theIndex + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '='; + output[theIndex + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '='; + } + + return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]; +} + ++ (NSDate *)expiryDateForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge +{ + NSDictionary *responseHeaders = [request responseHeaders]; + + // If we weren't given a custom max-age, lets look for one in the response headers + if (!maxAge) { + NSString *cacheControl = [[responseHeaders objectForKey:@"Cache-Control"] lowercaseString]; + if (cacheControl) { + NSScanner *scanner = [NSScanner scannerWithString:cacheControl]; + [scanner scanUpToString:@"max-age" intoString:NULL]; + if ([scanner scanString:@"max-age" intoString:NULL]) { + [scanner scanString:@"=" intoString:NULL]; + [scanner scanDouble:&maxAge]; + } + } + } + + // RFC 2612 says max-age must override any Expires header + if (maxAge) { + return [[NSDate date] addTimeInterval:maxAge]; + } else { + NSString *expires = [responseHeaders objectForKey:@"Expires"]; + if (expires) { + return [ASIHTTPRequest dateFromRFC1123String:expires]; + } + } + return nil; +} + +// Based on hints from http://stackoverflow.com/questions/1850824/parsing-a-rfc-822-date-with-nsdateformatter ++ (NSDate *)dateFromRFC1123String:(NSString *)string +{ + NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; + [formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; + // Does the string include a week day? + NSString *day = @""; + if ([string rangeOfString:@","].location != NSNotFound) { + day = @"EEE, "; + } + // Does the string include seconds? + NSString *seconds = @""; + if ([[string componentsSeparatedByString:@":"] count] == 3) { + seconds = @":ss"; + } + [formatter setDateFormat:[NSString stringWithFormat:@"%@dd MMM yyyy HH:mm%@ z",day,seconds]]; + return [formatter dateFromString:string]; +} + ++ (void)parseMimeType:(NSString **)mimeType andResponseEncoding:(NSStringEncoding *)stringEncoding fromContentType:(NSString *)contentType +{ + if (!contentType) { + return; + } + NSScanner *charsetScanner = [NSScanner scannerWithString: contentType]; + if (![charsetScanner scanUpToString:@";" intoString:mimeType] || [charsetScanner scanLocation] == [contentType length]) { + *mimeType = [contentType stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + return; + } + *mimeType = [*mimeType stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + NSString *charsetSeparator = @"charset="; + NSString *IANAEncoding = nil; + + if ([charsetScanner scanUpToString: charsetSeparator intoString: NULL] && [charsetScanner scanLocation] < [contentType length]) { + [charsetScanner setScanLocation: [charsetScanner scanLocation] + [charsetSeparator length]]; + [charsetScanner scanUpToString: @";" intoString: &IANAEncoding]; + } + + if (IANAEncoding) { + CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)IANAEncoding); + if (cfEncoding != kCFStringEncodingInvalidId) { + *stringEncoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding); + } + } +} + +#pragma mark - +#pragma mark blocks +#if NS_BLOCKS_AVAILABLE +- (void)setStartedBlock:(ASIBasicBlock)aStartedBlock +{ + [startedBlock release]; + startedBlock = [aStartedBlock copy]; +} + +- (void)setHeadersReceivedBlock:(ASIHeadersBlock)aReceivedBlock +{ + [headersReceivedBlock release]; + headersReceivedBlock = [aReceivedBlock copy]; +} + +- (void)setCompletionBlock:(ASIBasicBlock)aCompletionBlock +{ + [completionBlock release]; + completionBlock = [aCompletionBlock copy]; +} + +- (void)setFailedBlock:(ASIBasicBlock)aFailedBlock +{ + [failureBlock release]; + failureBlock = [aFailedBlock copy]; +} + +- (void)setBytesReceivedBlock:(ASIProgressBlock)aBytesReceivedBlock +{ + [bytesReceivedBlock release]; + bytesReceivedBlock = [aBytesReceivedBlock copy]; +} + +- (void)setBytesSentBlock:(ASIProgressBlock)aBytesSentBlock +{ + [bytesSentBlock release]; + bytesSentBlock = [aBytesSentBlock copy]; +} + +- (void)setDownloadSizeIncrementedBlock:(ASISizeBlock)aDownloadSizeIncrementedBlock{ + [downloadSizeIncrementedBlock release]; + downloadSizeIncrementedBlock = [aDownloadSizeIncrementedBlock copy]; +} + +- (void)setUploadSizeIncrementedBlock:(ASISizeBlock)anUploadSizeIncrementedBlock +{ + [uploadSizeIncrementedBlock release]; + uploadSizeIncrementedBlock = [anUploadSizeIncrementedBlock copy]; +} + +- (void)setDataReceivedBlock:(ASIDataBlock)aReceivedBlock +{ + [dataReceivedBlock release]; + dataReceivedBlock = [aReceivedBlock copy]; +} + +- (void)setAuthenticationNeededBlock:(ASIBasicBlock)anAuthenticationBlock +{ + [authenticationNeededBlock release]; + authenticationNeededBlock = [anAuthenticationBlock copy]; +} +- (void)setProxyAuthenticationNeededBlock:(ASIBasicBlock)aProxyAuthenticationBlock +{ + [proxyAuthenticationNeededBlock release]; + proxyAuthenticationNeededBlock = [aProxyAuthenticationBlock copy]; +} +- (void)setRequestRedirectedBlock:(ASIBasicBlock)aRedirectBlock +{ + [requestRedirectedBlock release]; + requestRedirectedBlock = [aRedirectBlock copy]; +} +#endif + +#pragma mark === + +@synthesize username; +@synthesize password; +@synthesize userAgent; +@synthesize domain; +@synthesize proxyUsername; +@synthesize proxyPassword; +@synthesize proxyDomain; +@synthesize url; +@synthesize originalURL; +@synthesize delegate; +@synthesize queue; +@synthesize uploadProgressDelegate; +@synthesize downloadProgressDelegate; +@synthesize useKeychainPersistence; +@synthesize useSessionPersistence; +@synthesize useCookiePersistence; +@synthesize downloadDestinationPath; +@synthesize temporaryFileDownloadPath; +@synthesize temporaryUncompressedDataDownloadPath; +@synthesize didStartSelector; +@synthesize didReceiveResponseHeadersSelector; +@synthesize willRedirectSelector; +@synthesize didFinishSelector; +@synthesize didFailSelector; +@synthesize didReceiveDataSelector; +@synthesize authenticationRealm; +@synthesize proxyAuthenticationRealm; +@synthesize error; +@synthesize complete; +@synthesize requestHeaders; +@synthesize responseHeaders; +@synthesize responseCookies; +@synthesize requestCookies; +@synthesize requestCredentials; +@synthesize responseStatusCode; +@synthesize rawResponseData; +@synthesize lastActivityTime; +@synthesize timeOutSeconds; +@synthesize requestMethod; +@synthesize postBody; +@synthesize compressedPostBody; +@synthesize contentLength; +@synthesize partialDownloadSize; +@synthesize postLength; +@synthesize shouldResetDownloadProgress; +@synthesize shouldResetUploadProgress; +@synthesize mainRequest; +@synthesize totalBytesRead; +@synthesize totalBytesSent; +@synthesize showAccurateProgress; +@synthesize uploadBufferSize; +@synthesize defaultResponseEncoding; +@synthesize responseEncoding; +@synthesize allowCompressedResponse; +@synthesize allowResumeForFileDownloads; +@synthesize userInfo; +@synthesize tag; +@synthesize postBodyFilePath; +@synthesize compressedPostBodyFilePath; +@synthesize postBodyWriteStream; +@synthesize postBodyReadStream; +@synthesize shouldStreamPostDataFromDisk; +@synthesize didCreateTemporaryPostDataFile; +@synthesize useHTTPVersionOne; +@synthesize lastBytesRead; +@synthesize lastBytesSent; +@synthesize cancelledLock; +@synthesize haveBuiltPostBody; +@synthesize fileDownloadOutputStream; +@synthesize inflatedFileDownloadOutputStream; +@synthesize authenticationRetryCount; +@synthesize proxyAuthenticationRetryCount; +@synthesize updatedProgress; +@synthesize shouldRedirect; +@synthesize validatesSecureCertificate; +@synthesize needsRedirect; +@synthesize redirectCount; +@synthesize shouldCompressRequestBody; +@synthesize proxyCredentials; +@synthesize proxyHost; +@synthesize proxyPort; +@synthesize proxyType; +@synthesize PACurl; +@synthesize authenticationScheme; +@synthesize proxyAuthenticationScheme; +@synthesize shouldPresentAuthenticationDialog; +@synthesize shouldPresentProxyAuthenticationDialog; +@synthesize authenticationNeeded; +@synthesize responseStatusMessage; +@synthesize shouldPresentCredentialsBeforeChallenge; +@synthesize haveBuiltRequestHeaders; +@synthesize inProgress; +@synthesize numberOfTimesToRetryOnTimeout; +@synthesize retryCount; +@synthesize willRetryRequest; +@synthesize shouldAttemptPersistentConnection; +@synthesize persistentConnectionTimeoutSeconds; +@synthesize connectionCanBeReused; +@synthesize connectionInfo; +@synthesize readStream; +@synthesize readStreamIsScheduled; +@synthesize shouldUseRFC2616RedirectBehaviour; +@synthesize downloadComplete; +@synthesize requestID; +@synthesize runLoopMode; +@synthesize statusTimer; +@synthesize downloadCache; +@synthesize cachePolicy; +@synthesize cacheStoragePolicy; +@synthesize didUseCachedResponse; +@synthesize secondsToCache; +@synthesize clientCertificates; +@synthesize redirectURL; +#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 +@synthesize shouldContinueWhenAppEntersBackground; +#endif +@synthesize dataDecompressor; +@synthesize shouldWaitToInflateCompressedResponses; + +@synthesize isPACFileRequest; +@synthesize PACFileRequest; +@synthesize PACFileReadStream; +@synthesize PACFileData; + +@synthesize isSynchronous; +@end diff --git a/client/osx/ASIHTTPRequestConfig.h b/client/osx/ASIHTTPRequestConfig.h new file mode 100644 index 0000000..cdaa8a4 --- /dev/null +++ b/client/osx/ASIHTTPRequestConfig.h @@ -0,0 +1,37 @@ +// +// ASIHTTPRequestConfig.h +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 14/12/2009. +// Copyright 2009 All-Seeing Interactive. All rights reserved. +// + + +// ====== +// Debug output configuration options +// ====== + +// When set to 1 ASIHTTPRequests will print information about what a request is doing +#ifndef DEBUG_REQUEST_STATUS + #define DEBUG_REQUEST_STATUS 0 +#endif + +// When set to 1, ASIFormDataRequests will print information about the request body to the console +#ifndef DEBUG_FORM_DATA_REQUEST + #define DEBUG_FORM_DATA_REQUEST 0 +#endif + +// When set to 1, ASIHTTPRequests will print information about bandwidth throttling to the console +#ifndef DEBUG_THROTTLING + #define DEBUG_THROTTLING 0 +#endif + +// When set to 1, ASIHTTPRequests will print information about persistent connections to the console +#ifndef DEBUG_PERSISTENT_CONNECTIONS + #define DEBUG_PERSISTENT_CONNECTIONS 0 +#endif + +// When set to 1, ASIHTTPRequests will print information about HTTP authentication (Basic, Digest or NTLM) to the console +#ifndef DEBUG_HTTP_AUTHENTICATION +#define DEBUG_HTTP_AUTHENTICATION 0 +#endif diff --git a/client/osx/ASIHTTPRequestDelegate.h b/client/osx/ASIHTTPRequestDelegate.h new file mode 100644 index 0000000..c495a27 --- /dev/null +++ b/client/osx/ASIHTTPRequestDelegate.h @@ -0,0 +1,35 @@ +// +// ASIHTTPRequestDelegate.h +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 13/04/2010. +// Copyright 2010 All-Seeing Interactive. All rights reserved. +// + +@class ASIHTTPRequest; + +@protocol ASIHTTPRequestDelegate + +@optional + +// These are the default delegate methods for request status +// You can use different ones by setting didStartSelector / didFinishSelector / didFailSelector +- (void)requestStarted:(ASIHTTPRequest *)request; +- (void)request:(ASIHTTPRequest *)request didReceiveResponseHeaders:(NSDictionary *)responseHeaders; +- (void)request:(ASIHTTPRequest *)request willRedirectToURL:(NSURL *)newURL; +- (void)requestFinished:(ASIHTTPRequest *)request; +- (void)requestFailed:(ASIHTTPRequest *)request; +- (void)requestRedirected:(ASIHTTPRequest *)request; + +// When a delegate implements this method, it is expected to process all incoming data itself +// This means that responseData / responseString / downloadDestinationPath etc are ignored +// You can have the request call a different method by setting didReceiveDataSelector +- (void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data; + +// If a delegate implements one of these, it will be asked to supply credentials when none are available +// The delegate can then either restart the request ([request retryUsingSuppliedCredentials]) once credentials have been set +// or cancel it ([request cancelAuthentication]) +- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request; +- (void)proxyAuthenticationNeededForRequest:(ASIHTTPRequest *)request; + +@end diff --git a/client/osx/ASIInputStream.h b/client/osx/ASIInputStream.h new file mode 100644 index 0000000..7b9f93e --- /dev/null +++ b/client/osx/ASIInputStream.h @@ -0,0 +1,26 @@ +// +// ASIInputStream.h +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 10/08/2009. +// Copyright 2009 All-Seeing Interactive. All rights reserved. +// + +#import + +@class ASIHTTPRequest; + +// This is a wrapper for NSInputStream that pretends to be an NSInputStream itself +// Subclassing NSInputStream seems to be tricky, and may involve overriding undocumented methods, so we'll cheat instead. +// It is used by ASIHTTPRequest whenever we have a request body, and handles measuring and throttling the bandwidth used for uploading + +@interface ASIInputStream : NSObject { + NSInputStream *stream; + ASIHTTPRequest *request; +} ++ (id)inputStreamWithFileAtPath:(NSString *)path request:(ASIHTTPRequest *)request; ++ (id)inputStreamWithData:(NSData *)data request:(ASIHTTPRequest *)request; + +@property (retain, nonatomic) NSInputStream *stream; +@property (assign, nonatomic) ASIHTTPRequest *request; +@end diff --git a/client/osx/ASIInputStream.m b/client/osx/ASIInputStream.m new file mode 100644 index 0000000..d2b8428 --- /dev/null +++ b/client/osx/ASIInputStream.m @@ -0,0 +1,138 @@ +// +// ASIInputStream.m +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 10/08/2009. +// Copyright 2009 All-Seeing Interactive. All rights reserved. +// + +#import "ASIInputStream.h" +#import "ASIHTTPRequest.h" + +// Used to ensure only one request can read data at once +static NSLock *readLock = nil; + +@implementation ASIInputStream + ++ (void)initialize +{ + if (self == [ASIInputStream class]) { + readLock = [[NSLock alloc] init]; + } +} + ++ (id)inputStreamWithFileAtPath:(NSString *)path request:(ASIHTTPRequest *)theRequest +{ + ASIInputStream *theStream = [[[self alloc] init] autorelease]; + [theStream setRequest:theRequest]; + [theStream setStream:[NSInputStream inputStreamWithFileAtPath:path]]; + return theStream; +} + ++ (id)inputStreamWithData:(NSData *)data request:(ASIHTTPRequest *)theRequest +{ + ASIInputStream *theStream = [[[self alloc] init] autorelease]; + [theStream setRequest:theRequest]; + [theStream setStream:[NSInputStream inputStreamWithData:data]]; + return theStream; +} + +- (void)dealloc +{ + [stream release]; + [super dealloc]; +} + +// Called when CFNetwork wants to read more of our request body +// When throttling is on, we ask ASIHTTPRequest for the maximum amount of data we can read +- (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len +{ + [readLock lock]; + unsigned long toRead = len; + if ([ASIHTTPRequest isBandwidthThrottled]) { + toRead = [ASIHTTPRequest maxUploadReadLength]; + if (toRead > len) { + toRead = len; + } else if (toRead == 0) { + toRead = 1; + } + [request performThrottling]; + } + [readLock unlock]; + NSInteger rv = [stream read:buffer maxLength:toRead]; + if (rv > 0) + [ASIHTTPRequest incrementBandwidthUsedInLastSecond:rv]; + return rv; +} + +/* + * Implement NSInputStream mandatory methods to make sure they are implemented + * (necessary for MacRuby for example) and avoid the overhead of method + * forwarding for these common methods. + */ +- (void)open +{ + [stream open]; +} + +- (void)close +{ + [stream close]; +} + +- (id)delegate +{ + return [stream delegate]; +} + +- (void)setDelegate:(id)delegate +{ + [stream setDelegate:delegate]; +} + +- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode +{ + [stream scheduleInRunLoop:aRunLoop forMode:mode]; +} + +- (void)removeFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode +{ + [stream removeFromRunLoop:aRunLoop forMode:mode]; +} + +- (id)propertyForKey:(NSString *)key +{ + return [stream propertyForKey:key]; +} + +- (BOOL)setProperty:(id)property forKey:(NSString *)key +{ + return [stream setProperty:property forKey:key]; +} + +- (NSStreamStatus)streamStatus +{ + return [stream streamStatus]; +} + +- (NSError *)streamError +{ + return [stream streamError]; +} + +// If we get asked to perform a method we don't have (probably internal ones), +// we'll just forward the message to our stream + +- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector +{ + return [stream methodSignatureForSelector:aSelector]; +} + +- (void)forwardInvocation:(NSInvocation *)anInvocation +{ + [anInvocation invokeWithTarget:stream]; +} + +@synthesize stream; +@synthesize request; +@end diff --git a/client/osx/ASINetworkQueue.h b/client/osx/ASINetworkQueue.h new file mode 100644 index 0000000..787f391 --- /dev/null +++ b/client/osx/ASINetworkQueue.h @@ -0,0 +1,108 @@ +// +// ASINetworkQueue.h +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 07/11/2008. +// Copyright 2008-2009 All-Seeing Interactive. All rights reserved. +// + +#import +#import "ASIHTTPRequestDelegate.h" +#import "ASIProgressDelegate.h" + +@interface ASINetworkQueue : NSOperationQueue { + + // Delegate will get didFail + didFinish messages (if set) + id delegate; + + // Will be called when a request starts with the request as the argument + SEL requestDidStartSelector; + + // Will be called when a request receives response headers + // Should take the form request:didRecieveResponseHeaders:, where the first argument is the request, and the second the headers dictionary + SEL requestDidReceiveResponseHeadersSelector; + + // Will be called when a request is about to redirect + // Should take the form request:willRedirectToURL:, where the first argument is the request, and the second the new url + SEL requestWillRedirectSelector; + + // Will be called when a request completes with the request as the argument + SEL requestDidFinishSelector; + + // Will be called when a request fails with the request as the argument + SEL requestDidFailSelector; + + // Will be called when the queue finishes with the queue as the argument + SEL queueDidFinishSelector; + + // Upload progress indicator, probably an NSProgressIndicator or UIProgressView + id uploadProgressDelegate; + + // Total amount uploaded so far for all requests in this queue + unsigned long long bytesUploadedSoFar; + + // Total amount to be uploaded for all requests in this queue - requests add to this figure as they work out how much data they have to transmit + unsigned long long totalBytesToUpload; + + // Download progress indicator, probably an NSProgressIndicator or UIProgressView + id downloadProgressDelegate; + + // Total amount downloaded so far for all requests in this queue + unsigned long long bytesDownloadedSoFar; + + // Total amount to be downloaded for all requests in this queue - requests add to this figure as they receive Content-Length headers + unsigned long long totalBytesToDownload; + + // When YES, the queue will cancel all requests when a request fails. Default is YES + BOOL shouldCancelAllRequestsOnFailure; + + //Number of real requests (excludes HEAD requests created to manage showAccurateProgress) + int requestsCount; + + // When NO, this request will only update the progress indicator when it completes + // When YES, this request will update the progress indicator according to how much data it has received so far + // When YES, the queue will first perform HEAD requests for all GET requests in the queue, so it can calculate the total download size before it starts + // NO means better performance, because it skips this step for GET requests, and it won't waste time updating the progress indicator until a request completes + // Set to YES if the size of a requests in the queue varies greatly for much more accurate results + // Default for requests in the queue is NO + BOOL showAccurateProgress; + + // Storage container for additional queue information. + NSDictionary *userInfo; + +} + +// Convenience constructor ++ (id)queue; + +// Call this to reset a queue - it will cancel all operations, clear delegates, and suspend operation +- (void)reset; + +// Used internally to manage HEAD requests when showAccurateProgress is YES, do not use! +- (void)addHEADOperation:(NSOperation *)operation; + +// All ASINetworkQueues are paused when created so that total size can be calculated before the queue starts +// This method will start the queue +- (void)go; + +@property (assign, nonatomic, setter=setUploadProgressDelegate:) id uploadProgressDelegate; +@property (assign, nonatomic, setter=setDownloadProgressDelegate:) id downloadProgressDelegate; + +@property (assign) SEL requestDidStartSelector; +@property (assign) SEL requestDidReceiveResponseHeadersSelector; +@property (assign) SEL requestWillRedirectSelector; +@property (assign) SEL requestDidFinishSelector; +@property (assign) SEL requestDidFailSelector; +@property (assign) SEL queueDidFinishSelector; +@property (assign) BOOL shouldCancelAllRequestsOnFailure; +@property (assign) id delegate; +@property (assign) BOOL showAccurateProgress; +@property (assign, readonly) int requestsCount; +@property (retain) NSDictionary *userInfo; + +@property (assign) unsigned long long bytesUploadedSoFar; +@property (assign) unsigned long long totalBytesToUpload; +@property (assign) unsigned long long bytesDownloadedSoFar; +@property (assign) unsigned long long totalBytesToDownload; + +@end diff --git a/client/osx/ASINetworkQueue.m b/client/osx/ASINetworkQueue.m new file mode 100644 index 0000000..b24076d --- /dev/null +++ b/client/osx/ASINetworkQueue.m @@ -0,0 +1,343 @@ +// +// ASINetworkQueue.m +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 07/11/2008. +// Copyright 2008-2009 All-Seeing Interactive. All rights reserved. +// + +#import "ASINetworkQueue.h" +#import "ASIHTTPRequest.h" + +// Private stuff +@interface ASINetworkQueue () + - (void)resetProgressDelegate:(id *)progressDelegate; + @property (assign) int requestsCount; +@end + +@implementation ASINetworkQueue + +- (id)init +{ + self = [super init]; + [self setShouldCancelAllRequestsOnFailure:YES]; + [self setMaxConcurrentOperationCount:4]; + [self setSuspended:YES]; + + return self; +} + ++ (id)queue +{ + return [[[self alloc] init] autorelease]; +} + +- (void)dealloc +{ + //We need to clear the queue on any requests that haven't got around to cleaning up yet, as otherwise they'll try to let us know if something goes wrong, and we'll be long gone by then + for (ASIHTTPRequest *request in [self operations]) { + [request setQueue:nil]; + } + [userInfo release]; + [super dealloc]; +} + +- (void)setSuspended:(BOOL)suspend +{ + [super setSuspended:suspend]; +} + +- (void)reset +{ + [self cancelAllOperations]; + [self setDelegate:nil]; + [self setDownloadProgressDelegate:nil]; + [self setUploadProgressDelegate:nil]; + [self setRequestDidStartSelector:NULL]; + [self setRequestDidReceiveResponseHeadersSelector:NULL]; + [self setRequestDidFailSelector:NULL]; + [self setRequestDidFinishSelector:NULL]; + [self setQueueDidFinishSelector:NULL]; + [self setSuspended:YES]; +} + + +- (void)go +{ + [self setSuspended:NO]; +} + +- (void)cancelAllOperations +{ + [self setBytesUploadedSoFar:0]; + [self setTotalBytesToUpload:0]; + [self setBytesDownloadedSoFar:0]; + [self setTotalBytesToDownload:0]; + [super cancelAllOperations]; +} + +- (void)setUploadProgressDelegate:(id)newDelegate +{ + uploadProgressDelegate = newDelegate; + [self resetProgressDelegate:&uploadProgressDelegate]; + +} + +- (void)setDownloadProgressDelegate:(id)newDelegate +{ + downloadProgressDelegate = newDelegate; + [self resetProgressDelegate:&downloadProgressDelegate]; +} + +- (void)resetProgressDelegate:(id *)progressDelegate +{ +#if !TARGET_OS_IPHONE + // If the uploadProgressDelegate is an NSProgressIndicator, we set its MaxValue to 1.0 so we can treat it similarly to UIProgressViews + SEL selector = @selector(setMaxValue:); + if ([*progressDelegate respondsToSelector:selector]) { + double max = 1.0; + [ASIHTTPRequest performSelector:selector onTarget:progressDelegate withObject:nil amount:&max callerToRetain:nil]; + } + selector = @selector(setDoubleValue:); + if ([*progressDelegate respondsToSelector:selector]) { + double value = 0.0; + [ASIHTTPRequest performSelector:selector onTarget:progressDelegate withObject:nil amount:&value callerToRetain:nil]; + } +#else + SEL selector = @selector(setProgress:); + if ([*progressDelegate respondsToSelector:selector]) { + float value = 0.0f; + [ASIHTTPRequest performSelector:selector onTarget:progressDelegate withObject:nil amount:&value callerToRetain:nil]; + } +#endif +} + +- (void)addHEADOperation:(NSOperation *)operation +{ + if ([operation isKindOfClass:[ASIHTTPRequest class]]) { + + ASIHTTPRequest *request = (ASIHTTPRequest *)operation; + [request setRequestMethod:@"HEAD"]; + [request setQueuePriority:10]; + [request setShowAccurateProgress:YES]; + [request setQueue:self]; + + // Important - we are calling NSOperation's add method - we don't want to add this as a normal request! + [super addOperation:request]; + } +} + +// Only add ASIHTTPRequests to this queue!! +- (void)addOperation:(NSOperation *)operation +{ + if (![operation isKindOfClass:[ASIHTTPRequest class]]) { + [NSException raise:@"AttemptToAddInvalidRequest" format:@"Attempted to add an object that was not an ASIHTTPRequest to an ASINetworkQueue"]; + } + + [self setRequestsCount:[self requestsCount]+1]; + + ASIHTTPRequest *request = (ASIHTTPRequest *)operation; + + if ([self showAccurateProgress]) { + + // Force the request to build its body (this may change requestMethod) + [request buildPostBody]; + + // If this is a GET request and we want accurate progress, perform a HEAD request first to get the content-length + // We'll only do this before the queue is started + // If requests are added after the queue is started they will probably move the overall progress backwards anyway, so there's no value performing the HEAD requests first + // Instead, they'll update the total progress if and when they receive a content-length header + if ([[request requestMethod] isEqualToString:@"GET"]) { + if ([self isSuspended]) { + ASIHTTPRequest *HEADRequest = [request HEADRequest]; + [self addHEADOperation:HEADRequest]; + [request addDependency:HEADRequest]; + if ([request shouldResetDownloadProgress]) { + [self resetProgressDelegate:&downloadProgressDelegate]; + [request setShouldResetDownloadProgress:NO]; + } + } + } + [request buildPostBody]; + [self request:nil incrementUploadSizeBy:[request postLength]]; + + + } else { + [self request:nil incrementDownloadSizeBy:1]; + [self request:nil incrementUploadSizeBy:1]; + } + // Tell the request not to increment the upload size when it starts, as we've already added its length + if ([request shouldResetUploadProgress]) { + [self resetProgressDelegate:&uploadProgressDelegate]; + [request setShouldResetUploadProgress:NO]; + } + + [request setShowAccurateProgress:[self showAccurateProgress]]; + + [request setQueue:self]; + [super addOperation:request]; + +} + +- (void)requestStarted:(ASIHTTPRequest *)request +{ + if ([self requestDidStartSelector]) { + [[self delegate] performSelector:[self requestDidStartSelector] withObject:request]; + } +} + +- (void)request:(ASIHTTPRequest *)request didReceiveResponseHeaders:(NSDictionary *)responseHeaders +{ + if ([self requestDidReceiveResponseHeadersSelector]) { + [[self delegate] performSelector:[self requestDidReceiveResponseHeadersSelector] withObject:request withObject:responseHeaders]; + } +} + +- (void)request:(ASIHTTPRequest *)request willRedirectToURL:(NSURL *)newURL +{ + if ([self requestWillRedirectSelector]) { + [[self delegate] performSelector:[self requestWillRedirectSelector] withObject:request withObject:newURL]; + } +} + +- (void)requestFinished:(ASIHTTPRequest *)request +{ + [self setRequestsCount:[self requestsCount]-1]; + if ([self requestDidFinishSelector]) { + [[self delegate] performSelector:[self requestDidFinishSelector] withObject:request]; + } + if ([self requestsCount] == 0) { + if ([self queueDidFinishSelector]) { + [[self delegate] performSelector:[self queueDidFinishSelector] withObject:self]; + } + } +} + +- (void)requestFailed:(ASIHTTPRequest *)request +{ + [self setRequestsCount:[self requestsCount]-1]; + if ([self requestDidFailSelector]) { + [[self delegate] performSelector:[self requestDidFailSelector] withObject:request]; + } + if ([self requestsCount] == 0) { + if ([self queueDidFinishSelector]) { + [[self delegate] performSelector:[self queueDidFinishSelector] withObject:self]; + } + } + if ([self shouldCancelAllRequestsOnFailure] && [self requestsCount] > 0) { + [self cancelAllOperations]; + } + +} + + +- (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes +{ + [self setBytesDownloadedSoFar:[self bytesDownloadedSoFar]+bytes]; + if ([self downloadProgressDelegate]) { + [ASIHTTPRequest updateProgressIndicator:&downloadProgressDelegate withProgress:[self bytesDownloadedSoFar] ofTotal:[self totalBytesToDownload]]; + } +} + +- (void)request:(ASIHTTPRequest *)request didSendBytes:(long long)bytes +{ + [self setBytesUploadedSoFar:[self bytesUploadedSoFar]+bytes]; + if ([self uploadProgressDelegate]) { + [ASIHTTPRequest updateProgressIndicator:&uploadProgressDelegate withProgress:[self bytesUploadedSoFar] ofTotal:[self totalBytesToUpload]]; + } +} + +- (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength +{ + [self setTotalBytesToDownload:[self totalBytesToDownload]+newLength]; +} + +- (void)request:(ASIHTTPRequest *)request incrementUploadSizeBy:(long long)newLength +{ + [self setTotalBytesToUpload:[self totalBytesToUpload]+newLength]; +} + + +// Since this queue takes over as the delegate for all requests it contains, it should forward authorisation requests to its own delegate +- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request +{ + if ([[self delegate] respondsToSelector:@selector(authenticationNeededForRequest:)]) { + [[self delegate] performSelector:@selector(authenticationNeededForRequest:) withObject:request]; + } +} + +- (void)proxyAuthenticationNeededForRequest:(ASIHTTPRequest *)request +{ + if ([[self delegate] respondsToSelector:@selector(proxyAuthenticationNeededForRequest:)]) { + [[self delegate] performSelector:@selector(proxyAuthenticationNeededForRequest:) withObject:request]; + } +} + + +- (BOOL)respondsToSelector:(SEL)selector +{ + // We handle certain methods differently because whether our delegate implements them or not can affect how the request should behave + + // If the delegate implements this, the request will stop to wait for credentials + if (selector == @selector(authenticationNeededForRequest:)) { + if ([[self delegate] respondsToSelector:@selector(authenticationNeededForRequest:)]) { + return YES; + } + return NO; + + // If the delegate implements this, the request will to wait for credentials + } else if (selector == @selector(proxyAuthenticationNeededForRequest:)) { + if ([[self delegate] respondsToSelector:@selector(proxyAuthenticationNeededForRequest:)]) { + return YES; + } + return NO; + + // If the delegate implements requestWillRedirectSelector, the request will stop to allow the delegate to change the url + } else if (selector == @selector(request:willRedirectToURL:)) { + if ([self requestWillRedirectSelector] && [[self delegate] respondsToSelector:[self requestWillRedirectSelector]]) { + return YES; + } + return NO; + } + return [super respondsToSelector:selector]; +} + +#pragma mark NSCopying + +- (id)copyWithZone:(NSZone *)zone +{ + ASINetworkQueue *newQueue = [[[self class] alloc] init]; + [newQueue setDelegate:[self delegate]]; + [newQueue setRequestDidStartSelector:[self requestDidStartSelector]]; + [newQueue setRequestWillRedirectSelector:[self requestWillRedirectSelector]]; + [newQueue setRequestDidReceiveResponseHeadersSelector:[self requestDidReceiveResponseHeadersSelector]]; + [newQueue setRequestDidFinishSelector:[self requestDidFinishSelector]]; + [newQueue setRequestDidFailSelector:[self requestDidFailSelector]]; + [newQueue setQueueDidFinishSelector:[self queueDidFinishSelector]]; + [newQueue setUploadProgressDelegate:[self uploadProgressDelegate]]; + [newQueue setDownloadProgressDelegate:[self downloadProgressDelegate]]; + [newQueue setShouldCancelAllRequestsOnFailure:[self shouldCancelAllRequestsOnFailure]]; + [newQueue setShowAccurateProgress:[self showAccurateProgress]]; + [newQueue setUserInfo:[[[self userInfo] copyWithZone:zone] autorelease]]; + return newQueue; +} + + +@synthesize requestsCount; +@synthesize bytesUploadedSoFar; +@synthesize totalBytesToUpload; +@synthesize bytesDownloadedSoFar; +@synthesize totalBytesToDownload; +@synthesize shouldCancelAllRequestsOnFailure; +@synthesize uploadProgressDelegate; +@synthesize downloadProgressDelegate; +@synthesize requestDidStartSelector; +@synthesize requestDidReceiveResponseHeadersSelector; +@synthesize requestWillRedirectSelector; +@synthesize requestDidFinishSelector; +@synthesize requestDidFailSelector; +@synthesize queueDidFinishSelector; +@synthesize delegate; +@synthesize showAccurateProgress; +@synthesize userInfo; +@end diff --git a/client/osx/ASIProgressDelegate.h b/client/osx/ASIProgressDelegate.h new file mode 100644 index 0000000..e2bb0cf --- /dev/null +++ b/client/osx/ASIProgressDelegate.h @@ -0,0 +1,38 @@ +// +// ASIProgressDelegate.h +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest +// +// Created by Ben Copsey on 13/04/2010. +// Copyright 2010 All-Seeing Interactive. All rights reserved. +// + +@class ASIHTTPRequest; + +@protocol ASIProgressDelegate + +@optional + +// These methods are used to update UIProgressViews (iPhone OS) or NSProgressIndicators (Mac OS X) +// If you are using a custom progress delegate, you may find it easier to implement didReceiveBytes / didSendBytes instead +#if TARGET_OS_IPHONE +- (void)setProgress:(float)newProgress; +#else +- (void)setDoubleValue:(double)newProgress; +- (void)setMaxValue:(double)newMax; +#endif + +// Called when the request receives some data - bytes is the length of that data +- (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes; + +// Called when the request sends some data +// The first 32KB (128KB on older platforms) of data sent is not included in this amount because of limitations with the CFNetwork API +// bytes may be less than zero if a request needs to remove upload progress (probably because the request needs to run again) +- (void)request:(ASIHTTPRequest *)request didSendBytes:(long long)bytes; + +// Called when a request needs to change the length of the content to download +- (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength; + +// Called when a request needs to change the length of the content to upload +// newLength may be less than zero when a request needs to remove the size of the internal buffer from progress tracking +- (void)request:(ASIHTTPRequest *)request incrementUploadSizeBy:(long long)newLength; +@end diff --git a/client/osx/Chrome.h b/client/osx/Chrome.h new file mode 100644 index 0000000..7a5b9d3 --- /dev/null +++ b/client/osx/Chrome.h @@ -0,0 +1,191 @@ +/* + * Chrome.h + */ + +#import +#import + + +@class ChromeApplication, ChromeWindow, ChromeTab, ChromeBookmarkFolder, ChromeBookmarkItem; + + + +/* + * Standard Suite + */ + +// The application's top-level scripting object. +@interface ChromeApplication : SBApplication + +- (SBElementArray *) windows; + +@property (copy, readonly) NSString *name; // The name of the application. +@property (readonly) BOOL frontmost; // Is this the frontmost (active) application? +@property (copy, readonly) NSString *version; // The version of the application. + +- (void) open:(NSArray *)x; // Open a document. +- (void) quit; // Quit the application. +- (BOOL) exists:(id)x; // Verify if an object exists. + +@end + +// A window. +@interface ChromeWindow : SBObject + +- (SBElementArray *) tabs; + +@property (copy, readonly) NSString *name; // The full title of the window. +- (NSInteger) id; // The unique identifier of the window. +@property NSInteger index; // The index of the window, ordered front to back. +@property NSRect bounds; // The bounding rectangle of the window. +@property (readonly) BOOL closeable; // Whether the window has a close box. +@property (readonly) BOOL minimizable; // Whether the window can be minimized. +@property BOOL minimized; // Whether the window is currently minimized. +@property (readonly) BOOL resizable; // Whether the window can be resized. +@property BOOL visible; // Whether the window is currently visible. +@property (readonly) BOOL zoomable; // Whether the window can be zoomed. +@property BOOL zoomed; // Whether the window is currently zoomed. +@property (copy, readonly) ChromeTab *activeTab; // Returns the currently selected tab +@property (copy) NSString *mode; // Represents the mode of the window which can be 'normal' or 'incognito', can be set only once during creation of the window. +@property NSInteger activeTabIndex; // The index of the active tab. + +- (void) saveIn:(NSURL *)in_ as:(NSString *)as; // Save an object. +- (void) close; // Close a window. +- (void) delete; // Delete an object. +- (SBObject *) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy object(s) and put the copies at a new location. +- (SBObject *) moveTo:(SBObject *)to; // Move object(s) to a new location. +- (void) print; // Print an object. +- (void) reload; // Reload a tab. +- (void) goBack; // Go Back (If Possible). +- (void) goForward; // Go Forward (If Possible). +- (void) selectAll; // Select all. +- (void) cutSelection; // Cut selected text (If Possible). +- (void) copySelection; // Copy text. +- (void) pasteSelection; // Paste text (If Possible). +- (void) undo; // Undo the last change. +- (void) redo; // Redo the last change. +- (void) stop; // Stop the current tab from loading. +- (void) viewSource; // View the HTML source of the tab. +- (id) executeJavascript:(NSString *)javascript; // Execute a piece of javascript. +- (void) enterPresentationMode; // Enter presentation mode in window. +- (void) exitPresentationMode; // Exit presentation mode in window. + +@end + + + +/* + * Chromium Suite + */ + +// The application's top-level scripting object. +@interface ChromeApplication (ChromiumSuite) + +- (SBElementArray *) bookmarkFolders; + +@property (copy, readonly) ChromeBookmarkFolder *bookmarksBar; // The bookmarks bar bookmark folder. +@property (copy, readonly) ChromeBookmarkFolder *otherBookmarks; // The other bookmarks bookmark folder. + +@end + +// A tab. +@interface ChromeTab : SBObject + +- (NSInteger) id; // Unique ID of the tab. +@property (copy, readonly) NSString *title; // The title of the tab. +@property (copy) NSString *URL; // The url visible to the user. +@property (readonly) BOOL loading; // Is loading? + +- (void) saveIn:(NSURL *)in_ as:(NSString *)as; // Save an object. +- (void) close; // Close a window. +- (void) delete; // Delete an object. +- (SBObject *) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy object(s) and put the copies at a new location. +- (SBObject *) moveTo:(SBObject *)to; // Move object(s) to a new location. +- (void) print; // Print an object. +- (void) reload; // Reload a tab. +- (void) goBack; // Go Back (If Possible). +- (void) goForward; // Go Forward (If Possible). +- (void) selectAll; // Select all. +- (void) cutSelection; // Cut selected text (If Possible). +- (void) copySelection; // Copy text. +- (void) pasteSelection; // Paste text (If Possible). +- (void) undo; // Undo the last change. +- (void) redo; // Redo the last change. +- (void) stop; // Stop the current tab from loading. +- (void) viewSource; // View the HTML source of the tab. +- (id) executeJavascript:(NSString *)javascript; // Execute a piece of javascript. +- (void) enterPresentationMode; // Enter presentation mode in window. +- (void) exitPresentationMode; // Exit presentation mode in window. + +@end + +// A bookmarks folder that contains other bookmarks folder and bookmark items. +@interface ChromeBookmarkFolder : SBObject + +- (SBElementArray *) bookmarkFolders; +- (SBElementArray *) bookmarkItems; + +- (NSNumber *) id; // Unique ID of the bookmark folder. +@property (copy) NSString *title; // The title of the folder. +@property (copy, readonly) NSNumber *index; // Returns the index with respect to its parent bookmark folder + +- (void) saveIn:(NSURL *)in_ as:(NSString *)as; // Save an object. +- (void) close; // Close a window. +- (void) delete; // Delete an object. +- (SBObject *) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy object(s) and put the copies at a new location. +- (SBObject *) moveTo:(SBObject *)to; // Move object(s) to a new location. +- (void) print; // Print an object. +- (void) reload; // Reload a tab. +- (void) goBack; // Go Back (If Possible). +- (void) goForward; // Go Forward (If Possible). +- (void) selectAll; // Select all. +- (void) cutSelection; // Cut selected text (If Possible). +- (void) copySelection; // Copy text. +- (void) pasteSelection; // Paste text (If Possible). +- (void) undo; // Undo the last change. +- (void) redo; // Redo the last change. +- (void) stop; // Stop the current tab from loading. +- (void) viewSource; // View the HTML source of the tab. +- (id) executeJavascript:(NSString *)javascript; // Execute a piece of javascript. +- (void) enterPresentationMode; // Enter presentation mode in window. +- (void) exitPresentationMode; // Exit presentation mode in window. + +@end + +// An item consists of an URL and the title of a bookmark +@interface ChromeBookmarkItem : SBObject + +- (NSInteger) id; // Unique ID of the bookmark item. +@property (copy) NSString *title; // The title of the bookmark item. +@property (copy) NSString *URL; // The URL of the bookmark. +@property (copy, readonly) NSNumber *index; // Returns the index with respect to its parent bookmark folder + +- (void) saveIn:(NSURL *)in_ as:(NSString *)as; // Save an object. +- (void) close; // Close a window. +- (void) delete; // Delete an object. +- (SBObject *) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy object(s) and put the copies at a new location. +- (SBObject *) moveTo:(SBObject *)to; // Move object(s) to a new location. +- (void) print; // Print an object. +- (void) reload; // Reload a tab. +- (void) goBack; // Go Back (If Possible). +- (void) goForward; // Go Forward (If Possible). +- (void) selectAll; // Select all. +- (void) cutSelection; // Cut selected text (If Possible). +- (void) copySelection; // Copy text. +- (void) pasteSelection; // Paste text (If Possible). +- (void) undo; // Undo the last change. +- (void) redo; // Redo the last change. +- (void) stop; // Stop the current tab from loading. +- (void) viewSource; // View the HTML source of the tab. +- (id) executeJavascript:(NSString *)javascript; // Execute a piece of javascript. +- (void) enterPresentationMode; // Enter presentation mode in window. +- (void) exitPresentationMode; // Exit presentation mode in window. + +@end + +@interface ChromeWindow (ChromiumSuite) + +@property (readonly) BOOL presenting; // Whether the window is in presentation mode. + +@end + diff --git a/client/osx/Defaults.plist b/client/osx/Defaults.plist new file mode 100644 index 0000000..029a143 --- /dev/null +++ b/client/osx/Defaults.plist @@ -0,0 +1,8 @@ + + + + + firstRun + + + diff --git a/client/osx/HPMacros.h b/client/osx/HPMacros.h new file mode 100644 index 0000000..9ad2360 --- /dev/null +++ b/client/osx/HPMacros.h @@ -0,0 +1,7 @@ +#ifdef HPLOGGING +#define HPNotify NSLog( @"%s", __PRETTY_FUNCTION__ ) +#define HPLog(args...) NSLog( @"%s: %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:args] ) +#else +#define HPNotify +#define HPLog(args...) +#endif diff --git a/client/osx/HackPad.xcodeproj/project.pbxproj b/client/osx/HackPad.xcodeproj/project.pbxproj new file mode 100644 index 0000000..ce82c04 --- /dev/null +++ b/client/osx/HackPad.xcodeproj/project.pbxproj @@ -0,0 +1,609 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 71263B2B159A37BC00D1F2E2 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 71263B2A159A37BC00D1F2E2 /* Carbon.framework */; }; + 71263B38159A3B6800D1F2E2 /* Defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = 71263B37159A3B6800D1F2E2 /* Defaults.plist */; }; + 7132D7621593826C00AF75DE /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7132D7611593826C00AF75DE /* WebKit.framework */; }; + 7132D76A1593927E00AF75DE /* NSString+URLEncoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 7132D7691593927E00AF75DE /* NSString+URLEncoding.m */; }; + 71740D0A15C834D300C3CD8D /* NSView+AnimationBlock.m in Sources */ = {isa = PBXBuildFile; fileRef = 71740D0915C834D300C3CD8D /* NSView+AnimationBlock.m */; }; + 71987A8715A620F200CF07EB /* NSStatusItem+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 71987A8615A620F200CF07EB /* NSStatusItem+Additions.m */; }; + 932FF5081597C8E900D8343D /* ScriptingBridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932FF5071597C8E900D8343D /* ScriptingBridge.framework */; }; + 932FF50A159814F800D8343D /* Hackpad.icns in Resources */ = {isa = PBXBuildFile; fileRef = 932FF509159814F800D8343D /* Hackpad.icns */; }; + 9377B4CE1462F89A0009558C /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9377B4CD1462F89A0009558C /* IOKit.framework */; }; + C314EEAB1423EDCC00EADA5C /* SeparatorCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C314EEAA1423EDCB00EADA5C /* SeparatorCell.m */; }; + C314EEAF1423EF5800EADA5C /* MenuTableColumn.m in Sources */ = {isa = PBXBuildFile; fileRef = C314EEAE1423EF5800EADA5C /* MenuTableColumn.m */; }; + C314EEB114244BEC00EADA5C /* plusbutton.png in Resources */ = {isa = PBXBuildFile; fileRef = C314EEB014244BEC00EADA5C /* plusbutton.png */; }; + C322A283141E9080006D3815 /* ROTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = C322A282141E907F006D3815 /* ROTableView.m */; }; + C322A287141E94D5006D3815 /* MenuArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = C322A286141E94D5006D3815 /* MenuArrayController.m */; }; + C3EA4566142A677F0010E89D /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3EA4565142A677F0010E89D /* Sparkle.framework */; }; + C3EA4569142A67B70010E89D /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = C3EA4565142A677F0010E89D /* Sparkle.framework */; }; + C3EBEDD91419506400AC1E28 /* ASIDataCompressor.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDC91419506400AC1E28 /* ASIDataCompressor.m */; }; + C3EBEDDA1419506400AC1E28 /* ASIDataDecompressor.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDCB1419506400AC1E28 /* ASIDataDecompressor.m */; }; + C3EBEDDB1419506400AC1E28 /* ASIDownloadCache.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDCD1419506400AC1E28 /* ASIDownloadCache.m */; }; + C3EBEDDC1419506400AC1E28 /* ASIFormDataRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDCF1419506400AC1E28 /* ASIFormDataRequest.m */; }; + C3EBEDDD1419506400AC1E28 /* ASIHTTPRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDD11419506400AC1E28 /* ASIHTTPRequest.m */; }; + C3EBEDDE1419506400AC1E28 /* ASIInputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDD51419506400AC1E28 /* ASIInputStream.m */; }; + C3EBEDDF1419506400AC1E28 /* ASINetworkQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDD71419506400AC1E28 /* ASINetworkQueue.m */; }; + C3EBEDEF1419508700AC1E28 /* NSObject+SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDE31419508700AC1E28 /* NSObject+SBJSON.m */; }; + C3EBEDF01419508700AC1E28 /* NSString+SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDE51419508700AC1E28 /* NSString+SBJSON.m */; }; + C3EBEDF21419508700AC1E28 /* SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDE81419508700AC1E28 /* SBJSON.m */; }; + C3EBEDF31419508700AC1E28 /* SBJsonBase.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDEA1419508700AC1E28 /* SBJsonBase.m */; }; + C3EBEDF41419508700AC1E28 /* SBJsonParser.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDEC1419508700AC1E28 /* SBJsonParser.m */; }; + C3EBEDF51419508700AC1E28 /* SBJsonWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDEE1419508700AC1E28 /* SBJsonWriter.m */; }; + C3EBEE0C141950C100AC1E28 /* ApplicationDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDF8141950C100AC1E28 /* ApplicationDelegate.m */; }; + C3EBEE0D141950C100AC1E28 /* BackgroundView.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEDFA141950C100AC1E28 /* BackgroundView.m */; }; + C3EBEE0E141950C100AC1E28 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = C3EBEDFC141950C100AC1E28 /* MainMenu.xib */; }; + C3EBEE0F141950C100AC1E28 /* HackPad-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = C3EBEDFE141950C100AC1E28 /* HackPad-Info.plist */; }; + C3EBEE10141950C100AC1E28 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEE00141950C100AC1E28 /* main.m */; }; + C3EBEE12141950C100AC1E28 /* Panel.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEE04141950C100AC1E28 /* Panel.m */; }; + C3EBEE13141950C100AC1E28 /* Panel.xib in Resources */ = {isa = PBXBuildFile; fileRef = C3EBEE05141950C100AC1E28 /* Panel.xib */; }; + C3EBEE14141950C100AC1E28 /* PanelController.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEE07141950C100AC1E28 /* PanelController.m */; }; + C3EBEE17141950C100AC1E28 /* StatusItemView.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEE0B141950C100AC1E28 /* StatusItemView.m */; }; + C3EBEE19141951D200AC1E28 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3EBEE18141951D200AC1E28 /* SystemConfiguration.framework */; }; + C3EBEE1B141951DB00AC1E28 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3EBEE1A141951DB00AC1E28 /* CoreServices.framework */; }; + C3EBEE1D141951E000AC1E28 /* libz.1.2.5.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = C3EBEE1C141951E000AC1E28 /* libz.1.2.5.dylib */; }; + C3EBEE251419550D00AC1E28 /* MenubarController.m in Sources */ = {isa = PBXBuildFile; fileRef = C3EBEE241419550D00AC1E28 /* MenubarController.m */; }; + C3EBEE301419589900AC1E28 /* Status.png in Resources */ = {isa = PBXBuildFile; fileRef = C3EBEE2E1419589800AC1E28 /* Status.png */; }; + C3EBEE311419589900AC1E28 /* StatusHighlighted.png in Resources */ = {isa = PBXBuildFile; fileRef = C3EBEE2F1419589800AC1E28 /* StatusHighlighted.png */; }; + C3F35DDD142ABB48007443C2 /* Splash.xib in Resources */ = {isa = PBXBuildFile; fileRef = C3F35DDC142ABB48007443C2 /* Splash.xib */; }; + C3F35E0F142AC654007443C2 /* HackpadApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = C3F35E0E142AC654007443C2 /* HackpadApplication.m */; }; + DD4F7C0913C30F9F00825C6E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD4F7C0813C30F9F00825C6E /* Cocoa.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + C3EA4568142A679C0010E89D /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + C3EA4569142A67B70010E89D /* Sparkle.framework in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 71263B2A159A37BC00D1F2E2 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; }; + 71263B36159A3AD000D1F2E2 /* PreferenceKeys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PreferenceKeys.h; sourceTree = ""; }; + 71263B37159A3B6800D1F2E2 /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Defaults.plist; sourceTree = ""; }; + 7132D7611593826C00AF75DE /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; + 7132D7681593927E00AF75DE /* NSString+URLEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+URLEncoding.h"; sourceTree = ""; }; + 7132D7691593927E00AF75DE /* NSString+URLEncoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+URLEncoding.m"; sourceTree = ""; }; + 71740D0815C834D300C3CD8D /* NSView+AnimationBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSView+AnimationBlock.h"; sourceTree = ""; }; + 71740D0915C834D300C3CD8D /* NSView+AnimationBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = "NSView+AnimationBlock.m"; sourceTree = ""; tabWidth = 2; }; + 71987A8515A620F200CF07EB /* NSStatusItem+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSStatusItem+Additions.h"; sourceTree = ""; }; + 71987A8615A620F200CF07EB /* NSStatusItem+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSStatusItem+Additions.m"; sourceTree = ""; }; + 71C2C17515C8762C00C958F7 /* HPMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPMacros.h; sourceTree = ""; }; + 932FF5021597BAD100D8343D /* Chrome.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Chrome.h; sourceTree = ""; }; + 932FF5041597BADA00D8343D /* Safari.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Safari.h; sourceTree = ""; }; + 932FF5071597C8E900D8343D /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = ../../../../../../../System/Library/Frameworks/ScriptingBridge.framework; sourceTree = ""; }; + 932FF509159814F800D8343D /* Hackpad.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Hackpad.icns; sourceTree = ""; }; + 9377B4CD1462F89A0009558C /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; }; + C314EEA91423EDCB00EADA5C /* SeparatorCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SeparatorCell.h; sourceTree = ""; }; + C314EEAA1423EDCB00EADA5C /* SeparatorCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SeparatorCell.m; sourceTree = ""; }; + C314EEAD1423EF5800EADA5C /* MenuTableColumn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuTableColumn.h; sourceTree = ""; }; + C314EEAE1423EF5800EADA5C /* MenuTableColumn.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MenuTableColumn.m; sourceTree = ""; }; + C314EEB014244BEC00EADA5C /* plusbutton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = plusbutton.png; sourceTree = ""; }; + C322A281141E907F006D3815 /* ROTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ROTableView.h; sourceTree = ""; }; + C322A282141E907F006D3815 /* ROTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ROTableView.m; sourceTree = ""; }; + C322A285141E94D5006D3815 /* MenuArrayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuArrayController.h; sourceTree = ""; }; + C322A286141E94D5006D3815 /* MenuArrayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MenuArrayController.m; sourceTree = ""; }; + C3EA4565142A677F0010E89D /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Sparkle.framework; sourceTree = ""; }; + C3EBEDC71419506400AC1E28 /* ASICacheDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASICacheDelegate.h; sourceTree = ""; }; + C3EBEDC81419506400AC1E28 /* ASIDataCompressor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIDataCompressor.h; sourceTree = ""; }; + C3EBEDC91419506400AC1E28 /* ASIDataCompressor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIDataCompressor.m; sourceTree = ""; }; + C3EBEDCA1419506400AC1E28 /* ASIDataDecompressor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIDataDecompressor.h; sourceTree = ""; }; + C3EBEDCB1419506400AC1E28 /* ASIDataDecompressor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIDataDecompressor.m; sourceTree = ""; }; + C3EBEDCC1419506400AC1E28 /* ASIDownloadCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIDownloadCache.h; sourceTree = ""; }; + C3EBEDCD1419506400AC1E28 /* ASIDownloadCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIDownloadCache.m; sourceTree = ""; }; + C3EBEDCE1419506400AC1E28 /* ASIFormDataRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIFormDataRequest.h; sourceTree = ""; }; + C3EBEDCF1419506400AC1E28 /* ASIFormDataRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIFormDataRequest.m; sourceTree = ""; }; + C3EBEDD01419506400AC1E28 /* ASIHTTPRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIHTTPRequest.h; sourceTree = ""; }; + C3EBEDD11419506400AC1E28 /* ASIHTTPRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIHTTPRequest.m; sourceTree = ""; }; + C3EBEDD21419506400AC1E28 /* ASIHTTPRequestConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIHTTPRequestConfig.h; sourceTree = ""; }; + C3EBEDD31419506400AC1E28 /* ASIHTTPRequestDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIHTTPRequestDelegate.h; sourceTree = ""; }; + C3EBEDD41419506400AC1E28 /* ASIInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIInputStream.h; sourceTree = ""; }; + C3EBEDD51419506400AC1E28 /* ASIInputStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIInputStream.m; sourceTree = ""; }; + C3EBEDD61419506400AC1E28 /* ASINetworkQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASINetworkQueue.h; sourceTree = ""; }; + C3EBEDD71419506400AC1E28 /* ASINetworkQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASINetworkQueue.m; sourceTree = ""; }; + C3EBEDD81419506400AC1E28 /* ASIProgressDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIProgressDelegate.h; sourceTree = ""; }; + C3EBEDE11419508700AC1E28 /* JSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSON.h; sourceTree = ""; }; + C3EBEDE21419508700AC1E28 /* NSObject+SBJSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+SBJSON.h"; sourceTree = ""; }; + C3EBEDE31419508700AC1E28 /* NSObject+SBJSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+SBJSON.m"; sourceTree = ""; }; + C3EBEDE41419508700AC1E28 /* NSString+SBJSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+SBJSON.h"; sourceTree = ""; }; + C3EBEDE51419508700AC1E28 /* NSString+SBJSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+SBJSON.m"; sourceTree = ""; }; + C3EBEDE71419508700AC1E28 /* SBJSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SBJSON.h; sourceTree = ""; }; + C3EBEDE81419508700AC1E28 /* SBJSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SBJSON.m; sourceTree = ""; }; + C3EBEDE91419508700AC1E28 /* SBJsonBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SBJsonBase.h; sourceTree = ""; }; + C3EBEDEA1419508700AC1E28 /* SBJsonBase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SBJsonBase.m; sourceTree = ""; }; + C3EBEDEB1419508700AC1E28 /* SBJsonParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SBJsonParser.h; sourceTree = ""; }; + C3EBEDEC1419508700AC1E28 /* SBJsonParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SBJsonParser.m; sourceTree = ""; }; + C3EBEDED1419508700AC1E28 /* SBJsonWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SBJsonWriter.h; sourceTree = ""; }; + C3EBEDEE1419508700AC1E28 /* SBJsonWriter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SBJsonWriter.m; sourceTree = ""; }; + C3EBEDF7141950C100AC1E28 /* ApplicationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ApplicationDelegate.h; path = Hackpad/ApplicationDelegate.h; sourceTree = ""; }; + C3EBEDF8141950C100AC1E28 /* ApplicationDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ApplicationDelegate.m; path = Hackpad/ApplicationDelegate.m; sourceTree = ""; }; + C3EBEDF9141950C100AC1E28 /* BackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BackgroundView.h; path = Hackpad/BackgroundView.h; sourceTree = ""; }; + C3EBEDFA141950C100AC1E28 /* BackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BackgroundView.m; path = Hackpad/BackgroundView.m; sourceTree = ""; }; + C3EBEDFD141950C100AC1E28 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = MainMenu.xib; sourceTree = ""; }; + C3EBEDFE141950C100AC1E28 /* HackPad-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "HackPad-Info.plist"; path = "Hackpad/HackPad-Info.plist"; sourceTree = ""; }; + C3EBEDFF141950C100AC1E28 /* HackPad-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "HackPad-Prefix.pch"; path = "Hackpad/HackPad-Prefix.pch"; sourceTree = ""; }; + C3EBEE00141950C100AC1E28 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Hackpad/main.m; sourceTree = ""; }; + C3EBEE03141950C100AC1E28 /* Panel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Panel.h; path = Hackpad/Panel.h; sourceTree = ""; }; + C3EBEE04141950C100AC1E28 /* Panel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Panel.m; path = Hackpad/Panel.m; sourceTree = ""; }; + C3EBEE05141950C100AC1E28 /* Panel.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = Panel.xib; path = Hackpad/Panel.xib; sourceTree = ""; }; + C3EBEE06141950C100AC1E28 /* PanelController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PanelController.h; path = Hackpad/PanelController.h; sourceTree = ""; }; + C3EBEE07141950C100AC1E28 /* PanelController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PanelController.m; path = Hackpad/PanelController.m; sourceTree = ""; }; + C3EBEE0A141950C100AC1E28 /* StatusItemView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StatusItemView.h; path = Hackpad/StatusItemView.h; sourceTree = ""; }; + C3EBEE0B141950C100AC1E28 /* StatusItemView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = StatusItemView.m; path = Hackpad/StatusItemView.m; sourceTree = ""; }; + C3EBEE18141951D200AC1E28 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; + C3EBEE1A141951DB00AC1E28 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; }; + C3EBEE1C141951E000AC1E28 /* libz.1.2.5.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.1.2.5.dylib; path = usr/lib/libz.1.2.5.dylib; sourceTree = SDKROOT; }; + C3EBEE231419550D00AC1E28 /* MenubarController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MenubarController.h; path = Hackpad/MenubarController.h; sourceTree = ""; }; + C3EBEE241419550D00AC1E28 /* MenubarController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MenubarController.m; path = Hackpad/MenubarController.m; sourceTree = ""; }; + C3EBEE2E1419589800AC1E28 /* Status.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Status.png; sourceTree = ""; }; + C3EBEE2F1419589800AC1E28 /* StatusHighlighted.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = StatusHighlighted.png; sourceTree = ""; }; + C3F35DDC142ABB48007443C2 /* Splash.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Splash.xib; sourceTree = ""; }; + C3F35E0D142AC654007443C2 /* HackpadApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HackpadApplication.h; sourceTree = ""; }; + C3F35E0E142AC654007443C2 /* HackpadApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HackpadApplication.m; sourceTree = ""; }; + DD4F7C0413C30F9F00825C6E /* HackPad.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HackPad.app; sourceTree = BUILT_PRODUCTS_DIR; }; + DD4F7C0813C30F9F00825C6E /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; + DD4F7C0B13C30F9F00825C6E /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; + DD4F7C0C13C30F9F00825C6E /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; + DD4F7C0D13C30F9F00825C6E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + DD4F7C0113C30F9F00825C6E /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 71263B2B159A37BC00D1F2E2 /* Carbon.framework in Frameworks */, + 7132D7621593826C00AF75DE /* WebKit.framework in Frameworks */, + C3EBEE1D141951E000AC1E28 /* libz.1.2.5.dylib in Frameworks */, + C3EBEE1B141951DB00AC1E28 /* CoreServices.framework in Frameworks */, + C3EBEE19141951D200AC1E28 /* SystemConfiguration.framework in Frameworks */, + DD4F7C0913C30F9F00825C6E /* Cocoa.framework in Frameworks */, + C3EA4566142A677F0010E89D /* Sparkle.framework in Frameworks */, + 9377B4CE1462F89A0009558C /* IOKit.framework in Frameworks */, + 932FF5081597C8E900D8343D /* ScriptingBridge.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 7132D76315938F3C00AF75DE /* Categories */ = { + isa = PBXGroup; + children = ( + 71740D0815C834D300C3CD8D /* NSView+AnimationBlock.h */, + 71740D0915C834D300C3CD8D /* NSView+AnimationBlock.m */, + 71987A8515A620F200CF07EB /* NSStatusItem+Additions.h */, + 71987A8615A620F200CF07EB /* NSStatusItem+Additions.m */, + 7132D7681593927E00AF75DE /* NSString+URLEncoding.h */, + 7132D7691593927E00AF75DE /* NSString+URLEncoding.m */, + ); + name = Categories; + sourceTree = ""; + }; + C3EBEDE01419506900AC1E28 /* ASI */ = { + isa = PBXGroup; + children = ( + C3EBEDC71419506400AC1E28 /* ASICacheDelegate.h */, + C3EBEDC81419506400AC1E28 /* ASIDataCompressor.h */, + C3EBEDC91419506400AC1E28 /* ASIDataCompressor.m */, + C3EBEDCA1419506400AC1E28 /* ASIDataDecompressor.h */, + C3EBEDCB1419506400AC1E28 /* ASIDataDecompressor.m */, + C3EBEDCC1419506400AC1E28 /* ASIDownloadCache.h */, + C3EBEDCD1419506400AC1E28 /* ASIDownloadCache.m */, + C3EBEDCE1419506400AC1E28 /* ASIFormDataRequest.h */, + C3EBEDCF1419506400AC1E28 /* ASIFormDataRequest.m */, + C3EBEDD01419506400AC1E28 /* ASIHTTPRequest.h */, + C3EBEDD11419506400AC1E28 /* ASIHTTPRequest.m */, + C3EBEDD21419506400AC1E28 /* ASIHTTPRequestConfig.h */, + C3EBEDD31419506400AC1E28 /* ASIHTTPRequestDelegate.h */, + C3EBEDD41419506400AC1E28 /* ASIInputStream.h */, + C3EBEDD51419506400AC1E28 /* ASIInputStream.m */, + C3EBEDD61419506400AC1E28 /* ASINetworkQueue.h */, + C3EBEDD71419506400AC1E28 /* ASINetworkQueue.m */, + C3EBEDD81419506400AC1E28 /* ASIProgressDelegate.h */, + ); + name = ASI; + sourceTree = ""; + }; + C3EBEDF61419509400AC1E28 /* JSON */ = { + isa = PBXGroup; + children = ( + C3EBEDE11419508700AC1E28 /* JSON.h */, + C3EBEDE21419508700AC1E28 /* NSObject+SBJSON.h */, + C3EBEDE31419508700AC1E28 /* NSObject+SBJSON.m */, + C3EBEDE41419508700AC1E28 /* NSString+SBJSON.h */, + C3EBEDE51419508700AC1E28 /* NSString+SBJSON.m */, + C3EBEDE71419508700AC1E28 /* SBJSON.h */, + C3EBEDE81419508700AC1E28 /* SBJSON.m */, + C3EBEDE91419508700AC1E28 /* SBJsonBase.h */, + C3EBEDEA1419508700AC1E28 /* SBJsonBase.m */, + C3EBEDEB1419508700AC1E28 /* SBJsonParser.h */, + C3EBEDEC1419508700AC1E28 /* SBJsonParser.m */, + C3EBEDED1419508700AC1E28 /* SBJsonWriter.h */, + C3EBEDEE1419508700AC1E28 /* SBJsonWriter.m */, + ); + name = JSON; + sourceTree = ""; + }; + C3EBEDFB141950C100AC1E28 /* en.lproj */ = { + isa = PBXGroup; + children = ( + ); + name = en.lproj; + path = Hackpad/en.lproj; + sourceTree = ""; + }; + C3EBEE1E1419544500AC1E28 /* Extras */ = { + isa = PBXGroup; + children = ( + C3EBEE00141950C100AC1E28 /* main.m */, + C3EBEDFF141950C100AC1E28 /* HackPad-Prefix.pch */, + ); + name = Extras; + sourceTree = ""; + }; + C3EBEE1F1419544F00AC1E28 /* Sources */ = { + isa = PBXGroup; + children = ( + 71263B36159A3AD000D1F2E2 /* PreferenceKeys.h */, + 71C2C17515C8762C00C958F7 /* HPMacros.h */, + 7132D76315938F3C00AF75DE /* Categories */, + C3EBEE22141954B000AC1E28 /* Controllers */, + C3EBEE201419546A00AC1E28 /* Views */, + C3EBEDFB141950C100AC1E28 /* en.lproj */, + C3EBEE1E1419544500AC1E28 /* Extras */, + C3EBEE211419548A00AC1E28 /* Resources */, + ); + name = Sources; + sourceTree = ""; + }; + C3EBEE201419546A00AC1E28 /* Views */ = { + isa = PBXGroup; + children = ( + C3EBEE03141950C100AC1E28 /* Panel.h */, + C3EBEE04141950C100AC1E28 /* Panel.m */, + C3EBEDF9141950C100AC1E28 /* BackgroundView.h */, + C3EBEDFA141950C100AC1E28 /* BackgroundView.m */, + C3EBEE0A141950C100AC1E28 /* StatusItemView.h */, + C3EBEE0B141950C100AC1E28 /* StatusItemView.m */, + ); + name = Views; + sourceTree = ""; + }; + C3EBEE211419548A00AC1E28 /* Resources */ = { + isa = PBXGroup; + children = ( + 932FF509159814F800D8343D /* Hackpad.icns */, + C3EBEDFE141950C100AC1E28 /* HackPad-Info.plist */, + 71263B37159A3B6800D1F2E2 /* Defaults.plist */, + ); + name = Resources; + sourceTree = ""; + }; + C3EBEE22141954B000AC1E28 /* Controllers */ = { + isa = PBXGroup; + children = ( + C3EBEDF7141950C100AC1E28 /* ApplicationDelegate.h */, + C3EBEDF8141950C100AC1E28 /* ApplicationDelegate.m */, + C3EBEE231419550D00AC1E28 /* MenubarController.h */, + C3EBEE241419550D00AC1E28 /* MenubarController.m */, + C3EBEE06141950C100AC1E28 /* PanelController.h */, + C3EBEE07141950C100AC1E28 /* PanelController.m */, + C322A285141E94D5006D3815 /* MenuArrayController.h */, + 932FF5041597BADA00D8343D /* Safari.h */, + C322A286141E94D5006D3815 /* MenuArrayController.m */, + 932FF5021597BAD100D8343D /* Chrome.h */, + C322A281141E907F006D3815 /* ROTableView.h */, + C322A282141E907F006D3815 /* ROTableView.m */, + C314EEAD1423EF5800EADA5C /* MenuTableColumn.h */, + C314EEAE1423EF5800EADA5C /* MenuTableColumn.m */, + C314EEA91423EDCB00EADA5C /* SeparatorCell.h */, + C314EEAA1423EDCB00EADA5C /* SeparatorCell.m */, + C3F35E0D142AC654007443C2 /* HackpadApplication.h */, + C3F35E0E142AC654007443C2 /* HackpadApplication.m */, + ); + name = Controllers; + sourceTree = ""; + }; + DD4F7BF913C30F9F00825C6E = { + isa = PBXGroup; + children = ( + C3EBEE1F1419544F00AC1E28 /* Sources */, + C3EBEDF61419509400AC1E28 /* JSON */, + C3EBEDE01419506900AC1E28 /* ASI */, + DD4F7C2813C3123E00825C6E /* User Interface */, + DD4F7C0713C30F9F00825C6E /* Frameworks */, + DD4F7C0513C30F9F00825C6E /* Products */, + ); + indentWidth = 4; + sourceTree = ""; + tabWidth = 4; + }; + DD4F7C0513C30F9F00825C6E /* Products */ = { + isa = PBXGroup; + children = ( + DD4F7C0413C30F9F00825C6E /* HackPad.app */, + ); + name = Products; + sourceTree = ""; + }; + DD4F7C0713C30F9F00825C6E /* Frameworks */ = { + isa = PBXGroup; + children = ( + 71263B2A159A37BC00D1F2E2 /* Carbon.framework */, + 932FF5071597C8E900D8343D /* ScriptingBridge.framework */, + 7132D7611593826C00AF75DE /* WebKit.framework */, + 9377B4CD1462F89A0009558C /* IOKit.framework */, + C3EA4565142A677F0010E89D /* Sparkle.framework */, + C3EBEE1C141951E000AC1E28 /* libz.1.2.5.dylib */, + C3EBEE1A141951DB00AC1E28 /* CoreServices.framework */, + C3EBEE18141951D200AC1E28 /* SystemConfiguration.framework */, + DD4F7C0B13C30F9F00825C6E /* AppKit.framework */, + DD4F7C0C13C30F9F00825C6E /* CoreData.framework */, + DD4F7C0D13C30F9F00825C6E /* Foundation.framework */, + DD4F7C0813C30F9F00825C6E /* Cocoa.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + DD4F7C2813C3123E00825C6E /* User Interface */ = { + isa = PBXGroup; + children = ( + DD4F7C4813C322D800825C6E /* Graphics */, + DD4F7C2913C3124300825C6E /* XIBs */, + ); + name = "User Interface"; + sourceTree = ""; + }; + DD4F7C2913C3124300825C6E /* XIBs */ = { + isa = PBXGroup; + children = ( + C3EBEE05141950C100AC1E28 /* Panel.xib */, + C3F35DDC142ABB48007443C2 /* Splash.xib */, + C3EBEDFC141950C100AC1E28 /* MainMenu.xib */, + ); + name = XIBs; + sourceTree = ""; + }; + DD4F7C4813C322D800825C6E /* Graphics */ = { + isa = PBXGroup; + children = ( + C314EEB014244BEC00EADA5C /* plusbutton.png */, + C3EBEE2E1419589800AC1E28 /* Status.png */, + C3EBEE2F1419589800AC1E28 /* StatusHighlighted.png */, + ); + name = Graphics; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + DD4F7C0313C30F9F00825C6E /* HackPad */ = { + isa = PBXNativeTarget; + buildConfigurationList = DD4F7C2213C30F9F00825C6E /* Build configuration list for PBXNativeTarget "HackPad" */; + buildPhases = ( + DD4F7C0013C30F9F00825C6E /* Sources */, + DD4F7C0113C30F9F00825C6E /* Frameworks */, + DD4F7C0213C30F9F00825C6E /* Resources */, + C3EA4568142A679C0010E89D /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = HackPad; + productName = Popup; + productReference = DD4F7C0413C30F9F00825C6E /* HackPad.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + DD4F7BFB13C30F9F00825C6E /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0450; + }; + buildConfigurationList = DD4F7BFE13C30F9F00825C6E /* Build configuration list for PBXProject "HackPad" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = DD4F7BF913C30F9F00825C6E; + productRefGroup = DD4F7C0513C30F9F00825C6E /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + DD4F7C0313C30F9F00825C6E /* HackPad */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + DD4F7C0213C30F9F00825C6E /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C3EBEE0E141950C100AC1E28 /* MainMenu.xib in Resources */, + C3EBEE0F141950C100AC1E28 /* HackPad-Info.plist in Resources */, + C3EBEE13141950C100AC1E28 /* Panel.xib in Resources */, + C3EBEE301419589900AC1E28 /* Status.png in Resources */, + C3EBEE311419589900AC1E28 /* StatusHighlighted.png in Resources */, + C314EEB114244BEC00EADA5C /* plusbutton.png in Resources */, + C3F35DDD142ABB48007443C2 /* Splash.xib in Resources */, + 932FF50A159814F800D8343D /* Hackpad.icns in Resources */, + 71263B38159A3B6800D1F2E2 /* Defaults.plist in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + DD4F7C0013C30F9F00825C6E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C3EBEDD91419506400AC1E28 /* ASIDataCompressor.m in Sources */, + C3EBEDDA1419506400AC1E28 /* ASIDataDecompressor.m in Sources */, + C3EBEDDB1419506400AC1E28 /* ASIDownloadCache.m in Sources */, + C3EBEDDC1419506400AC1E28 /* ASIFormDataRequest.m in Sources */, + C3EBEDDD1419506400AC1E28 /* ASIHTTPRequest.m in Sources */, + C3EBEDDE1419506400AC1E28 /* ASIInputStream.m in Sources */, + C3EBEDDF1419506400AC1E28 /* ASINetworkQueue.m in Sources */, + C3EBEDEF1419508700AC1E28 /* NSObject+SBJSON.m in Sources */, + C3EBEDF01419508700AC1E28 /* NSString+SBJSON.m in Sources */, + C3EBEDF21419508700AC1E28 /* SBJSON.m in Sources */, + C3EBEDF31419508700AC1E28 /* SBJsonBase.m in Sources */, + C3EBEDF41419508700AC1E28 /* SBJsonParser.m in Sources */, + C3EBEDF51419508700AC1E28 /* SBJsonWriter.m in Sources */, + C3EBEE0C141950C100AC1E28 /* ApplicationDelegate.m in Sources */, + C3EBEE0D141950C100AC1E28 /* BackgroundView.m in Sources */, + C3EBEE10141950C100AC1E28 /* main.m in Sources */, + C3EBEE12141950C100AC1E28 /* Panel.m in Sources */, + C3EBEE14141950C100AC1E28 /* PanelController.m in Sources */, + C3EBEE17141950C100AC1E28 /* StatusItemView.m in Sources */, + C3EBEE251419550D00AC1E28 /* MenubarController.m in Sources */, + C322A283141E9080006D3815 /* ROTableView.m in Sources */, + C322A287141E94D5006D3815 /* MenuArrayController.m in Sources */, + C314EEAB1423EDCC00EADA5C /* SeparatorCell.m in Sources */, + C314EEAF1423EF5800EADA5C /* MenuTableColumn.m in Sources */, + C3F35E0F142AC654007443C2 /* HackpadApplication.m in Sources */, + 7132D76A1593927E00AF75DE /* NSString+URLEncoding.m in Sources */, + 71987A8715A620F200CF07EB /* NSStatusItem+Additions.m in Sources */, + 71740D0A15C834D300C3CD8D /* NSView+AnimationBlock.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + C3EBEDFC141950C100AC1E28 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + C3EBEDFD141950C100AC1E28 /* en */, + ); + name = MainMenu.xib; + path = Hackpad/en.lproj; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + DD4F7C2013C30F9F00825C6E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + HPLOGGING, + DEBUG, + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.6; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + DD4F7C2113C30F9F00825C6E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.6; + SDKROOT = macosx; + }; + name = Release; + }; + DD4F7C2313C30F9F00825C6E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)\"", + ); + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "HackPad/HackPad-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)"; + INFOPLIST_FILE = "HackPad/HackPad-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Debug; + }; + DD4F7C2413C30F9F00825C6E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)\"", + ); + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "HackPad/HackPad-Prefix.pch"; + INFOPLIST_FILE = "HackPad/HackPad-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + DD4F7BFE13C30F9F00825C6E /* Build configuration list for PBXProject "HackPad" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DD4F7C2013C30F9F00825C6E /* Debug */, + DD4F7C2113C30F9F00825C6E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + DD4F7C2213C30F9F00825C6E /* Build configuration list for PBXNativeTarget "HackPad" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DD4F7C2313C30F9F00825C6E /* Debug */, + DD4F7C2413C30F9F00825C6E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = DD4F7BFB13C30F9F00825C6E /* Project object */; +} diff --git a/client/osx/HackPad.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/client/osx/HackPad.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..c1d63f0 --- /dev/null +++ b/client/osx/HackPad.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/client/osx/Hackpad.icns b/client/osx/Hackpad.icns new file mode 100644 index 0000000..35da498 Binary files /dev/null and b/client/osx/Hackpad.icns differ diff --git a/client/osx/Hackpad.xcworkspace/contents.xcworkspacedata b/client/osx/Hackpad.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..593bba3 --- /dev/null +++ b/client/osx/Hackpad.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/client/osx/Hackpad/ApplicationDelegate.h b/client/osx/Hackpad/ApplicationDelegate.h new file mode 100644 index 0000000..8266787 --- /dev/null +++ b/client/osx/Hackpad/ApplicationDelegate.h @@ -0,0 +1,23 @@ +#import "MenubarController.h" +#import "PanelController.h" + +@class PRHotkeyManager; + +@interface ApplicationDelegate : NSObject { +@private + MenubarController *_menubarController; + PanelController *_panelController; + NSWindow *_splashLogo; + struct timeval _lastKeyTime; +} + +@property (nonatomic, retain) MenubarController *menubarController; +@property (nonatomic, readonly) PanelController *panelController; +@property (retain) IBOutlet NSWindow *splashLogo; + +- (IBAction)togglePanel:(id)sender; + +-(void) addAppAsLoginItem; +-(void) deleteAppFromLoginItems; + +@end diff --git a/client/osx/Hackpad/ApplicationDelegate.m b/client/osx/Hackpad/ApplicationDelegate.m new file mode 100644 index 0000000..e7b282d --- /dev/null +++ b/client/osx/Hackpad/ApplicationDelegate.m @@ -0,0 +1,231 @@ +#include +#include + +#import "ApplicationDelegate.h" +#import "Sparkle/Sparkle.h" +#import "PreferenceKeys.h" + +void *kContextActivePanel = &kContextActivePanel; + + +OSStatus HotkeyPressedHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inUserData); +OSStatus HotkeyPressedHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inUserData) +{ + [(ApplicationDelegate*)inUserData performSelectorOnMainThread:@selector(togglePanel:) withObject:nil waitUntilDone:NO]; + return noErr; +} +EventHotKeyRef hotKeyRef = NULL; + +@implementation ApplicationDelegate + +@synthesize menubarController = _menubarController; +@synthesize splashLogo = _splashLogo; + +#pragma mark - + +- (void)dealloc +{ + [_menubarController release]; + [_panelController removeObserver:self forKeyPath:@"hasActivePanel"]; + [_panelController release]; + + [super dealloc]; +} + +#pragma mark - + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + if (context == kContextActivePanel) + { + self.menubarController.hasActiveIcon = self.panelController.hasActivePanel; + } + else + { + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; + } +} + +#pragma mark - NSApplicationDelegate + ++ (void)initialize +{ + // Set up User Defaults + NSMutableDictionary* defaults = [NSMutableDictionary dictionaryWithContentsOfFile: + [[NSBundle mainBundle] pathForResource:@"Defaults" ofType:@"plist"]]; + [DEFAULTS registerDefaults:defaults]; +} + +- (void)applicationDidFinishLaunching:(NSNotification *)notification +{ + // Install icon into the menu bar + [self.menubarController = [[MenubarController alloc] init] release]; + + // Make us auto-launch + [self addAppAsLoginItem]; + + // Register for URL invocations + [[NSAppleEventManager sharedAppleEventManager] + setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) + forEventClass:kInternetEventClass andEventID:kAEGetURL]; + + + [[SUUpdater sharedUpdater] checkForUpdatesInBackground]; + + [self togglePanel:self]; + + if(FIRST_RUN) + { + [self togglePanel:self]; + [DEFAULTS setBool:NO forKey:FIRST_RUN_KEY]; + } + + //Install the hotkey + + EventTypeSpec eventType = {kEventClassKeyboard,kEventHotKeyPressed}; + OSStatus err = InstallApplicationEventHandler(HotkeyPressedHandler, 1, &eventType, self, NULL); + if(!err) + { + RegisterEventHotKey(kVK_Escape, cmdKey, (EventHotKeyID){0,0}, GetEventDispatcherTarget(), 0, &hotKeyRef); + } +} + + + +- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent +{ + NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; + // NSURL *callbackURL = [NSURL URLWithString:url]; + // Now you can parse the URL and perform whatever action is needed + // save the token and mark ourselves as logged in + self.panelController.oauthToken = [url substringFromIndex:[@"hackpad://auth/" length]]; + [self togglePanel:self]; +} + + + +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender +{ + // Explicitly remove the icon from the menu bar + self.menubarController = nil; + + UnregisterEventHotKey(hotKeyRef); + + [DEFAULTS synchronize]; + + return NSTerminateNow; +} + +#pragma mark - Actions + +- (IBAction)togglePanel:(id)sender +{ + self.menubarController.hasActiveIcon = !self.menubarController.hasActiveIcon; + self.panelController.hasActivePanel = self.menubarController.hasActiveIcon; +} + +#pragma mark - Public accessors + +- (PanelController *)panelController +{ + if (_panelController == nil) + { + _panelController = [[PanelController alloc] initWithDelegate:self]; + [_panelController addObserver:self forKeyPath:@"hasActivePanel" options:NSKeyValueObservingOptionInitial context:kContextActivePanel]; + } + return _panelController; +} + +#pragma mark - PanelControllerDelegate + +- (StatusItemView *)statusItemViewForPanelController:(PanelController *)controller +{ + return self.menubarController.statusItemView; +} + +// via http://cocoatutorial.grapewave.com/tag/lssharedfilelistinsertitemurl/ +-(void) addAppAsLoginItem { + NSString * appPath = [[NSBundle mainBundle] bundlePath]; + + // This will retrieve the path for the application + // For example, /Applications/test.app + CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath]; + + // Create a reference to the shared file list. + // We are adding it to the current user only. + // If we want to add it all users, use + // kLSSharedFileListGlobalLoginItems instead of + //kLSSharedFileListSessionLoginItems + LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, + kLSSharedFileListSessionLoginItems, NULL); + if (loginItems) { + + //Check whether we're already in the list + BOOL found = NO; + UInt32 seedValue; + NSArray *loginItemsArray = (NSArray *)LSSharedFileListCopySnapshot(loginItems, &seedValue); + for(int i = 0; i< [loginItemsArray count]; i++){ + LSSharedFileListItemRef itemRef = (LSSharedFileListItemRef)[loginItemsArray + objectAtIndex:i]; + //Resolve the item with URL + CFURLRef currentUrl; + if (LSSharedFileListItemResolve(itemRef, 0, (CFURLRef*) ¤tUrl, NULL) == noErr) { + NSString * urlPath = [(NSURL*)currentUrl path]; + if ([urlPath compare:appPath] == NSOrderedSame){ + CFRelease(currentUrl); + found = YES; + break; + } + CFRelease(currentUrl); + } + } + [loginItemsArray release]; + + //Insert an item to the list. + if (!found) { + LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems, + kLSSharedFileListItemLast, NULL, NULL, + url, NULL, NULL); + if (item){ + CFRelease(item); + } + } + CFRelease(loginItems); + } + +} + + +-(void) deleteAppFromLoginItems{ + NSString * appPath = [[NSBundle mainBundle] bundlePath]; + + // This will retrieve the path for the application + // For example, /Applications/test.app + CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath]; + + // Create a reference to the shared file list. + LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, + kLSSharedFileListSessionLoginItems, NULL); + + if (loginItems) { + UInt32 seedValue; + //Retrieve the list of Login Items and cast them to + // a NSArray so that it will be easier to iterate. + NSArray *loginItemsArray = (NSArray *)LSSharedFileListCopySnapshot(loginItems, &seedValue); + for(int i =0; i< [loginItemsArray count]; i++){ + LSSharedFileListItemRef itemRef = (LSSharedFileListItemRef)[loginItemsArray + objectAtIndex:i]; + //Resolve the item with URL + if (LSSharedFileListItemResolve(itemRef, 0, (CFURLRef*) &url, NULL) == noErr) { + NSString * urlPath = [(NSURL*)url path]; + if ([urlPath compare:appPath] == NSOrderedSame){ + LSSharedFileListItemRemove(loginItems,itemRef); + } + CFRelease(url); + } + } + [loginItemsArray release]; + } +} + +@end diff --git a/client/osx/Hackpad/BackgroundView.h b/client/osx/Hackpad/BackgroundView.h new file mode 100644 index 0000000..c93aedf --- /dev/null +++ b/client/osx/Hackpad/BackgroundView.h @@ -0,0 +1,11 @@ +#define ARROW_WIDTH 12 +#define ARROW_HEIGHT 8 + +@interface BackgroundView : NSView +{ + NSInteger _arrowX; +} + +@property (nonatomic, assign) NSInteger arrowX; + +@end diff --git a/client/osx/Hackpad/BackgroundView.m b/client/osx/Hackpad/BackgroundView.m new file mode 100644 index 0000000..b3266ef --- /dev/null +++ b/client/osx/Hackpad/BackgroundView.m @@ -0,0 +1,77 @@ +#import "BackgroundView.h" + +#define FILL_OPACITY 1.0 +#define STROKE_OPACITY .8 + +#define LINE_THICKNESS 1 +#define CORNER_RADIUS 6 + +#define SEARCH_INSET 10 + +#pragma mark - + +@implementation BackgroundView + +@synthesize arrowX = _arrowX; + +#pragma mark - + +- (void)drawRect:(NSRect)dirtyRect +{ + NSRect contentRect = NSInsetRect([self bounds], LINE_THICKNESS, LINE_THICKNESS); + NSBezierPath *path = [NSBezierPath bezierPath]; + + [path moveToPoint:NSMakePoint(_arrowX, NSMaxY(contentRect))]; + [path lineToPoint:NSMakePoint(_arrowX + ARROW_WIDTH / 2, NSMaxY(contentRect) - ARROW_HEIGHT)]; + [path lineToPoint:NSMakePoint(NSMaxX(contentRect) - CORNER_RADIUS, NSMaxY(contentRect) - ARROW_HEIGHT)]; + + NSPoint topRightCorner = NSMakePoint(NSMaxX(contentRect), NSMaxY(contentRect) - ARROW_HEIGHT); + [path curveToPoint:NSMakePoint(NSMaxX(contentRect), NSMaxY(contentRect) - ARROW_HEIGHT - CORNER_RADIUS) + controlPoint1:topRightCorner controlPoint2:topRightCorner]; + + [path lineToPoint:NSMakePoint(NSMaxX(contentRect), NSMinY(contentRect) + CORNER_RADIUS)]; + + NSPoint bottomRightCorner = NSMakePoint(NSMaxX(contentRect), NSMinY(contentRect)); + [path curveToPoint:NSMakePoint(NSMaxX(contentRect) - CORNER_RADIUS, NSMinY(contentRect)) + controlPoint1:bottomRightCorner controlPoint2:bottomRightCorner]; + + [path lineToPoint:NSMakePoint(NSMinX(contentRect) + CORNER_RADIUS, NSMinY(contentRect))]; + + [path curveToPoint:NSMakePoint(NSMinX(contentRect), NSMinY(contentRect) + CORNER_RADIUS) + controlPoint1:contentRect.origin controlPoint2:contentRect.origin]; + + [path lineToPoint:NSMakePoint(NSMinX(contentRect), NSMaxY(contentRect) - ARROW_HEIGHT - CORNER_RADIUS)]; + + NSPoint topLeftCorner = NSMakePoint(NSMinX(contentRect), NSMaxY(contentRect) - ARROW_HEIGHT); + [path curveToPoint:NSMakePoint(NSMinX(contentRect) + CORNER_RADIUS, NSMaxY(contentRect) - ARROW_HEIGHT) + controlPoint1:topLeftCorner controlPoint2:topLeftCorner]; + + [path lineToPoint:NSMakePoint(_arrowX - ARROW_WIDTH / 2, NSMaxY(contentRect) - ARROW_HEIGHT)]; + [path closePath]; + + [[NSColor colorWithDeviceWhite:1 alpha:FILL_OPACITY] setFill]; + [path fill]; + + [NSGraphicsContext saveGraphicsState]; + + NSBezierPath *clip = [NSBezierPath bezierPathWithRect:[self bounds]]; + [clip appendBezierPath:path]; + [clip addClip]; + + [path setLineWidth:LINE_THICKNESS * 2]; + [[NSColor colorWithDeviceWhite:0.5 alpha:STROKE_OPACITY] setStroke]; + [path stroke]; + + [NSGraphicsContext restoreGraphicsState]; +} + +#pragma mark - +#pragma mark Public accessors + +- (void)setArrowX:(NSInteger)value +{ + _arrowX = value; + [self setNeedsDisplay:YES]; +} + +@end diff --git a/client/osx/Hackpad/HackPad-Info.plist b/client/osx/Hackpad/HackPad-Info.plist new file mode 100644 index 0000000..f287ad9 --- /dev/null +++ b/client/osx/Hackpad/HackPad-Info.plist @@ -0,0 +1,53 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + Hackpad.icns + CFBundleIdentifier + com.hackpad.hackpadapp + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 0.6.2 + CFBundleSignature + ???? + CFBundleURLTypes + + + CFBundleURLName + com.hackpad.hackpad + CFBundleURLSchemes + + hackpad + + + + CFBundleVersion + 0.6.2 + LSApplicationCategoryType + public.app-category.utilities + LSMinimumSystemVersion + ${MACOSX_DEPLOYMENT_TARGET} + LSUIElement + + NSHumanReadableCopyright + Copyright © 2012 Hackpad + NSMainNibFile + MainMenu + NSPrincipalClass + HackpadApplication + SUEnableAutomaticChecks + YES + SUFeedURL + https://hackpad.com/static/sparkle.xml + + diff --git a/client/osx/Hackpad/HackPad-Prefix.pch b/client/osx/Hackpad/HackPad-Prefix.pch new file mode 100644 index 0000000..8515a30 --- /dev/null +++ b/client/osx/Hackpad/HackPad-Prefix.pch @@ -0,0 +1,9 @@ +// +// Prefix header for all source files of the 'Popup' target in the 'Popup' project +// + +#ifdef __OBJC__ + +#import + +#endif diff --git a/client/osx/Hackpad/MenubarController.h b/client/osx/Hackpad/MenubarController.h new file mode 100644 index 0000000..47b1d7d --- /dev/null +++ b/client/osx/Hackpad/MenubarController.h @@ -0,0 +1,16 @@ +#define STATUS_ITEM_VIEW_WIDTH 24.0 + +#pragma mark - + +@class StatusItemView; + +@interface MenubarController : NSObject { +@private + StatusItemView *_statusItemView; +} + +@property (nonatomic, assign) BOOL hasActiveIcon; +@property (nonatomic, readonly) NSStatusItem *statusItem; +@property (nonatomic, readonly) StatusItemView *statusItemView; + +@end diff --git a/client/osx/Hackpad/MenubarController.m b/client/osx/Hackpad/MenubarController.m new file mode 100644 index 0000000..f00de71 --- /dev/null +++ b/client/osx/Hackpad/MenubarController.m @@ -0,0 +1,54 @@ +#import "MenubarController.h" +#import "StatusItemView.h" + +@implementation MenubarController + +@synthesize statusItemView = _statusItemView; + +#pragma mark - + +- (id)init +{ + self = [super init]; + if (self != nil) + { + // Install status item into the menu bar + NSStatusItem *statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:STATUS_ITEM_VIEW_WIDTH]; + _statusItemView = [[StatusItemView alloc] initWithStatusItem:statusItem]; + _statusItemView.image = [NSImage imageNamed:@"Status"]; + _statusItemView.alternateImage = [NSImage imageNamed:@"StatusHighlighted"]; + _statusItemView.action = @selector(togglePanel:); + } + return self; +} + +- (void)dealloc +{ + [[NSStatusBar systemStatusBar] removeStatusItem:self.statusItem]; + [_statusItemView release]; + [super dealloc]; +} + +#pragma mark - +#pragma mark Public accessors + +- (NSStatusItem *)statusItem +{ + return self.statusItemView.statusItem; +} + +#pragma mark - + +- (BOOL)hasActiveIcon +{ + return self.statusItemView.isHighlighted; +} + +- (void)setHasActiveIcon:(BOOL)flag +{ + self.statusItemView.isHighlighted = flag; +} + + + +@end diff --git a/client/osx/Hackpad/Panel.h b/client/osx/Hackpad/Panel.h new file mode 100644 index 0000000..6439fae --- /dev/null +++ b/client/osx/Hackpad/Panel.h @@ -0,0 +1,2 @@ +@interface Panel : NSPanel +@end diff --git a/client/osx/Hackpad/Panel.m b/client/osx/Hackpad/Panel.m new file mode 100644 index 0000000..75c6257 --- /dev/null +++ b/client/osx/Hackpad/Panel.m @@ -0,0 +1,10 @@ +#import "Panel.h" + +@implementation Panel + +- (BOOL)canBecomeKeyWindow; +{ + return YES; // Allow Search field to become the first responder +} + +@end diff --git a/client/osx/Hackpad/Panel.xib b/client/osx/Hackpad/Panel.xib new file mode 100644 index 0000000..a33a155 --- /dev/null +++ b/client/osx/Hackpad/Panel.xib @@ -0,0 +1,937 @@ + + + + 1080 + 12A269 + 2549 + 1187 + 624.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 2549 + + + YES + NSArrayController + NSButton + NSButtonCell + NSCustomObject + NSProgressIndicator + NSScrollView + NSScroller + NSSearchField + NSSearchFieldCell + NSTableColumn + NSTableView + NSTextFieldCell + NSUserDefaultsController + NSView + NSWindowTemplate + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + YES + + PanelController + + + FirstResponder + + + NSApplication + + + 145 + 2 + {{283, 209}, {282, 310}} + 1685586944 + + Panel + + + + + 256 + + YES + + + 266 + {{40, 276}, {222, 22}} + + + YES + + 342884416 + 33856 + + + LucidaGrande + 11 + 16 + + + + YES + 1 + + 6 + System + textBackgroundColor + + 3 + MQA + + + + 6 + System + textColor + + 3 + MAA + + + + 0 + 0 + search + + _searchFieldSearch: + + 138690560 + 0 + + 400 + 75 + + + 0 + 0 + clear + + YES + + YES + + YES + AXDescription + NSAccessibilityEncodedAttributesValueType + + + YES + cancel + + + + + + _searchFieldCancel: + + 138690560 + 0 + + 400 + 75 + + 255 + + NO + + + + 301 + + YES + + + 2304 + + YES + + + 4352 + {318, 270} + + + _NS:1197 + YES + NO + YES + + + -2147483392 + {{224, 0}, {16, 17}} + _NS:1202 + + + YES + + 276 + 276 + 276 + + 75497536 + 2048 + + + LucidaGrande + 11 + 3100 + + + 3 + MC4zMzMzMzI5ODU2AA + + + 6 + System + headerTextColor + + + + + 67108928 + 33556544 + Text Cell + + LucidaGrande + 13 + 1044 + + + + 6 + System + controlBackgroundColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 6 + System + controlTextColor + + + + 1 + YES + YES + + + + 42 + 2 + + 1 + MSAwLjk5OTM4MDM2OTggMC40NTc5MTM2MTk4IDAAA + + + 4 + MSAwAA + + 20 + 39845888 + + + 0 + 15 + 0 + NO + 1 + 1 + + + {278, 270} + + + _NS:1195 + + + 1 + MSAwLjk5OTM4MDM2OTggMC40NTc5MTM2MTk4IDAAA + + 2 + + + + -2147483392 + {{-100, -100}, {15, 102}} + + + _NS:1214 + NO + + _doScroller: + 1 + 0.99275362318840576 + + + + -2147483392 + {{-100, -100}, {223, 15}} + + + _NS:1216 + YES + NO + 1 + + _doScroller: + 0.98360655737704916 + + + {278, 270} + + + _NS:1193 + 133760 + + + + QSAAAEEgAABBsAAAQbAAAA + 0.25 + 4 + 1 + + + + 1289 + {{27, 294}, {16, 16}} + + + _NS:3954 + 28938 + 100 + + + + 268 + {{5, 276}, {30, 25}} + + + _NS:161 + YES + + 67108864 + 134217728 + + + _NS:161 + + -2041823232 + 32 + + NSImage + plusbutton + + + + 200 + 25 + + NO + + + {282, 310} + + + {{0, 0}, {2560, 1418}} + {10000000000000, 10000000000000} + YES + + + YES + + + YES + YES + + YES + YES + YES + YES + YES + + + + + YES + + + window + + + + 7 + + + + backgroundView + + + + 20 + + + + searchField + + + + 21 + + + + arrayController + + + + 108 + + + + tableView + + + + 116 + + + + scrollView + + + + 138 + + + + handleTableClick: + + + + 139 + + + + progress + + + + 182 + + + + createNewPadButton + + + + 239 + + + + createPad: + + + + 240 + + + + delegate + + + + 8 + + + + delegate + + + + 29 + + + + content: arrangedObjects + + + + + + content: arrangedObjects + content + arrangedObjects + 2 + + + 72 + + + + delegate + + + + 107 + + + + dataSource + + + + 223 + + + + value: arrangedObjects.title + + + + + + value: arrangedObjects.title + value + arrangedObjects.title + 2 + + + 113 + + + + contentArray: self.arraySource + + + + + + contentArray: self.arraySource + contentArray + self.arraySource + 2 + + + 59 + + + + + YES + + 0 + + YES + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 5 + + + YES + + + + + + 6 + + + YES + + + + + + + + + 48 + + + + + 53 + + + Array Controller + + + 38 + + + YES + + + + + + Scroll View - Table View + + + 42 + + + YES + + + + Table View + + + 43 + + + YES + + + + Table Column + + + 46 + + + + + 41 + + + + + 39 + + + + + 18 + + + YES + + + + + + 19 + + + + + 189 + + + YES + + + + + + 190 + + + + + 140 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 140.IBPluginDependency + 18.IBPluginDependency + 189.IBPluginDependency + 19.IBPluginDependency + 190.IBPluginDependency + 38.IBPluginDependency + 39.IBPluginDependency + 41.IBPluginDependency + 42.CustomClassName + 42.IBPluginDependency + 43.CustomClassName + 43.IBPluginDependency + 46.IBPluginDependency + 48.IBPluginDependency + 5.IBPluginDependency + 5.IBWindowTemplateEditedContentRect + 5.NSWindowTemplate.visibleAtLaunch + 53.CustomClassName + 53.IBPluginDependency + 6.CustomClassName + 6.IBPluginDependency + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + ROTableView + com.apple.InterfaceBuilder.CocoaPlugin + MenuTableColumn + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{609, 381}, {280, 378}} + + MenuArrayController + com.apple.InterfaceBuilder.CocoaPlugin + BackgroundView + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + + + + + YES + + + + + 240 + + + + YES + + BackgroundView + NSView + + IBProjectSource + ./Classes/BackgroundView.h + + + + MenuArrayController + NSArrayController + + IBProjectSource + ./Classes/MenuArrayController.h + + + + MenuTableColumn + NSTableColumn + + IBProjectSource + ./Classes/MenuTableColumn.h + + + + Panel + NSPanel + + IBProjectSource + ./Classes/Panel.h + + + + PanelController + NSWindowController + + YES + + YES + createPad: + handleTableClick: + login: + + + YES + id + id + id + + + + YES + + YES + createPad: + handleTableClick: + login: + + + YES + + createPad: + id + + + handleTableClick: + id + + + login: + id + + + + + YES + + YES + arrayController + backgroundView + createNewPadButton + loginButton + pads + progress + scrollView + searchField + tableView + textField + + + YES + MenuArrayController + BackgroundView + NSButton + NSButton + NSMutableArray + NSProgressIndicator + NSScrollView + NSSearchField + ROTableView + NSTextField + + + + YES + + YES + arrayController + backgroundView + createNewPadButton + loginButton + pads + progress + scrollView + searchField + tableView + textField + + + YES + + arrayController + MenuArrayController + + + backgroundView + BackgroundView + + + createNewPadButton + NSButton + + + loginButton + NSButton + + + pads + NSMutableArray + + + progress + NSProgressIndicator + + + scrollView + NSScrollView + + + searchField + NSSearchField + + + tableView + ROTableView + + + textField + NSTextField + + + + + IBProjectSource + ./Classes/PanelController.h + + + + ROTableView + NSTableView + + IBProjectSource + ./Classes/ROTableView.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + plusbutton + {30, 22} + + + diff --git a/client/osx/Hackpad/PanelController.h b/client/osx/Hackpad/PanelController.h new file mode 100644 index 0000000..2d65650 --- /dev/null +++ b/client/osx/Hackpad/PanelController.h @@ -0,0 +1,77 @@ +#import + +#import "BackgroundView.h" +#import "StatusItemView.h" + +@class PanelController; +@class ROTableView; +@class MenuArrayController; + +@protocol PanelControllerDelegate + +@optional + +- (StatusItemView *)statusItemViewForPanelController:(PanelController *)controller; + +@end + +#pragma mark - + +@interface PanelController : NSWindowController +{ + BOOL _hasActivePanel; + BackgroundView *_backgroundView; + id _delegate; + NSSearchField *_searchField; + NSTextField *_textField; + NSMutableArray *_arraySource; + NSMutableArray *_pads; + NSMutableArray *_collections; + MenuArrayController *_arrayController; + NSString* _oauthToken; + ROTableView* _tableView; + NSButton* _loginButton; + NSScrollView* _scrollView; + NSProgressIndicator *_progress; + NSButton *_newPadButton; + dispatch_source_t timer_; +} + +@property (assign) IBOutlet BackgroundView *backgroundView; +@property (assign) IBOutlet NSSearchField *searchField; +@property (assign) IBOutlet NSTextField *textField; +@property (retain) IBOutlet NSMutableArray *arraySource; +@property (retain) NSMutableArray *pads; +@property (retain) NSMutableArray *collections; +@property (retain) IBOutlet MenuArrayController *arrayController; +@property (retain) IBOutlet ROTableView *tableView; +@property (retain) IBOutlet NSScrollView *scrollView; +@property (retain) IBOutlet NSButton *loginButton; +@property (retain) NSString *oauthToken; +@property (retain) IBOutlet NSProgressIndicator *progress; +@property (retain) IBOutlet NSButton *createNewPadButton; + +@property (nonatomic, assign) BOOL hasActivePanel; +@property (nonatomic, readonly) id delegate; + +- (id)initWithDelegate:(id)delegate; +- (void) padSelected:(NSMutableDictionary*)row; + +-(IBAction)login:(id)sender; +-(IBAction)createPad:(id)sender; +- (IBAction) handleTableClick:(id)sender; + +- (void)openPanel; +- (void)closePanel; +- (void)refreshPadList; +- (void)refreshCollectionsList; + +- (void)selectPreviousRow; +- (void)selectNextRow; +- (void)selectPadForSelectedRow; +- (void)resizePanelWithCount:(NSUInteger)count animated:(BOOL)animated duration:(NSTimeInterval)duration; + +- (NSRect)statusRect; +- (NSRect)mainScreenRect; + +@end diff --git a/client/osx/Hackpad/PanelController.m b/client/osx/Hackpad/PanelController.m new file mode 100644 index 0000000..77a1c47 --- /dev/null +++ b/client/osx/Hackpad/PanelController.m @@ -0,0 +1,780 @@ +#import "PanelController.h" +#import "BackgroundView.h" +#import "StatusItemView.h" +#import "MenubarController.h" +#import "ASIHTTPRequest.h" +#import "ROTableView.h" +#import "MenuArrayController.h" +#import "NSString+SBJSON.h" +#import "NSString+URLEncoding.h" +#import "Chrome.h" +#import "Safari.h" +#import "NSStatusItem+Additions.h" +#import "NSView+AnimationBlock.h" + +#define OPEN_DURATION .15 +#define TRANSITION_DURATION .1 +#define CLOSE_DURATION .1 + +#define HORIZONTAL_PADDING 0 +#define VERTICAL_PADDING 12 + +#define POPUP_HEIGHT 222 +#define PANEL_WIDTH 310 +#define MENU_ANIMATION_DURATION .1 + +#pragma mark - + +@implementation PanelController + +@synthesize backgroundView = _backgroundView; +@synthesize delegate = _delegate; +@synthesize searchField = _searchField; +@synthesize textField = _textField; +@synthesize arraySource = _arraySource; +@synthesize arrayController = _arrayController; +@synthesize tableView = _tableView; +@synthesize scrollView = _scrollView; +@synthesize loginButton = _loginButton; +@synthesize progress = _progress; +@synthesize createNewPadButton = _newPadButton; +@synthesize collections = _collections; +@synthesize pads = _pads; + +NSString *serverURL = @"https://hackpad.com"; +//NSString *serverURL = @"http://bar.hackpad.com:9000"; //used for internal testing +NSString *FILLER = @"__FILLER__"; + +#pragma mark - + +- (id)initWithDelegate:(id)delegate +{ + self = [super initWithWindowNibName:@"Panel"]; + if (self != nil) + { + _delegate = delegate; + + NSString* savedToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"oauthToken"]; + if (savedToken) { + _oauthToken = [savedToken retain]; + } + + timer_ = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0)); + dispatch_source_set_timer(timer_, + DISPATCH_TIME_NOW, + 15 * 60 * NSEC_PER_SEC, 0); + dispatch_source_set_event_handler(timer_, ^{ [self refreshPadList]; [self refreshCollectionsList]; }); + dispatch_resume(timer_); + + } + return self; +} + +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSControlTextDidChangeNotification object:self.searchField]; + dispatch_source_cancel(timer_); + dispatch_release(timer_); + timer_ = NULL; + [super dealloc]; +} + +#pragma mark - + +- (void)awakeFromNib +{ + [super awakeFromNib]; + + + // Make a fully skinned panel + NSPanel *panel = (id)[self window]; + [panel setAcceptsMouseMovedEvents:YES]; + [panel setStyleMask:[panel styleMask] ^ NSTitledWindowMask]; + [panel setLevel:NSPopUpMenuWindowLevel]; + [panel setOpaque:NO]; + [panel setBackgroundColor:[NSColor clearColor]]; + + [self.arrayController setDelegate:self]; + [[self.tableView.tableColumns objectAtIndex:0] setDelegate:self.arrayController]; + + if (!self.oauthToken) { + [self logout:nil]; + } else { + self.arraySource = [NSMutableArray arrayWithCapacity:1]; + [self.arraySource addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:FILLER, @"title", nil]]; + [self.arrayController setSignedIn:true]; + [self.arrayController rearrangeObjects]; + // [self.arrayController arrangeObjects:[NSMutableArray arrayWithCapacity:4]]; + [self runSearch]; + if (!self.arraySource || [self.arraySource count] == 1) { + [self.progress setUsesThreadedAnimation:TRUE]; + [self.progress startAnimation:self]; + } + + } + + [[NSNotificationCenter defaultCenter] addObserverForName:NSControlTextDidChangeNotification object:self.searchField queue:nil usingBlock:^(NSNotification *note) { + if([[[self searchField] stringValue] length] > 0) + { + [self.arrayController setSearchString:[[self searchField] stringValue]]; + [self.arrayController setSearching:YES]; + } + else + { + [self.arrayController setSearchString:nil]; + [self.arrayController setSearching:NO]; + } + [self runSearch]; + NSNumber* shouldResize = [[note userInfo] objectForKey:@"shouldResize"]; + if(shouldResize != nil) + { + if([shouldResize boolValue] == NO) + return; + } + + [self resizePanelWithCount:[self.arrayController.arrangedObjects count] animated:NO duration:TRANSITION_DURATION]; + }]; + + [self.scrollView setHasHorizontalScroller:NO]; + [self.scrollView setHasVerticalScroller:NO]; + [self refreshPadList]; + [self refreshCollectionsList]; +} + +- (void)clearSearchField +{ + if(![[self.searchField stringValue] isEqualToString:@""]) + { + [self.searchField setStringValue:@""]; + [[NSNotificationCenter defaultCenter] postNotificationName:NSControlTextDidChangeNotification object:self.searchField userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:@"shouldResize"]]; + } +} + +#pragma mark - Public accessors + +-(BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row +{ + if(row < 0) + return NO; + + if ([[[self.arrayController.arrangedObjects objectAtIndex:row] objectForKey:@"type"] isEqualToString:@"separator"]) + return NO; + if ([[[self.arrayController.arrangedObjects objectAtIndex:row] objectForKey:@"type"] isEqualToString:@"text"]) + return NO; + return YES; +} + +- (BOOL)hasActivePanel +{ + return _hasActivePanel; +} + +- (void)setHasActivePanel:(BOOL)flag +{ + if (_hasActivePanel != flag) + { + _hasActivePanel = flag; + + if (_hasActivePanel) + { + [self openPanel]; + } + else + { + [self closePanel]; + } + } +} + +#pragma mark - NSWindowDelegate + +- (void)windowWillClose:(NSNotification *)notification +{ + self.hasActivePanel = NO; +} + +- (void)windowDidResignKey:(NSNotification *)notification; +{ + if ([[self window] isVisible]) + { + self.hasActivePanel = NO; + } +} + +- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector { + if (commandSelector == @selector(moveUp:)) { + [self selectPreviousRow]; + return YES; + } + if (commandSelector == @selector(moveDown:)) { + [self selectNextRow]; + return YES; + } + if (commandSelector == @selector(insertNewline:)) { + [self selectPadForSelectedRow]; + return YES; + } + + return NO; +} + +- (void)selectPreviousRow +{ + // Get the index of the previous row + int newRow = MAX(0,(int)([self.tableView selectedRow] - 1)); + + // Check to see if we can select the row at newRow index + while(newRow >= 0 && ![self tableView:nil shouldSelectRow:newRow]) + { + // If we can't, try the next one up + newRow--; + } + + // We can't select any rows above our current row, so don't do anything + if(newRow < 0) + return; + + [self.tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:newRow] byExtendingSelection:NO]; +} +- (void)selectNextRow +{ + // Get the index of the next row + int newRow = MIN((int)([self.tableView numberOfRows]),(int)([self.tableView selectedRow] + 1)); + NSUInteger count = [self.arrayController.arrangedObjects count]; + + // Check to see if we can select the next row + while(newRow != count && ![self tableView:nil shouldSelectRow:newRow]) + { + // If we can't, try the next after that + newRow++; + } + + // There are no rows below our current row, so don't do anything + if(newRow == count) + return; + + + [self.tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:newRow] byExtendingSelection:NO]; +} + +- (void)selectPadForSelectedRow +{ + [self padSelected:[[self.arrayController arrangedObjects] objectAtIndex:[self.tableView selectedRow]]]; +} + +- (void) padSelected:(NSMutableDictionary*)row { + if([[row objectForKey:@"ignoreClicks"] boolValue] == YES) + return; + if ([row objectForKey:@"selector"]) { + // if the selected item is a + [[row objectForKey:@"target"] performSelector:NSSelectorFromString([row objectForKey:@"selector"])]; + return; + } + + NSString *localPadId = [row objectForKey:@"localPadId"]; + NSString *urlString = [NSString stringWithFormat:@"%@/%@", serverURL, localPadId]; + + bool foundTab = false; + + if ([[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.google.Chrome"] count]) { + ChromeApplication *chrome = [SBApplication applicationWithBundleIdentifier:@"com.google.Chrome"]; + for (ChromeWindow *window in [chrome windows]) { + int tabIdx = 0; + for (ChromeTab *tab in [window tabs]) { + tabIdx++; + if ([[tab URL] hasPrefix:urlString]) { + [window setActiveTabIndex: tabIdx]; + [chrome activate]; + [window setIndex:1]; + foundTab = true; + break; + } + } + if (foundTab) { break; } + } + } + + if (!foundTab && [[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.Safari"] count]) { + SafariApplication *safari = [SBApplication applicationWithBundleIdentifier:@"com.apple.Safari"]; + for (SafariWindow *window in [safari windows]) { + for (SafariTab *tab in [window tabs]) { + if ([[tab URL] hasPrefix:urlString]) { + window.currentTab = tab; + [safari activate]; + [window setIndex:1]; + foundTab = true; + break; + } + } + if (foundTab) { break; } + } + } + + if (!foundTab) { + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]]; + } + + [self closePanel]; +} + +- (void)collectionSelected:(id)sender +{ + NSMutableDictionary* selectedItem = [[self.arrayController arrangedObjects] objectAtIndex:[self.tableView selectedRow]]; + + [NSView animateWithDuration:TRANSITION_DURATION animation:^{ + [[self.scrollView animator] setAlphaValue:0.0]; + } completion:^{ + [self clearSearchField]; + [self.arrayController setShowAllPadsOption:YES]; + [self.arrayController setShowCollectionsBackOption:YES]; + [self.arrayController setShowCollectionsOption:NO]; + self.arraySource = [selectedItem objectForKey:@"pads"]; + + [self resizePanelWithCount:[self.arrayController.arrangedObjects count] animated:YES duration:TRANSITION_DURATION]; + }]; + + [self.tableView deselectAll:nil]; +} + +- (void) quitApplication { + [[[NSApplication sharedApplication] delegate] performSelector:@selector(deleteAppFromLoginItems)]; + [[NSApplication sharedApplication] terminate:self]; +} + +- (void)windowDidResize:(NSNotification *)notification +{ + NSWindow *panel = [self window]; + NSRect statusRect = [self statusRect]; + NSRect panelRect = [panel frame]; + + CGFloat statusX = roundf(NSMidX(statusRect)); + CGFloat panelX = statusX - NSMinX(panelRect); + + self.backgroundView.arrowX = panelX; + + NSRect searchRect = [self.searchField frame]; + searchRect.size.width = [self.backgroundView bounds].size.width - 21 * 2 - [self.createNewPadButton frame].size.width - 10; + searchRect.origin.x = 234; + + searchRect.origin.x = 21 + [self.createNewPadButton frame].size.width + 10; //HORIZONTAL_PADDING ; + searchRect.origin.y = NSHeight([self.backgroundView bounds]) - ARROW_HEIGHT - VERTICAL_PADDING - NSHeight(searchRect); + + NSRect buttonRect = [self.createNewPadButton frame]; + buttonRect.origin.x = 21+1; //HORIZONTAL_PADDING ; + buttonRect.origin.y = searchRect.origin.y ; + + if (NSIsEmptyRect(searchRect)) + { + [self.searchField setHidden:YES]; + [self.createNewPadButton setHidden:YES]; + [self.progress setHidden:YES]; + } + else + { + [self.searchField setFrame:searchRect]; + [self.searchField setHidden:NO]; + [self.createNewPadButton setFrame:buttonRect]; + [self.createNewPadButton setHidden:NO]; + [self.progress setHidden:NO]; + [self.progress setFrame:NSMakeRect(searchRect.origin.x + searchRect.size.width - self.progress.frame.size.width - 10, searchRect.origin.y+2, self.progress.frame.size.width, self.progress.frame.size.height)]; + } + + NSRect searchResRect = [self.scrollView frame]; + searchResRect.size.width = NSWidth([self.backgroundView bounds]) - HORIZONTAL_PADDING * 2; + searchResRect.origin.x = HORIZONTAL_PADDING; + searchResRect.size.height = NSHeight([self.backgroundView bounds]) - ARROW_HEIGHT - VERTICAL_PADDING * 3 - NSHeight(searchRect); + searchResRect.origin.y = VERTICAL_PADDING; + + if (NSIsEmptyRect(searchResRect)) + { + [self.scrollView setHidden:YES]; + } + else + { + [self.scrollView setFrame:searchResRect]; + [self.scrollView setHidden:NO]; + } + self.scrollView.contentView.frame = NSRectFromCGRect((CGRect){0,0,self.scrollView.frame.size.width, self.scrollView.frame.size.height}); + [self.scrollView.documentView setFrame:NSRectFromCGRect((CGRect){0,0,self.scrollView.frame.size.width, self.scrollView.frame.size.height})]; +} + +#pragma mark - Keyboard + +- (void)cancelOperation:(id)sender +{ + self.hasActivePanel = NO; +} + +- (IBAction) handleTableClick:(id)sender { + if([self.tableView clickedRow] >= 0 && [self.tableView clickedRow] < [self.arrayController.arrangedObjects count]) + [self padSelected:[[self.arrayController arrangedObjects] objectAtIndex:[self.tableView clickedRow]]]; +} + +- (void)runSearch +{ + NSString *searchFormat = @""; + NSString *searchString = [self.searchField stringValue]; + if ([searchString length] > 0) + { + self.arrayController.filterPredicate = [NSPredicate predicateWithFormat:@"(title contains[cd] %@) AND (title != %@)", searchString, FILLER]; + searchFormat = NSLocalizedString(@"Search for ‘%@’…", @"Format for search request"); + [self.tableView setSearching:YES]; + } else { + self.arrayController.filterPredicate = [NSPredicate predicateWithFormat:@"(title != %@)", FILLER]; + [self.tableView setSearching:NO]; + } + + NSString *searchRequest = [NSString stringWithFormat:searchFormat, searchString]; + [self.textField setStringValue:searchRequest]; +} + +- (void)resizePanelWithCount:(NSUInteger)count animated:(BOOL)animated duration:(NSTimeInterval)duration +{ + // Resize panel + NSWindow* panel = [self window]; + NSRect panelRect = [panel frame]; + NSRect statusRect = [self statusRect]; + NSRect screenRect = [self mainScreenRect]; + + panelRect.size.width = PANEL_WIDTH; + panelRect.origin.x = roundf(NSMidX(statusRect) - NSWidth(panelRect) / 2); + + if (NSMaxX(panelRect) > (NSMaxX(screenRect) - ARROW_HEIGHT)) + panelRect.origin.x -= NSMaxX(panelRect) - (NSMaxX(screenRect) - ARROW_HEIGHT); + + + int panelHeight = ([self.tableView intercellSpacing].height + [self.tableView rowHeight]) * count + + self.searchField.frame.size.height + 3 * VERTICAL_PADDING + ARROW_HEIGHT; + + panelRect.origin.y = NSMaxY(statusRect) - panelHeight; + panelRect.size.height = panelHeight; + + if(animated) + { + [NSView animateWithDuration:duration animation:^{ + [[panel animator] setAlphaValue:1]; + [[panel animator] setFrame:panelRect display:YES]; + } completion:^{ + [NSView animateWithDuration:TRANSITION_DURATION animation:^{ + [[self.scrollView animator] setAlphaValue:1.0]; + }]; + }]; + } + else + { + [panel setAlphaValue:1]; + [panel setFrame:panelRect display:YES]; + } + + [self.window makeFirstResponder:self.searchField]; + [[self.searchField currentEditor] setSelectedRange:NSMakeRange([[self.searchField stringValue] length], 0)]; +} + +#pragma mark - Public methods + +- (NSRect)mainScreenRect +{ + StatusItemView *statusItemView = nil; + if ([self.delegate respondsToSelector:@selector(statusItemViewForPanelController:)]) + { + statusItemView = [self.delegate statusItemViewForPanelController:self]; + } + + return [[[[statusItemView statusItem] window] screen] frame]; +} + +- (NSRect)statusRect +{ + NSRect statusRect = NSZeroRect; + + StatusItemView *statusItemView = nil; + if ([self.delegate respondsToSelector:@selector(statusItemViewForPanelController:)]) + { + statusItemView = [self.delegate statusItemViewForPanelController:self]; + } + + if (statusItemView) + { + statusRect = statusItemView.globalRect; + statusRect.origin.y = NSMinY(statusRect) - NSHeight(statusRect); + } + return statusRect; +} + +-(IBAction)login:(id)sender { + + NSString* urlString = @"https://hackpad.com/ep/account/auth-token"; + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]]; + + [self closePanel]; +} + + +-(IBAction)logout:(id)sender { + self.arraySource = [NSMutableArray arrayWithCapacity:1]; + [self.arraySource addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:FILLER, @"title", nil]]; + + self.oauthToken = nil; + [self.pads removeAllObjects]; + [self.collections removeAllObjects]; + + self.arrayController.showAllPadsOption = NO; + self.arrayController.showCollectionsOption = NO; + self.arrayController.showCollectionsBackOption = NO; + + [self.arrayController rearrangeObjects]; + [self runSearch]; + + [self resizePanelWithCount:[self.arrayController.arrangedObjects count] animated:YES duration:TRANSITION_DURATION]; +} + +-(IBAction)createPad:(id)sender { + //TODO: modify the URL string to create pad with title of search (if exists) + + NSString *urlString = nil; + + if([[[self searchField] stringValue] length] > 0) + urlString = [NSString stringWithFormat:@"%@/ep/pad/newpad?title=%@", serverURL, [[[self searchField] stringValue] stringByUrlEncoding]]; + else + urlString = [serverURL stringByAppendingString:@"/ep/pad/newpad"]; + + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]]; + [self closePanel]; +} +-(void)showCollections:(id)sender { + [NSView animateWithDuration:TRANSITION_DURATION animation:^{ + [[self.scrollView animator] setAlphaValue:0.0]; + } completion:^{ + [self clearSearchField]; + self.arrayController.showAllPadsOption = YES; + self.arrayController.showCollectionsOption = NO; + self.arrayController.showCollectionsBackOption = NO; + + self.arraySource = self.collections; + [self.tableView deselectAll:nil]; + + [self resizePanelWithCount:[self.arrayController.arrangedObjects count] animated:YES duration:TRANSITION_DURATION]; + }]; +} +-(void)showAllPads:(id)sender { + [NSView animateWithDuration:TRANSITION_DURATION animation:^{ + [[self.scrollView animator] setAlphaValue:0.0]; + } completion:^{ + [self clearSearchField]; + self.arrayController.showAllPadsOption = NO; + self.arrayController.showCollectionsBackOption = NO; + if(self.collections) + self.arrayController.showCollectionsOption = YES; + + self.arraySource = self.pads; + [self.tableView deselectAll:nil]; + + [self resizePanelWithCount:[self.arrayController.arrangedObjects count] animated:YES duration:TRANSITION_DURATION]; + }]; +} + +- (void)openPanel +{ + [self refreshCollectionsList]; + [self refreshPadList]; + + NSRect statusRect = [self statusRect]; + + NSWindow *panel = [self window]; + + [NSApp activateIgnoringOtherApps:NO]; + [panel setAlphaValue:0]; + [panel setFrame:statusRect display:YES]; + [panel makeKeyAndOrderFront:nil]; + [self.scrollView setAlphaValue:1.0]; + + NSTimeInterval openDuration = OPEN_DURATION; + + NSEvent *currentEvent = [NSApp currentEvent]; + if ([currentEvent type] == NSLeftMouseDown) + { + NSUInteger clearFlags = ([currentEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask); + BOOL shiftPressed = (clearFlags == NSShiftKeyMask); + BOOL shiftOptionPressed = (clearFlags == (NSShiftKeyMask | NSAlternateKeyMask)); + if (shiftPressed || shiftOptionPressed) + { + openDuration *= 10; + } + } + + self.arrayController.showAllPadsOption = NO; + self.arrayController.showCollectionsBackOption = NO; + if(self.collections.count) + self.arrayController.showCollectionsOption = YES; + + if (self.pads.count) + self.arraySource = self.pads; + [self.tableView deselectAll:nil]; + + [self resizePanelWithCount:[self.arrayController.arrangedObjects count] animated:YES duration:TRANSITION_DURATION]; + + [panel performSelector:@selector(makeFirstResponder:) withObject:self.searchField afterDelay:openDuration]; + self.tableView.allowsEmptySelection = TRUE; + [self.tableView deselectAll:self]; +} + +- (void)closePanel +{ + [NSAnimationContext beginGrouping]; + [[NSAnimationContext currentContext] setDuration:CLOSE_DURATION]; + [[[self window] animator] setAlphaValue:0]; + [NSAnimationContext endGrouping]; + + dispatch_after(dispatch_walltime(NULL, NSEC_PER_SEC * CLOSE_DURATION * 2), dispatch_get_main_queue(), ^{ + + [self close]; + }); +} + + +- (void)refreshPadList { + if (!self.oauthToken) { + return; + } + // make a request + // + NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/ep/api/pad-list?token=%@", serverURL, self.oauthToken]]; + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; + [request setAllowCompressedResponse:YES]; + [request setDelegate:self]; + [request startAsynchronous]; + [[NSApplication sharedApplication] updateWindows]; + if (!self.arraySource || [self.arraySource count] == 1) { + [self.progress setUsesThreadedAnimation:TRUE]; + [self.progress startAnimation:self]; + } +} +- (void)refreshCollectionsList { + if (!self.oauthToken) { + return; + } + // make a request + // + NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/ep/api/collection-info?token=%@", serverURL, self.oauthToken]]; + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; + [request setAllowCompressedResponse:YES]; + [request setDelegate:self]; + [request startAsynchronous]; + [request setUserInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:@"collection"]]; +} + +//- (void)statusItemClicked { +// [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(showMenu) userInfo:nil repeats:NO]; +// [NSApp activateIgnoringOtherApps:YES]; +//} + +- (void)requestFinished:(ASIHTTPRequest *)request +{ + if (!self.oauthToken) { + return; + } + + BOOL shouldResize = NO; + + if (![request.url.host isEqualToString:request.originalURL.host]) { + [serverURL release]; + serverURL = [[[[[NSURL alloc] initWithString:@"/" relativeToURL:request.url] autorelease] absoluteString] autorelease]; + serverURL = [[serverURL substringToIndex:[serverURL length] - 1] retain]; // trailing '/' + //NSLog(@"setting serverURL to %@", serverURL); + } + + // Use when fetching text data + NSString *responseString = [request responseString]; + + if([[[request userInfo] objectForKey:@"collection"] boolValue] == YES) + { + NSMutableArray* collections = [responseString JSONValue]; + if(collections) + { + for(NSMutableDictionary* item in collections) + { + [item setObject:self forKey:@"target"]; + [item setObject:@"collectionSelected:" forKey:@"selector"]; + + for(NSMutableDictionary* pad in [item objectForKey:@"pads"]) + { + if([[pad objectForKey:@"title"] isEqualToString:@""]) + [pad setObject:@"Untitled" forKey:@"title"]; + } + } + + if(self.collections.count != collections.count) + shouldResize = YES; + + self.collections = collections; + if(!self.arrayController.showAllPadsOption) + { + self.arrayController.showCollectionsOption = YES; + [self.tableView reloadData]; + } + } + } + else + { + if(!self.arrayController.showAllPadsOption) + { + NSMutableArray* pads = [responseString JSONValue]; + + for(NSMutableDictionary* pad in pads) + { + if([[pad objectForKey:@"title"] isEqualToString:@""]) + [pad setObject:@"Untitled" forKey:@"title"]; + } + + if(self.pads.count != pads.count) + shouldResize = YES; + + self.pads = pads; + self.arraySource = self.pads; + [self.tableView reloadData]; + + [self.progress stopAnimation:self]; + } + } + + [self runSearch]; + + if(shouldResize) + { + [self resizePanelWithCount:[self.arrayController.arrangedObjects count] animated:YES duration:TRANSITION_DURATION]; + } + +} + + +- (void)requestFailed:(ASIHTTPRequest *)request +{ + // NSError *error = [request error]; + [self.progress stopAnimation:self]; +} + +- (NSString*) oauthToken { + return _oauthToken; +} + +- (void) setOauthToken:(NSString *)oauthToken { + [_oauthToken release]; + _oauthToken = [oauthToken retain]; + [[NSUserDefaults standardUserDefaults] setObject:oauthToken forKey:@"oauthToken"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + if (self.oauthToken) { + [self.arrayController setSignedIn:true]; + self.arraySource = [NSMutableArray arrayWithCapacity:1]; + [self.arraySource addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:FILLER, @"title", nil]]; + [self.arrayController rearrangeObjects]; + [self runSearch]; + [self refreshPadList]; + + + } else { + [self.arrayController setSignedIn:false]; + [self refreshPadList]; + } +} + +@end diff --git a/client/osx/Hackpad/StatusItemView.h b/client/osx/Hackpad/StatusItemView.h new file mode 100644 index 0000000..add92b5 --- /dev/null +++ b/client/osx/Hackpad/StatusItemView.h @@ -0,0 +1,21 @@ +@interface StatusItemView : NSView { +@private + NSImage *_image; + NSImage *_alternateImage; + NSStatusItem *_statusItem; + BOOL _isHighlighted; + SEL _action; + id _target; +} + +- (id)initWithStatusItem:(NSStatusItem *)statusItem; + +@property (nonatomic, readonly) NSStatusItem *statusItem; +@property (nonatomic, retain) NSImage *image; +@property (nonatomic, retain) NSImage *alternateImage; +@property (nonatomic, setter = setHighlighted:) BOOL isHighlighted; +@property (nonatomic, readonly) NSRect globalRect; +@property (nonatomic) SEL action; +@property (nonatomic, assign) id target; + +@end diff --git a/client/osx/Hackpad/StatusItemView.m b/client/osx/Hackpad/StatusItemView.m new file mode 100644 index 0000000..09a308a --- /dev/null +++ b/client/osx/Hackpad/StatusItemView.m @@ -0,0 +1,102 @@ +#import "StatusItemView.h" + +@implementation StatusItemView + +@synthesize statusItem = _statusItem; +@synthesize image = _image; +@synthesize alternateImage = _alternateImage; +@synthesize isHighlighted = _isHighlighted; +@synthesize action = _action; +@synthesize target = _target; + +#pragma mark - + +- (id)initWithStatusItem:(NSStatusItem *)statusItem +{ + CGFloat itemWidth = [statusItem length]; + CGFloat itemHeight = [[NSStatusBar systemStatusBar] thickness]; + NSRect itemRect = NSMakeRect(0.0, 0.0, itemWidth, itemHeight); + self = [super initWithFrame:itemRect]; + + if (self != nil) + { + _statusItem = [statusItem retain]; + _statusItem.view = self; + } + + [self setToolTip:@"Hackpad (⌘-⎋)"]; + + return self; +} + +- (void)dealloc +{ + [_statusItem release]; + [_image release]; + [_alternateImage release]; + + [super dealloc]; +} + +#pragma mark - + +- (void)drawRect:(NSRect)dirtyRect +{ + [self.statusItem drawStatusBarBackgroundInRect:dirtyRect withHighlight:self.isHighlighted]; + + NSImage *icon = self.isHighlighted ? self.alternateImage : self.image; + NSSize iconSize = [icon size]; + NSRect bounds = self.bounds; + CGFloat iconX = roundf((NSWidth(bounds) - iconSize.width) / 2); + CGFloat iconY = roundf((NSHeight(bounds) - iconSize.height) / 2); + NSPoint iconPoint = NSMakePoint(iconX, iconY); + [icon compositeToPoint:iconPoint operation:NSCompositeSourceOver]; +} + +#pragma mark - +#pragma mark Mouse tracking + +- (void)mouseDown:(NSEvent *)theEvent +{ + [NSApp sendAction:self.action to:self.target from:self]; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setHighlighted:(BOOL)newFlag +{ + if (_isHighlighted == newFlag) return; + _isHighlighted = newFlag; + [self setNeedsDisplay:YES]; +} + +#pragma mark - + +- (void)setImage:(NSImage *)newImage +{ + [newImage retain]; + [_image release]; + _image = newImage; + [self setNeedsDisplay:YES]; +} + +- (void)setAlternateImage:(NSImage *)newImage +{ + [newImage retain]; + [_alternateImage release]; + _alternateImage = newImage; + if (self.isHighlighted) + [self setNeedsDisplay:YES]; +} + +#pragma mark - + +- (NSRect)globalRect +{ + NSRect frame = [self frame]; + frame.origin = [self.window convertBaseToScreen:frame.origin]; + return frame; +} + +@end diff --git a/client/osx/Hackpad/en.lproj/MainMenu.xib b/client/osx/Hackpad/en.lproj/MainMenu.xib new file mode 100644 index 0000000..15f454e --- /dev/null +++ b/client/osx/Hackpad/en.lproj/MainMenu.xib @@ -0,0 +1,2786 @@ + + + + 1070 + 11B26 + 1617 + 1138 + 566.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 1617 + + + YES + NSMenu + NSMenuItem + NSCustomObject + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + YES + + YES + + + + + YES + + NSApplication + + + FirstResponder + + + NSApplication + + + ApplicationDelegate + + + NSFontManager + + + SUUpdater + + + AMainMenu + + YES + + + HackPad + + 1048576 + 2147483647 + + NSImage + NSMenuCheckmark + + + NSImage + NSMenuMixedState + + submenuAction: + + HackPad + + YES + + + About asdasdfasasdf + + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Preferences… + , + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Services + + 1048576 + 2147483647 + + + submenuAction: + + Services + + YES + + _NSServicesMenu + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Hide asdasdfasasdf + h + 1048576 + 2147483647 + + + + + + Hide Others + h + 1572864 + 2147483647 + + + + + + Show All + + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Quit asdasdfasasdf + q + 1048576 + 2147483647 + + + + + _NSAppleMenu + + + + + File + + 1048576 + 2147483647 + + + submenuAction: + + File + + YES + + + New + n + 1048576 + 2147483647 + + + + + + Open… + o + 1048576 + 2147483647 + + + + + + Open Recent + + 1048576 + 2147483647 + + + submenuAction: + + Open Recent + + YES + + + Clear Menu + + 1048576 + 2147483647 + + + + + _NSRecentDocumentsMenu + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Close + w + 1048576 + 2147483647 + + + + + + Save… + s + 1048576 + 2147483647 + + + + + + Revert to Saved + + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Page Setup... + P + 1179648 + 2147483647 + + + + + + + Print… + p + 1048576 + 2147483647 + + + + + + + + + Edit + + 1048576 + 2147483647 + + + submenuAction: + + Edit + + YES + + + Undo + z + 1048576 + 2147483647 + + + + + + Redo + Z + 1179648 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Cut + x + 1048576 + 2147483647 + + + + + + Copy + c + 1048576 + 2147483647 + + + + + + Paste + v + 1048576 + 2147483647 + + + + + + Paste and Match Style + V + 1572864 + 2147483647 + + + + + + Delete + + 1048576 + 2147483647 + + + + + + Select All + a + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Find + + 1048576 + 2147483647 + + + submenuAction: + + Find + + YES + + + Find… + f + 1048576 + 2147483647 + + + 1 + + + + Find and Replace… + f + 1572864 + 2147483647 + + + 12 + + + + Find Next + g + 1048576 + 2147483647 + + + 2 + + + + Find Previous + G + 1179648 + 2147483647 + + + 3 + + + + Use Selection for Find + e + 1048576 + 2147483647 + + + 7 + + + + Jump to Selection + j + 1048576 + 2147483647 + + + + + + + + + Spelling and Grammar + + 1048576 + 2147483647 + + + submenuAction: + + Spelling and Grammar + + YES + + + Show Spelling and Grammar + : + 1048576 + 2147483647 + + + + + + Check Document Now + ; + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Check Spelling While Typing + + 1048576 + 2147483647 + + + + + + Check Grammar With Spelling + + 1048576 + 2147483647 + + + + + + Correct Spelling Automatically + + 2147483647 + + + + + + + + + Substitutions + + 1048576 + 2147483647 + + + submenuAction: + + Substitutions + + YES + + + Show Substitutions + + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Smart Copy/Paste + f + 1048576 + 2147483647 + + + 1 + + + + Smart Quotes + g + 1048576 + 2147483647 + + + 2 + + + + Smart Dashes + + 2147483647 + + + + + + Smart Links + G + 1179648 + 2147483647 + + + 3 + + + + Text Replacement + + 2147483647 + + + + + + + + + Transformations + + 2147483647 + + + submenuAction: + + Transformations + + YES + + + Make Upper Case + + 2147483647 + + + + + + Make Lower Case + + 2147483647 + + + + + + Capitalize + + 2147483647 + + + + + + + + + Speech + + 1048576 + 2147483647 + + + submenuAction: + + Speech + + YES + + + Start Speaking + + 1048576 + 2147483647 + + + + + + Stop Speaking + + 1048576 + 2147483647 + + + + + + + + + + + + Format + + 2147483647 + + + submenuAction: + + Format + + YES + + + Font + + 2147483647 + + + submenuAction: + + Font + + YES + + + Show Fonts + t + 1048576 + 2147483647 + + + + + + Bold + b + 1048576 + 2147483647 + + + 2 + + + + Italic + i + 1048576 + 2147483647 + + + 1 + + + + Underline + u + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Bigger + + + 1048576 + 2147483647 + + + 3 + + + + Smaller + - + 1048576 + 2147483647 + + + 4 + + + + YES + YES + + + 2147483647 + + + + + + Kern + + 2147483647 + + + submenuAction: + + Kern + + YES + + + Use Default + + 2147483647 + + + + + + Use None + + 2147483647 + + + + + + Tighten + + 2147483647 + + + + + + Loosen + + 2147483647 + + + + + + + + + Ligature + + 2147483647 + + + submenuAction: + + Ligature + + YES + + + Use Default + + 2147483647 + + + + + + Use None + + 2147483647 + + + + + + Use All + + 2147483647 + + + + + + + + + Baseline + + 2147483647 + + + submenuAction: + + Baseline + + YES + + + Use Default + + 2147483647 + + + + + + Superscript + + 2147483647 + + + + + + Subscript + + 2147483647 + + + + + + Raise + + 2147483647 + + + + + + Lower + + 2147483647 + + + + + + + + + YES + YES + + + 2147483647 + + + + + + Show Colors + C + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Copy Style + c + 1572864 + 2147483647 + + + + + + Paste Style + v + 1572864 + 2147483647 + + + + + _NSFontMenu + + + + + Text + + 2147483647 + + + submenuAction: + + Text + + YES + + + Align Left + { + 1048576 + 2147483647 + + + + + + Center + | + 1048576 + 2147483647 + + + + + + Justify + + 2147483647 + + + + + + Align Right + } + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Writing Direction + + 2147483647 + + + submenuAction: + + Writing Direction + + YES + + + YES + Paragraph + + 2147483647 + + + + + + CURlZmF1bHQ + + 2147483647 + + + + + + CUxlZnQgdG8gUmlnaHQ + + 2147483647 + + + + + + CVJpZ2h0IHRvIExlZnQ + + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + YES + Selection + + 2147483647 + + + + + + CURlZmF1bHQ + + 2147483647 + + + + + + CUxlZnQgdG8gUmlnaHQ + + 2147483647 + + + + + + CVJpZ2h0IHRvIExlZnQ + + 2147483647 + + + + + + + + + YES + YES + + + 2147483647 + + + + + + Show Ruler + + 2147483647 + + + + + + Copy Ruler + c + 1310720 + 2147483647 + + + + + + Paste Ruler + v + 1310720 + 2147483647 + + + + + + + + + + + + View + + 1048576 + 2147483647 + + + submenuAction: + + View + + YES + + + Show Toolbar + t + 1572864 + 2147483647 + + + + + + Customize Toolbar… + + 1048576 + 2147483647 + + + + + + + + + Window + + 1048576 + 2147483647 + + + submenuAction: + + Window + + YES + + + Minimize + m + 1048576 + 2147483647 + + + + + + Zoom + + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Bring All to Front + + 1048576 + 2147483647 + + + + + _NSWindowsMenu + + + + + Help + + 2147483647 + + + submenuAction: + + Help + + YES + + + asdasdfasasdf Help + ? + 1048576 + 2147483647 + + + + + _NSHelpMenu + + + + _NSMainMenu + + + + + YES + + + delegate + + + + 495 + + + + + YES + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 420 + + + + + 494 + + + + + 542 + + + Object + + + 697 + + + YES + + + + + + + + + + + + 698 + + + YES + + + + + + 699 + + + YES + + + + + + 700 + + + YES + + + + + + 701 + + + YES + + + + + + 702 + + + YES + + + + + + 703 + + + YES + + + + + + 704 + + + YES + + + + + + 705 + + + YES + + + + + + + + + 706 + + + + + 707 + + + + + 708 + + + + + 709 + + + + + 710 + + + YES + + + + + + + + + + + + + + + + 711 + + + + + 712 + + + + + 713 + + + YES + + + + + + 714 + + + + + 715 + + + + + 716 + + + + + 717 + + + + + 718 + + + + + 719 + + + + + 720 + + + + + 721 + + + + + 722 + + + + + 723 + + + YES + + + + + + + + + + + + + + + + + + + + 724 + + + + + 725 + + + YES + + + + + + 726 + + + YES + + + + + + 727 + + + YES + + + + + + 728 + + + YES + + + + + + 729 + + + YES + + + + + + 730 + + + + + 731 + + + + + 732 + + + + + 733 + + + + + 734 + + + + + 735 + + + + + 736 + + + + + 737 + + + + + 738 + + + + + 739 + + + YES + + + + + + + + + + + 740 + + + + + 741 + + + + + 742 + + + + + 743 + + + + + 744 + + + + + 745 + + + + + 746 + + + YES + + + + + + + + + + + 747 + + + + + 748 + + + + + 749 + + + + + 750 + + + + + 751 + + + + + 752 + + + + + 753 + + + YES + + + + + + + 754 + + + + + 755 + + + + + 756 + + + YES + + + + + + + + + + + + 757 + + + + + 758 + + + + + 759 + + + + + 760 + + + + + 761 + + + + + 762 + + + + + 763 + + + + + 764 + + + YES + + + + + + + + 765 + + + + + 766 + + + + + 767 + + + + + 768 + + + YES + + + + + + + + + + + + + + + 769 + + + + + 770 + + + + + 771 + + + + + 772 + + + + + 773 + + + + + 774 + + + YES + + + + + + 775 + + + + + 776 + + + + + 777 + + + + + 778 + + + + + 779 + + + YES + + + + + + 780 + + + + + 781 + + + YES + + + + + + + 782 + + + + + 783 + + + + + 784 + + + YES + + + + + + + 785 + + + YES + + + + + + 786 + + + YES + + + + + + 787 + + + YES + + + + + + + + + + + + + + + + + + + + + 788 + + + + + 789 + + + + + 790 + + + + + 791 + + + + + 792 + + + + + 793 + + + YES + + + + + + 794 + + + YES + + + + + + 795 + + + YES + + + + + + 796 + + + + + 797 + + + + + 798 + + + + + 799 + + + + + 800 + + + + + 801 + + + + + 802 + + + + + 803 + + + + + 804 + + + YES + + + + + + + + + 805 + + + + + 806 + + + + + 807 + + + + + 808 + + + + + 809 + + + YES + + + + + + + + 810 + + + + + 811 + + + + + 812 + + + + + 813 + + + YES + + + + + + + + + + 814 + + + + + 815 + + + + + 816 + + + + + 817 + + + + + 818 + + + + + 819 + + + YES + + + + + + + + + + + + + + + 820 + + + + + 821 + + + + + 822 + + + + + 823 + + + + + 824 + + + YES + + + + + + 825 + + + + + 826 + + + + + 827 + + + + + 828 + + + + + 829 + + + + + 830 + + + YES + + + + + + + + + + + + + + 831 + + + + + 832 + + + + + 833 + + + + + 834 + + + + + 835 + + + + + 836 + + + + + 837 + + + + + 838 + + + + + 839 + + + + + 840 + + + YES + + + + + + 841 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 420.IBPluginDependency + 494.IBPluginDependency + 542.IBPluginDependency + 697.IBPluginDependency + 698.IBPluginDependency + 699.IBPluginDependency + 700.IBPluginDependency + 701.IBPluginDependency + 702.IBPluginDependency + 703.IBPluginDependency + 704.IBPluginDependency + 705.IBPluginDependency + 706.IBPluginDependency + 707.IBPluginDependency + 708.IBPluginDependency + 709.IBPluginDependency + 710.IBPluginDependency + 711.IBPluginDependency + 712.IBPluginDependency + 713.IBPluginDependency + 714.IBPluginDependency + 715.IBPluginDependency + 716.IBPluginDependency + 717.IBPluginDependency + 718.IBPluginDependency + 719.IBPluginDependency + 720.IBPluginDependency + 721.IBPluginDependency + 722.IBPluginDependency + 723.IBPluginDependency + 724.IBPluginDependency + 725.IBPluginDependency + 726.IBPluginDependency + 727.IBPluginDependency + 728.IBPluginDependency + 729.IBPluginDependency + 730.IBPluginDependency + 731.IBPluginDependency + 732.IBPluginDependency + 733.IBPluginDependency + 734.IBPluginDependency + 735.IBPluginDependency + 736.IBPluginDependency + 737.IBPluginDependency + 738.IBPluginDependency + 739.IBPluginDependency + 740.IBPluginDependency + 741.IBPluginDependency + 742.IBPluginDependency + 743.IBPluginDependency + 744.IBPluginDependency + 745.IBPluginDependency + 746.IBPluginDependency + 747.IBPluginDependency + 748.IBPluginDependency + 749.IBPluginDependency + 750.IBPluginDependency + 751.IBPluginDependency + 752.IBPluginDependency + 753.IBPluginDependency + 754.IBPluginDependency + 755.IBPluginDependency + 756.IBPluginDependency + 757.IBPluginDependency + 758.IBPluginDependency + 759.IBPluginDependency + 760.IBPluginDependency + 761.IBPluginDependency + 762.IBPluginDependency + 763.IBPluginDependency + 764.IBPluginDependency + 765.IBPluginDependency + 766.IBPluginDependency + 767.IBPluginDependency + 768.IBPluginDependency + 769.IBPluginDependency + 770.IBPluginDependency + 771.IBPluginDependency + 772.IBPluginDependency + 773.IBPluginDependency + 774.IBPluginDependency + 775.IBPluginDependency + 776.IBPluginDependency + 777.IBPluginDependency + 778.IBPluginDependency + 779.IBPluginDependency + 780.IBPluginDependency + 781.IBPluginDependency + 782.IBPluginDependency + 783.IBPluginDependency + 784.IBPluginDependency + 785.IBPluginDependency + 786.IBPluginDependency + 787.IBPluginDependency + 788.IBPluginDependency + 789.IBPluginDependency + 790.IBPluginDependency + 791.IBPluginDependency + 792.IBPluginDependency + 793.IBPluginDependency + 794.IBPluginDependency + 795.IBPluginDependency + 796.IBPluginDependency + 797.IBPluginDependency + 798.IBPluginDependency + 799.IBPluginDependency + 800.IBPluginDependency + 801.IBPluginDependency + 802.IBPluginDependency + 803.IBPluginDependency + 804.IBPluginDependency + 805.IBPluginDependency + 806.IBPluginDependency + 807.IBPluginDependency + 808.IBPluginDependency + 809.IBPluginDependency + 810.IBPluginDependency + 811.IBPluginDependency + 812.IBPluginDependency + 813.IBPluginDependency + 814.IBPluginDependency + 815.IBPluginDependency + 816.IBPluginDependency + 817.IBPluginDependency + 818.IBPluginDependency + 819.IBPluginDependency + 820.IBPluginDependency + 821.IBPluginDependency + 822.IBPluginDependency + 823.IBPluginDependency + 824.IBPluginDependency + 825.IBPluginDependency + 826.IBPluginDependency + 827.IBPluginDependency + 828.IBPluginDependency + 829.IBPluginDependency + 830.IBPluginDependency + 831.IBPluginDependency + 832.IBPluginDependency + 833.IBPluginDependency + 834.IBPluginDependency + 835.IBPluginDependency + 836.IBPluginDependency + 837.IBPluginDependency + 838.IBPluginDependency + 839.IBPluginDependency + 840.IBPluginDependency + 841.IBPluginDependency + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + + + + + YES + + + + + 841 + + + + YES + + ApplicationDelegate + NSObject + + togglePanel: + id + + + togglePanel: + + togglePanel: + id + + + + splashLogo + NSWindow + + + splashLogo + + splashLogo + NSWindow + + + + IBProjectSource + ./Classes/ApplicationDelegate.h + + + + SUUpdater + NSObject + + checkForUpdates: + id + + + checkForUpdates: + + checkForUpdates: + id + + + + delegate + id + + + delegate + + delegate + id + + + + IBProjectSource + ./Classes/SUUpdater.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + YES + + YES + NSMenuCheckmark + NSMenuMixedState + + + YES + {9, 8} + {7, 2} + + + + diff --git a/client/osx/Hackpad/main.m b/client/osx/Hackpad/main.m new file mode 100644 index 0000000..df0d443 --- /dev/null +++ b/client/osx/Hackpad/main.m @@ -0,0 +1,14 @@ +// +// main.m +// Popup +// +// Created by Vadim Shpakovski on 7/5/11. +// Copyright 2011 __MyCompanyName__. All rights reserved. +// + +#import + +int main(int argc, char *argv[]) +{ + return NSApplicationMain(argc, (const char **)argv); +} diff --git a/client/osx/HackpadApplication.h b/client/osx/HackpadApplication.h new file mode 100644 index 0000000..471552a --- /dev/null +++ b/client/osx/HackpadApplication.h @@ -0,0 +1,13 @@ +// +// HackpadApplication.h +// HackPad +// +// +// Copyright 2011 Social Interfaces. All rights reserved. +// + +#import + +@interface HackpadApplication : NSApplication + +@end diff --git a/client/osx/HackpadApplication.m b/client/osx/HackpadApplication.m new file mode 100644 index 0000000..cf8fe4b --- /dev/null +++ b/client/osx/HackpadApplication.m @@ -0,0 +1,56 @@ +// +// HackpadApplication.m +// HackPad +// +// +// Copyright 2011 Social Interfaces. All rights reserved. +// + +#import "HackpadApplication.h" + +@implementation HackpadApplication + +- (id)init +{ + self = [super init]; + if (self) { + // Initialization code here. + } + + return self; +} +- (void) sendEvent:(NSEvent *)event { + if ([event type] == NSKeyDown) { + if (([event modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) { + if ([[event charactersIgnoringModifiers] isEqualToString:@"x"]) { + if ([self sendAction:@selector(cut:) to:nil from:self]) + return; + } + else if ([[event charactersIgnoringModifiers] isEqualToString:@"c"]) { + if ([self sendAction:@selector(copy:) to:nil from:self]) + return; + } + else if ([[event charactersIgnoringModifiers] isEqualToString:@"v"]) { + if ([self sendAction:@selector(paste:) to:nil from:self]) + return; + } + else if ([[event charactersIgnoringModifiers] isEqualToString:@"z"]) { + if ([self sendAction:@selector(undo:) to:nil from:self]) + return; + } + else if ([[event charactersIgnoringModifiers] isEqualToString:@"a"]) { + if ([self sendAction:@selector(selectAll:) to:nil from:self]) + return; + } + } + else if (([event modifierFlags] & NSDeviceIndependentModifierFlagsMask) == (NSCommandKeyMask | NSShiftKeyMask)) { + if ([[event charactersIgnoringModifiers] isEqualToString:@"Z"]) { + if ([self sendAction:@selector(redo:) to:nil from:self]) + return; + } + } + } + [super sendEvent:event]; +} + +@end diff --git a/client/osx/JSON.h b/client/osx/JSON.h new file mode 100644 index 0000000..1e58c9a --- /dev/null +++ b/client/osx/JSON.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2009 Stig Brautaset. 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 the author 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. + */ + +/** + @mainpage A strict JSON parser and generator for Objective-C + + JSON (JavaScript Object Notation) is a lightweight data-interchange + format. This framework provides two apis for parsing and generating + JSON. One standard object-based and a higher level api consisting of + categories added to existing Objective-C classes. + + Learn more on the http://code.google.com/p/json-framework project site. + + This framework does its best to be as strict as possible, both in what it + accepts and what it generates. For example, it does not support trailing commas + in arrays or objects. Nor does it support embedded comments, or + anything else not in the JSON specification. This is considered a feature. + +*/ + +#import "SBJSON.h" +#import "NSObject+SBJSON.h" +#import "NSString+SBJSON.h" + diff --git a/client/osx/MenuArrayController.h b/client/osx/MenuArrayController.h new file mode 100644 index 0000000..b1b2516 --- /dev/null +++ b/client/osx/MenuArrayController.h @@ -0,0 +1,31 @@ +// +// MenuArrayController.h +// HackPad +// +// +// Copyright 2011 Hackpad. All rights reserved. +// + + + +@interface MenuArrayController : NSArrayController +{ + BOOL _signedIn; + id _delegate; + BOOL _searching; + NSString* _searchString; + + BOOL _showCollectionsOption; + BOOL _showCollectionsBackOption; + BOOL _showAllPadsOption; +} + +@property (assign) BOOL signedIn; +@property (assign) id delegate; +@property (readwrite, assign, getter = isSearching) BOOL searching; +@property (readwrite, copy) NSString* searchString; +@property (readwrite, copy) NSString* title; +@property (readwrite, assign) BOOL showCollectionsOption; +@property (readwrite, assign) BOOL showCollectionsBackOption; +@property (readwrite, assign) BOOL showAllPadsOption; +@end diff --git a/client/osx/MenuArrayController.m b/client/osx/MenuArrayController.m new file mode 100644 index 0000000..9bcf6a0 --- /dev/null +++ b/client/osx/MenuArrayController.m @@ -0,0 +1,99 @@ +// +// MenuArrayController.m +// HackPad +// +// +// Copyright 2011 Hackpad. All rights reserved. +// + +#import "MenuArrayController.h" + +#define SEPARATOR [NSMutableDictionary dictionaryWithObjectsAndKeys:@"separator", @"type", [NSNumber numberWithBool:YES], @"ignoreClicks", nil] + +@implementation MenuArrayController + +@synthesize signedIn = _signedIn; +@synthesize delegate = _delegate; +@synthesize searching = _searching; +@synthesize searchString = _searchString; +@synthesize showCollectionsOption = _showCollectionsOption; +@synthesize showCollectionsBackOption = _showCollectionsBackOption; +@synthesize showAllPadsOption = _showAllPadsOption; + +- (id)init +{ + self = [super init]; + if (self) { + // Initialization code here. + } + + return self; +} + +- (NSArray *)arrangeObjects:(NSArray *)objects { + NSArray *superArrangedObjects = [super arrangeObjects:objects]; + if ([superArrangedObjects count] > 19) { + superArrangedObjects = [superArrangedObjects subarrayWithRange:NSMakeRange(0, 19)]; + } /*else + { + return superArrangedObjects; + }*/ + + NSMutableArray *result = [NSMutableArray arrayWithArray:superArrangedObjects]; + + if([self signedIn] && [self isSearching]) + { + [result addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Create pad \"%@\"",[self searchString]], @"title", + @"createPad:", @"selector", self.delegate, @"target", nil]]; + } + + + if (!self.signedIn){ + [result addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Login...", @"title", + @"login:", @"selector", self.delegate, @"target", nil]]; + } + + [result addObject:SEPARATOR]; + + if (self.signedIn){ + if (!self.searching) + { + + BOOL addSeparator = NO; + if(self.showCollectionsOption) + { + [result addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Collections ▶", @"title", + @"showCollections:", @"selector", self.delegate, @"target", nil]]; + addSeparator = YES; + } + if(self.showCollectionsBackOption) + { + [result addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"◀ Collections", @"title", + @"showCollections:", @"selector", self.delegate, @"target", nil]]; + addSeparator = YES; + } + if(self.showAllPadsOption) + { + [result addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"◀ All Pads", @"title", + @"showAllPads:", @"selector", self.delegate, @"target", nil]]; + addSeparator = YES; + } + + if(addSeparator) + { + [result addObject:SEPARATOR]; + } + } + + [result addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Logout", @"title", + @"logout:", @"selector", self.delegate, @"target", nil]]; + + } + + [result addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Quit", @"title", + @"quitApplication", @"selector", self.delegate, @"target", nil]]; + + return result; +} + +@end diff --git a/client/osx/MenuTableColumn.h b/client/osx/MenuTableColumn.h new file mode 100644 index 0000000..4c5d99d --- /dev/null +++ b/client/osx/MenuTableColumn.h @@ -0,0 +1,18 @@ +// +// MenuTableColumn.h +// HackPad +// +// +// Copyright 2011 Hackpad. All rights reserved. +// + + + +@interface MenuTableColumn : NSTableColumn +{ + id delegate; +} + +@property (assign) id delegate; + +@end diff --git a/client/osx/MenuTableColumn.m b/client/osx/MenuTableColumn.m new file mode 100644 index 0000000..bac6fa6 --- /dev/null +++ b/client/osx/MenuTableColumn.m @@ -0,0 +1,48 @@ +// +// MenuTableColumn.m +// HackPad +// +// +// Copyright 2011 Hackpad. All rights reserved. +// + +#import "MenuTableColumn.h" +#import "SeparatorCell.h" + +@implementation MenuTableColumn +@synthesize delegate; + +- (id)init +{ + self = [super init]; + if (self) { + // Initialization code here. + } + + return self; +} + + +- (id)dataCellForRow:(NSInteger)row { + id foo = [[self.delegate arrangedObjects]objectAtIndex:row]; + if ([[foo objectForKey:@"type"] isEqualToString: @"separator"]) { + return [[[SeparatorCell alloc]init] autorelease]; + } + if ([[foo objectForKey:@"type"] isEqualToString:@"text"]) { + NSTextFieldCell* cell = [[[NSTextFieldCell alloc] initTextCell:[foo objectForKey:@"title"]] autorelease]; + [cell setTextColor:[NSColor grayColor]]; + return cell; + } + // [self + // NSMutableDictionary *data = [self.tableView. tableView:self.tableView objectValueForTableColumn:self row:row]; + + // NSCell *foo = [self.tableView preparedCellAtColumn:0 row:row]; +// NSLog([[foo representedObject] stringRepresentation]); + return [self dataCell]; + + //return [[[SeparatorCell alloc]init] autorelease]; +} + + + +@end diff --git a/client/osx/NSObject+SBJSON.h b/client/osx/NSObject+SBJSON.h new file mode 100644 index 0000000..ecf0ee4 --- /dev/null +++ b/client/osx/NSObject+SBJSON.h @@ -0,0 +1,68 @@ +/* + Copyright (C) 2009 Stig Brautaset. 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 the author 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. + */ + +#import + + +/** + @brief Adds JSON generation to Foundation classes + + This is a category on NSObject that adds methods for returning JSON representations + of standard objects to the objects themselves. This means you can call the + -JSONRepresentation method on an NSArray object and it'll do what you want. + */ +@interface NSObject (NSObject_SBJSON) + +/** + @brief Returns a string containing the receiver encoded as a JSON fragment. + + This method is added as a category on NSObject but is only actually + supported for the following objects: + @li NSDictionary + @li NSArray + @li NSString + @li NSNumber (also used for booleans) + @li NSNull + + @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. + */ +- (NSString *)JSONFragment; + +/** + @brief Returns a string containing the receiver encoded in JSON. + + This method is added as a category on NSObject but is only actually + supported for the following objects: + @li NSDictionary + @li NSArray + */ +- (NSString *)JSONRepresentation; + +@end + diff --git a/client/osx/NSObject+SBJSON.m b/client/osx/NSObject+SBJSON.m new file mode 100644 index 0000000..20b084b --- /dev/null +++ b/client/osx/NSObject+SBJSON.m @@ -0,0 +1,53 @@ +/* + Copyright (C) 2009 Stig Brautaset. 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 the author 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. + */ + +#import "NSObject+SBJSON.h" +#import "SBJsonWriter.h" + +@implementation NSObject (NSObject_SBJSON) + +- (NSString *)JSONFragment { + SBJsonWriter *jsonWriter = [SBJsonWriter new]; + NSString *json = [jsonWriter stringWithFragment:self]; + if (!json) + NSLog(@"-JSONFragment failed. Error trace is: %@", [jsonWriter errorTrace]); + [jsonWriter release]; + return json; +} + +- (NSString *)JSONRepresentation { + SBJsonWriter *jsonWriter = [SBJsonWriter new]; + NSString *json = [jsonWriter stringWithObject:self]; + if (!json) + NSLog(@"-JSONRepresentation failed. Error trace is: %@", [jsonWriter errorTrace]); + [jsonWriter release]; + return json; +} + +@end diff --git a/client/osx/NSStatusItem+Additions.h b/client/osx/NSStatusItem+Additions.h new file mode 100644 index 0000000..6e1133e --- /dev/null +++ b/client/osx/NSStatusItem+Additions.h @@ -0,0 +1,7 @@ +#import + + +@interface NSStatusItem (Additions) +- (NSWindow*)window; +- (NSRect)frameInScreenCoordinates; +@end \ No newline at end of file diff --git a/client/osx/NSStatusItem+Additions.m b/client/osx/NSStatusItem+Additions.m new file mode 100644 index 0000000..b8eb7e4 --- /dev/null +++ b/client/osx/NSStatusItem+Additions.m @@ -0,0 +1,20 @@ +#import "NSStatusItem+Additions.h" + +@implementation NSStatusItem (Additions) + +- (NSWindow*)window { + if ([self respondsToSelector: @selector(_window)]) { + return [self performSelector: @selector(_window)]; + } + return nil; +} + +- (NSRect)frameInScreenCoordinates { + NSWindow *theWindow = [self window]; + if (theWindow) { + return [theWindow frame]; + } + return NSZeroRect; +} + +@end \ No newline at end of file diff --git a/client/osx/NSString+SBJSON.h b/client/osx/NSString+SBJSON.h new file mode 100644 index 0000000..fad7179 --- /dev/null +++ b/client/osx/NSString+SBJSON.h @@ -0,0 +1,58 @@ +/* + Copyright (C) 2009 Stig Brautaset. 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 the author 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. + */ + +#import + +/** + @brief Adds JSON parsing methods to NSString + +This is a category on NSString that adds methods for parsing the target string. +*/ +@interface NSString (NSString_SBJSON) + + +/** + @brief Returns the object represented in the receiver, or nil on error. + + Returns a a scalar object represented by the string's JSON fragment representation. + + @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. + */ +- (id)JSONFragmentValue; + +/** + @brief Returns the NSDictionary or NSArray represented by the current string's JSON representation. + + Returns the dictionary or array represented in the receiver, or nil on error. + + Returns the NSDictionary or NSArray represented by the current string's JSON representation. + */ +- (id)JSONValue; + +@end diff --git a/client/osx/NSString+SBJSON.m b/client/osx/NSString+SBJSON.m new file mode 100644 index 0000000..41a5a85 --- /dev/null +++ b/client/osx/NSString+SBJSON.m @@ -0,0 +1,55 @@ +/* + Copyright (C) 2007-2009 Stig Brautaset. 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 the author 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. + */ + +#import "NSString+SBJSON.h" +#import "SBJsonParser.h" + +@implementation NSString (NSString_SBJSON) + +- (id)JSONFragmentValue +{ + SBJsonParser *jsonParser = [SBJsonParser new]; + id repr = [jsonParser fragmentWithString:self]; + if (!repr) + NSLog(@"-JSONFragmentValue failed. Error trace is: %@", [jsonParser errorTrace]); + [jsonParser release]; + return repr; +} + +- (id)JSONValue +{ + SBJsonParser *jsonParser = [SBJsonParser new]; + id repr = [jsonParser objectWithString:self]; + if (!repr) + NSLog(@"-JSONValue failed. Error trace is: %@", [jsonParser errorTrace]); + [jsonParser release]; + return repr; +} + +@end diff --git a/client/osx/NSString+URLEncoding.h b/client/osx/NSString+URLEncoding.h new file mode 100644 index 0000000..4e8cafd --- /dev/null +++ b/client/osx/NSString+URLEncoding.h @@ -0,0 +1,15 @@ +// +// NSString+URLEncoding.h +// HackPad +// +// Created by Tyler Bunnell on 6/21/12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +@interface NSString (URLEncoding) + +- (NSString *) stringByUrlEncoding; + +@end diff --git a/client/osx/NSString+URLEncoding.m b/client/osx/NSString+URLEncoding.m new file mode 100644 index 0000000..53d7d98 --- /dev/null +++ b/client/osx/NSString+URLEncoding.m @@ -0,0 +1,18 @@ +// +// NSString+URLEncoding.m +// HackPad +// +// Created by Tyler Bunnell on 6/21/12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "NSString+URLEncoding.h" + +@implementation NSString (URLEncoding) + +- (NSString *) stringByUrlEncoding +{ + return (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); +} + +@end diff --git a/client/osx/NSView+AnimationBlock.h b/client/osx/NSView+AnimationBlock.h new file mode 100644 index 0000000..cee68b8 --- /dev/null +++ b/client/osx/NSView+AnimationBlock.h @@ -0,0 +1,13 @@ +#import + +@interface NSView (AnimationBlock) + ++ (void)animation:(void (^)(void))animationBlock; ++ (void)animation:(void (^)(void))animationBlock + completion:(void (^)(void))completionBlock; ++ (void)animateWithDuration:(NSTimeInterval)duration + animation:(void (^)(void))animationBlock; ++ (void)animateWithDuration:(NSTimeInterval)duration + animation:(void (^)(void))animationBlock + completion:(void (^)(void))completionBlock; +@end diff --git a/client/osx/NSView+AnimationBlock.m b/client/osx/NSView+AnimationBlock.m new file mode 100644 index 0000000..dd6453b --- /dev/null +++ b/client/osx/NSView+AnimationBlock.m @@ -0,0 +1,57 @@ +#import "NSView+AnimationBlock.h" + +typedef void(^VoidBlock)(void); + +@interface NSView (AnimationBlockInternal) ++ (void)runEndBlock:(void (^)(void))completionBlock; +@end + +@implementation NSView (AnimationBlock) + ++ (void)animation:(void (^)(void))animationBlock +{ + [self animateWithDuration:0.25 animation:animationBlock]; +} ++ (void)animation:(void (^)(void))animationBlock + completion:(void (^)(void))completionBlock +{ + [self animateWithDuration:0.25 animation:animationBlock completion:completionBlock]; +} + + ++ (void)animateWithDuration:(NSTimeInterval)duration + animation:(void (^)(void))animationBlock +{ + [self animateWithDuration:duration animation:animationBlock completion:nil]; +} ++ (void)animateWithDuration:(NSTimeInterval)duration + animation:(void (^)(void))animationBlock + completion:(void (^)(void))completionBlock +{ + [NSAnimationContext beginGrouping]; + [[NSAnimationContext currentContext] setDuration:duration]; + animationBlock(); + [NSAnimationContext endGrouping]; + + if(completionBlock) + { + VoidBlock completionBlockCopy = [[completionBlock copy] autorelease]; + + double delayInSeconds = duration; + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); + dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ + completionBlockCopy(); + }); + } +} + +@end + +@implementation NSView (AnimationBlockInternal) + ++ (void)runEndBlock:(void (^)(void))completionBlock +{ + completionBlock(); +} + +@end diff --git a/client/osx/PreferenceKeys.h b/client/osx/PreferenceKeys.h new file mode 100644 index 0000000..4165ecf --- /dev/null +++ b/client/osx/PreferenceKeys.h @@ -0,0 +1,13 @@ +// Define all the keys used in the preferences +#define FIRST_RUN_KEY @"firstRun" + +// Define convenience methods for accessing the above keys +#define DEFAULTS [NSUserDefaults standardUserDefaults] + +#define EncodeAndSaveObject(object,key) [DEFAULTS setObject:[NSKeyedArchiver archivedDataWithRootObject:object] forKey:key] +#define LoadAndDecodeObject(key) [DEFAULTS objectForKey:key] != nil ? [NSKeyedUnarchiver unarchiveObjectWithData:[DEFAULTS objectForKey:key]] : nil + +#define FIRST_RUN [DEFAULTS boolForKey:FIRST_RUN_KEY] + + + diff --git a/client/osx/ROTableView.h b/client/osx/ROTableView.h new file mode 100644 index 0000000..31cdfa8 --- /dev/null +++ b/client/osx/ROTableView.h @@ -0,0 +1,20 @@ +// +// ROTableView.h +// HackPad +// +// +// Copyright 2011 Hackpad. All rights reserved. +// + + +@interface ROTableView : NSTableView +{ + NSTrackingArea* trackingArea; + BOOL mouseOverView; + NSInteger mouseOverRow; + BOOL _searching; +} + +@property (readwrite,assign,nonatomic) BOOL searching; + +@end diff --git a/client/osx/ROTableView.m b/client/osx/ROTableView.m new file mode 100644 index 0000000..f9be4ad --- /dev/null +++ b/client/osx/ROTableView.m @@ -0,0 +1,109 @@ +// +// ROTableView.m +// HackPad +// +// +// Copyright 2011 Hackpad. All rights reserved. +// + +#import + +#import "ROTableView.h" +#import "SeparatorCell.h" +#import "PanelController.h" + +@implementation ROTableView + +@synthesize searching = _searching; + + +- (void)awakeFromNib +{ + [[self window] makeFirstResponder:self]; + trackingArea = [[NSTrackingArea alloc] initWithRect:[self frame] options:(NSTrackingActiveInActiveApp | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved) owner:self userInfo:nil]; + [self addTrackingArea:trackingArea]; + mouseOverView = NO; + mouseOverRow = -1; + +} + +- (void)dealloc +{ + [self removeTrackingArea:trackingArea]; + trackingArea = nil; + [super dealloc]; +} + +- (void)mouseEntered:(NSEvent*)theEvent +{ + mouseOverView = YES; +} + +- (void)keyDown:(NSEvent *)theEvent +{ + switch ([theEvent keyCode]) + { + case kVK_UpArrow: + [self.delegate performSelector:@selector(selectPreviousRow)]; + break; + case kVK_DownArrow: + [self.delegate performSelector:@selector(selectNextRow)]; + break; + case kVK_Return: + [self.delegate performSelector:@selector(selectPadForSelectedRow)]; + break; + default: + break; + } +} + +- (void)setSearching:(BOOL)searching +{ + _searching = searching; + if(searching) + { + [self selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO]; + [self setNeedsDisplayInRect:[self rectOfRow:0]]; + } +} + + +- (void)mouseMoved:(NSEvent*)theEvent +{ + if (mouseOverView) + { + mouseOverRow = [self rowAtPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil]]; + + if([self.delegate tableView:self shouldSelectRow:mouseOverRow]) + { + [self selectRowIndexes:[NSIndexSet indexSetWithIndex:mouseOverRow] byExtendingSelection:NO]; + [self setNeedsDisplayInRect:[self rectOfRow:mouseOverRow]]; + } + else + { + [self deselectAll:self]; + } + } +} + +- (void)mouseExited:(NSEvent *)theEvent +{ + mouseOverView = NO; + [self setNeedsDisplayInRect:[self rectOfRow:mouseOverRow]]; + mouseOverRow = -1; +} + +- (NSInteger)mouseOverRow +{ + return mouseOverRow; +} + +-(void)resetCursorRects +{ + [super resetCursorRects]; + [self removeTrackingArea:trackingArea]; + trackingArea = [[NSTrackingArea alloc] initWithRect:[self frame] options:(NSTrackingActiveInActiveApp | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved) owner:self userInfo:nil]; + [self addTrackingArea:trackingArea]; +} + +@end \ No newline at end of file diff --git a/client/osx/SBJSON.h b/client/osx/SBJSON.h new file mode 100644 index 0000000..43d63c3 --- /dev/null +++ b/client/osx/SBJSON.h @@ -0,0 +1,75 @@ +/* + Copyright (C) 2007-2009 Stig Brautaset. 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 the author 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. + */ + +#import +#import "SBJsonParser.h" +#import "SBJsonWriter.h" + +/** + @brief Facade for SBJsonWriter/SBJsonParser. + + Requests are forwarded to instances of SBJsonWriter and SBJsonParser. + */ +@interface SBJSON : SBJsonBase { + +@private + SBJsonParser *jsonParser; + SBJsonWriter *jsonWriter; +} + + +/// Return the fragment represented by the given string +- (id)fragmentWithString:(NSString*)jsonrep + error:(NSError**)error; + +/// Return the object represented by the given string +- (id)objectWithString:(NSString*)jsonrep + error:(NSError**)error; + +/// Parse the string and return the represented object (or scalar) +- (id)objectWithString:(id)value + allowScalar:(BOOL)x + error:(NSError**)error; + + +/// Return JSON representation of an array or dictionary +- (NSString*)stringWithObject:(id)value + error:(NSError**)error; + +/// Return JSON representation of any legal JSON value +- (NSString*)stringWithFragment:(id)value + error:(NSError**)error; + +/// Return JSON representation (or fragment) for the given object +- (NSString*)stringWithObject:(id)value + allowScalar:(BOOL)x + error:(NSError**)error; + + +@end diff --git a/client/osx/SBJSON.m b/client/osx/SBJSON.m new file mode 100644 index 0000000..2a30f1a --- /dev/null +++ b/client/osx/SBJSON.m @@ -0,0 +1,212 @@ +/* + Copyright (C) 2007-2009 Stig Brautaset. 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 the author 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. + */ + +#import "SBJSON.h" + +@implementation SBJSON + +- (id)init { + self = [super init]; + if (self) { + jsonWriter = [SBJsonWriter new]; + jsonParser = [SBJsonParser new]; + [self setMaxDepth:512]; + + } + return self; +} + +- (void)dealloc { + [jsonWriter release]; + [jsonParser release]; + [super dealloc]; +} + +#pragma mark Writer + + +- (NSString *)stringWithObject:(id)obj { + NSString *repr = [jsonWriter stringWithObject:obj]; + if (repr) + return repr; + + [errorTrace release]; + errorTrace = [[jsonWriter errorTrace] mutableCopy]; + return nil; +} + +/** + Returns a string containing JSON representation of the passed in value, or nil on error. + If nil is returned and @p error is not NULL, @p *error can be interrogated to find the cause of the error. + + @param value any instance that can be represented as a JSON fragment + @param allowScalar wether to return json fragments for scalar objects + @param error used to return an error by reference (pass NULL if this is not desired) + +@deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. + */ +- (NSString*)stringWithObject:(id)value allowScalar:(BOOL)allowScalar error:(NSError**)error { + + NSString *json = allowScalar ? [jsonWriter stringWithFragment:value] : [jsonWriter stringWithObject:value]; + if (json) + return json; + + [errorTrace release]; + errorTrace = [[jsonWriter errorTrace] mutableCopy]; + + if (error) + *error = [errorTrace lastObject]; + return nil; +} + +/** + Returns a string containing JSON representation of the passed in value, or nil on error. + If nil is returned and @p error is not NULL, @p error can be interrogated to find the cause of the error. + + @param value any instance that can be represented as a JSON fragment + @param error used to return an error by reference (pass NULL if this is not desired) + + @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. + */ +- (NSString*)stringWithFragment:(id)value error:(NSError**)error { + return [self stringWithObject:value + allowScalar:YES + error:error]; +} + +/** + Returns a string containing JSON representation of the passed in value, or nil on error. + If nil is returned and @p error is not NULL, @p error can be interrogated to find the cause of the error. + + @param value a NSDictionary or NSArray instance + @param error used to return an error by reference (pass NULL if this is not desired) + */ +- (NSString*)stringWithObject:(id)value error:(NSError**)error { + return [self stringWithObject:value + allowScalar:NO + error:error]; +} + +#pragma mark Parsing + +- (id)objectWithString:(NSString *)repr { + id obj = [jsonParser objectWithString:repr]; + if (obj) + return obj; + + [errorTrace release]; + errorTrace = [[jsonParser errorTrace] mutableCopy]; + + return nil; +} + +/** + Returns the object represented by the passed-in string or nil on error. The returned object can be + a string, number, boolean, null, array or dictionary. + + @param value the json string to parse + @param allowScalar whether to return objects for JSON fragments + @param error used to return an error by reference (pass NULL if this is not desired) + + @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. + */ +- (id)objectWithString:(id)value allowScalar:(BOOL)allowScalar error:(NSError**)error { + + id obj = allowScalar ? [jsonParser fragmentWithString:value] : [jsonParser objectWithString:value]; + if (obj) + return obj; + + [errorTrace release]; + errorTrace = [[jsonParser errorTrace] mutableCopy]; + + if (error) + *error = [errorTrace lastObject]; + return nil; +} + +/** + Returns the object represented by the passed-in string or nil on error. The returned object can be + a string, number, boolean, null, array or dictionary. + + @param repr the json string to parse + @param error used to return an error by reference (pass NULL if this is not desired) + + @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. + */ +- (id)fragmentWithString:(NSString*)repr error:(NSError**)error { + return [self objectWithString:repr + allowScalar:YES + error:error]; +} + +/** + Returns the object represented by the passed-in string or nil on error. The returned object + will be either a dictionary or an array. + + @param repr the json string to parse + @param error used to return an error by reference (pass NULL if this is not desired) + */ +- (id)objectWithString:(NSString*)repr error:(NSError**)error { + return [self objectWithString:repr + allowScalar:NO + error:error]; +} + + + +#pragma mark Properties - parsing + +- (NSUInteger)maxDepth { + return jsonParser.maxDepth; +} + +- (void)setMaxDepth:(NSUInteger)d { + jsonWriter.maxDepth = jsonParser.maxDepth = d; +} + + +#pragma mark Properties - writing + +- (BOOL)humanReadable { + return jsonWriter.humanReadable; +} + +- (void)setHumanReadable:(BOOL)x { + jsonWriter.humanReadable = x; +} + +- (BOOL)sortKeys { + return jsonWriter.sortKeys; +} + +- (void)setSortKeys:(BOOL)x { + jsonWriter.sortKeys = x; +} + +@end diff --git a/client/osx/SBJsonBase.h b/client/osx/SBJsonBase.h new file mode 100644 index 0000000..7b10844 --- /dev/null +++ b/client/osx/SBJsonBase.h @@ -0,0 +1,86 @@ +/* + Copyright (C) 2009 Stig Brautaset. 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 the author 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. + */ + +#import + +extern NSString * SBJSONErrorDomain; + + +enum { + EUNSUPPORTED = 1, + EPARSENUM, + EPARSE, + EFRAGMENT, + ECTRL, + EUNICODE, + EDEPTH, + EESCAPE, + ETRAILCOMMA, + ETRAILGARBAGE, + EEOF, + EINPUT +}; + +/** + @brief Common base class for parsing & writing. + + This class contains the common error-handling code and option between the parser/writer. + */ +@interface SBJsonBase : NSObject { + NSMutableArray *errorTrace; + +@protected + NSUInteger depth, maxDepth; +} + +/** + @brief The maximum recursing depth. + + Defaults to 512. If the input is nested deeper than this the input will be deemed to be + malicious and the parser returns nil, signalling an error. ("Nested too deep".) You can + turn off this security feature by setting the maxDepth value to 0. + */ +@property NSUInteger maxDepth; + +/** + @brief Return an error trace, or nil if there was no errors. + + Note that this method returns the trace of the last method that failed. + You need to check the return value of the call you're making to figure out + if the call actually failed, before you know call this method. + */ + @property(copy,readonly) NSArray* errorTrace; + +/// @internal for use in subclasses to add errors to the stack trace +- (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str; + +/// @internal for use in subclasess to clear the error before a new parsing attempt +- (void)clearErrorTrace; + +@end diff --git a/client/osx/SBJsonBase.m b/client/osx/SBJsonBase.m new file mode 100644 index 0000000..6684325 --- /dev/null +++ b/client/osx/SBJsonBase.m @@ -0,0 +1,78 @@ +/* + Copyright (C) 2009 Stig Brautaset. 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 the author 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. + */ + +#import "SBJsonBase.h" +NSString * SBJSONErrorDomain = @"org.brautaset.JSON.ErrorDomain"; + + +@implementation SBJsonBase + +@synthesize errorTrace; +@synthesize maxDepth; + +- (id)init { + self = [super init]; + if (self) + self.maxDepth = 512; + return self; +} + +- (void)dealloc { + [errorTrace release]; + [super dealloc]; +} + +- (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str { + NSDictionary *userInfo; + if (!errorTrace) { + errorTrace = [NSMutableArray new]; + userInfo = [NSDictionary dictionaryWithObject:str forKey:NSLocalizedDescriptionKey]; + + } else { + userInfo = [NSDictionary dictionaryWithObjectsAndKeys: + str, NSLocalizedDescriptionKey, + [errorTrace lastObject], NSUnderlyingErrorKey, + nil]; + } + + NSError *error = [NSError errorWithDomain:SBJSONErrorDomain code:code userInfo:userInfo]; + + [self willChangeValueForKey:@"errorTrace"]; + [errorTrace addObject:error]; + [self didChangeValueForKey:@"errorTrace"]; +} + +- (void)clearErrorTrace { + [self willChangeValueForKey:@"errorTrace"]; + [errorTrace release]; + errorTrace = nil; + [self didChangeValueForKey:@"errorTrace"]; +} + +@end diff --git a/client/osx/SBJsonParser.h b/client/osx/SBJsonParser.h new file mode 100644 index 0000000..e95304d --- /dev/null +++ b/client/osx/SBJsonParser.h @@ -0,0 +1,87 @@ +/* + Copyright (C) 2009 Stig Brautaset. 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 the author 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. + */ + +#import +#import "SBJsonBase.h" + +/** + @brief Options for the parser class. + + This exists so the SBJSON facade can implement the options in the parser without having to re-declare them. + */ +@protocol SBJsonParser + +/** + @brief Return the object represented by the given string. + + Returns the object represented by the passed-in string or nil on error. The returned object can be + a string, number, boolean, null, array or dictionary. + + @param repr the json string to parse + */ +- (id)objectWithString:(NSString *)repr; + +@end + + +/** + @brief The JSON parser class. + + JSON is mapped to Objective-C types in the following way: + + @li Null -> NSNull + @li String -> NSMutableString + @li Array -> NSMutableArray + @li Object -> NSMutableDictionary + @li Boolean -> NSNumber (initialised with -initWithBool:) + @li Number -> NSDecimalNumber + + Since Objective-C doesn't have a dedicated class for boolean values, these turns into NSNumber + instances. These are initialised with the -initWithBool: method, and + round-trip back to JSON properly. (They won't silently suddenly become 0 or 1; they'll be + represented as 'true' and 'false' again.) + + JSON numbers turn into NSDecimalNumber instances, + as we can thus avoid any loss of precision. (JSON allows ridiculously large numbers.) + + */ +@interface SBJsonParser : SBJsonBase { + +@private + const char *c; +} + +@end + +// don't use - exists for backwards compatibility with 2.1.x only. Will be removed in 2.3. +@interface SBJsonParser (Private) +- (id)fragmentWithString:(id)repr; +@end + + diff --git a/client/osx/SBJsonParser.m b/client/osx/SBJsonParser.m new file mode 100644 index 0000000..eda051a --- /dev/null +++ b/client/osx/SBJsonParser.m @@ -0,0 +1,475 @@ +/* + Copyright (C) 2009 Stig Brautaset. 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 the author 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. + */ + +#import "SBJsonParser.h" + +@interface SBJsonParser () + +- (BOOL)scanValue:(NSObject **)o; + +- (BOOL)scanRestOfArray:(NSMutableArray **)o; +- (BOOL)scanRestOfDictionary:(NSMutableDictionary **)o; +- (BOOL)scanRestOfNull:(NSNull **)o; +- (BOOL)scanRestOfFalse:(NSNumber **)o; +- (BOOL)scanRestOfTrue:(NSNumber **)o; +- (BOOL)scanRestOfString:(NSMutableString **)o; + +// Cannot manage without looking at the first digit +- (BOOL)scanNumber:(NSNumber **)o; + +- (BOOL)scanHexQuad:(unichar *)x; +- (BOOL)scanUnicodeChar:(unichar *)x; + +- (BOOL)scanIsAtEnd; + +@end + +#define skipWhitespace(c) while (isspace(*c)) c++ +#define skipDigits(c) while (isdigit(*c)) c++ + + +@implementation SBJsonParser + +static char ctrl[0x22]; + + ++ (void)initialize { + ctrl[0] = '\"'; + ctrl[1] = '\\'; + for (int i = 1; i < 0x20; i++) + ctrl[i+1] = i; + ctrl[0x21] = 0; +} + +/** + @deprecated This exists in order to provide fragment support in older APIs in one more version. + It should be removed in the next major version. + */ +- (id)fragmentWithString:(id)repr { + [self clearErrorTrace]; + + if (!repr) { + [self addErrorWithCode:EINPUT description:@"Input was 'nil'"]; + return nil; + } + + depth = 0; + c = [repr UTF8String]; + + id o; + if (![self scanValue:&o]) { + return nil; + } + + // We found some valid JSON. But did it also contain something else? + if (![self scanIsAtEnd]) { + [self addErrorWithCode:ETRAILGARBAGE description:@"Garbage after JSON"]; + return nil; + } + + NSAssert1(o, @"Should have a valid object from %@", repr); + return o; +} + +- (id)objectWithString:(NSString *)repr { + + id o = [self fragmentWithString:repr]; + if (!o) + return nil; + + // Check that the object we've found is a valid JSON container. + if (![o isKindOfClass:[NSDictionary class]] && ![o isKindOfClass:[NSArray class]]) { + [self addErrorWithCode:EFRAGMENT description:@"Valid fragment, but not JSON"]; + return nil; + } + + return o; +} + +/* + In contrast to the public methods, it is an error to omit the error parameter here. + */ +- (BOOL)scanValue:(NSObject **)o +{ + skipWhitespace(c); + + switch (*c++) { + case '{': + return [self scanRestOfDictionary:(NSMutableDictionary **)o]; + break; + case '[': + return [self scanRestOfArray:(NSMutableArray **)o]; + break; + case '"': + return [self scanRestOfString:(NSMutableString **)o]; + break; + case 'f': + return [self scanRestOfFalse:(NSNumber **)o]; + break; + case 't': + return [self scanRestOfTrue:(NSNumber **)o]; + break; + case 'n': + return [self scanRestOfNull:(NSNull **)o]; + break; + case '-': + case '0'...'9': + c--; // cannot verify number correctly without the first character + return [self scanNumber:(NSNumber **)o]; + break; + case '+': + [self addErrorWithCode:EPARSENUM description: @"Leading + disallowed in number"]; + return NO; + break; + case 0x0: + [self addErrorWithCode:EEOF description:@"Unexpected end of string"]; + return NO; + break; + default: + [self addErrorWithCode:EPARSE description: @"Unrecognised leading character"]; + return NO; + break; + } + + NSAssert(0, @"Should never get here"); + return NO; +} + +- (BOOL)scanRestOfTrue:(NSNumber **)o +{ + if (!strncmp(c, "rue", 3)) { + c += 3; + *o = [NSNumber numberWithBool:YES]; + return YES; + } + [self addErrorWithCode:EPARSE description:@"Expected 'true'"]; + return NO; +} + +- (BOOL)scanRestOfFalse:(NSNumber **)o +{ + if (!strncmp(c, "alse", 4)) { + c += 4; + *o = [NSNumber numberWithBool:NO]; + return YES; + } + [self addErrorWithCode:EPARSE description: @"Expected 'false'"]; + return NO; +} + +- (BOOL)scanRestOfNull:(NSNull **)o { + if (!strncmp(c, "ull", 3)) { + c += 3; + *o = [NSNull null]; + return YES; + } + [self addErrorWithCode:EPARSE description: @"Expected 'null'"]; + return NO; +} + +- (BOOL)scanRestOfArray:(NSMutableArray **)o { + if (maxDepth && ++depth > maxDepth) { + [self addErrorWithCode:EDEPTH description: @"Nested too deep"]; + return NO; + } + + *o = [NSMutableArray arrayWithCapacity:8]; + + for (; *c ;) { + id v; + + skipWhitespace(c); + if (*c == ']' && c++) { + depth--; + return YES; + } + + if (![self scanValue:&v]) { + [self addErrorWithCode:EPARSE description:@"Expected value while parsing array"]; + return NO; + } + + [*o addObject:v]; + + skipWhitespace(c); + if (*c == ',' && c++) { + skipWhitespace(c); + if (*c == ']') { + [self addErrorWithCode:ETRAILCOMMA description: @"Trailing comma disallowed in array"]; + return NO; + } + } + } + + [self addErrorWithCode:EEOF description: @"End of input while parsing array"]; + return NO; +} + +- (BOOL)scanRestOfDictionary:(NSMutableDictionary **)o +{ + if (maxDepth && ++depth > maxDepth) { + [self addErrorWithCode:EDEPTH description: @"Nested too deep"]; + return NO; + } + + *o = [NSMutableDictionary dictionaryWithCapacity:7]; + + for (; *c ;) { + id k, v; + + skipWhitespace(c); + if (*c == '}' && c++) { + depth--; + return YES; + } + + if (!(*c == '\"' && c++ && [self scanRestOfString:&k])) { + [self addErrorWithCode:EPARSE description: @"Object key string expected"]; + return NO; + } + + skipWhitespace(c); + if (*c != ':') { + [self addErrorWithCode:EPARSE description: @"Expected ':' separating key and value"]; + return NO; + } + + c++; + if (![self scanValue:&v]) { + NSString *string = [NSString stringWithFormat:@"Object value expected for key: %@", k]; + [self addErrorWithCode:EPARSE description: string]; + return NO; + } + + [*o setObject:v forKey:k]; + + skipWhitespace(c); + if (*c == ',' && c++) { + skipWhitespace(c); + if (*c == '}') { + [self addErrorWithCode:ETRAILCOMMA description: @"Trailing comma disallowed in object"]; + return NO; + } + } + } + + [self addErrorWithCode:EEOF description: @"End of input while parsing object"]; + return NO; +} + +- (BOOL)scanRestOfString:(NSMutableString **)o +{ + *o = [NSMutableString stringWithCapacity:16]; + do { + // First see if there's a portion we can grab in one go. + // Doing this caused a massive speedup on the long string. + size_t len = strcspn(c, ctrl); + if (len) { + // check for + id t = [[NSString alloc] initWithBytesNoCopy:(char*)c + length:len + encoding:NSUTF8StringEncoding + freeWhenDone:NO]; + if (t) { + [*o appendString:t]; + [t release]; + c += len; + } + } + + if (*c == '"') { + c++; + return YES; + + } else if (*c == '\\') { + unichar uc = *++c; + switch (uc) { + case '\\': + case '/': + case '"': + break; + + case 'b': uc = '\b'; break; + case 'n': uc = '\n'; break; + case 'r': uc = '\r'; break; + case 't': uc = '\t'; break; + case 'f': uc = '\f'; break; + + case 'u': + c++; + if (![self scanUnicodeChar:&uc]) { + [self addErrorWithCode:EUNICODE description: @"Broken unicode character"]; + return NO; + } + c--; // hack. + break; + default: + [self addErrorWithCode:EESCAPE description: [NSString stringWithFormat:@"Illegal escape sequence '0x%x'", uc]]; + return NO; + break; + } + CFStringAppendCharacters((CFMutableStringRef)*o, &uc, 1); + c++; + + } else if (*c < 0x20) { + [self addErrorWithCode:ECTRL description: [NSString stringWithFormat:@"Unescaped control character '0x%x'", *c]]; + return NO; + + } else { + NSLog(@"should not be able to get here"); + } + } while (*c); + + [self addErrorWithCode:EEOF description:@"Unexpected EOF while parsing string"]; + return NO; +} + +- (BOOL)scanUnicodeChar:(unichar *)x +{ + unichar hi, lo; + + if (![self scanHexQuad:&hi]) { + [self addErrorWithCode:EUNICODE description: @"Missing hex quad"]; + return NO; + } + + if (hi >= 0xd800) { // high surrogate char? + if (hi < 0xdc00) { // yes - expect a low char + + if (!(*c == '\\' && ++c && *c == 'u' && ++c && [self scanHexQuad:&lo])) { + [self addErrorWithCode:EUNICODE description: @"Missing low character in surrogate pair"]; + return NO; + } + + if (lo < 0xdc00 || lo >= 0xdfff) { + [self addErrorWithCode:EUNICODE description:@"Invalid low surrogate char"]; + return NO; + } + + hi = (hi - 0xd800) * 0x400 + (lo - 0xdc00) + 0x10000; + + } else if (hi < 0xe000) { + [self addErrorWithCode:EUNICODE description:@"Invalid high character in surrogate pair"]; + return NO; + } + } + + *x = hi; + return YES; +} + +- (BOOL)scanHexQuad:(unichar *)x +{ + *x = 0; + for (int i = 0; i < 4; i++) { + unichar uc = *c; + c++; + int d = (uc >= '0' && uc <= '9') + ? uc - '0' : (uc >= 'a' && uc <= 'f') + ? (uc - 'a' + 10) : (uc >= 'A' && uc <= 'F') + ? (uc - 'A' + 10) : -1; + if (d == -1) { + [self addErrorWithCode:EUNICODE description:@"Missing hex digit in quad"]; + return NO; + } + *x *= 16; + *x += d; + } + return YES; +} + +- (BOOL)scanNumber:(NSNumber **)o +{ + const char *ns = c; + + // The logic to test for validity of the number formatting is relicensed + // from JSON::XS with permission from its author Marc Lehmann. + // (Available at the CPAN: http://search.cpan.org/dist/JSON-XS/ .) + + if ('-' == *c) + c++; + + if ('0' == *c && c++) { + if (isdigit(*c)) { + [self addErrorWithCode:EPARSENUM description: @"Leading 0 disallowed in number"]; + return NO; + } + + } else if (!isdigit(*c) && c != ns) { + [self addErrorWithCode:EPARSENUM description: @"No digits after initial minus"]; + return NO; + + } else { + skipDigits(c); + } + + // Fractional part + if ('.' == *c && c++) { + + if (!isdigit(*c)) { + [self addErrorWithCode:EPARSENUM description: @"No digits after decimal point"]; + return NO; + } + skipDigits(c); + } + + // Exponential part + if ('e' == *c || 'E' == *c) { + c++; + + if ('-' == *c || '+' == *c) + c++; + + if (!isdigit(*c)) { + [self addErrorWithCode:EPARSENUM description: @"No digits after exponent"]; + return NO; + } + skipDigits(c); + } + + id str = [[NSString alloc] initWithBytesNoCopy:(char*)ns + length:c - ns + encoding:NSUTF8StringEncoding + freeWhenDone:NO]; + [str autorelease]; + if (str && (*o = [NSDecimalNumber decimalNumberWithString:str])) + return YES; + + [self addErrorWithCode:EPARSENUM description: @"Failed creating decimal instance"]; + return NO; +} + +- (BOOL)scanIsAtEnd +{ + skipWhitespace(c); + return !*c; +} + + +@end diff --git a/client/osx/SBJsonWriter.h b/client/osx/SBJsonWriter.h new file mode 100644 index 0000000..f6f5e17 --- /dev/null +++ b/client/osx/SBJsonWriter.h @@ -0,0 +1,129 @@ +/* + Copyright (C) 2009 Stig Brautaset. 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 the author 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. + */ + +#import +#import "SBJsonBase.h" + +/** + @brief Options for the writer class. + + This exists so the SBJSON facade can implement the options in the writer without having to re-declare them. + */ +@protocol SBJsonWriter + +/** + @brief Whether we are generating human-readable (multiline) JSON. + + Set whether or not to generate human-readable JSON. The default is NO, which produces + JSON without any whitespace. (Except inside strings.) If set to YES, generates human-readable + JSON with linebreaks after each array value and dictionary key/value pair, indented two + spaces per nesting level. + */ +@property BOOL humanReadable; + +/** + @brief Whether or not to sort the dictionary keys in the output. + + If this is set to YES, the dictionary keys in the JSON output will be in sorted order. + (This is useful if you need to compare two structures, for example.) The default is NO. + */ +@property BOOL sortKeys; + +/** + @brief Return JSON representation (or fragment) for the given object. + + Returns a string containing JSON representation of the passed in value, or nil on error. + If nil is returned and @p error is not NULL, @p *error can be interrogated to find the cause of the error. + + @param value any instance that can be represented as a JSON fragment + + */ +- (NSString*)stringWithObject:(id)value; + +@end + + +/** + @brief The JSON writer class. + + Objective-C types are mapped to JSON types in the following way: + + @li NSNull -> Null + @li NSString -> String + @li NSArray -> Array + @li NSDictionary -> Object + @li NSNumber (-initWithBool:) -> Boolean + @li NSNumber -> Number + + In JSON the keys of an object must be strings. NSDictionary keys need + not be, but attempting to convert an NSDictionary with non-string keys + into JSON will throw an exception. + + NSNumber instances created with the +initWithBool: method are + converted into the JSON boolean "true" and "false" values, and vice + versa. Any other NSNumber instances are converted to a JSON number the + way you would expect. + + */ +@interface SBJsonWriter : SBJsonBase { + +@private + BOOL sortKeys, humanReadable; +} + +@end + +// don't use - exists for backwards compatibility. Will be removed in 2.3. +@interface SBJsonWriter (Private) +- (NSString*)stringWithFragment:(id)value; +@end + +/** + @brief Allows generation of JSON for otherwise unsupported classes. + + If you have a custom class that you want to create a JSON representation for you can implement + this method in your class. It should return a representation of your object defined + in terms of objects that can be translated into JSON. For example, a Person + object might implement it like this: + + @code + - (id)jsonProxyObject { + return [NSDictionary dictionaryWithObjectsAndKeys: + name, @"name", + phone, @"phone", + email, @"email", + nil]; + } + @endcode + + */ +@interface NSObject (SBProxyForJson) +- (id)proxyForJson; +@end + diff --git a/client/osx/SBJsonWriter.m b/client/osx/SBJsonWriter.m new file mode 100644 index 0000000..0f32904 --- /dev/null +++ b/client/osx/SBJsonWriter.m @@ -0,0 +1,237 @@ +/* + Copyright (C) 2009 Stig Brautaset. 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 the author 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. + */ + +#import "SBJsonWriter.h" + +@interface SBJsonWriter () + +- (BOOL)appendValue:(id)fragment into:(NSMutableString*)json; +- (BOOL)appendArray:(NSArray*)fragment into:(NSMutableString*)json; +- (BOOL)appendDictionary:(NSDictionary*)fragment into:(NSMutableString*)json; +- (BOOL)appendString:(NSString*)fragment into:(NSMutableString*)json; + +- (NSString*)indent; + +@end + +@implementation SBJsonWriter + +static NSMutableCharacterSet *kEscapeChars; + ++ (void)initialize { + kEscapeChars = [[NSMutableCharacterSet characterSetWithRange: NSMakeRange(0,32)] retain]; + [kEscapeChars addCharactersInString: @"\"\\"]; +} + + +@synthesize sortKeys; +@synthesize humanReadable; + +/** + @deprecated This exists in order to provide fragment support in older APIs in one more version. + It should be removed in the next major version. + */ +- (NSString*)stringWithFragment:(id)value { + [self clearErrorTrace]; + depth = 0; + NSMutableString *json = [NSMutableString stringWithCapacity:128]; + + if ([self appendValue:value into:json]) + return json; + + return nil; +} + + +- (NSString*)stringWithObject:(id)value { + + if ([value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]]) { + return [self stringWithFragment:value]; + } + + if ([value respondsToSelector:@selector(proxyForJson)]) { + NSString *tmp = [self stringWithObject:[value proxyForJson]]; + if (tmp) + return tmp; + } + + + [self clearErrorTrace]; + [self addErrorWithCode:EFRAGMENT description:@"Not valid type for JSON"]; + return nil; +} + + +- (NSString*)indent { + return [@"\n" stringByPaddingToLength:1 + 2 * depth withString:@" " startingAtIndex:0]; +} + +- (BOOL)appendValue:(id)fragment into:(NSMutableString*)json { + if ([fragment isKindOfClass:[NSDictionary class]]) { + if (![self appendDictionary:fragment into:json]) + return NO; + + } else if ([fragment isKindOfClass:[NSArray class]]) { + if (![self appendArray:fragment into:json]) + return NO; + + } else if ([fragment isKindOfClass:[NSString class]]) { + if (![self appendString:fragment into:json]) + return NO; + + } else if ([fragment isKindOfClass:[NSNumber class]]) { + if ('c' == *[fragment objCType]) + [json appendString:[fragment boolValue] ? @"true" : @"false"]; + else + [json appendString:[fragment stringValue]]; + + } else if ([fragment isKindOfClass:[NSNull class]]) { + [json appendString:@"null"]; + } else if ([fragment respondsToSelector:@selector(proxyForJson)]) { + [self appendValue:[fragment proxyForJson] into:json]; + + } else { + [self addErrorWithCode:EUNSUPPORTED description:[NSString stringWithFormat:@"JSON serialisation not supported for %@", [fragment class]]]; + return NO; + } + return YES; +} + +- (BOOL)appendArray:(NSArray*)fragment into:(NSMutableString*)json { + if (maxDepth && ++depth > maxDepth) { + [self addErrorWithCode:EDEPTH description: @"Nested too deep"]; + return NO; + } + [json appendString:@"["]; + + BOOL addComma = NO; + for (id value in fragment) { + if (addComma) + [json appendString:@","]; + else + addComma = YES; + + if ([self humanReadable]) + [json appendString:[self indent]]; + + if (![self appendValue:value into:json]) { + return NO; + } + } + + depth--; + if ([self humanReadable] && [fragment count]) + [json appendString:[self indent]]; + [json appendString:@"]"]; + return YES; +} + +- (BOOL)appendDictionary:(NSDictionary*)fragment into:(NSMutableString*)json { + if (maxDepth && ++depth > maxDepth) { + [self addErrorWithCode:EDEPTH description: @"Nested too deep"]; + return NO; + } + [json appendString:@"{"]; + + NSString *colon = [self humanReadable] ? @" : " : @":"; + BOOL addComma = NO; + NSArray *keys = [fragment allKeys]; + if (self.sortKeys) + keys = [keys sortedArrayUsingSelector:@selector(compare:)]; + + for (id value in keys) { + if (addComma) + [json appendString:@","]; + else + addComma = YES; + + if ([self humanReadable]) + [json appendString:[self indent]]; + + if (![value isKindOfClass:[NSString class]]) { + [self addErrorWithCode:EUNSUPPORTED description: @"JSON object key must be string"]; + return NO; + } + + if (![self appendString:value into:json]) + return NO; + + [json appendString:colon]; + if (![self appendValue:[fragment objectForKey:value] into:json]) { + [self addErrorWithCode:EUNSUPPORTED description:[NSString stringWithFormat:@"Unsupported value for key %@ in object", value]]; + return NO; + } + } + + depth--; + if ([self humanReadable] && [fragment count]) + [json appendString:[self indent]]; + [json appendString:@"}"]; + return YES; +} + +- (BOOL)appendString:(NSString*)fragment into:(NSMutableString*)json { + + [json appendString:@"\""]; + + NSRange esc = [fragment rangeOfCharacterFromSet:kEscapeChars]; + if ( !esc.length ) { + // No special chars -- can just add the raw string: + [json appendString:fragment]; + + } else { + NSUInteger length = [fragment length]; + for (NSUInteger i = 0; i < length; i++) { + unichar uc = [fragment characterAtIndex:i]; + switch (uc) { + case '"': [json appendString:@"\\\""]; break; + case '\\': [json appendString:@"\\\\"]; break; + case '\t': [json appendString:@"\\t"]; break; + case '\n': [json appendString:@"\\n"]; break; + case '\r': [json appendString:@"\\r"]; break; + case '\b': [json appendString:@"\\b"]; break; + case '\f': [json appendString:@"\\f"]; break; + default: + if (uc < 0x20) { + [json appendFormat:@"\\u%04x", uc]; + } else { + CFStringAppendCharacters((CFMutableStringRef)json, &uc, 1); + } + break; + + } + } + } + + [json appendString:@"\""]; + return YES; +} + + +@end diff --git a/client/osx/Safari.h b/client/osx/Safari.h new file mode 100644 index 0000000..2b3f63a --- /dev/null +++ b/client/osx/Safari.h @@ -0,0 +1,265 @@ +/* + * Safari.h + */ + +#import +#import + + +@class SafariItem, SafariApplication, SafariColor, SafariDocument, SafariWindow, SafariAttributeRun, SafariCharacter, SafariParagraph, SafariText, SafariAttachment, SafariWord, SafariTab, SafariPrintSettings; + +enum SafariSavo { + SafariSavoAsk = 'ask ' /* Ask the user whether or not to save the file. */, + SafariSavoNo = 'no ' /* Do not save the file. */, + SafariSavoYes = 'yes ' /* Save the file. */ +}; +typedef enum SafariSavo SafariSavo; + +enum SafariEnum { + SafariEnumStandard = 'lwst' /* Standard PostScript error handling */, + SafariEnumDetailed = 'lwdt' /* print a detailed report of PostScript errors */ +}; +typedef enum SafariEnum SafariEnum; + + + +/* + * Standard Suite + */ + +// A scriptable object. +@interface SafariItem : SBObject + +@property (copy) NSDictionary *properties; // All of the object's properties. + +- (void) closeSaving:(SafariSavo)saving savingIn:(NSURL *)savingIn; // Close an object. +- (void) delete; // Delete an object. +- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy object(s) and put the copies at a new location. +- (BOOL) exists; // Verify if an object exists. +- (void) moveTo:(SBObject *)to; // Move object(s) to a new location. +- (void) saveAs:(NSString *)as in:(NSURL *)in_; // Save an object. +- (void) emailContentsOf:(SafariTab *)of; // Emails the contents of a tab. +- (void) searchTheWebFor:(NSString *)for_ in:(SafariTab *)in_; // Searches the web using Safari's current search provider. + +@end + +// An application's top level scripting object. +@interface SafariApplication : SBApplication + +- (SBElementArray *) documents; +- (SBElementArray *) windows; + +@property (readonly) BOOL frontmost; // Is this the frontmost (active) application? +@property (copy, readonly) NSString *name; // The name of the application. +@property (copy, readonly) NSString *version; // The version of the application. + +- (SafariDocument *) open:(NSURL *)x; // Open an object. +- (void) print:(NSURL *)x printDialog:(BOOL)printDialog withProperties:(SafariPrintSettings *)withProperties; // Print an object. +- (void) quitSaving:(SafariSavo)saving; // Quit an application. +- (void) addReadingListItem:(NSString *)x andPreviewText:(NSString *)andPreviewText withTitle:(NSString *)withTitle; // Add a new Reading List item with the given URL. Allows a custom title and preview text to be specified. +- (id) doJavaScript:(NSString *)x in:(SafariTab *)in_; // Applies a string of JavaScript code to a document. +- (void) showBookmarks; // Shows Safari's bookmarks. + +@end + +// A color. +@interface SafariColor : SafariItem + + +@end + +// A document. +@interface SafariDocument : SafariItem + +@property (readonly) BOOL modified; // Has the document been modified since the last save? +@property (copy) NSString *name; // The document's name. +@property (copy) NSString *path; // The document's path. + + +@end + +// A window. +@interface SafariWindow : SafariItem + +@property NSRect bounds; // The bounding rectangle of the window. +@property (readonly) BOOL closeable; // Whether the window has a close box. +@property (copy, readonly) SafariDocument *document; // The document whose contents are being displayed in the window. +@property (readonly) BOOL floating; // Whether the window floats. +- (NSInteger) id; // The unique identifier of the window. +@property NSInteger index; // The index of the window, ordered front to back. +@property (readonly) BOOL miniaturizable; // Whether the window can be miniaturized. +@property BOOL miniaturized; // Whether the window is currently miniaturized. +@property (readonly) BOOL modal; // Whether the window is the application's current modal window. +@property (copy) NSString *name; // The full title of the window. +@property (readonly) BOOL resizable; // Whether the window can be resized. +@property (readonly) BOOL titled; // Whether the window has a title bar. +@property BOOL visible; // Whether the window is currently visible. +@property (readonly) BOOL zoomable; // Whether the window can be zoomed. +@property BOOL zoomed; // Whether the window is currently zoomed. + + +@end + + + +/* + * Text Suite + */ + +// This subdivides the text into chunks that all have the same attributes. +@interface SafariAttributeRun : SafariItem + +- (SBElementArray *) attachments; +- (SBElementArray *) attributeRuns; +- (SBElementArray *) characters; +- (SBElementArray *) paragraphs; +- (SBElementArray *) words; + +@property (copy) NSColor *color; // The color of the first character. +@property (copy) NSString *font; // The name of the font of the first character. +@property NSInteger size; // The size in points of the first character. + + +@end + +// This subdivides the text into characters. +@interface SafariCharacter : SafariItem + +- (SBElementArray *) attachments; +- (SBElementArray *) attributeRuns; +- (SBElementArray *) characters; +- (SBElementArray *) paragraphs; +- (SBElementArray *) words; + +@property (copy) NSColor *color; // The color of the first character. +@property (copy) NSString *font; // The name of the font of the first character. +@property NSInteger size; // The size in points of the first character. + + +@end + +// This subdivides the text into paragraphs. +@interface SafariParagraph : SafariItem + +- (SBElementArray *) attachments; +- (SBElementArray *) attributeRuns; +- (SBElementArray *) characters; +- (SBElementArray *) paragraphs; +- (SBElementArray *) words; + +@property (copy) NSColor *color; // The color of the first character. +@property (copy) NSString *font; // The name of the font of the first character. +@property NSInteger size; // The size in points of the first character. + + +@end + +// Rich (styled) text +@interface SafariText : SafariItem + +- (SBElementArray *) attachments; +- (SBElementArray *) attributeRuns; +- (SBElementArray *) characters; +- (SBElementArray *) paragraphs; +- (SBElementArray *) words; + +@property (copy) NSColor *color; // The color of the first character. +@property (copy) NSString *font; // The name of the font of the first character. +@property NSInteger size; // The size in points of the first character. + +- (void) addReadingListItemAndPreviewText:(NSString *)andPreviewText withTitle:(NSString *)withTitle; // Add a new Reading List item with the given URL. Allows a custom title and preview text to be specified. +- (id) doJavaScriptIn:(SafariTab *)in_; // Applies a string of JavaScript code to a document. + +@end + +// Represents an inline text attachment. This class is used mainly for make commands. +@interface SafariAttachment : SafariText + +@property (copy) NSString *fileName; // The path to the file for the attachment + + +@end + +// This subdivides the text into words. +@interface SafariWord : SafariItem + +- (SBElementArray *) attachments; +- (SBElementArray *) attributeRuns; +- (SBElementArray *) characters; +- (SBElementArray *) paragraphs; +- (SBElementArray *) words; + +@property (copy) NSColor *color; // The color of the first character. +@property (copy) NSString *font; // The name of the font of the first character. +@property NSInteger size; // The size in points of the first character. + + +@end + + + +/* + * Safari suite + */ + +// A Safari document representing the active tab in a window. +@interface SafariDocument (SafariSuite) + +@property (copy, readonly) NSString *source; // The HTML source of the web page currently loaded in the document. +@property (copy, readonly) SafariText *text; // The text of the web page currently loaded in the document. Modifications to text aren't reflected on the web page. +@property (copy) NSString *URL; // The current URL of the document. + +@end + +// A Safari window tab. +@interface SafariTab : SafariItem + +@property (readonly) NSInteger index; // The index of the tab, ordered left to right. +@property (copy, readonly) NSString *name; // The name of the tab. +@property (copy, readonly) NSString *source; // The HTML source of the web page currently loaded in the tab. +@property (copy, readonly) SafariText *text; // The text of the web page currently loaded in the tab. Modifications to text aren't reflected on the web page. +@property (copy) NSString *URL; // The current URL of the tab. +@property (readonly) BOOL visible; // Whether the tab is currently visible. + + +@end + +// A Safari window. +@interface SafariWindow (SafariSuite) + +- (SBElementArray *) tabs; + +@property (copy) SafariTab *currentTab; // The current tab. + +@end + + + +/* + * Type Definitions + */ + +@interface SafariPrintSettings : SBObject + +@property NSInteger copies; // the number of copies of a document to be printed +@property BOOL collating; // Should printed copies be collated? +@property NSInteger startingPage; // the first page of the document to be printed +@property NSInteger endingPage; // the last page of the document to be printed +@property NSInteger pagesAcross; // number of logical pages laid across a physical page +@property NSInteger pagesDown; // number of logical pages laid out down a physical page +@property (copy) NSDate *requestedPrintTime; // the time at which the desktop printer should print the document +@property SafariEnum errorHandling; // how errors are handled +@property (copy) NSString *faxNumber; // for fax number +@property (copy) NSString *targetPrinter; // for target printer + +- (void) closeSaving:(SafariSavo)saving savingIn:(NSURL *)savingIn; // Close an object. +- (void) delete; // Delete an object. +- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy object(s) and put the copies at a new location. +- (BOOL) exists; // Verify if an object exists. +- (void) moveTo:(SBObject *)to; // Move object(s) to a new location. +- (void) saveAs:(NSString *)as in:(NSURL *)in_; // Save an object. +- (void) emailContentsOf:(SafariTab *)of; // Emails the contents of a tab. +- (void) searchTheWebFor:(NSString *)for_ in:(SafariTab *)in_; // Searches the web using Safari's current search provider. + +@end + diff --git a/client/osx/SeparatorCell.h b/client/osx/SeparatorCell.h new file mode 100644 index 0000000..230168b --- /dev/null +++ b/client/osx/SeparatorCell.h @@ -0,0 +1,13 @@ +// +// SeparatorCell.h +// HackPad +// +// +// Copyright 2011 Hackpad. All rights reserved. +// + + + +@interface SeparatorCell : NSCell + +@end diff --git a/client/osx/SeparatorCell.m b/client/osx/SeparatorCell.m new file mode 100644 index 0000000..2594ae4 --- /dev/null +++ b/client/osx/SeparatorCell.m @@ -0,0 +1,47 @@ +// +// SeparatorCell.m +// HackPad +// +// +// Copyright 2011 Hackpad. All rights reserved. +// + +#import "SeparatorCell.h" + +@implementation SeparatorCell + +- (id)init +{ + self = [super init]; + if (self) { + // Initialization code here. + [self setSelectable:false]; + } + + return self; +} +- (BOOL)isSelectable { + return false; +} +- (void)setPlaceholderString:(NSString *)string{ + + +} +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView +{ + // return [super drawWithFrame:cellFrame inView:controlView]; + + NSGraphicsContext* theContext = [NSGraphicsContext currentContext]; + [theContext saveGraphicsState]; + + NSBezierPath* aPath = [NSBezierPath bezierPath]; + [aPath setLineWidth:1.0]; + [aPath moveToPoint:NSMakePoint(cellFrame.origin.x-21, cellFrame.origin.y + cellFrame.size.height/2 + 0.5)]; + [aPath lineToPoint:NSMakePoint(cellFrame.origin.x+21 + cellFrame.size.width, cellFrame.origin.y + cellFrame.size.height/2 +0.5)]; + [[NSColor lightGrayColor] set]; + [aPath stroke]; + + [theContext restoreGraphicsState]; + +} +@end diff --git a/client/osx/Sparkle.framework/Headers b/client/osx/Sparkle.framework/Headers new file mode 120000 index 0000000..a177d2a --- /dev/null +++ b/client/osx/Sparkle.framework/Headers @@ -0,0 +1 @@ +Versions/Current/Headers \ No newline at end of file diff --git a/client/osx/Sparkle.framework/Resources b/client/osx/Sparkle.framework/Resources new file mode 120000 index 0000000..953ee36 --- /dev/null +++ b/client/osx/Sparkle.framework/Resources @@ -0,0 +1 @@ +Versions/Current/Resources \ No newline at end of file diff --git a/client/osx/Sparkle.framework/Sparkle b/client/osx/Sparkle.framework/Sparkle new file mode 120000 index 0000000..b2c5273 --- /dev/null +++ b/client/osx/Sparkle.framework/Sparkle @@ -0,0 +1 @@ +Versions/Current/Sparkle \ No newline at end of file diff --git a/client/osx/Sparkle.framework/Versions/A/Headers/SUAppcast.h b/client/osx/Sparkle.framework/Versions/A/Headers/SUAppcast.h new file mode 100644 index 0000000..171148a --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Headers/SUAppcast.h @@ -0,0 +1,33 @@ +// +// SUAppcast.h +// Sparkle +// +// Created by Andy Matuschak on 3/12/06. +// Copyright 2006 Andy Matuschak. All rights reserved. +// + +#ifndef SUAPPCAST_H +#define SUAPPCAST_H + +@class SUAppcastItem; +@interface SUAppcast : NSObject { + NSArray *items; + NSString *userAgentString; + id delegate; + NSMutableData *incrementalData; +} + +- (void)fetchAppcastFromURL:(NSURL *)url; +- (void)setDelegate:delegate; +- (void)setUserAgentString:(NSString *)userAgentString; + +- (NSArray *)items; + +@end + +@interface NSObject (SUAppcastDelegate) +- (void)appcastDidFinishLoading:(SUAppcast *)appcast; +- (void)appcast:(SUAppcast *)appcast failedToLoadWithError:(NSError *)error; +@end + +#endif diff --git a/client/osx/Sparkle.framework/Versions/A/Headers/SUAppcastItem.h b/client/osx/Sparkle.framework/Versions/A/Headers/SUAppcastItem.h new file mode 100644 index 0000000..7f1ca65 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Headers/SUAppcastItem.h @@ -0,0 +1,47 @@ +// +// SUAppcastItem.h +// Sparkle +// +// Created by Andy Matuschak on 3/12/06. +// Copyright 2006 Andy Matuschak. All rights reserved. +// + +#ifndef SUAPPCASTITEM_H +#define SUAPPCASTITEM_H + +@interface SUAppcastItem : NSObject { + NSString *title; + NSDate *date; + NSString *itemDescription; + + NSURL *releaseNotesURL; + + NSString *DSASignature; + NSString *minimumSystemVersion; + + NSURL *fileURL; + NSString *versionString; + NSString *displayVersionString; + + NSDictionary *propertiesDictionary; +} + +// Initializes with data from a dictionary provided by the RSS class. +- initWithDictionary:(NSDictionary *)dict; + +- (NSString *)title; +- (NSString *)versionString; +- (NSString *)displayVersionString; +- (NSDate *)date; +- (NSString *)itemDescription; +- (NSURL *)releaseNotesURL; +- (NSURL *)fileURL; +- (NSString *)DSASignature; +- (NSString *)minimumSystemVersion; + +// Returns the dictionary provided in initWithDictionary; this might be useful later for extensions. +- (NSDictionary *)propertiesDictionary; + +@end + +#endif diff --git a/client/osx/Sparkle.framework/Versions/A/Headers/SUUpdater.h b/client/osx/Sparkle.framework/Versions/A/Headers/SUUpdater.h new file mode 100644 index 0000000..e78c4d3 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Headers/SUUpdater.h @@ -0,0 +1,118 @@ +// +// SUUpdater.h +// Sparkle +// +// Created by Andy Matuschak on 1/4/06. +// Copyright 2006 Andy Matuschak. All rights reserved. +// + +#ifndef SUUPDATER_H +#define SUUPDATER_H + +#import + +@class SUUpdateDriver, SUAppcastItem, SUHost, SUAppcast; +@interface SUUpdater : NSObject { + NSTimer *checkTimer; + SUUpdateDriver *driver; + + SUHost *host; + IBOutlet id delegate; +} + ++ (SUUpdater *)sharedUpdater; ++ (SUUpdater *)updaterForBundle:(NSBundle *)bundle; +- (NSBundle *)hostBundle; + +- (void)setDelegate:(id)delegate; +- delegate; + +- (void)setAutomaticallyChecksForUpdates:(BOOL)automaticallyChecks; +- (BOOL)automaticallyChecksForUpdates; + +- (void)setUpdateCheckInterval:(NSTimeInterval)interval; +- (NSTimeInterval)updateCheckInterval; + +- (void)setFeedURL:(NSURL *)feedURL; +- (NSURL *)feedURL; + +- (void)setSendsSystemProfile:(BOOL)sendsSystemProfile; +- (BOOL)sendsSystemProfile; + +- (void)setAutomaticallyDownloadsUpdates:(BOOL)automaticallyDownloadsUpdates; +- (BOOL)automaticallyDownloadsUpdates; + +// This IBAction is meant for a main menu item. Hook up any menu item to this action, +// and Sparkle will check for updates and report back its findings verbosely. +- (IBAction)checkForUpdates:sender; + +// This kicks off an update meant to be programmatically initiated. That is, it will display no UI unless it actually finds an update, +// in which case it proceeds as usual. If the fully automated updating is turned on, however, this will invoke that behavior, and if an +// update is found, it will be downloaded and prepped for installation. +- (void)checkForUpdatesInBackground; + +// Date of last update check. Returns null if no check has been performed. +- (NSDate*)lastUpdateCheckDate; + +// This begins a "probing" check for updates which will not actually offer to update to that version. The delegate methods, though, +// (up to updater:didFindValidUpdate: and updaterDidNotFindUpdate:), are called, so you can use that information in your UI. +- (void)checkForUpdateInformation; + +// Call this to appropriately schedule or cancel the update checking timer according to the preferences for time interval and automatic checks. This call does not change the date of the next check, but only the internal NSTimer. +- (void)resetUpdateCycle; + +- (BOOL)updateInProgress; +@end + +@interface NSObject (SUUpdaterDelegateInformalProtocol) +// This method allows you to add extra parameters to the appcast URL, potentially based on whether or not Sparkle will also be sending along the system profile. This method should return an array of dictionaries with keys: "key", "value", "displayKey", "displayValue", the latter two being specifically for display to the user. +- (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile:(BOOL)sendingProfile; + +// Use this to override the default behavior for Sparkle prompting the user about automatic update checks. +- (BOOL)updaterShouldPromptForPermissionToCheckForUpdates:(SUUpdater *)bundle; + +// Implement this if you want to do some special handling with the appcast once it finishes loading. +- (void)updater:(SUUpdater *)updater didFinishLoadingAppcast:(SUAppcast *)appcast; + +// If you're using special logic or extensions in your appcast, implement this to use your own logic for finding +// a valid update, if any, in the given appcast. +- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forUpdater:(SUUpdater *)bundle; + +// Sent when a valid update is found by the update driver. +- (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)update; + +// Sent when a valid update is not found. +- (void)updaterDidNotFindUpdate:(SUUpdater *)update; + +// Sent immediately before installing the specified update. +- (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update; + +// Return YES to delay the relaunch until you do some processing; invoke the given NSInvocation to continue. +- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update untilInvoking:(NSInvocation *)invocation; + +// Called immediately before relaunching. +- (void)updaterWillRelaunchApplication:(SUUpdater *)updater; + +// This method allows you to provide a custom version comparator. +// If you don't implement this method or return nil, the standard version comparator will be used. +- (id )versionComparatorForUpdater:(SUUpdater *)updater; + +// Returns the path which is used to relaunch the client after the update is installed. By default, the path of the host bundle. +- (NSString *)pathToRelaunchForUpdater:(SUUpdater *)updater; + +@end + +// Define some minimum intervals to avoid DOS-like checking attacks. These are in seconds. +#ifdef DEBUG +#define SU_MIN_CHECK_INTERVAL 60 +#else +#define SU_MIN_CHECK_INTERVAL 60*60 +#endif + +#ifdef DEBUG +#define SU_DEFAULT_CHECK_INTERVAL 60 +#else +#define SU_DEFAULT_CHECK_INTERVAL 60*60*24 +#endif + +#endif diff --git a/client/osx/Sparkle.framework/Versions/A/Headers/SUVersionComparisonProtocol.h b/client/osx/Sparkle.framework/Versions/A/Headers/SUVersionComparisonProtocol.h new file mode 100644 index 0000000..3d11ae8 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Headers/SUVersionComparisonProtocol.h @@ -0,0 +1,27 @@ +// +// SUVersionComparisonProtocol.h +// Sparkle +// +// Created by Andy Matuschak on 12/21/07. +// Copyright 2007 Andy Matuschak. All rights reserved. +// + +#ifndef SUVERSIONCOMPARISONPROTOCOL_H +#define SUVERSIONCOMPARISONPROTOCOL_H + +/*! + @protocol + @abstract Implement this protocol to provide version comparison facilities for Sparkle. +*/ +@protocol SUVersionComparison + +/*! + @method + @abstract An abstract method to compare two version strings. + @discussion Should return NSOrderedAscending if b > a, NSOrderedDescending if b < a, and NSOrderedSame if they are equivalent. +*/ +- (NSComparisonResult)compareVersion:(NSString *)versionA toVersion:(NSString *)versionB; + +@end + +#endif diff --git a/client/osx/Sparkle.framework/Versions/A/Headers/Sparkle.h b/client/osx/Sparkle.framework/Versions/A/Headers/Sparkle.h new file mode 100644 index 0000000..08dd577 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Headers/Sparkle.h @@ -0,0 +1,21 @@ +// +// Sparkle.h +// Sparkle +// +// Created by Andy Matuschak on 3/16/06. (Modified by CDHW on 23/12/07) +// Copyright 2006 Andy Matuschak. All rights reserved. +// + +#ifndef SPARKLE_H +#define SPARKLE_H + +// This list should include the shared headers. It doesn't matter if some of them aren't shared (unless +// there are name-space collisions) so we can list all of them to start with: + +#import + +#import +#import +#import + +#endif diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/Info.plist b/client/osx/Sparkle.framework/Versions/A/Resources/Info.plist new file mode 100644 index 0000000..c7f277d --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + Sparkle + CFBundleIdentifier + org.andymatuschak.Sparkle + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Sparkle + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.5 Beta 6 + CFBundleSignature + ???? + CFBundleVersion + 313 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/License.txt b/client/osx/Sparkle.framework/Versions/A/Resources/License.txt new file mode 100644 index 0000000..20466c4 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/License.txt @@ -0,0 +1,7 @@ +Copyright (c) 2006 Andy Matuschak + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/SUModelTranslation.plist b/client/osx/Sparkle.framework/Versions/A/Resources/SUModelTranslation.plist new file mode 100644 index 0000000..92ef947 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/SUModelTranslation.plist @@ -0,0 +1,174 @@ + + + + + ADP2,1 + Developer Transition Kit + MacBook1,1 + MacBook (Core Duo) + MacBook2,1 + MacBook (Core 2 Duo) + MacBook4,1 + MacBook (Core 2 Duo Feb 2008) + MacBookAir1,1 + MacBook Air (January 2008) + MacBookPro1,1 + MacBook Pro Core Duo (15-inch) + MacBookPro1,2 + MacBook Pro Core Duo (17-inch) + MacBookPro2,1 + MacBook Pro Core 2 Duo (17-inch) + MacBookPro2,2 + MacBook Pro Core 2 Duo (15-inch) + MacBookPro3,1 + MacBook Pro Core 2 Duo (15-inch LED, Core 2 Duo) + MacBookPro3,2 + MacBook Pro Core 2 Duo (17-inch HD, Core 2 Duo) + MacBookPro4,1 + MacBook Pro (Core 2 Duo Feb 2008) + MacPro1,1 + Mac Pro (four-core) + MacPro2,1 + Mac Pro (eight-core) + MacPro3,1 + Mac Pro (January 2008 4- or 8- core "Harpertown") + Macmini1,1 + Mac Mini (Core Solo/Duo) + PowerBook1,1 + PowerBook G3 + PowerBook2,1 + iBook G3 + PowerBook2,2 + iBook G3 (FireWire) + PowerBook2,3 + iBook G3 + PowerBook2,4 + iBook G3 + PowerBook3,1 + PowerBook G3 (FireWire) + PowerBook3,2 + PowerBook G4 + PowerBook3,3 + PowerBook G4 (Gigabit Ethernet) + PowerBook3,4 + PowerBook G4 (DVI) + PowerBook3,5 + PowerBook G4 (1GHz / 867MHz) + PowerBook4,1 + iBook G3 (Dual USB, Late 2001) + PowerBook4,2 + iBook G3 (16MB VRAM) + PowerBook4,3 + iBook G3 Opaque 16MB VRAM, 32MB VRAM, Early 2003) + PowerBook5,1 + PowerBook G4 (17 inch) + PowerBook5,2 + PowerBook G4 (15 inch FW 800) + PowerBook5,3 + PowerBook G4 (17-inch 1.33GHz) + PowerBook5,4 + PowerBook G4 (15 inch 1.5/1.33GHz) + PowerBook5,5 + PowerBook G4 (17-inch 1.5GHz) + PowerBook5,6 + PowerBook G4 (15 inch 1.67GHz/1.5GHz) + PowerBook5,7 + PowerBook G4 (17-inch 1.67GHz) + PowerBook5,8 + PowerBook G4 (Double layer SD, 15 inch) + PowerBook5,9 + PowerBook G4 (Double layer SD, 17 inch) + PowerBook6,1 + PowerBook G4 (12 inch) + PowerBook6,2 + PowerBook G4 (12 inch, DVI) + PowerBook6,3 + iBook G4 + PowerBook6,4 + PowerBook G4 (12 inch 1.33GHz) + PowerBook6,5 + iBook G4 (Early-Late 2004) + PowerBook6,7 + iBook G4 (Mid 2005) + PowerBook6,8 + PowerBook G4 (12 inch 1.5GHz) + PowerMac1,1 + Power Macintosh G3 (Blue & White) + PowerMac1,2 + Power Macintosh G4 (PCI Graphics) + PowerMac10,1 + Mac Mini G4 + PowerMac10,2 + Mac Mini (Late 2005) + PowerMac11,2 + Power Macintosh G5 (Late 2005) + PowerMac12,1 + iMac G5 (iSight) + PowerMac2,1 + iMac G3 (Slot-loading CD-ROM) + PowerMac2,2 + iMac G3 (Summer 2000) + PowerMac3,1 + Power Macintosh G4 (AGP Graphics) + PowerMac3,2 + Power Macintosh G4 (AGP Graphics) + PowerMac3,3 + Power Macintosh G4 (Gigabit Ethernet) + PowerMac3,4 + Power Macintosh G4 (Digital Audio) + PowerMac3,5 + Power Macintosh G4 (Quick Silver) + PowerMac3,6 + Power Macintosh G4 (Mirrored Drive Door) + PowerMac4,1 + iMac G3 (Early/Summer 2001) + PowerMac4,2 + iMac G4 (Flat Panel) + PowerMac4,4 + eMac + PowerMac4,5 + iMac G4 (17-inch Flat Panel) + PowerMac5,1 + Power Macintosh G4 Cube + PowerMac6,1 + iMac G4 (USB 2.0) + PowerMac6,3 + iMac G4 (20-inch Flat Panel) + PowerMac6,4 + eMac (USB 2.0, 2005) + PowerMac7,2 + Power Macintosh G5 + PowerMac7,3 + Power Macintosh G5 + PowerMac8,1 + iMac G5 + PowerMac8,2 + iMac G5 (Ambient Light Sensor) + PowerMac9,1 + Power Macintosh G5 (Late 2005) + RackMac1,1 + Xserve G4 + RackMac1,2 + Xserve G4 (slot-loading, cluster node) + RackMac3,1 + Xserve G5 + Xserve1,1 + Xserve (Intel Xeon) + Xserve2,1 + Xserve (January 2008 quad-core) + iMac1,1 + iMac G3 (Rev A-D) + iMac4,1 + iMac (Core Duo) + iMac4,2 + iMac for Education (17-inch, Core Duo) + iMac5,1 + iMac (Core 2 Duo, 17 or 20 inch, SuperDrive) + iMac5,2 + iMac (Core 2 Duo, 17 inch, Combo Drive) + iMac6,1 + iMac (Core 2 Duo, 24 inch, SuperDrive) + iMac8,1 + iMac (April 2008) + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/SUStatus.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/SUStatus.nib/classes.nib new file mode 100644 index 0000000..22f13f8 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/SUStatus.nib/classes.nib @@ -0,0 +1,56 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + CLASS + NSApplication + LANGUAGE + ObjC + SUPERCLASS + NSResponder + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + CLASS + SUStatusController + LANGUAGE + ObjC + OUTLETS + + actionButton + NSButton + progressBar + NSProgressIndicator + + SUPERCLASS + SUWindowController + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/SUStatus.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/SUStatus.nib/info.nib new file mode 100644 index 0000000..a9ac867 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/SUStatus.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 670 + IBLastKnownRelativeProjectPath + Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 10A96 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/SUStatus.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/SUStatus.nib/keyedobjects.nib new file mode 100644 index 0000000..4f1d598 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/SUStatus.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUAutomaticUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUAutomaticUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..4b1ab30 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUAutomaticUpdateAlert.nib/classes.nib @@ -0,0 +1,50 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + doNotInstall + id + installLater + id + installNow + id + + CLASS + SUAutomaticUpdateAlert + LANGUAGE + ObjC + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUAutomaticUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUAutomaticUpdateAlert.nib/info.nib new file mode 100644 index 0000000..2e04cfa --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUAutomaticUpdateAlert.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 667 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..6b92630 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..994d4c3 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdateAlert.nib/classes.nib @@ -0,0 +1,67 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + CLASS + NSApplication + LANGUAGE + ObjC + SUPERCLASS + NSResponder + + + ACTIONS + + installUpdate + id + remindMeLater + id + skipThisVersion + id + + CLASS + SUUpdateAlert + LANGUAGE + ObjC + OUTLETS + + delegate + id + description + NSTextField + releaseNotesView + WebView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdateAlert.nib/info.nib new file mode 100644 index 0000000..2e04cfa --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdateAlert.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 667 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..b4353d2 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdatePermissionPrompt.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdatePermissionPrompt.nib/classes.nib new file mode 100644 index 0000000..5220a22 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdatePermissionPrompt.nib/classes.nib @@ -0,0 +1,59 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + finishPrompt + id + toggleMoreInfo + id + + CLASS + SUUpdatePermissionPrompt + LANGUAGE + ObjC + OUTLETS + + delegate + id + descriptionTextField + NSTextField + moreInfoButton + NSButton + moreInfoView + NSView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdatePermissionPrompt.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdatePermissionPrompt.nib/info.nib new file mode 100644 index 0000000..2e04cfa --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdatePermissionPrompt.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 667 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib new file mode 100644 index 0000000..b403a3e Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/Sparkle.strings b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/Sparkle.strings new file mode 100644 index 0000000..b31f928 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/de.lproj/Sparkle.strings differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUAutomaticUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUAutomaticUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..4b1ab30 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUAutomaticUpdateAlert.nib/classes.nib @@ -0,0 +1,50 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + doNotInstall + id + installLater + id + installNow + id + + CLASS + SUAutomaticUpdateAlert + LANGUAGE + ObjC + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUAutomaticUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUAutomaticUpdateAlert.nib/info.nib new file mode 100644 index 0000000..ab36d31 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUAutomaticUpdateAlert.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 658 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9C7010 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..7630390 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..994d4c3 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdateAlert.nib/classes.nib @@ -0,0 +1,67 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + CLASS + NSApplication + LANGUAGE + ObjC + SUPERCLASS + NSResponder + + + ACTIONS + + installUpdate + id + remindMeLater + id + skipThisVersion + id + + CLASS + SUUpdateAlert + LANGUAGE + ObjC + OUTLETS + + delegate + id + description + NSTextField + releaseNotesView + WebView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdateAlert.nib/info.nib new file mode 100644 index 0000000..2fb8a83 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdateAlert.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 670 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 18 + + IBSystem Version + 10A96 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..e7e7497 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdatePermissionPrompt.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdatePermissionPrompt.nib/classes.nib new file mode 100644 index 0000000..5220a22 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdatePermissionPrompt.nib/classes.nib @@ -0,0 +1,59 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + finishPrompt + id + toggleMoreInfo + id + + CLASS + SUUpdatePermissionPrompt + LANGUAGE + ObjC + OUTLETS + + delegate + id + descriptionTextField + NSTextField + moreInfoButton + NSButton + moreInfoView + NSView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdatePermissionPrompt.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdatePermissionPrompt.nib/info.nib new file mode 100644 index 0000000..b1cd28e --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdatePermissionPrompt.nib/info.nib @@ -0,0 +1,21 @@ + + + + + IBFramework Version + 670 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + 41 + + IBSystem Version + 10A96 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib new file mode 100644 index 0000000..e8dc5b8 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/Sparkle.strings b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/Sparkle.strings new file mode 100644 index 0000000..16e0787 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/en.lproj/Sparkle.strings differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUAutomaticUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUAutomaticUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..4b1ab30 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUAutomaticUpdateAlert.nib/classes.nib @@ -0,0 +1,50 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + doNotInstall + id + installLater + id + installNow + id + + CLASS + SUAutomaticUpdateAlert + LANGUAGE + ObjC + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUAutomaticUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUAutomaticUpdateAlert.nib/info.nib new file mode 100644 index 0000000..2e04cfa --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUAutomaticUpdateAlert.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 667 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..6b2f938 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..994d4c3 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdateAlert.nib/classes.nib @@ -0,0 +1,67 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + CLASS + NSApplication + LANGUAGE + ObjC + SUPERCLASS + NSResponder + + + ACTIONS + + installUpdate + id + remindMeLater + id + skipThisVersion + id + + CLASS + SUUpdateAlert + LANGUAGE + ObjC + OUTLETS + + delegate + id + description + NSTextField + releaseNotesView + WebView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdateAlert.nib/info.nib new file mode 100644 index 0000000..2e04cfa --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdateAlert.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 667 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..c9b1e7d Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdatePermissionPrompt.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdatePermissionPrompt.nib/classes.nib new file mode 100644 index 0000000..5220a22 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdatePermissionPrompt.nib/classes.nib @@ -0,0 +1,59 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + finishPrompt + id + toggleMoreInfo + id + + CLASS + SUUpdatePermissionPrompt + LANGUAGE + ObjC + OUTLETS + + delegate + id + descriptionTextField + NSTextField + moreInfoButton + NSButton + moreInfoView + NSView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdatePermissionPrompt.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdatePermissionPrompt.nib/info.nib new file mode 100644 index 0000000..3eb7f81 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdatePermissionPrompt.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 667 + IBLastKnownRelativeProjectPath + ../../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib new file mode 100644 index 0000000..8c54c21 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/Sparkle.strings b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/Sparkle.strings new file mode 100644 index 0000000..f83ea23 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/es.lproj/Sparkle.strings differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUAutomaticUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUAutomaticUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..4b1ab30 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUAutomaticUpdateAlert.nib/classes.nib @@ -0,0 +1,50 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + doNotInstall + id + installLater + id + installNow + id + + CLASS + SUAutomaticUpdateAlert + LANGUAGE + ObjC + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUAutomaticUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUAutomaticUpdateAlert.nib/info.nib new file mode 100644 index 0000000..33a6020 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUAutomaticUpdateAlert.nib/info.nib @@ -0,0 +1,16 @@ + + + + + IBFramework Version + 629 + IBOldestOS + 5 + IBOpenObjects + + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..4cd529a Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..994d4c3 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdateAlert.nib/classes.nib @@ -0,0 +1,67 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + CLASS + NSApplication + LANGUAGE + ObjC + SUPERCLASS + NSResponder + + + ACTIONS + + installUpdate + id + remindMeLater + id + skipThisVersion + id + + CLASS + SUUpdateAlert + LANGUAGE + ObjC + OUTLETS + + delegate + id + description + NSTextField + releaseNotesView + WebView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdateAlert.nib/info.nib new file mode 100644 index 0000000..d2586ea --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdateAlert.nib/info.nib @@ -0,0 +1,16 @@ + + + + + IBFramework Version + 629 + IBOldestOS + 5 + IBOpenObjects + + IBSystem Version + 9E17 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..65dfc95 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdatePermissionPrompt.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdatePermissionPrompt.nib/classes.nib new file mode 100644 index 0000000..5220a22 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdatePermissionPrompt.nib/classes.nib @@ -0,0 +1,59 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + finishPrompt + id + toggleMoreInfo + id + + CLASS + SUUpdatePermissionPrompt + LANGUAGE + ObjC + OUTLETS + + delegate + id + descriptionTextField + NSTextField + moreInfoButton + NSButton + moreInfoView + NSView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdatePermissionPrompt.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdatePermissionPrompt.nib/info.nib new file mode 100644 index 0000000..d2586ea --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdatePermissionPrompt.nib/info.nib @@ -0,0 +1,16 @@ + + + + + IBFramework Version + 629 + IBOldestOS + 5 + IBOpenObjects + + IBSystem Version + 9E17 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib new file mode 100644 index 0000000..4b7cc90 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/Sparkle.strings b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/Sparkle.strings new file mode 100644 index 0000000..ea175ae Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/Sparkle.strings differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/fr.lproj b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/fr.lproj new file mode 120000 index 0000000..88614fe --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/fr.lproj/fr.lproj @@ -0,0 +1 @@ +/Users/andym/Development/Build Products/Release/Sparkle.framework/Resources/fr.lproj \ No newline at end of file diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/fr_CA.lproj b/client/osx/Sparkle.framework/Versions/A/Resources/fr_CA.lproj new file mode 120000 index 0000000..88614fe --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/fr_CA.lproj @@ -0,0 +1 @@ +/Users/andym/Development/Build Products/Release/Sparkle.framework/Resources/fr.lproj \ No newline at end of file diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUAutomaticUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUAutomaticUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..4b1ab30 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUAutomaticUpdateAlert.nib/classes.nib @@ -0,0 +1,50 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + doNotInstall + id + installLater + id + installNow + id + + CLASS + SUAutomaticUpdateAlert + LANGUAGE + ObjC + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUAutomaticUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUAutomaticUpdateAlert.nib/info.nib new file mode 100644 index 0000000..2e04cfa --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUAutomaticUpdateAlert.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 667 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..15ba8f4 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..994d4c3 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdateAlert.nib/classes.nib @@ -0,0 +1,67 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + CLASS + NSApplication + LANGUAGE + ObjC + SUPERCLASS + NSResponder + + + ACTIONS + + installUpdate + id + remindMeLater + id + skipThisVersion + id + + CLASS + SUUpdateAlert + LANGUAGE + ObjC + OUTLETS + + delegate + id + description + NSTextField + releaseNotesView + WebView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdateAlert.nib/info.nib new file mode 100644 index 0000000..2e04cfa --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdateAlert.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 667 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..2984064 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdatePermissionPrompt.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdatePermissionPrompt.nib/classes.nib new file mode 100644 index 0000000..5220a22 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdatePermissionPrompt.nib/classes.nib @@ -0,0 +1,59 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + finishPrompt + id + toggleMoreInfo + id + + CLASS + SUUpdatePermissionPrompt + LANGUAGE + ObjC + OUTLETS + + delegate + id + descriptionTextField + NSTextField + moreInfoButton + NSButton + moreInfoView + NSView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdatePermissionPrompt.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdatePermissionPrompt.nib/info.nib new file mode 100644 index 0000000..c493485 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdatePermissionPrompt.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 667 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 5 + + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib new file mode 100644 index 0000000..55cc2c2 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/Sparkle.strings b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/Sparkle.strings new file mode 100644 index 0000000..5c410d0 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/it.lproj/Sparkle.strings differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUAutomaticUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUAutomaticUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..4b1ab30 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUAutomaticUpdateAlert.nib/classes.nib @@ -0,0 +1,50 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + doNotInstall + id + installLater + id + installNow + id + + CLASS + SUAutomaticUpdateAlert + LANGUAGE + ObjC + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUAutomaticUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUAutomaticUpdateAlert.nib/info.nib new file mode 100644 index 0000000..3f09790 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUAutomaticUpdateAlert.nib/info.nib @@ -0,0 +1,18 @@ + + + + + IBFramework Version + 629 + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..aa38f86 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..994d4c3 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdateAlert.nib/classes.nib @@ -0,0 +1,67 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + CLASS + NSApplication + LANGUAGE + ObjC + SUPERCLASS + NSResponder + + + ACTIONS + + installUpdate + id + remindMeLater + id + skipThisVersion + id + + CLASS + SUUpdateAlert + LANGUAGE + ObjC + OUTLETS + + delegate + id + description + NSTextField + releaseNotesView + WebView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdateAlert.nib/info.nib new file mode 100644 index 0000000..d2586ea --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdateAlert.nib/info.nib @@ -0,0 +1,16 @@ + + + + + IBFramework Version + 629 + IBOldestOS + 5 + IBOpenObjects + + IBSystem Version + 9E17 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..c82d358 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdatePermissionPrompt.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdatePermissionPrompt.nib/classes.nib new file mode 100644 index 0000000..5220a22 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdatePermissionPrompt.nib/classes.nib @@ -0,0 +1,59 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + finishPrompt + id + toggleMoreInfo + id + + CLASS + SUUpdatePermissionPrompt + LANGUAGE + ObjC + OUTLETS + + delegate + id + descriptionTextField + NSTextField + moreInfoButton + NSButton + moreInfoView + NSView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdatePermissionPrompt.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdatePermissionPrompt.nib/info.nib new file mode 100644 index 0000000..d2586ea --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdatePermissionPrompt.nib/info.nib @@ -0,0 +1,16 @@ + + + + + IBFramework Version + 629 + IBOldestOS + 5 + IBOpenObjects + + IBSystem Version + 9E17 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib new file mode 100644 index 0000000..ac298ce Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/Sparkle.strings b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/Sparkle.strings new file mode 100644 index 0000000..67cf535 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/nl.lproj/Sparkle.strings differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/relaunch b/client/osx/Sparkle.framework/Versions/A/Resources/relaunch new file mode 100755 index 0000000..e7b96d6 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/relaunch differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUAutomaticUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUAutomaticUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..4b1ab30 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUAutomaticUpdateAlert.nib/classes.nib @@ -0,0 +1,50 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + doNotInstall + id + installLater + id + installNow + id + + CLASS + SUAutomaticUpdateAlert + LANGUAGE + ObjC + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUAutomaticUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUAutomaticUpdateAlert.nib/info.nib new file mode 100644 index 0000000..2b3d425 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUAutomaticUpdateAlert.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 670 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9E17 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..1d4655c Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..994d4c3 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdateAlert.nib/classes.nib @@ -0,0 +1,67 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + CLASS + NSApplication + LANGUAGE + ObjC + SUPERCLASS + NSResponder + + + ACTIONS + + installUpdate + id + remindMeLater + id + skipThisVersion + id + + CLASS + SUUpdateAlert + LANGUAGE + ObjC + OUTLETS + + delegate + id + description + NSTextField + releaseNotesView + WebView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdateAlert.nib/info.nib new file mode 100644 index 0000000..2b3d425 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdateAlert.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 670 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 9E17 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..103b1cf Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdatePermissionPrompt.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdatePermissionPrompt.nib/classes.nib new file mode 100644 index 0000000..0f776c8 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdatePermissionPrompt.nib/classes.nib @@ -0,0 +1,59 @@ + + + + + IBClasses + + + CLASS + NSObject + LANGUAGE + ObjC + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + finishPrompt + id + toggleMoreInfo + id + + CLASS + SUUpdatePermissionPrompt + LANGUAGE + ObjC + OUTLETS + + delegate + id + descriptionTextField + NSTextField + moreInfoButton + NSButton + moreInfoView + NSView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdatePermissionPrompt.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdatePermissionPrompt.nib/info.nib new file mode 100644 index 0000000..5132e29 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdatePermissionPrompt.nib/info.nib @@ -0,0 +1,18 @@ + + + + + IBFramework Version + 670 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + IBSystem Version + 9E17 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib new file mode 100644 index 0000000..c09d9e7 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/Sparkle.strings b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/Sparkle.strings new file mode 100644 index 0000000..f3ff9d8 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/ru.lproj/Sparkle.strings differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUAutomaticUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUAutomaticUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..4b1ab30 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUAutomaticUpdateAlert.nib/classes.nib @@ -0,0 +1,50 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + doNotInstall + id + installLater + id + installNow + id + + CLASS + SUAutomaticUpdateAlert + LANGUAGE + ObjC + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUAutomaticUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUAutomaticUpdateAlert.nib/info.nib new file mode 100644 index 0000000..c5a067e --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUAutomaticUpdateAlert.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 670 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 10A96 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..53cb91a Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUAutomaticUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdateAlert.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdateAlert.nib/classes.nib new file mode 100644 index 0000000..018710a --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdateAlert.nib/classes.nib @@ -0,0 +1,39 @@ +{ + IBClasses = ( + { + CLASS = FirstResponder; + LANGUAGE = ObjC; + SUPERCLASS = NSObject; + }, + { + CLASS = NSApplication; + LANGUAGE = ObjC; + SUPERCLASS = NSResponder; + }, + { + CLASS = NSObject; + LANGUAGE = ObjC; + }, + { + ACTIONS = { + installUpdate = id; + remindMeLater = id; + skipThisVersion = id; + }; + CLASS = SUUpdateAlert; + LANGUAGE = ObjC; + OUTLETS = { + delegate = id; + description = NSTextField; + releaseNotesView = WebView; + }; + SUPERCLASS = SUWindowController; + }, + { + CLASS = SUWindowController; + LANGUAGE = ObjC; + SUPERCLASS = NSWindowController; + } + ); + IBVersion = 1; +} \ No newline at end of file diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdateAlert.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdateAlert.nib/info.nib new file mode 100644 index 0000000..6b787d4 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdateAlert.nib/info.nib @@ -0,0 +1,18 @@ + + + + + IBDocumentLocation + 69 14 356 240 0 0 1280 778 + IBFramework Version + 489.0 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBSystem Version + 9D34 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdateAlert.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdateAlert.nib/keyedobjects.nib new file mode 100644 index 0000000..7e6d490 Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdateAlert.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdatePermissionPrompt.nib/classes.nib b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdatePermissionPrompt.nib/classes.nib new file mode 100644 index 0000000..5220a22 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdatePermissionPrompt.nib/classes.nib @@ -0,0 +1,59 @@ + + + + + IBClasses + + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + + + ACTIONS + + finishPrompt + id + toggleMoreInfo + id + + CLASS + SUUpdatePermissionPrompt + LANGUAGE + ObjC + OUTLETS + + delegate + id + descriptionTextField + NSTextField + moreInfoButton + NSButton + moreInfoView + NSView + + SUPERCLASS + SUWindowController + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + NSObject + LANGUAGE + ObjC + + + IBVersion + 1 + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdatePermissionPrompt.nib/info.nib b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdatePermissionPrompt.nib/info.nib new file mode 100644 index 0000000..c5a067e --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdatePermissionPrompt.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 670 + IBLastKnownRelativeProjectPath + ../Sparkle.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 6 + + IBSystem Version + 10A96 + targetFramework + IBCocoaFramework + + diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib new file mode 100644 index 0000000..64babac Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib differ diff --git a/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/Sparkle.strings b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/Sparkle.strings new file mode 100644 index 0000000..b676a4f Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Resources/sv.lproj/Sparkle.strings differ diff --git a/client/osx/Sparkle.framework/Versions/A/Sparkle b/client/osx/Sparkle.framework/Versions/A/Sparkle new file mode 100755 index 0000000..0db0a8f Binary files /dev/null and b/client/osx/Sparkle.framework/Versions/A/Sparkle differ diff --git a/client/osx/Sparkle.framework/Versions/Current b/client/osx/Sparkle.framework/Versions/Current new file mode 120000 index 0000000..8c7e5a6 --- /dev/null +++ b/client/osx/Sparkle.framework/Versions/Current @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/client/osx/Splash.xib b/client/osx/Splash.xib new file mode 100644 index 0000000..4428677 --- /dev/null +++ b/client/osx/Splash.xib @@ -0,0 +1,239 @@ + + + + 1070 + 11E53 + 2182 + 1138.47 + 569.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 2182 + + + NSTextField + NSTextFieldCell + NSWindowTemplate + NSView + NSCustomObject + + + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + + NSObject + + + FirstResponder + + + NSApplication + + + 270 + YES + 2 + {{711, 388}, {163, 231}} + 611845120 + Window + NSWindow + + + + + 256 + + + + 268 + {{-45, 6}, {219, 236}} + + + + _NS:3936 + YES + + 72482368 + 272630784 + h + + LucidaGrande + 200 + 16 + + _NS:3936 + + YES + + 6 + System + keyboardFocusIndicatorColor + + 3 + MAA + + + + 6 + System + controlLightHighlightColor + + 3 + MQA + + + + + + + 268 + {{7, 20}, {149, 23}} + + + + _NS:3936 + YES + + 68288064 + 138413056 + HackPad + + LucidaGrande-Bold + 21 + 16 + + _NS:3936 + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2NjY3AA + + + + + + + {163, 231} + + + + _NS:2818 + + {{0, 0}, {2560, 1418}} + {10000000000000, 10000000000000} + YES + + + + + + + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 3 + + + + + + + + 4 + + + + + + + + + 6 + + + + + + + + 7 + + + + + 5 + + + + + + + + 8 + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + 8 + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + diff --git a/client/osx/Status.png b/client/osx/Status.png new file mode 100644 index 0000000..230f6fd Binary files /dev/null and b/client/osx/Status.png differ diff --git a/client/osx/StatusHighlighted.png b/client/osx/StatusHighlighted.png new file mode 100644 index 0000000..af5ff58 Binary files /dev/null and b/client/osx/StatusHighlighted.png differ diff --git a/client/osx/plusbutton.png b/client/osx/plusbutton.png new file mode 100644 index 0000000..b1b49c7 Binary files /dev/null and b/client/osx/plusbutton.png differ diff --git a/contrib/cron/cron.daily/etherpad-remove-ooconvert b/contrib/cron/cron.daily/etherpad-remove-ooconvert new file mode 100755 index 0000000..8794886 --- /dev/null +++ b/contrib/cron/cron.daily/etherpad-remove-ooconvert @@ -0,0 +1,5 @@ +#!/bin/sh +PATH=/usr/sbin:/usr/bin:/sbin:/bin:$PATH + +# Clears out all ooconvert-* files that are more than 24 hours old +find /tmp -daystart -mtime +0 -name "ooconvert-*" | xargs rm diff --git a/contrib/glue/.gitignore b/contrib/glue/.gitignore new file mode 100644 index 0000000..984e963 --- /dev/null +++ b/contrib/glue/.gitignore @@ -0,0 +1,6 @@ +*.pyc +*.egg-info +dist +build +.DS_Store +tests_tmp diff --git a/contrib/glue/COPYING.txt b/contrib/glue/COPYING.txt new file mode 100644 index 0000000..fecfc7b --- /dev/null +++ b/contrib/glue/COPYING.txt @@ -0,0 +1,30 @@ +Copyright (c) 2013 Benito Jorge Bastida +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. 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. + + 3. Neither the name of the author nor the names of other + 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. diff --git a/contrib/glue/glue.py b/contrib/glue/glue.py new file mode 100755 index 0000000..606759b --- /dev/null +++ b/contrib/glue/glue.py @@ -0,0 +1,1577 @@ +#!/usr/bin/env python + +import re +import os +import sys +import copy +import time +import signal +import StringIO +import hashlib +import subprocess +import ConfigParser +from optparse import OptionParser, OptionGroup + +try: + from PIL import PImage + from PIL import PngImagePlugin +except: + import Image as PImage + import PngImagePlugin + +__version__ = '0.3' + + +PADDING_REGEXP = re.compile("^(\d+-?){,3}\d+$") + +TRANSPARENT = (255, 255, 255, 0) +CAMELCASE_SEPARATOR = 'camelcase' +CONFIG_FILENAME = 'sprite.conf' +ORDERINGS = ['maxside', 'width', 'height', 'area'] +VALID_IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif'] +PSEUDO_CLASSES = set(['link', 'visited', 'active', 'hover', 'focus', + 'first-letter', 'first-line', 'first-child', + 'before', 'after']) + +DEFAULT_SETTINGS = { + 'padding': '0', + 'margin': '0', + 'algorithm': 'square', + 'ordering': 'maxside', + 'namespace': 'sprite', + 'sprite_namespace': '%(sprite)s', + 'crop': False, + 'url': '', + 'less': False, + 'force': False, + 'optipng': False, + 'html': False, + 'ignore_filename_paddings': False, + 'png8': False, + 'ratios': '', + 'retina': False, + 'imagemagick': False, + 'imagemagickpath': 'convert', + 'separator': '-', + 'optipngpath': 'optipng', + 'optipng': False, + 'project': False, + 'recursive': False, + 'follow_links': False, + 'quiet': False, + 'no_css': False, + 'no_img': False, + 'cachebuster': False, + 'cachebuster-filename': False, + 'global_template': + ('%(all_classes)s{background-image:url(\'%(sprite_url)s\');' + 'background-repeat:no-repeat}\n'), + 'each_template': + ('%(class_name)s{background-position:%(x)s %(y)s;' + 'width:%(width)s;height:%(height)s;}\n'), + 'ratio_template': + ('@media ' + 'only screen and (-webkit-min-device-pixel-ratio: %(ratio)s), ' + 'only screen and (min--moz-device-pixel-ratio: %(ratio)s), ' + 'only screen and (-o-min-device-pixel-ratio: %(ratio_fraction)s), ' + 'only screen and (min-device-pixel-ratio: %(ratio)s) {' + '%(all_classes)s{background-image:url(\'%(sprite_url)s\');' + '-webkit-background-size: %(width)s %(height)s;' + '-moz-background-size: %(width)s %(height)s;' + 'background-size: %(width)s %(height)s;' + '}}\n') + } + +TEST_HTML_TEMPLATE = """ +Glue Sprite Test Html + +

CSS Classes

+%(sprites)s
CSS ClassResult
+

Generated using Glue v%(version)s +

+""" + +TEST_HTML_SPRITE_TEMPLATE = """ +.%(class_name)s
+""" + + +class MultipleImagesWithSameNameError(Exception): + """Raised if two images pretend to generate the same CSS class name.""" + error_code = 2 + + +class SourceImagesNotFoundError(Exception): + """Raised if a folder doesn't contain any valid image.""" + error_code = 3 + + +class NoSpritesFoldersFoundError(Exception): + """Raised if no sprites folders could be found.""" + error_code = 4 + + +class InvalidImageAlgorithmError(Exception): + """Raised if the provided algorithm name is invalid.""" + error_code = 5 + + +class InvalidImageOrderingError(Exception): + """Raised if the provided ordering is invalid.""" + error_code = 6 + + +class PILUnavailableError(Exception): + """Raised if some PIL decoder isn't available.""" + error_code = 7 + + +class _Missing(object): + """ Missing object necessary for cached_property""" + def __repr__(self): + return 'no value' + + def __reduce__(self): + return '_missing' + +_missing = _Missing() + + +class cached_property(object): + """ + Decorator inspired/copied from mitsuhiko/werkzeug. + + A decorator that converts a function into a lazy property. The + function wrapped is called the first time to retrieve the result + and then that calculated result is used the next time you access + the value""" + + def __init__(self, func, name=None, doc=None): + self.__name__ = name or func.__name__ + self.__module__ = func.__module__ + self.__doc__ = doc or func.__doc__ + self.func = func + + def __get__(self, obj, type=None): + if obj is None: + return self + value = obj.__dict__.get(self.__name__, _missing) + if value is _missing: + value = self.func(obj) + obj.__dict__[self.__name__] = value + return value + + +def round_up(value): + int_value = int(value) + diff = 1 if int_value > 0 else -1 + return int_value + diff if value != int_value else int_value + + +def nearest_fration(value): + """ + Return the nearest fraction. + If fraction.Fraction is not available, return a fraction. + + Note: used for Opera CSS pixel-ratio media queries. + """ + try: + from fraction import Fraction + return str(Fraction(value)) + except ImportError: + return '%i/100' % int(float(value) * 100) + + +class SquareAlgorithmNode(object): + + def __init__(self, x=0, y=0, width=0, height=0, used=False, + down=None, right=None): + """Node constructor. + + :param x: X coordinate. + :param y: Y coordinate. + :param width: Image width. + :param height: Image height. + :param used: Flag to determine if the node is used. + :param down: Down :class:`~Node`. + :param right Right :class:`~Node`. + """ + self.x = x + self.y = y + self.width = width + self.height = height + self.used = used + self.right = right + self.down = down + + def find(self, node, width, height): + """Find a node to allocate this image size (width, height). + + :param node: Node to search in. + :param width: Pixels to grow down (width). + :param height: Pixels to grow down (height). + """ + if node.used: + return self.find(node.right, width, height) or \ + self.find(node.down, width, height) + elif node.width >= width and node.height >= height: + return node + return None + + def grow(self, width, height): + """ Grow the canvas to the most appropriate direction. + + :param width: Pixels to grow down (width). + :param height: Pixels to grow down (height). + """ + can_grow_d = width <= self.width + can_grow_r = height <= self.height + + should_grow_r = can_grow_r and self.height >= (self.width + width) + should_grow_d = can_grow_d and self.width >= (self.height + height) + + if should_grow_r: + return self.grow_right(width, height) + elif should_grow_d: + return self.grow_down(width, height) + elif can_grow_r: + return self.grow_right(width, height) + elif can_grow_d: + return self.grow_down(width, height) + + return None + + def grow_right(self, width, height): + """Grow the canvas to the right. + + :param width: Pixels to grow down (width). + :param height: Pixels to grow down (height). + """ + old_self = copy.copy(self) + self.used = True + self.x = self.y = 0 + self.width += width + self.down = old_self + self.right = SquareAlgorithmNode(x=old_self.width, + y=0, + width=width, + height=self.height) + + node = self.find(self, width, height) + if node: + return self.split(node, width, height) + return None + + def grow_down(self, width, height): + """Grow the canvas down. + + :param width: Pixels to grow down (width). + :param height: Pixels to grow down (height). + """ + old_self = copy.copy(self) + self.used = True + self.x = self.y = 0 + self.height += height + self.right = old_self + self.down = SquareAlgorithmNode(x=0, + y=old_self.height, + width=self.width, + height=height) + + node = self.find(self, width, height) + if node: + return self.split(node, width, height) + return None + + def split(self, node, width, height): + """Split the node to allocate a new one of this size. + + :param node: Node to be splitted. + :param width: New node width. + :param height: New node height. + """ + node.used = True + node.down = SquareAlgorithmNode(x=node.x, + y=node.y + height, + width=node.width, + height=node.height - height) + node.right = SquareAlgorithmNode(x=node.x + width, + y=node.y, + width=node.width - width, + height=height) + return node + + +class SquareAlgorithm(object): + + def process(self, sprite): + + root = SquareAlgorithmNode(width=sprite.images[0].absolute_width, + height=sprite.images[0].absolute_height) + + # Loot all over the images creating a binary tree + for image in sprite.images: + node = root.find(root, image.absolute_width, image.absolute_height) + if node: # Use this node + node = root.split(node, image.absolute_width, + image.absolute_height) + else: # Grow the canvas + node = root.grow(image.absolute_width, image.absolute_height) + + image.x = node.x + image.y = node.y + + +class VerticalAlgorithm(object): + + def process(self, sprite): + y = 0 + for image in sprite.images: + image.x = 0 + image.y = y + y += image.absolute_height + + +class VerticalRightAlgorithm(object): + + def process(self, sprite): + max_width = max([i.width for i in sprite.images]) + y = 0 + for image in sprite.images: + image.x = max_width - image.width + image.y = y + y += image.absolute_height + + +class HorizontalAlgorithm(object): + + def process(self, sprite): + x = 0 + for image in sprite.images: + image.y = 0 + image.x = x + x += image.absolute_width + + +class HorizontalBottomAlgorithm(object): + + def process(self, sprite): + max_height = max([i.height for i in sprite.images]) + x = 0 + for image in sprite.images: + image.y = max_height - image.height + image.x = x + x += image.absolute_width + + +class DiagonalAlgorithm(object): + + def process(self, sprite): + x = y = 0 + for image in sprite.images: + image.x = x + image.y = y + x += image.absolute_width + y += image.absolute_height + + +ALGORITHMS = {'square': SquareAlgorithm, + 'vertical': VerticalAlgorithm, + 'vertical-right': VerticalRightAlgorithm, + 'horizontal': HorizontalAlgorithm, + 'horizontal-bottom': HorizontalBottomAlgorithm, + 'diagonal': DiagonalAlgorithm} + + +class Image(object): + + def __init__(self, name, sprite, path=None): + """Image constructor + + :param name: Image name. + :param sprite: :class:`~Sprite` instance for this image.""" + self.x = None + self.y = None + self.name = name + self.sprite = sprite + self.filename, self.format = name.rsplit('.', 1) + + if '_' in self.filename: + pseudo = set(self.filename.split('_')).intersection(PSEUDO_CLASSES) + self.pseudo = ':%s' % list(pseudo)[-1] if pseudo else '' + else: + self.pseudo = '' + + self.path = path or os.path.join(sprite.path, name) + + with open(self.path, "rb") as image_file: + self._data = image_file.read() + + @cached_property + def image(self): + """Return a Pil representation of this image """ + io = StringIO.StringIO(self._data) + try: + source_image = PImage.open(io) + img = PImage.new('RGBA', source_image.size, (0, 0, 0, 0)) + + if source_image.mode == 'L': + alpha = source_image.split()[0] + transparency = source_image.info.get('transparency') + mask = PImage.eval(alpha, lambda a: 0 if a == transparency else 255) + img.paste(source_image, (0, 0), mask=mask) + else: + img.paste(source_image, (0, 0)) + except IOError, e: + raise PILUnavailableError(e.args[0].split()[1]) + finally: + io.close() + + # Crop the image searching for the smallest possible bounding box + # without losing any non-transparent pixel. + # This crop is only used if the crop flag is set in the config. + + if self.sprite.config.crop: + width, height = img.size + maxx = maxy = 0 + minx = miny = sys.maxint + + for x in xrange(width): + for y in xrange(height): + if y > miny and y < maxy and maxx == x: + continue + if img.getpixel((x, y)) != TRANSPARENT: + if x < minx: + minx = x + if x > maxx: + maxx = x + if y < miny: + miny = y + if y > maxy: + maxy = y + img = img.crop((minx, miny, maxx + 1, maxy + 1)) + + return img + + @cached_property + def width(self): + """Return Image width""" + return self.image.size[0] + + @cached_property + def height(self): + """Return Image height""" + return self.image.size[1] + + @cached_property + def absolute_width(self): + """Return the total width of the image taking count of the margin, + padding and ratio.""" + margin = int(self.sprite.config.margin) + return round_up(self.width + + (self.horizontal_padding + 2 * margin) * self.sprite.max_ratio) + + @cached_property + def absolute_height(self): + """Return the total height of the image taking count of the margin, + padding and ratio. + """ + margin = int(self.sprite.config.margin) + return round_up(self.height + + (self.vertical_padding + 2 * margin) * self.sprite.max_ratio) + + def _generate_padding(self, padding): + """Return a 4-elements list with the desired padding. + + :param padding: Padding as a list or a raw string representing + the padding for this image.""" + + if type(padding) == str: + padding = padding.replace('px', '').split() + + if len(padding) == 4: + padding = padding + elif len(padding) == 3: + padding = padding + [padding[1]] + elif len(padding) == 2: + padding = padding * 2 + elif len(padding) == 1: + padding = padding * 4 + else: + padding = [DEFAULT_SETTINGS['padding']] * 4 + return map(int, padding) + + @cached_property + def class_name(self): + """Return the CSS class name for this file. + + This CSS class name will have the following format: + + ``.[namespace]-[sprite-namespace]-[image_name]{ ... }`` + + The image_name will only contain alphanumeric characters, + ``-`` and ``_``. The default namespace is ``sprite``, but it could + be overridden using the ``--namespace`` optional argument. + + * ``animals/cat.png`` will be ``.sprite-animals-cat`` + * ``animals/cow_20.png`` will be ``.sprite-animals-cow`` + * ``animals/cat_hover.png`` will be ``.sprite-animals-cat:hover`` + * ``animals/cow_20_hover.png`` will be ``.sprite-animals-cow:hover`` + + The separator used is also configurable using the ``--separator`` + option. For a camelCase representation of the CSS class name use + ``camelcase`` as separator. + """ + name = self.filename + + # Remove padding information + if not self.sprite.manager.config.ignore_filename_paddings: + padding_info_name = '-'.join(self._padding_info) + if padding_info_name: + padding_info_name = '_%s' % padding_info_name + name = name.replace(padding_info_name, '') + + # Remove pseudo-class information + if self.pseudo: + name = name.replace('_%s' % self.pseudo[1:], '') + + # Clean filename + name = re.sub(r'[^\w\-_]', '', name) + + separator = self.sprite.manager.config.separator + + # Add pseudo-class information + name = '%s%s' % (name, self.pseudo) + + # Create the minimal namespace + namespace = [name] + + # Add sprite namespace if required + if self.sprite.manager.config.sprite_namespace: + sprite_name = re.sub(r'[^\w\-_]', '', self.sprite.name) + namespace.insert(0, self.sprite.manager.config.sprite_namespace % {'sprite': sprite_name}) + + # Add global namespace if required + if self.sprite.manager.config.namespace: + namespace.insert(0, self.sprite.manager.config.namespace) + + # Handle CamelCase separator + if separator == CAMELCASE_SEPARATOR: + namespace = [n[:1].title() + n[1:] if i > 0 else n for i, n in enumerate(namespace)] + separator = '' + + return separator.join(namespace) + + @cached_property + def _padding_info(self): + """Return the padding information from the filename.""" + for block in self.filename.split('_')[:0:-1]: + if PADDING_REGEXP.match(block): + return block.split('-') + return [] + + @cached_property + def padding(self): + """Return the padding for this image based on the filename and + the sprite settings file. + + * ``filename.png`` will have the default padding ``10px``. + * ``filename_20.png`` -> ``20px`` all around the image. + * ``filename_1-2-3.png`` -> ``1px 2px 3px 2px`` around the image. + * ``filename_1-2-3-4.png`` -> ``1px 2px 3px 4px`` around the image. + + """ + padding = self._padding_info + if len(padding) == 0 or \ + self.sprite.manager.config.ignore_filename_paddings: + padding = self.sprite.config.padding + return self._generate_padding(padding) + + @cached_property + def horizontal_padding(self): + """Return the horizontal padding for this image.""" + return self.padding[1] + self.padding[3] + + @cached_property + def vertical_padding(self): + """Return the vertical padding for this image.""" + return self.padding[0] + self.padding[2] + + def __lt__(self, img): + """Use maxside, width, height or area as ordering algorithm. + + :param img: Another :class:`~Image`.""" + ordering = self.sprite.config.ordering + ordering = ordering[1:] if ordering.startswith('-') else ordering + + if ordering not in ORDERINGS: + raise InvalidImageOrderingError(ordering) + + if ordering == 'width': + return self.absolute_width <= img.absolute_width + elif ordering == 'height': + return self.absolute_height <= img.absolute_height + elif ordering == 'area': + return self.absolute_width * self.absolute_height <= \ + img.absolute_width * img.absolute_height + else: + return max(self.absolute_width, self.absolute_height) <= \ + max(img.absolute_width, img.absolute_height) + + +class Sprite(object): + + def __init__(self, name, path, manager): + """Sprite constructor. + + :param name: Sprite name. + :param path: Sprite path + :param manager: Sprite manager. :class:`~ProjectSpriteManager` or + :class:`SimpleSpriteManager`""" + self.name = name + self.manager = manager + self.images = [] + self.path = path + self._processed = False + + self.config = manager.config.extend(get_file_config(self.path)) + + # Build the set of ratios this sprite needs. + ratios = self.config.ratios.split(',') + self.ratios = set([float(r.strip()) for r in ratios if r.strip()]) + + # If the retina shortcut is in use add 2.0 as a required ratio. + if self.config.retina: + self.ratios.add(2.0) + + # Always add 1.0 as a required ratio + self.ratios.add(1.0) + + # Create a sorted list of ratios + self.ratios = sorted(self.ratios) + + # Locate images + self.images = self._locate_images() + + def validate(self): + """Validate this sprite cheking that all images will have different + CCS class names. + """ + class_names = [i.class_name for i in self.images] + if len(set(class_names)) != len(self.images): + dup = [i for i in self.images if class_names.count(i.class_name) > 1] + raise MultipleImagesWithSameNameError(dup) + + for image in self.images: + self.manager.log("\t %s => .%s" % (image.name, image.class_name)) + + return True + + def process(self): + """Process a sprite path searching for all the images and then + allocate all of them in the most appropriate position. + """ + if self._processed: + return + + algorithm = ALGORITHMS.get(self.config.algorithm) + + if not algorithm: + raise InvalidImageAlgorithmError(self.config.algorithm) + + self.algorithm = algorithm() + self.images = sorted(self.images, reverse=self.config.ordering[0] != '-') + self.algorithm.process(self) + self._processed = True + + def _locate_images(self): + """Return all valid images within a folder. + + All files with a extension not included i + (png, jpg, jpeg and gif) or beginning with '.' will be ignored. + + If the folder doesn't contain any valid image it will raise + :class:`~MultipleImagesWithSameNameError` + + The list of images will be ordered using the desired ordering + algorithm. The default is 'maxside'. + """ + extensions = '|'.join(VALID_IMAGE_EXTENSIONS) + extension_re = re.compile('.+\.(%s)$' % extensions, re.IGNORECASE) + files = sorted(os.listdir(self.path)) + + images = [] + for root, dirs, files in os.walk(self.path, followlinks=self.config.follow_links): + for f in sorted(files): + if not f.startswith('.') and extension_re.match(f): + images.append(Image(f, path=os.path.join(root, f), sprite=self)) + if not self.config.recursive: + break + + if not images: + raise SourceImagesNotFoundError(self.path) + + return images + + @cached_property + def canvas_size(self): + """Return the width and height for this sprite canvas""" + width = height = 0 + for image in self.images: + x = image.x + image.absolute_width + y = image.y + image.absolute_height + if width < x: + width = x + if height < y: + height = y + return round_up(width), round_up(height) + + def save_image(self): + """Create the image file for this sprite.""" + + if self.config.no_img: + return + + # Check if we need to create any sprite. + ratios_to_process = [] + + for ratio in self.ratios: + sprite_image_path = self.image_path(ratio) + try: + assert not self.config.force + existing_sprite = PImage.open(sprite_image_path) + assert existing_sprite.info['Software'] == 'glue-%s' % __version__ + assert existing_sprite.info['Comment'] == self.hash + already_created = True + except Exception: + already_created = False + + if not already_created: + ratios_to_process.append(ratio) + + if not ratios_to_process: + self.manager.log("Already exists '%s' image file..." % self.name) + return + + self.manager.log("Creating '%s' image file..." % self.name) + + # Process the sprite if necessary. + self.process() + + # Create the sprite canvas + width, height = self.canvas_size + canvas = PImage.new('RGBA', (width, height), (0, 0, 0, 0)) + + # Paste the images inside the canvas + margin = int(self.config.margin) + for image in self.images: + canvas.paste(image.image, + (round_up(image.x + (image.padding[3] + margin) * self.max_ratio), + round_up(image.y + (image.padding[0] + margin) * self.max_ratio))) + + meta = PngImagePlugin.PngInfo() + meta.add_text('Software', 'glue-%s' % __version__) + meta.add_text('Comment', self.hash) + + # Customize how the png is going to be saved + kwargs = dict(optimize=False, pnginfo=meta) + + if self.config.png8: + # Get the alpha band + alpha = canvas.split()[-1] + canvas = canvas.convert('RGB' + ).convert('P', + palette=PImage.ADAPTIVE, + colors=255) + + # Set all pixel values below 128 to 255, and the rest to 0 + mask = PImage.eval(alpha, lambda a: 255 if a <= 128 else 0) + + # Paste the color of index 255 and use alpha as a mask + canvas.paste(255, mask) + kwargs.update({'transparency': 255}) + + # Loop all over the ratios and save one image for each one + for ratio in ratios_to_process: + sprite_image_path = self.image_path(ratio) + + save_full_size = lambda: canvas.save(sprite_image_path, **kwargs) + + # If this canvas isn't the biggest one scale it using the ratio + if self.max_ratio != ratio: + + def pil_save(): + reduced_canvas = canvas.resize( + (round_up((width / self.max_ratio) * ratio), + round_up((height / self.max_ratio) * ratio)), + PImage.ANTIALIAS) + reduced_canvas.save(sprite_image_path, **kwargs) + + if self.config.imagemagick: + def save(): + save_full_size() + data = {'path': sprite_image_path, + 'imagemagickpath': self.config.imagemagickpath, + 'ratio': (100.0 / self.max_ratio) * ratio} + command = ["%(imagemagickpath)s %(path)s -resize %(ratio)s%% %(path)s" % data] + error = subprocess.call(command, + shell=True, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + if error: + self.manager.log("Error: ImageMagic has failed, using Pillow to scale the sprite.") + pil_save() + else: + save = pil_save + else: + save = save_full_size + + save() + + # Optimize the image using optipng, if for some reason, it fails + # rollback to the original one. + if self.config.optipng: + command = ["%s %s" % (self.config.optipngpath, + sprite_image_path)] + error = subprocess.call(command, + shell=True, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + if error: + self.manager.log("Error: optipng has failed, reverting to " + "the original file.") + save() + + def save_css(self): + """Create the CSS or LESS file for this sprite.""" + + if self.config.no_css: + return + + format = 'less' if self.config.less else 'css' + output_path = self.manager.output_path('css') + filename = '%s.%s' % (self.filename, format) + css_filename = os.path.join(output_path, filename) + hash_line = '/* glue: %s hash: %s */\n' % (__version__, self.hash) + + # Check if the CSS file already exists and has the same hash + try: + assert not self.config.force + with open(css_filename, 'r') as existing_css: + first_line = existing_css.readline() + assert first_line == hash_line + self.manager.log("Already exists '%s' %s file..." % (self.name, format)) + return + except Exception: + pass + + self.manager.log("Creating '%s' %s file..." % (self.name, format)) + + # Process the sprite if necessary. + self.process() + + css_file = open(css_filename, 'w') + + # Write the hash line to the file. + css_file.write(hash_line) + + # Get all the class names + class_names = ['.%s' % i.class_name for i in self.images] + + # Exclude pseudo classes if the class is already in the list + class_names = [cn for cn in class_names if ':' not in cn or cn.rsplit(':')[0] not in class_names] + + # Join class names + class_names = ',\n'.join(class_names) + + # add the global style for all the sprites for less bloat + template = self.config.global_template.decode('unicode-escape') + css_file.write(template % {'all_classes': class_names, + 'sprite_url': self.image_url()}) + + # compile one template for each file + margin = int(self.config.margin) + + for image in self.images: + + x = '%spx' % round_up((image.x * -1 - margin * self.max_ratio) / self.max_ratio) + y = '%spx' % round_up((image.y * -1 - margin * self.max_ratio) / self.max_ratio) + + height = '%spx' % round_up((image.height / self.max_ratio) + image.vertical_padding) + width = '%spx' % round_up((image.width / self.max_ratio) + image.horizontal_padding) + + template = self.config.each_template.decode('unicode-escape') + css_file.write(template % {'class_name': '.%s' % image.class_name, + 'identifier': image.class_name, + 'sprite_url': self.image_url(), + 'height': height, + 'width': width, + 'y': y, + 'x': x}) + + # If we have some additional ratio, we need to add one media query + # for each one. + if len(self.ratios) > 1: + canvas_size = zip(('width', 'height'), + map(lambda s: '%spx' % int(s / self.max_ratio), + self.canvas_size)) + + for ratio in self.ratios: + if ratio != 1: + data = dict(ratio=ratio, + ratio_fraction=nearest_fration(ratio), + sprite_url=self.image_url(ratio), + all_classes=class_names, + **dict(canvas_size)) + css_file.write(self.config.ratio_template % data) + css_file.close() + + def save_html(self): + """Create the HTML file for this sprite.""" + self.manager.log("Creating '%s' html file..." % self.name) + + output_path = self.manager.output_path('css') + filename = '%s.html' % self.filename + html_filename = os.path.join(output_path, filename) + + # CSS output format + format = 'less' if self.config.less else 'css' + + html_file = open(html_filename, 'w') + + # get all the class names and join them + class_names = [i.class_name for i in self.images \ + if ':' not in i.class_name] + + sprite_template = TEST_HTML_SPRITE_TEMPLATE.decode('unicode-escape') + sprites_html = [sprite_template % {'class_name':c} for c in class_names] + + file_template = TEST_HTML_TEMPLATE.decode('unicode-escape') + html_file.write(file_template % {'sprites': ''.join(sprites_html), + 'css_url': '%s.%s' % (self.filename, format), + 'version': __version__}) + html_file.close() + + @cached_property + def filename(self): + """Return the desired filename for files generated by this sprite.""" + if self.config.cachebuster_filename: + return '%s_%s' % (self.name, self.hash[:6]) + return self.name + + def image_path(self, ratio=1, full=True): + reference = self.__get_reference(ratio) + """Return the output path for the image file. + If full, prepend the img output path, if not only return the filename. + :param ratio: Ratio. + """ + filename = '%s%s.png' % (self.filename, reference) + if full: + return os.path.join(self.manager.output_path('img'), filename) + return filename + + def __get_reference(self, ratio): + """ Return the reference @Nx for this ratio. + + :param ratio: Ratio. + """ + reference = '@%.1fx' % ratio if int(ratio) != ratio else '@%ix' % ratio + if reference == '@1x': + reference = '' + return reference + + @cached_property + def max_ratio(self): + """ Return the maximum ratio """ + return max(self.ratios) + + def image_url(self, ratio=1): + """Return the sprite image url. + + :param ratio: Ratio. + """ + + if self.config.url: + image_path = self.image_path(ratio, full=False) + url = os.path.join(self.config.url, image_path) + else: + image_path = self.image_path(ratio) + url = os.path.relpath(image_path, self.manager.output_path('css')) + url = os.path.normpath(url) + + # Fix css urls on Windows + if os.name == 'nt': + url = url.replace('\\', '/') + + if self.config.cachebuster: + url = "%s?%s" % (url, self.hash[:6]) + + return url + + @cached_property + def hash(self): + """ Return a hash of this sprite. In order to detect any change on + the source images it use the data, order and path of each image. + In the same way it use this sprite settings as part of the hash. + """ + hash_list = [] + for image in sorted(self.images, key=lambda i: i.path): + hash_list.append(image.path) + hash_list.append(image._data) + + for key in DEFAULT_SETTINGS: + + # Ignore this settings as they don't change the result. + if key in ['html', 'quiet', 'force']: + continue + + hash_list.append(key) + hash_list.append(str(getattr(self.config, key))) + + return hashlib.sha1(''.join(hash_list)).hexdigest()[:10] + + +class ConfigManager(object): + """Manage all the available configuration. + + If no config is available, return the default one.""" + + def __init__(self, *args, **kwargs): + """ConfigManager constructor. + + :param *args: List of config dictionaries. The order of this list is + important because as soon as a config property + is available it will be returned. + :param defaults: Dictionary with the default configuration. + :param priority: Dictionary with the command line configuration. This + configuration will override any other from any source. + """ + self.defaults = kwargs.get('defaults', {}) + self.priority = kwargs.get('priority', {}) + self.sources = list(args) + self._cache = {} + + def extend(self, config): + """Return a new :class:`~ConfigManager` instance with this new config + inside the sources list. + + :param config: Dictionary with the new config. + """ + return self.__class__(config, priority=self.priority, + defaults=self.defaults, *self.sources) + + def __getattr__(self, name): + """Return the first available configuration value for this key. This + method always prioritizes the command line configuration. If this key + is not available within any configuration dictionary, it returns the + default value + + :param name: Configuration property name. + """ + if name in self._cache: + return self._cache[name] + + try: + value = super(ConfigManager, self).__getattribute__('_%s' % name)() + self._cache[name] = value + return value + except AttributeError: + pass + + self._cache[name] = self.find(name) + + return self._cache[name] + + @cached_property + def _sources(self): + return [self.priority] + self.sources + + def find(self, name): + for source in self._sources: + value = source.get(name) + if value is not None: + return value + return self.defaults.get(name) + + +class BaseManager(object): + + def __init__(self, path, config, output=None): + """BaseManager constructor. + + :param path: Sprite path. + :param config: :class:`~ConfigManager` instance with all the + configuration for this sprite. + :param output: output dir. + """ + self.path = path + self.config = config + self.output = output + self.sprites = [] + + def process_sprite(self, path, name): + """Create a new Sprite using this path and name and append it to the + sprites list. + + :param path: Sprite path. + :param name: Sprite name. + """ + sprite = Sprite(name=name, path=path, manager=self) + self.sprites.append(sprite) + + def validate(self): + """Validate CSS class names collision between sprites""" + + class_names = reduce(lambda x, y: x + y, [[i.class_name for i in sprite.images] for sprite in self.sprites]) + + if len(class_names) != len(set(class_names)): + dup = [[i for i in sprite.images if class_names.count(i.class_name) > 1] for sprite in self.sprites] + dup = reduce(lambda x, y: x + y, dup) + raise MultipleImagesWithSameNameError(dup) + + return True + + def save(self): + """Save all the sprites inside this manager.""" + + # Validate sprites individualy + for sprite in self.sprites: + self.log("Processing '%s':" % sprite.name) + sprite.validate() + + # Validate collisions between sprites + self.validate() + + for sprite in self.sprites: + sprite.save_image() + sprite.save_css() + if sprite.manager.config.html: + sprite.save_html() + + def output_path(self, format): + """Return the path where all the generated files will be saved. + + :param format: File format. + """ + if format == 'css' and self.config.css_dir: + sprite_output_path = self.config.css_dir + elif format == 'img' and self.config.img_dir: + sprite_output_path = self.config.img_dir + else: + sprite_output_path = self.output + if not os.path.exists(sprite_output_path): + os.makedirs(sprite_output_path) + return sprite_output_path + + def log(self, message): + """Print the message if necessary. + + :param message: Message to log. + """ + if not self.config.quiet: + print(message) + + def process(self): + raise NotImplementedError() + + +class ProjectSpriteManager(BaseManager): + + def process(self): + """Process a path searching for folders that contain images. + Every folder will be a new sprite with all the images inside. + + The filename of the image can also contain information about the + padding needed around the image. + + * ``filename.png`` will have the default padding (10px). + * ``filename_20.png`` will have 20px all around the image. + * ``filename_1-2-3.png`` will have 1px 2px 3px 2px around the image. + * ``filename_1-2-3-4.png`` will have 1px 2px 3px 4px around the image. + + The generated CSS file will have a CSS class for every image found + inside the sprites folder. These CSS class names will have the + following format: + + ``.[namespace]-[sprite_name]-[image_name]{ ... }`` + + The image_name will only contain alphanumeric characters, + ``-`` and ``_``. The default namespace is ``sprite``, but it could be + overridden using the ``--namespace`` optional argument. + + + * ``animals/cat.png`` CSS class will be ``.sprite-animals-cat`` + * ``animals/cow_20.png`` CSS class will be ``.sprite-animals-cow`` + + If two images have the same name, + :class:`~MultipleImagesWithSameNameError` will be raised. + + This is not the default manager. It is only used if you use + the ``--project`` argument. + """ + + for sprite_name in sorted(os.listdir(self.path)): + + # Only process folders + path = os.path.join(self.path, sprite_name) + + # Ignore folders starting with '.' + if sprite_name.startswith('.'): + continue + + # Ignore symlinks if necessary. + if os.path.isdir(path) or (os.path.islink(path) and self.config.follow_links): + self.process_sprite(path=path, name=sprite_name) + + if not self.sprites: + raise NoSpritesFoldersFoundError(self.path) + + self.save() + + +class SimpleSpriteManager(BaseManager): + + def process(self): + """Process a single folder and create one sprite. It works the + same way as :class:`~ProjectSpriteManager`, but only for one folder. + + This is the default manager. + """ + self.process_sprite(path=self.path, name=os.path.basename(self.path)) + self.save() + + +class WatchManager(object): + """ Watch a path for changes. """ + + def __init__(self, path, action): + """ + :param path: Path to watch. + :param action: Action to run when a change happens. + """ + self.action = action + self.path = path + self.last_hash = None + + def run(self): + """ Start watching the path for changes """ + signal.signal(signal.SIGINT, self.signal_handler) + + while True: + try: + current_hash = self.generate_hash() + if self.last_hash != current_hash: + self.action() + self.last_hash = current_hash + except Exception: + pass + finally: + time.sleep(0.2) + + def signal_handler(self, signal, frame): + """ Gracefully close the app if Ctrl+C is pressed.""" + print 'You pressed Ctrl+C!' + sys.exit(0) + + def generate_hash(self): + """ Return a hash of files and modification times to determine if a + change has occourred.""" + + hash_list = [] + for root, dirs, files in os.walk(self.path): + for f in sorted([f for f in files if not f.startswith('.')]): + hash_list.append(os.path.join(root, f)) + hash_list.append(str(os.path.getmtime(os.path.join(root, f)))) + hash_list = ''.join(hash_list) + return hashlib.sha1(hash_list).hexdigest() + + +def get_file_config(path, section='sprite'): + """Return, as a dictionary, all the available configuration inside the + sprite configuration file on this path. + + :param path: Path where the configuration file is. + :param section: The configuration file section that needs to be read. + """ + def clean(value): + return {'true': True, 'false': False}.get(value.lower(), value) + + config = ConfigParser.RawConfigParser() + config.read(os.path.join(path, CONFIG_FILENAME)) + try: + keys = config.options(section) + except ConfigParser.NoSectionError: + return {} + return dict([[k, clean(config.get(section, k))] for k in keys]) + + +def command_exists(command): + """Check if a command exists by running it. + + :param command: command name. + """ + try: + subprocess.check_call([command], shell=True, stdin=subprocess.PIPE, + stderr=subprocess.PIPE, stdout=subprocess.PIPE) + except subprocess.CalledProcessError: + return False + return True + + +######################################################################### +# PIL currently doesn't support full alpha for PNG8 so it's necessary to +# monkey patch PIL to support them. +# http://mail.python.org/pipermail/image-sig/2010-October/006533.html +######################################################################### + +try: + from PIL import ImageFile, PngImagePlugin +except: + import ImageFile, PngImagePlugin + +def patched_chunk_tRNS(self, pos, len): + i16 = PngImagePlugin.i16 + s = ImageFile._safe_read(self.fp, len) + if self.im_mode == "P": + self.im_info["transparency"] = map(ord, s) + elif self.im_mode == "L": + self.im_info["transparency"] = i16(s) + elif self.im_mode == "RGB": + self.im_info["transparency"] = i16(s), i16(s[2:]), i16(s[4:]) + return s +PngImagePlugin.PngStream.chunk_tRNS = patched_chunk_tRNS + + +def patched_load(self): + if self.im and self.palette and self.palette.dirty: + apply(self.im.putpalette, self.palette.getdata()) + self.palette.dirty = 0 + self.palette.rawmode = None + try: + trans = self.info["transparency"] + except KeyError: + self.palette.mode = "RGB" + else: + try: + for i, a in enumerate(trans): + self.im.putpalettealpha(i, a) + except TypeError: + self.im.putpalettealpha(trans, 0) + self.palette.mode = "RGBA" + if self.im: + return self.im.pixel_access(self.readonly) +PImage.Image.load = patched_load +######################################################################### + + +def main(): + parser = OptionParser(usage=("usage: %prog [options] source_dir [ " + "| --css= --img=]")) + parser.add_option("--project", action="store_true", dest="project", + help="generate sprites for multiple folders") + parser.add_option("-r", "--recursive", dest="recursive", action='store_true', + help=("Read directories recursively and add all the " + "images to the same sprite.")) + parser.add_option("--follow-links", dest="follow_links", action='store_true', + help="Follow symbolic links.") + parser.add_option("-c", "--crop", dest="crop", action='store_true', + help="crop images removing unnecessary transparent margins") + parser.add_option("-l", "--less", dest="less", action='store_true', + help="generate output stylesheets as .less instead of .css") + parser.add_option("-u", "--url", dest="url", + help="prepend this url to the sprites filename") + parser.add_option("-q", "--quiet", dest="quiet", action='store_true', + help="suppress all normal output") + parser.add_option("-p", "--padding", dest="padding", + help="force this padding in all images") + parser.add_option("--ratios", dest="ratios", + help="Create sprites based on these ratios") + parser.add_option("--retina", dest="retina", action='store_true', + help="Shortcut for --ratios=2,1") + parser.add_option("-f", "--force", dest="force", action='store_true', + help=("force glue to create every sprite and CSS file even if " + "they already exists in the output directory.")) + parser.add_option("-w", "--watch", dest="watch", default=False, + action='store_true', + help=("Watch the source folder for changes and rebuild " + "when new files appear, disappear or change.")) + parser.add_option("-v", "--version", action="store_true", dest="version", + help="show program's version number and exit") + + group = OptionGroup(parser, "Output Options") + group.add_option("--css", dest="css_dir", default='', metavar='DIR', + help="output directory for css files") + group.add_option("--img", dest="img_dir", default='', metavar='DIR', + help="output directory for img files") + group.add_option("--html", dest="html", action="store_true", + help="generate test html file using the sprite image and CSS.") + group.add_option("--no-css", dest="no_css", action="store_true", + help="don't genereate CSS files.") + group.add_option("--no-img", dest="no_img", action="store_true", + help="don't genereate IMG files.") + + parser.add_option_group(group) + + group = OptionGroup(parser, "Advanced Options") + group.add_option("-a", "--algorithm", dest="algorithm", metavar='NAME', + help=("allocation algorithm: square, vertical, horizontal, " + "vertical-right, horizontal-bottom, diagonal. " + "(default: square)")) + group.add_option("--ordering", dest="ordering", metavar='NAME', + help=("ordering criteria: maxside, width, height or " + "area (default: maxside)")) + group.add_option("--margin", dest="margin", type=int, + help="force this margin in all images") + group.add_option("--namespace", dest="namespace", + help="namespace for all css classes (default: sprite)") + group.add_option("--sprite-namespace", dest="sprite_namespace", + help="namespace for all sprites (default: sprite name)") + group.add_option("--png8", action="store_true", dest="png8", + help="the output image format will be png8 instead of png32") + group.add_option("--ignore-filename-paddings", action='store_true', + dest="ignore_filename_paddings", help="ignore filename paddings") + group.add_option("--debug", dest="debug", action='store_true', + help="don't catch unexpected errors and let glue fail hardly") + parser.add_option_group(group) + + group = OptionGroup(parser, "Output CSS Template Options") + group.add_option("--separator", dest="separator", metavar='SEPARATOR', + help=("Customize the separator used to join CSS class " + "names. If you want to use camelCase use " + "'camelcase' as separator.")) + group.add_option("--global-template", dest="global_template", + metavar='TEMPLATE', + help=("Customize the global section of the output CSS." + "This section will be added only once for each " + "sprite.")) + group.add_option("--each-template", dest="each_template", + metavar='TEMPLATE', + help=("Customize each image output CSS." + "This section will be added once for each " + "image inside the sprite.")) + group.add_option("--ratio-template", dest="ratio_template", + metavar='TEMPLATE', + help=("Customize ratios CSS media queries template." + "This section will be added once for each " + "ratio different than 1.")) + parser.add_option_group(group) + + group = OptionGroup(parser, "Optipng Options", + "You need to install optipng before using these options") + group.add_option("--optipng", dest="optipng", action='store_true', + help="postprocess images using optipng") + group.add_option("--optipngpath", dest="optipngpath", + help="path to optipng (default: optipng)", metavar='PATH') + parser.add_option_group(group) + + group = OptionGroup(parser, "ImageMagick Options", + "You need to install ImageMagick before using these options") + group.add_option("--imagemagick", dest="imagemagick", action='store_true', + help="Use ImageMagick to scale down retina sprites instead of Pillow.") + group.add_option("--imagemagickpath", dest="imagemagickpath", + help="path to imagemagick (default: convert)", metavar='PATH') + parser.add_option_group(group) + + group = OptionGroup(parser, "Browser Cache Invalidation Options") + group.add_option("--cachebuster", dest="cachebuster", action='store_true', + help=("use the sprite's sha1 first 6 characters as a " + "queryarg everytime that file is referred from the css")) + group.add_option("--cachebuster-filename", dest="cachebuster_filename", + action='store_true', + help=("append the sprite's sha first 6 characters " + "to the otput filename")) + parser.add_option_group(group) + + (options, args) = parser.parse_args() + + if options.version: + sys.stdout.write("%s\n" % __version__) + sys.exit(0) + + if options.cachebuster and options.cachebuster_filename: + parser.error("You can't use --cachebuster and " + "--cachebuster-filename at the same time.") + + if not len(args): + parser.error("You must provide the folder containing the sprites.") + + if len(args) == 1 and not (options.css_dir and options.img_dir): + parser.error(("You must choose the output folder using either the " + "output argument or both --img and --css.")) + + if len(args) == 2 and (options.css_dir or options.img_dir): + parser.error(("You must choose between using an unique output dir, or " + "using --css and --img.")) + + source = os.path.abspath(args[0]) + output = os.path.abspath(args[1]) if len(args) == 2 else None + + if not os.path.isdir(source): + parser.error("Directory not found: '%s'" % source) + + if options.project: + manager_cls = ProjectSpriteManager + else: + manager_cls = SimpleSpriteManager + + # Get configuration from file + config = get_file_config(source) + + # Convert options to dict + options = options.__dict__ + + config = ConfigManager(config, priority=options, defaults=DEFAULT_SETTINGS) + + manager = manager_cls(path=source, output=output, config=config) + + if config.optipng and not command_exists(config.optipngpath): + parser.error("'optipng' seems to be unavailable. You need to " + "install it before using --optipng, or " + "provide a path using --optipngpath.") + + if manager.config.watch: + WatchManager(path=source, action=manager.process).run() + sys.exit(0) + + try: + manager.process() + except MultipleImagesWithSameNameError, e: + sys.stderr.write("Error: Some images will have the same class name:\n") + for image in e.args[0]: + rel_path = os.path.relpath(image.path) + sys.stderr.write('\t%s => .%s\n' % (rel_path, image.class_name)) + sys.exit(e.error_code) + except SourceImagesNotFoundError, e: + sys.stderr.write("Error: No images found in %s.\n" % e.args[0]) + sys.exit(e.error_code) + except NoSpritesFoldersFoundError, e: + sys.stderr.write("Error: No sprites folders found in %s.\n" % e.args[0]) + sys.exit(e.error_code) + except InvalidImageOrderingError, e: + sys.stderr.write("Error: Invalid image ordering %s.\n" % e.args[0]) + sys.exit(e.error_code) + except InvalidImageAlgorithmError, e: + sys.stderr.write("Error: Invalid image algorithm %s.\n" % e.args[0]) + sys.exit(e.error_code) + except PILUnavailableError, e: + sys.stderr.write(("Error: PIL %s decoder is unavailable" + "Please read the documentation and " + "install it before spriting this kind of " + "images.\n") % e.args[0]) + sys.exit(e.error_code) + except Exception: + if config.debug: + import platform + sys.stderr.write("Glue version: %s\n" % __version__) + sys.stderr.write("PIL version: %s\n" % PImage.VERSION) + sys.stderr.write("Platform: %s\n" % platform.platform()) + sys.stderr.write("Config: %s\n" % config.sources) + sys.stderr.write("Args: %s\n" % sys.argv) + sys.stderr.write("\n") + + sys.stderr.write("Error: Unknown Error.\n") + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/contrib/glue/hackpad_README.txt b/contrib/glue/hackpad_README.txt new file mode 100644 index 0000000..fa96c62 --- /dev/null +++ b/contrib/glue/hackpad_README.txt @@ -0,0 +1,6 @@ +Installation: +sudo python setup.py install + +Using the tool: +./glue.py ../../etherpad/src/static/img/icons/ -a horizontal --cachebuster --img=../../etherpad/src/static/img/ --css=../../etherpad/src/static/css/ +./glue.py ../../etherpad/src/static/img/icons-ace/ -a horizontal --margin=400 --cachebuster --img=../../etherpad/src/static/img/ --css=../../etherpad/src/static/css/ diff --git a/contrib/glue/setup.py b/contrib/glue/setup.py new file mode 100644 index 0000000..31ab113 --- /dev/null +++ b/contrib/glue/setup.py @@ -0,0 +1,39 @@ +try: + from setuptools import setup + kw = {'entry_points': + """[console_scripts]\nglue = glue:main\n""", + 'zip_safe': False} +except ImportError: + from distutils.core import setup + kw = {'scripts': ['glue.py']} + +setup( + name='glue', + version='0.3', + url='http://github.com/jorgebastida/glue', + license='BSD', + author='Jorge Bastida', + author_email='me@jorgebastida.com', + description='Glue is a simple command line tool to generate CSS sprites.', + long_description=('Glue is a simple command line tool to generate CSS ' + 'sprites using any kind of source images like ' + 'PNG, JPEG or GIF. Glue will generate a unique PNG ' + 'file containing every source image and a CSS file ' + 'including the necessary CSS classes to use the ' + 'sprite.'), + py_modules=['glue'], + platforms='any', + install_requires=[ + 'Pillow==1.7.8' + ], + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Utilities' + ], + **kw +) diff --git a/contrib/nginx.conf b/contrib/nginx.conf new file mode 100644 index 0000000..10f8540 --- /dev/null +++ b/contrib/nginx.conf @@ -0,0 +1,134 @@ +user www-data; +worker_processes 4; + +error_log /var/log/nginx/error.log; +pid /var/run/nginx.pid; + +events { + worker_connections 4096; + use epoll; +} + +http { + sendfile on; + proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=staticfilecache:180m max_size=500m; + + upstream frontends { + # Add main .com handling frontends here + ip_hash; + } + upstream pro_frontends { + # Add subdomain handling frondends here + ip_hash; + } + + map $host $pro_or_main { + default frontends; + ~\d+comet\.hackpad\.com frontends; + ~[a-zA-Z0-9]+\.hackpad\.com pro_frontends; + } + + map $host $pro_or_main_header { + default "Main"; + ~\d+comet\.hackpad\.com "Main"; + ~[a-zA-Z0-9]+\.hackpad\.com "Pro"; + } + + proxy_pass_header Server; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Scheme $scheme; + + log_format timed_combined '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent" ' + '$request_time $upstream_response_time $pipe'; + access_log /var/log/nginx/access.log timed_combined; + error_log /var/log/nginx/error.log; + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; + ssl_ciphers ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:RC4:HIGH:!aNULL:!MD5:!kEDH; + ssl_prefer_server_ciphers on; + ssl_certificate /home/ubuntu/hackpad_combined.crt; + ssl_certificate_key /home/ubuntu/hackpad.com.key; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 15m; + keepalive_timeout 140; + + server { + listen 80; + listen 443 ssl; + server_name www.hackpad.com; + rewrite ^(.*) https://hackpad.com$1 permanent; + } + + server { + listen 80; + server_name .hackpad.com; + rewrite ^(.*) https://$host$1 permanent; + } + + server { + listen 443 ssl default_server; + server_name .hackpad.com; + add_header Strict-Transport-Security "max-age=31557600; includeSubdomains;" ; + add_header X-Hackpad-Server-Id $pro_or_main_header; + + error_page 502 = /502.html; + location /502.html { + root /home/ubuntu/pad/etherpad/src/static; + } + + location /solr { + deny all; + } + + location /static/compressed { + proxy_pass http://$pro_or_main; + proxy_cache staticfilecache; + } + + location /ep/api/spaces-info { + proxy_pass http://pro_frontends; + } + location /ep/api/accounts-info-pro { + proxy_pass http://pro_frontends; + } + location /ep/api/accounts-info-main { + proxy_pass http://frontends; + } + + location /comet { + proxy_buffering off; + proxy_pass http://$pro_or_main; + } + + location = / { + if ($http_cookie ~* ES2|PUAS2|PUAS3) { + set $cookie_nocache 1; + add_header X-No-Cache ON; + } + if ($host ~* .hackpad\.com) { + set $cookie_nocache 1; + add_header X-No-Cache ON; + } + proxy_cache staticfilecache; + proxy_cache_valid 60s; + proxy_no_cache $cookie_nocache; + proxy_cache_bypass $cookie_nocache; + proxy_pass http://$pro_or_main; + } + + location / { + if ($http_user_agent ~ (Thunderbird) ) { + return 403; + } + if ($host ~* .*[0-9]+comet\.hackpad\.com) { + return 404; + } + + proxy_pass http://$pro_or_main; + } + } +} diff --git a/contrib/runit/log/run b/contrib/runit/log/run new file mode 100755 index 0000000..84fb1aa --- /dev/null +++ b/contrib/runit/log/run @@ -0,0 +1,6 @@ +#!/bin/bash + +export LC_ALL=en_US.UTF-8 +export LANG=en_US.UTF-8 +export LANGUAGE=en_US.UTF-8 +exec svlogd /var/log/hackpad diff --git a/contrib/runit/run b/contrib/runit/run new file mode 100755 index 0000000..5c42cd9 --- /dev/null +++ b/contrib/runit/run @@ -0,0 +1,8 @@ +#!/bin/bash + +ulimit -n 16000 +cd /home/ubuntu/pad +export LC_ALL=en_US.UTF-8 +export LANG=en_US.UTF-8 +export LANGUAGE=en_US.UTF-8 +exec chpst bin/run.sh 9G 2>&1 diff --git a/contrib/runit/setup.sh b/contrib/runit/setup.sh new file mode 100755 index 0000000..d77bf36 --- /dev/null +++ b/contrib/runit/setup.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +apt-get install runit +cp -R /home/ubuntu/pad/contrib/runit /etc/sv/hackpad +ln -s /etc/sv/hackpad /etc/service/hackpad + +sv down hackpad +echo "sv up hackpad" \ No newline at end of file diff --git a/contrib/scripts/setup-appserver.sh b/contrib/scripts/setup-appserver.sh new file mode 100644 index 0000000..fef3f72 --- /dev/null +++ b/contrib/scripts/setup-appserver.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +### Extracted from Setting up a new EC2 Server + +## Update Ubuntu +apt-get update +apt-get dist-upgrade -y + +## Replace OpenJDK with Oracle Java 7 +add-apt-repository ppa:webupd8team/java -y +apt-get update +apt-get install oracle-java7-installer -y + +## Install NTP (time syncronization) +apt-get install ntp -y + +## Install Runit (sv command) +apt-get install runit -y + +## Tune sysctl.conf +echo "# options added by boot RightScript: +net.ipv4.tcp_tw_reuse = 1 +net.ipv4.ip_local_port_range = 1024 65023 +net.ipv4.tcp_max_syn_backlog = 10240 +net.ipv4.tcp_max_tw_buckets = 400000 +net.ipv4.tcp_max_orphans = 60000 +net.ipv4.tcp_synack_retries = 3 +net.core.somaxconn = 10000 +" >> /etc/sysctl.conf + +sysctl -p + +## Setup Git +apt-get install git -y +git init pad +(cd pad && git config receive.denyCurrentBranch ignore) +(cd pad/.git/hooks && echo -e '#!/bin/sh\ncd ..\nenv -i git reset --hard' > post-receive && chmod +x post-receive) +chown -R ubuntu.ubuntu pad + +ln -s /var/log/hackpad ~/logs +ln -s pad/hackpad/data/logs/backend/jvm-gc.log ~/jvm-gc.log + +echo Please restart and run contrib/runit/setup.sh + diff --git a/contrib/scripts/setup-mysql-db.sh b/contrib/scripts/setup-mysql-db.sh new file mode 100755 index 0000000..fa3b3e7 --- /dev/null +++ b/contrib/scripts/setup-mysql-db.sh @@ -0,0 +1,25 @@ +#!/bin/bash -e + +# Copyright 2009 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS-IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +db="hackpad" +mysql="mysql" +echo "Creating database ${db}..." +echo "create database ${db};" | ${mysql} -u root -p + +echo "Granting priviliges..." +echo "grant all privileges on ${db}.* to 'hackpad'@'localhost' identified by 'password';" | ${mysql} -u root -p + +echo "Success" diff --git a/contrib/testing/.gitignore b/contrib/testing/.gitignore new file mode 100644 index 0000000..23be601 --- /dev/null +++ b/contrib/testing/.gitignore @@ -0,0 +1,2 @@ +screenshots/diffs/ +screenshots/results/ diff --git a/contrib/testing/README.txt b/contrib/testing/README.txt new file mode 100644 index 0000000..16d50c0 --- /dev/null +++ b/contrib/testing/README.txt @@ -0,0 +1,41 @@ +Installation +-------------- + +Selenium: +sudo pip install -U selenium + +ImageMagick: +http://www.imagemagick.org/script/binary-releases.php + +PIL: +https://developers.google.com/appengine/docs/python/images/installingPIL + +Wand: +sudo pip install Wand + +(mac users might need to export MAGICK_HOME=/opt/local) + + + +Pre-requistes on website +-------------- +jQuery (for sendkeys library support) + + + +Setup +-------------- +Edit global.cfg + - required: command_executor + - optional: cookie_* values + + + +Running +-------------- +./run.py + + +Comparing/Saving +-------------- +./compare.py diff --git a/contrib/testing/compare.py b/contrib/testing/compare.py new file mode 100755 index 0000000..84ee406 --- /dev/null +++ b/contrib/testing/compare.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python + +import ConfigParser +import os +import shutil +import sys +import wand.api +import ctypes +import argparse + +# Set constants. +current_dir = os.path.dirname(os.path.realpath(__file__)) +screenshots_dir = os.path.join(current_dir, 'screenshots') +screenshots_reference_dir = os.path.join(screenshots_dir, 'reference') +screenshots_results_dir = os.path.join(screenshots_dir, 'results') +screenshots_diffs_dir = os.path.join(screenshots_dir, 'diffs') +global_cfg_path = os.path.join(current_dir, 'global.cfg') + +# Clear previous diffs. +if os.path.exists(screenshots_diffs_dir): + shutil.rmtree(screenshots_diffs_dir) + +# Read global config. +global_config = ConfigParser.ConfigParser() +global_config.read(global_cfg_path) +image_diff_percentage = float(global_config.get('general', + 'image_diff_percentage')) + +# Colors. +blue = '\033[94m' +green = '\033[92m' +orange = '\033[33m' +red = '\033[91m' +end_color = '\033[0m' + +parser = argparse.ArgumentParser(description='Compare screenshot results!') +parser.add_argument('--nogui', action='store_true', default=False, help='show results as pass/fail in stdout') +parser.add_argument('--nocolors', action='store_true', default=False, + help='no color formatting of stdout') + +args = parser.parse_args() + +skip_gui = args.nogui + +if args.nocolors: + blue = green = orange = red = end_color = '' + +# Setup ImageMagick ctypes interface. +wand_lib = wand.api.library +wand_lib.MagickReadImage.argtypes = [ctypes.c_void_p, ctypes.c_char_p] +wand_lib.MagickCompareImages.restype = ctypes.c_void_p +wand_lib.MagickCompareImages.argtypes = [ctypes.c_void_p, ctypes.c_void_p, + ctypes.c_int, ctypes.c_void_p] +wand_lib.MagickWriteImage.argtypes = [ctypes.c_void_p, ctypes.c_char_p] +wand_lib.DestroyMagickWand.argtypes = [ctypes.c_void_p] + +wand_lib.MagickWandGenesis() + +for f in os.walk(screenshots_results_dir): + for filename in f[2]: + if os.path.splitext(filename)[1] != '.png': + continue + + result_path = os.path.join(f[0], filename) + result_parent_dir = os.path.basename(os.path.dirname(result_path)) + reference_file_dir = os.path.join(screenshots_reference_dir, + result_parent_dir) + reference_path = os.path.join(reference_file_dir, filename) + diff_file_dir = os.path.join(screenshots_diffs_dir, result_parent_dir) + diff_path = os.path.join(diff_file_dir, filename) + if not os.path.exists(reference_file_dir): + os.makedirs(reference_file_dir) + + test_result = 'PASSED' + + if not os.path.exists(reference_path): + print blue + os.path.basename(os.path.dirname(reference_path)) + ': ' + \ + orange + os.path.basename(reference_path) + end_color + # If file doesn't exist, it's the reference file automatically. + shutil.copyfile(result_path, reference_path) + else: + # Read images. + reference = wand_lib.NewMagickWand() + wand_lib.MagickReadImage(reference, reference_path) + result = wand_lib.NewMagickWand() + wand_lib.MagickReadImage(result, result_path) + + # Compare. + distortion = ctypes.c_double() + # 5 == Peak Absolute Error: http://www.imagemagick.org/api/MagickCore/compare_8h.html + comparison = wand_lib.MagickCompareImages(reference, result, 5, + ctypes.byref(distortion)) + + if not os.path.exists(diff_file_dir): + os.makedirs(diff_file_dir) + + if comparison: + # Write out comparison file if needed. + if distortion.value > image_diff_percentage: + wand_lib.MagickWriteImage(comparison, diff_path) + test_result = 'FAILED' + else: + test_result = 'FAILED (SIZE MISMATCH)' + print >> sys.stderr, red + \ + 'Error! Non-matching image size to reference: ' + \ + result_path + end_color + shutil.copyfile(result_path, diff_path) + + # Clean up. + wand_lib.DestroyMagickWand(reference) + wand_lib.DestroyMagickWand(result) + if comparison: + wand_lib.DestroyMagickWand(comparison) + + show_value = test_result != 'FAILED (SIZE MISMATCH)' + + print "{blue}{config}: {orange}{test_image}{end_color}: {distortion} {pass_or_fail}".format( + blue=blue, + orange=orange, + config=os.path.basename(os.path.dirname(reference_path)), + test_image=os.path.basename(reference_path), + end_color=end_color, + distortion=str(distortion.value) if show_value else "", + pass_or_fail=(green if test_result == 'PASSED' else red) + test_result + end_color) + +wand_lib.MagickWandTerminus() + +if not skip_gui: + os.system("./gui.py") diff --git a/contrib/testing/global.cfg b/contrib/testing/global.cfg new file mode 100644 index 0000000..2a87426 --- /dev/null +++ b/contrib/testing/global.cfg @@ -0,0 +1,17 @@ +[general] +project = Hackpad +screen_resolution = 1024x768 +browser_size = 1024x768 +image_diff_percentage = 0.01 +async = false +parallel_threads = 4 +command_executor = +browsers = Windows-7-chrome-27 + Windows-7-firefox-23 + Windows-7-internet explorer-10 + OS X-10.8-iPad-6 + OS X-10.8-iPhone-6 +cookie_domain = +cookie_login_domain = +cookie_login_name = +cookie_login_value = diff --git a/contrib/testing/gui.py b/contrib/testing/gui.py new file mode 100755 index 0000000..b7bca13 --- /dev/null +++ b/contrib/testing/gui.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from Tkinter import * +import Image +import ImageTk +import os +import shutil + +# Set constants. +current_dir = os.path.dirname(os.path.realpath(__file__)) +screenshots_dir = os.path.join(current_dir, 'screenshots') +screenshots_reference_dir = os.path.join(screenshots_dir, 'reference') +screenshots_results_dir = os.path.join(screenshots_dir, 'results') +screenshots_diffs_dir = os.path.join(screenshots_dir, 'diffs') +global_cfg_path = os.path.join(current_dir, 'global.cfg') + + +class Application: + def __init__(self, master): + self.width = 1024 + self.height = 768 + self.index = 0 + self.text1 = None + self.diff_images = [] + self.frame = None + self.master = master + self.image_type = 1 # 0 == ref, 1 == result, 2 == diffs + + for f in os.walk(screenshots_diffs_dir): + for filename in f[2]: + if os.path.splitext(filename)[1] != '.png': + continue + self.diff_images.append(os.path.join(f[0], filename)) + + self.frame = Frame(master) + self.frame.pack(side='top', expand=1, fill='x') + self.master.bind('', self.rotate_image_up) + self.master.bind('', self.rotate_image_down) + self.master.bind('', self.prev_image) + self.master.bind('', self.next_image) + + if len(self.diff_images): + self.createWidgets() + self.draw_image() + else: + print 'All good!' + self.master.destroy() + + def createWidgets(self): + self.prev_btn = Button(self.frame, text="← prev", command=self.prev_image) + self.prev_btn.grid(row=0) + self.next_btn = Button(self.frame, text="next →", command=self.next_image) + self.next_btn.grid(row=0, column=1) + self.rotate_btn_up = Button(self.frame, text="↑ cycle up", + command=self.rotate_image_up) + self.rotate_btn_up.grid(row=0, column=2, padx=(30, 0)) + self.rotate_btn_down = Button(self.frame, text="cycle down ↓", + command=self.rotate_image_down) + self.rotate_btn_down.grid(row=0, column=3) + self.ref = Button(self.frame, text="update ref.", command=self.update_ref) + self.ref.grid(row=0, column=4, padx=30) + self.type_lbl = Label(self.frame, text='') + self.type_lbl.grid(row=0, column=5, padx=30) + self.update_button_states() + + def draw_image(self): + reference_path, result_path, diff_path = self.get_paths() + file_path = diff_path + if self.image_type == 0: + file_path = reference_path + elif self.image_type == 1: + file_path = result_path + + browser_name = os.path.basename(os.path.dirname(file_path)) + test_name = os.path.splitext(os.path.basename(file_path))[0] + self.master.title(browser_name + ': ' + test_name) + + try: + image = Image.open(file_path) + except: + return + self.tkimage = ImageTk.PhotoImage(image) + if self.text1: + self.text1.pack_forget() + self.scroll.pack_forget() + self.text1 = Text(root, width=1000, height=800) + self.scroll = Scrollbar(self.master, command=self.text1.yview) + self.tkimage = ImageTk.PhotoImage(image) + self.text1.insert(END,'\n') + self.text1.image_create(END, image=self.tkimage) + self.scroll.pack(side=RIGHT, fill=Y) + self.text1.pack(side=LEFT) + + def update_button_states(self): + reference_path, result_path, diff_path = self.get_paths() + + self.prev_btn.config(state = NORMAL + if self.index > 0 else DISABLED) + self.next_btn.config(state = NORMAL + if self.index < len(self.diff_images) - 1 else DISABLED) + self.ref.config(state = NORMAL + if os.path.exists(diff_path) else DISABLED) + + self.ref['text'] = 'Update ref.' if os.path.exists(diff_path) else 'updated' + if self.image_type == 0: + self.type_lbl['text'] = 'reference' + elif self.image_type == 1: + self.type_lbl['text'] = 'result' + elif self.image_type == 2: + self.type_lbl['text'] = 'diff' + + def prev_image(self, event=None): + self.index = max(0, self.index - 1) + self.draw_image() + self.update_button_states() + + def next_image(self, event=None): + self.index = min(len(self.diff_images) - 1, self.index + 1) + self.draw_image() + self.update_button_states() + + def rotate_image_up(self, event=None): + self.image_type = (self.image_type - 1) % 3 + self.draw_image() + self.update_button_states() + + def rotate_image_down(self, event=None): + self.image_type = (self.image_type + 1) % 3 + self.draw_image() + self.update_button_states() + + def get_paths(self): + diff_path = self.diff_images[self.index] + filename = os.path.basename(diff_path) + diff_parent_dir = os.path.basename(os.path.dirname(diff_path)) + reference_file_dir = os.path.join(screenshots_reference_dir, + diff_parent_dir) + reference_path = os.path.join(reference_file_dir, filename) + result_file_dir = os.path.join(screenshots_results_dir, diff_parent_dir) + result_path = os.path.join(result_file_dir, filename) + + return reference_path, result_path, diff_path + + def update_ref(self): + reference_path, result_path, diff_path = self.get_paths() + shutil.copyfile(result_path, reference_path) + os.remove(diff_path) + self.update_button_states() + +root = Tk() +app = Application(root) +root.mainloop() diff --git a/contrib/testing/jenkins/run.sh b/contrib/testing/jenkins/run.sh new file mode 100755 index 0000000..99d5660 --- /dev/null +++ b/contrib/testing/jenkins/run.sh @@ -0,0 +1,5 @@ +#!/bin/bash +. /etc/default/jenkins +export JENKINS_HOME=$JENKINS_HOME +exec $JAVA $JAVA_ARGS -jar $JENKINS_WAR $JENKINS_ARGS + diff --git a/contrib/testing/jenkins/runit/log/run b/contrib/testing/jenkins/runit/log/run new file mode 100755 index 0000000..1e7a5a1 --- /dev/null +++ b/contrib/testing/jenkins/runit/log/run @@ -0,0 +1,6 @@ +#!/bin/bash + +export LC_ALL=en_US.UTF-8 +export LANG=en_US.UTF-8 +export LANGUAGE=en_US.UTF-8 +exec svlogd /var/log/jenkins diff --git a/contrib/testing/jenkins/runit/run b/contrib/testing/jenkins/runit/run new file mode 100755 index 0000000..b01d1ac --- /dev/null +++ b/contrib/testing/jenkins/runit/run @@ -0,0 +1,8 @@ +#!/bin/bash +exec 2>&1 +ulimit -n 16000 +cd /home/ubuntu/pad +export LC_ALL=en_US.UTF-8 +export LANG=en_US.UTF-8 +export LANGUAGE=en_US.UTF-8 +exec chpst -ujenkins contrib/testing/jenkins/run.sh diff --git a/contrib/testing/jenkins/runit/setup.sh b/contrib/testing/jenkins/runit/setup.sh new file mode 100755 index 0000000..f518d05 --- /dev/null +++ b/contrib/testing/jenkins/runit/setup.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +apt-get install runit +cp -R /home/ubuntu/pad/contrib/testing/jenkins/runit /etc/sv/jenkins +ln -s /etc/sv/jenkins /etc/service/jenkins + +echo "sv up jenkins" diff --git a/contrib/testing/jenkins/screenshot_tests.sh b/contrib/testing/jenkins/screenshot_tests.sh new file mode 100755 index 0000000..0c13b25 --- /dev/null +++ b/contrib/testing/jenkins/screenshot_tests.sh @@ -0,0 +1,18 @@ +#! /bin/bash +HIPCHAT_ROOM="hackpad" +HIPCHAT_START_MESSAGE="Starting screenshot tests. (click here to stop me)" + +DESTINATION_BRANCH=master + +echo "Starting screenshot tests..." +cd ../Hackpad\ Unit\ Tests/contrib/testing/ +./run.py --nogui --nocolors + +# copy the diff files into the Hackpad Screenshot Tests workspace in order for the +# image gallery plugin to see the artifacts +cd ~/workspace/Hackpad\ Screenshot\ Tests/ +rm -rf broken/*.png +# Check if files exist since the copy error would cause the build script to fail (even though no diffs means PASS) +if ls ../Hackpad\ Unit\ Tests/contrib/testing/screenshots/diffs/*/*.png > /dev/null 2>&1; then + cp ../Hackpad\ Unit\ Tests/contrib/testing/screenshots/diffs/*/*.png broken/ +fi diff --git a/contrib/testing/jenkins/screenshot_tests_done.sh b/contrib/testing/jenkins/screenshot_tests_done.sh new file mode 100755 index 0000000..bc923cd --- /dev/null +++ b/contrib/testing/jenkins/screenshot_tests_done.sh @@ -0,0 +1,4 @@ +#! /bin/bash +HIPCHAT_ROOM="hackpad" +HIPCHAT_MESSAGE="All unit tests are passing! See diff screenshots or a list view." +curl --data-urlencode "room_id=${HIPCHAT_ROOM}" -d "from=Jenkins&color=green" --data-urlencode "message=${HIPCHAT_MESSAGE}" https://api.hipchat.com/v1/rooms/message?auth_token=$HIPCHAT_API_KEY diff --git a/contrib/testing/jenkins/screenshot_tests_on_fail.sh b/contrib/testing/jenkins/screenshot_tests_on_fail.sh new file mode 100755 index 0000000..bbdc281 --- /dev/null +++ b/contrib/testing/jenkins/screenshot_tests_on_fail.sh @@ -0,0 +1,5 @@ +#! /bin/bash +HIPCHAT_ROOM="hackpad" +HIPCHAT_FAIL_MESSAGE="All unit tests are passing! However, screenshots are a different story: diffs or list view. " +curl --data-urlencode "room_id=${HIPCHAT_ROOM}" -d "from=Jenkins&color=red" --data-urlencode "message=${HIPCHAT_FAIL_MESSAGE}" https://api.hipchat.com/v1/rooms/message?auth_token=$HIPCHAT_API_KEY + diff --git a/contrib/testing/jenkins/screenshot_tests_on_success.sh b/contrib/testing/jenkins/screenshot_tests_on_success.sh new file mode 100755 index 0000000..e527948 --- /dev/null +++ b/contrib/testing/jenkins/screenshot_tests_on_success.sh @@ -0,0 +1,4 @@ +#! /bin/bash +HIPCHAT_ROOM="hackpad" +HIPCHAT_SUCCESS_MESSAGE="All unit and screenshot tests are passing! Awesomesauce." +curl --data-urlencode "room_id=${HIPCHAT_ROOM}" -d "from=Jenkins&color=green" --data-urlencode "message=${HIPCHAT_SUCCESS_MESSAGE}" https://api.hipchat.com/v1/rooms/message?auth_token=$HIPCHAT_API_KEY diff --git a/contrib/testing/jenkins/unit_tests.sh b/contrib/testing/jenkins/unit_tests.sh new file mode 100755 index 0000000..1537665 --- /dev/null +++ b/contrib/testing/jenkins/unit_tests.sh @@ -0,0 +1,19 @@ +#! /bin/bash +WAIT_TIME=30 +HIPCHAT_ROOM="hackpad" +HIPCHAT_START_MESSAGE="I'm taking over stage to run unit tests in ${WAIT_TIME} seconds. (click here to stop me)" + +DESTINATION_BRANCH=master + +echo "Notifying hipchat of build start" +curl --data-urlencode "room_id=${HIPCHAT_ROOM}" -d "from=Jenkins" --data-urlencode "message=${HIPCHAT_START_MESSAGE}" https://api.hipchat.com/v1/rooms/message?auth_token=$HIPCHAT_API_KEY + +echo "Waiting $WAIT_TIME seconds to start" +sleep $WAIT_TIME + +echo "Pushing to ${GIT_COMMIT} to stage" +git push stage $GIT_COMMIT:$DESTINATION_BRANCH -f +ssh ubuntu@stage.hackpad.com "cd /home/ubuntu/pad && git checkout ${DESTINATION_BRANCH}" + +echo "Starting unit tests on stage..." +curl -k -b ~/cookies.txt https://stage.hackpad.com/ep/unit-tests/run \ No newline at end of file diff --git a/contrib/testing/jenkins/unit_tests_on_fail.sh b/contrib/testing/jenkins/unit_tests_on_fail.sh new file mode 100755 index 0000000..4e9787f --- /dev/null +++ b/contrib/testing/jenkins/unit_tests_on_fail.sh @@ -0,0 +1,4 @@ +#! /bin/bash +HIPCHAT_ROOM="hackpad" +HIPCHAT_FAIL_MESSAGE="Aww snap, a unit test is failing! Have a look" +curl --data-urlencode "room_id=${HIPCHAT_ROOM}" -d "from=Jenkins&color=red" --data-urlencode "message=${HIPCHAT_FAIL_MESSAGE}" https://api.hipchat.com/v1/rooms/message?auth_token=$HIPCHAT_API_KEY diff --git a/contrib/testing/jenkins/unit_tests_on_success.sh b/contrib/testing/jenkins/unit_tests_on_success.sh new file mode 100755 index 0000000..c1f9891 --- /dev/null +++ b/contrib/testing/jenkins/unit_tests_on_success.sh @@ -0,0 +1,5 @@ +#! /bin/bash +HIPCHAT_ROOM="hackpad" +HIPCHAT_SUCCESS_MESSAGE="All unit tests are passing!" +# do nothing for now, let the screenshot job handle the hipchat messages +#curl --data-urlencode "room_id=${HIPCHAT_ROOM}" -d "from=Jenkins&color=green" --data-urlencode "message=${HIPCHAT_SUCCESS_MESSAGE}" https://api.hipchat.com/v1/rooms/message?auth_token=$HIPCHAT_API_KEY diff --git a/contrib/testing/lib/bililiteRange.js b/contrib/testing/lib/bililiteRange.js new file mode 100644 index 0000000..0a95e3e --- /dev/null +++ b/contrib/testing/lib/bililiteRange.js @@ -0,0 +1,426 @@ +// Cross-broswer implementation of text ranges and selections +// documentation: http://bililite.com/blog/2011/01/17/cross-browser-text-ranges-and-selections/ +// Version: 1.6 +// Copyright (c) 2010 Daniel Wachsstock +// MIT license: +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: + +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + +(function(){ + +bililiteRange = function(el, debug){ + var ret; + if (debug){ + ret = new NothingRange(); // Easier to force it to use the no-selection type than to try to find an old browser + }else if (document.selection){ + // Internet Explorer + ret = new IERange(); + }else if (window.getSelection && el.setSelectionRange){ + // Standards. Element is an input or textarea + ret = new InputRange(); + }else if (window.getSelection){ + // Standards, with any other kind of element + ret = new W3CRange() + }else{ + // doesn't support selection + ret = new NothingRange(); + } + ret._el = el; + // determine parent document, as implemented by John McLear + ret._doc = el.ownerDocument; + ret._win = 'defaultView' in ret._doc ? ret._doc.defaultView : ret._doc.parentWindow; + ret._textProp = textProp(el); + ret._bounds = [0, ret.length()]; + return ret; +} + +function textProp(el){ + // returns the property that contains the text of the element + // note that for elements the text attribute represents the obsolete text color, not the textContent. + // we document that these routines do not work for elements so that should not be relevant + if (typeof el.value != 'undefined') return 'value'; + if (typeof el.text != 'undefined') return 'text'; + if (typeof el.textContent != 'undefined') return 'textContent'; + return 'innerText'; +} + +// base class +function Range(){} +Range.prototype = { + length: function() { + return this._el[this._textProp].replace(/\r/g, '').length; // need to correct for IE's CrLf weirdness + }, + bounds: function(s){ + if (s === 'all'){ + this._bounds = [0, this.length()]; + }else if (s === 'start'){ + this._bounds = [0, 0]; + }else if (s === 'end'){ + this._bounds = [this.length(), this.length()]; + }else if (s === 'selection'){ + this.bounds ('all'); // first select the whole thing for constraining + this._bounds = this._nativeSelection(); + }else if (s){ + this._bounds = s; // don't do error checking now; things may change at a moment's notice + }else{ + var b = [ + Math.max(0, Math.min (this.length(), this._bounds[0])), + Math.max(0, Math.min (this.length(), this._bounds[1])) + ]; + b[1] = Math.max(b[0], b[1]); + return b; // need to constrain it to fit + } + return this; // allow for chaining + }, + select: function(){ + this._nativeSelect(this._nativeRange(this.bounds())); + return this; // allow for chaining + }, + text: function(text, select){ + if (arguments.length){ + this._nativeSetText(text, this._nativeRange(this.bounds())); + try { // signal the text change (IE < 9 doesn't support this, so we live with it) + this._el.dispatchEvent(new CustomEvent('input', {detail: {text: text, bounds: this.bounds()}})); + }catch(e){ /* ignore */ } + if (select == 'start'){ + this.bounds ([this._bounds[0], this._bounds[0]]); + }else if (select == 'end'){ + this.bounds ([this._bounds[0]+text.length, this._bounds[0]+text.length]); + }else if (select == 'all'){ + this.bounds ([this._bounds[0], this._bounds[0]+text.length]); + } + return this; // allow for chaining + }else{ + return this._nativeGetText(this._nativeRange(this.bounds())); + } + }, + insertEOL: function (){ + this._nativeEOL(); + this._bounds = [this._bounds[0]+1, this._bounds[0]+1]; // move past the EOL marker + return this; + }, + scrollIntoView: function(){ + this._nativeScrollIntoView(this._nativeRange(this.bounds())); + return this; + }, + wrap: function (n){ + this._nativeWrap(n, this._nativeRange(this.bounds())); + return this; + } +}; + +// allow extensions ala jQuery +bililiteRange.fn = Range.prototype; // to allow monkey patching +bililiteRange.extend = function(fns){ + for (fn in fns) Range.prototype[fn] = fns[fn]; +}; + +function IERange(){} +IERange.prototype = new Range(); +IERange.prototype._nativeRange = function (bounds){ + var rng; + if (this._el.tagName == 'INPUT'){ + // IE 8 is very inconsistent; textareas have createTextRange but it doesn't work + rng = this._el.createTextRange(); + }else{ + rng = this._doc.body.createTextRange (); + rng.moveToElementText(this._el); + } + if (bounds){ + if (bounds[1] < 0) bounds[1] = 0; // IE tends to run elements out of bounds + if (bounds[0] > this.length()) bounds[0] = this.length(); + if (bounds[1] < rng.text.replace(/\r/g, '').length){ // correct for IE's CrLf wierdness + // block-display elements have an invisible, uncounted end of element marker, so we move an extra one and use the current length of the range + rng.moveEnd ('character', -1); + rng.moveEnd ('character', bounds[1]-rng.text.replace(/\r/g, '').length); + } + if (bounds[0] > 0) rng.moveStart('character', bounds[0]); + } + return rng; +}; +IERange.prototype._nativeSelect = function (rng){ + rng.select(); +}; +IERange.prototype._nativeSelection = function (){ + // returns [start, end] for the selection constrained to be in element + var rng = this._nativeRange(); // range of the element to constrain to + var len = this.length(); + if (this._doc.selection.type != 'Text') return [len, len]; // append to the end + var sel = this._doc.selection.createRange(); + try{ + return [ + iestart(sel, rng), + ieend (sel, rng) + ]; + }catch (e){ + // IE gets upset sometimes about comparing text to input elements, but the selections cannot overlap, so make a best guess + return (sel.parentElement().sourceIndex < this._el.sourceIndex) ? [0,0] : [len, len]; + } +}; +IERange.prototype._nativeGetText = function (rng){ + return rng.text.replace(/\r/g, ''); // correct for IE's CrLf weirdness +}; +IERange.prototype._nativeSetText = function (text, rng){ + rng.text = text; +}; +IERange.prototype._nativeEOL = function(){ + if (typeof this._el.value != 'undefined'){ + this.text('\n'); // for input and textarea, insert it straight + }else{ + this._nativeRange(this.bounds()).pasteHTML('
'); + } +}; +IERange.prototype._nativeScrollIntoView = function(rng){ + rng.scrollIntoView(); +} +IERange.prototype._nativeWrap = function(n, rng) { + // hacky to use string manipulation but I don't see another way to do it. + var div = document.createElement('div'); + div.appendChild(n); + // insert the existing range HTML after the first tag + var html = div.innerHTML.replace('><', '>'+rng.htmlText+'<'); + rng.pasteHTML(html); +}; + +// IE internals +function iestart(rng, constraint){ + // returns the position (in character) of the start of rng within constraint. If it's not in constraint, returns 0 if it's before, length if it's after + var len = constraint.text.replace(/\r/g, '').length; // correct for IE's CrLf wierdness + if (rng.compareEndPoints ('StartToStart', constraint) <= 0) return 0; // at or before the beginning + if (rng.compareEndPoints ('StartToEnd', constraint) >= 0) return len; + for (var i = 0; rng.compareEndPoints ('StartToStart', constraint) > 0; ++i, rng.moveStart('character', -1)); + return i; +} +function ieend (rng, constraint){ + // returns the position (in character) of the end of rng within constraint. If it's not in constraint, returns 0 if it's before, length if it's after + var len = constraint.text.replace(/\r/g, '').length; // correct for IE's CrLf wierdness + if (rng.compareEndPoints ('EndToEnd', constraint) >= 0) return len; // at or after the end + if (rng.compareEndPoints ('EndToStart', constraint) <= 0) return 0; + for (var i = 0; rng.compareEndPoints ('EndToStart', constraint) > 0; ++i, rng.moveEnd('character', -1)); + return i; +} + +// an input element in a standards document. "Native Range" is just the bounds array +function InputRange(){} +InputRange.prototype = new Range(); +InputRange.prototype._nativeRange = function(bounds) { + return bounds || [0, this.length()]; +}; +InputRange.prototype._nativeSelect = function (rng){ + this._el.setSelectionRange(rng[0], rng[1]); +}; +InputRange.prototype._nativeSelection = function(){ + return [this._el.selectionStart, this._el.selectionEnd]; +}; +InputRange.prototype._nativeGetText = function(rng){ + return this._el.value.substring(rng[0], rng[1]); +}; +InputRange.prototype._nativeSetText = function(text, rng){ + var val = this._el.value; + this._el.value = val.substring(0, rng[0]) + text + val.substring(rng[1]); +}; +InputRange.prototype._nativeEOL = function(){ + this.text('\n'); +}; +InputRange.prototype._nativeScrollIntoView = function(rng){ + // I can't remember where I found this clever hack to find the location of text in a text area + var clone = this._el.cloneNode(true); + clone.style.visibility = 'hidden'; + clone.style.position = 'absolute'; + this._el.parentNode.insertBefore(clone, this._el); + clone.style.height = '1px'; + clone.value = this._el.value.slice(0, rng[0]); + var top = clone.scrollHeight; + // this gives the bottom of the text, so we have to subtract the height of a single line + clone.value = 'X'; + top -= 2*clone.scrollHeight; // show at least a line above + clone.parentNode.removeChild(clone); + // scroll into position if necessary + if (this._el.scrollTop > top || this._el.scrollTop+this._el.clientHeight < top){ + this._el.scrollTop = top; + } + // now scroll the element into view; get its position as in jQuery.offset + var rect = this._el.getBoundingClientRect(); + rect.top += this._win.pageYOffset - this._doc.documentElement.clientTop; + rect.left += this._win.pageXOffset - this._doc.documentElement.clientLeft; + // create an element to scroll to (can't just use the clone above, since scrollIntoView wants a visible element) + var div = this._doc.createElement('div'); + div.style.position = 'absolute'; + div.style.top = (rect.top+top-this._el.scrollTop)+'px'; // adjust for how far in the range is; it may not have scrolled all the way to the top + div.style.left = rect.left+'px'; + div.innerHTML = ' '; + this._doc.body.appendChild(div); + div.scrollIntoViewIfNeeded ? div.scrollIntoViewIfNeeded() : div.scrollIntoView(); + div.parentNode.removeChild(div); +} +InputRange.prototype._nativeWrap = function() {throw "Cannot wrap in a text element"}; + +function W3CRange(){} +W3CRange.prototype = new Range(); +W3CRange.prototype._nativeRange = function (bounds){ + var rng = this._doc.createRange(); + rng.selectNodeContents(this._el); + if (bounds){ + w3cmoveBoundary (rng, bounds[0], true, this._el); + rng.collapse (true); + w3cmoveBoundary (rng, bounds[1]-bounds[0], false, this._el); + } + return rng; +}; +W3CRange.prototype._nativeSelect = function (rng){ + this._win.getSelection().removeAllRanges(); + this._win.getSelection().addRange (rng); +}; +W3CRange.prototype._nativeSelection = function (){ + // returns [start, end] for the selection constrained to be in element + var rng = this._nativeRange(); // range of the element to constrain to + if (this._win.getSelection().rangeCount == 0) return [this.length(), this.length()]; // append to the end + var sel = this._win.getSelection().getRangeAt(0); + return [ + w3cstart(sel, rng), + w3cend (sel, rng) + ]; + } +W3CRange.prototype._nativeGetText = function (rng){ + return rng.toString(); +}; +W3CRange.prototype._nativeSetText = function (text, rng){ + rng.deleteContents(); + rng.insertNode (this._doc.createTextNode(text)); + this._el.normalize(); // merge the text with the surrounding text +}; +W3CRange.prototype._nativeEOL = function(){ + var rng = this._nativeRange(this.bounds()); + rng.deleteContents(); + var br = this._doc.createElement('br'); + br.setAttribute ('_moz_dirty', ''); // for Firefox + rng.insertNode (br); + rng.insertNode (this._doc.createTextNode('\n')); + rng.collapse (false); +}; +W3CRange.prototype._nativeScrollIntoView = function(rng){ + // can't scroll to a range; have to scroll to an element instead + var span = this._doc.createElement('span'); + rng.insertNode(span); + span.scrollIntoViewIfNeeded ? span.scrollIntoViewIfNeeded() : span.scrollIntoView(); + span.parentNode.removeChild(span); +} +W3CRange.prototype._nativeWrap = function(n, rng) { + rng.surroundContents(n); +}; + +// W3C internals +function nextnode (node, root){ + // in-order traversal + // we've already visited node, so get kids then siblings + if (node.firstChild) return node.firstChild; + if (node.nextSibling) return node.nextSibling; + if (node===root) return null; + while (node.parentNode){ + // get uncles + node = node.parentNode; + if (node == root) return null; + if (node.nextSibling) return node.nextSibling; + } + return null; +} +function w3cmoveBoundary (rng, n, bStart, el){ + // move the boundary (bStart == true ? start : end) n characters forward, up to the end of element el. Forward only! + // if the start is moved after the end, then an exception is raised + if (n <= 0) return; + var node = rng[bStart ? 'startContainer' : 'endContainer']; + if (node.nodeType == 3){ + // we may be starting somewhere into the text + n += rng[bStart ? 'startOffset' : 'endOffset']; + } + while (node){ + if (node.nodeType == 3){ + if (n <= node.nodeValue.length){ + rng[bStart ? 'setStart' : 'setEnd'](node, n); + // special case: if we end next to a
, include that node. + if (n == node.nodeValue.length){ + // skip past zero-length text nodes + for (var next = nextnode (node, el); next && next.nodeType==3 && next.nodeValue.length == 0; next = nextnode(next, el)){ + rng[bStart ? 'setStartAfter' : 'setEndAfter'](next); + } + if (next && next.nodeType == 1 && next.nodeName == "BR") rng[bStart ? 'setStartAfter' : 'setEndAfter'](next); + } + return; + }else{ + rng[bStart ? 'setStartAfter' : 'setEndAfter'](node); // skip past this one + n -= node.nodeValue.length; // and eat these characters + } + } + node = nextnode (node, el); + } +} +var START_TO_START = 0; // from the w3c definitions +var START_TO_END = 1; +var END_TO_END = 2; +var END_TO_START = 3; +// from the Mozilla documentation, for range.compareBoundaryPoints(how, sourceRange) +// -1, 0, or 1, indicating whether the corresponding boundary-point of range is respectively before, equal to, or after the corresponding boundary-point of sourceRange. + // * Range.END_TO_END compares the end boundary-point of sourceRange to the end boundary-point of range. + // * Range.END_TO_START compares the end boundary-point of sourceRange to the start boundary-point of range. + // * Range.START_TO_END compares the start boundary-point of sourceRange to the end boundary-point of range. + // * Range.START_TO_START compares the start boundary-point of sourceRange to the start boundary-point of range. +function w3cstart(rng, constraint){ + if (rng.compareBoundaryPoints (START_TO_START, constraint) <= 0) return 0; // at or before the beginning + if (rng.compareBoundaryPoints (END_TO_START, constraint) >= 0) return constraint.toString().length; + rng = rng.cloneRange(); // don't change the original + rng.setEnd (constraint.endContainer, constraint.endOffset); // they now end at the same place + return constraint.toString().length - rng.toString().length; +} +function w3cend (rng, constraint){ + if (rng.compareBoundaryPoints (END_TO_END, constraint) >= 0) return constraint.toString().length; // at or after the end + if (rng.compareBoundaryPoints (START_TO_END, constraint) <= 0) return 0; + rng = rng.cloneRange(); // don't change the original + rng.setStart (constraint.startContainer, constraint.startOffset); // they now start at the same place + return rng.toString().length; +} + +function NothingRange(){} +NothingRange.prototype = new Range(); +NothingRange.prototype._nativeRange = function(bounds) { + return bounds || [0,this.length()]; +}; +NothingRange.prototype._nativeSelect = function (rng){ // do nothing +}; +NothingRange.prototype._nativeSelection = function(){ + return [0,0]; +}; +NothingRange.prototype._nativeGetText = function (rng){ + return this._el[this._textProp].substring(rng[0], rng[1]); +}; +NothingRange.prototype._nativeSetText = function (text, rng){ + var val = this._el[this._textProp]; + this._el[this._textProp] = val.substring(0, rng[0]) + text + val.substring(rng[1]); +}; +NothingRange.prototype._nativeEOL = function(){ + this.text('\n'); +}; +NothingRange.prototype._nativeScrollIntoView = function(){ + this._el.scrollIntoView(); +}; +NothingRange.prototype._nativeWrap = function() {throw "Wrapping not implemented"}; + + +})(); \ No newline at end of file diff --git a/contrib/testing/lib/hackpad.js b/contrib/testing/lib/hackpad.js new file mode 100644 index 0000000..f21e6be --- /dev/null +++ b/contrib/testing/lib/hackpad.js @@ -0,0 +1,5 @@ +function typeAndSelect(keys) { + $('#editor').sendkeys(keys); + var rng = bililiteRange($('#editor')[0]); + rng.bounds([rng.length() - keys.length, rng.length()]).select() +} diff --git a/contrib/testing/lib/jquery.sendkeys.js b/contrib/testing/lib/jquery.sendkeys.js new file mode 100644 index 0000000..7d27e0e --- /dev/null +++ b/contrib/testing/lib/jquery.sendkeys.js @@ -0,0 +1,117 @@ +// insert characters in a textarea or text input field +// special characters are enclosed in {}; use {{} for the { character itself +// documentation: http://bililite.com/blog/2008/08/20/the-fnsendkeys-plugin/ +// Version: 2.2 +// Copyright (c) 2013 Daniel Wachsstock +// MIT license: +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: + +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + +(function($){ + +$.fn.sendkeys = function (x, opts){ + return this.each( function(){ + var localkeys = $.extend({}, opts, $(this).data('sendkeys')); // allow for element-specific key functions + // most elements to not keep track of their selection when they lose focus, so we have to do it for them + var rng = $.data (this, 'sendkeys.selection'); + if (!rng){ + rng = bililiteRange(this).bounds('selection'); + $.data(this, 'sendkeys.selection', rng); + $(this).bind('mouseup.sendkeys', function(){ + // we have to update the saved range. The routines here update the bounds with each press, but actual keypresses and mouseclicks do not + $.data(this, 'sendkeys.selection').bounds('selection'); + }).bind('keyup.sendkeys', function(evt){ + // restore the selection if we got here with a tab (a click should select what was clicked on) + if (evt.which == 9){ + // there's a flash of selection when we restore the focus, but I don't know how to avoid that. + $.data(this, 'sendkeys.selection').select(); + }else{ + $.data(this, 'sendkeys.selection').bounds('selection'); + } + }); + } + this.focus(); + if (typeof x === 'undefined') return; // no string, so we just set up the event handlers + $.data(this, 'sendkeys.originalText', rng.text()); + x.replace(/\n/g, '{enter}'). // turn line feeds into explicit break insertions + replace(/{[^}]*}|[^{]+/g, function(s){ + (localkeys[s] || $.fn.sendkeys.defaults[s] || $.fn.sendkeys.defaults.simplechar)(rng, s); + rng.select(); + }); + $(this).trigger({type: 'sendkeys', which: x}); + }); +}; // sendkeys + + +// add the functions publicly so they can be overridden +$.fn.sendkeys.defaults = { + simplechar: function (rng, s){ + // deal with unknown {key}s + if (/^{.*}$/.test(s)) s = s.slice(1,-1); + rng.text(s, 'end'); + for (var i =0; i < s.length; ++i){ + var x = s.charCodeAt(i); + // a bit of cheating: rng._el is the element associated with rng. + $(rng._el).trigger({type: 'keypress', keyCode: x, which: x, charCode: x}); + } + }, + '{enter}': function (rng){ + rng.insertEOL(); + rng.select(); + var x = '\n'.charCodeAt(0); + $(rng._el).trigger({type: 'keypress', keyCode: x, which: x, charCode: x}); + }, + '{backspace}': function (rng){ + var b = rng.bounds(); + if (b[0] == b[1]) rng.bounds([b[0]-1, b[0]]); // no characters selected; it's just an insertion point. Remove the previous character + rng.text('', 'end'); // delete the characters and update the selection + }, + '{del}': function (rng){ + var b = rng.bounds(); + if (b[0] == b[1]) rng.bounds([b[0], b[0]+1]); // no characters selected; it's just an insertion point. Remove the next character + rng.text('', 'end'); // delete the characters and update the selection + }, + '{rightarrow}': function (rng){ + var b = rng.bounds(); + if (b[0] == b[1]) ++b[1]; // no characters selected; it's just an insertion point. Move to the right + rng.bounds([b[1], b[1]]); + }, + '{leftarrow}': function (rng){ + var b = rng.bounds(); + if (b[0] == b[1]) --b[0]; // no characters selected; it's just an insertion point. Move to the left + rng.bounds([b[0], b[0]]); + }, + '{selectall}' : function (rng){ + rng.bounds('all'); + }, + '{selection}': function (rng){ + $.fn.sendkeys.defaults.simplechar(rng, $.data(rng._el, 'sendkeys.originalText')); + }, + '{mark}' : function (rng){ + var bounds = rng.bounds(); + $(rng._el).one('sendkeys', function(){ + // set up the event listener to change the selection after the sendkeys is done + rng.bounds(bounds).select(); + }); + } +}; + +})(jQuery) \ No newline at end of file diff --git a/contrib/testing/run.py b/contrib/testing/run.py new file mode 100755 index 0000000..582118d --- /dev/null +++ b/contrib/testing/run.py @@ -0,0 +1,272 @@ +#!/usr/bin/env python + +import ConfigParser +import Image +import datetime +import os +import shutil +import subprocess +import argparse +import sys +import time +from multiprocessing import Pool +from selenium import webdriver +from selenium.webdriver.common.desired_capabilities import DesiredCapabilities + +# Set constants. +mobile_browsers = ['iPad', 'iPhone', 'android'] +current_dir = os.path.dirname(os.path.realpath(__file__)) +jslib_dir = os.path.join(current_dir, 'lib') +tests_dir = os.path.join(current_dir, 'tests') +screenshots_dir = os.path.join(current_dir, 'screenshots') +screenshots_results_dir = os.path.join(screenshots_dir, 'results') +global_cfg_path = os.path.join(current_dir, 'global.cfg') + +# Clear previous screenshots. +if os.path.exists(screenshots_results_dir): + shutil.rmtree(screenshots_results_dir) + +# Retrieve js libraries. +bilite_js = file(os.path.join(jslib_dir, 'bililiteRange.js')).read() +sendkeys_js = file(os.path.join(jslib_dir, 'jquery.sendkeys.js')).read() +hackpad_js = file(os.path.join(jslib_dir, 'hackpad.js')).read() + +# Read global config. +global_config = ConfigParser.ConfigParser() +global_config.read(global_cfg_path) +command_executor = global_config.get('general', 'command_executor') +global_browsers = global_config.get('general', 'browsers').split('\n') +global_project = global_config.get('general', 'project') +global_screen_resolution = global_config.get('general', 'screen_resolution') +global_browser_size = global_config.get('general', 'browser_size') +global_async = global_config.get('general', 'async') == 'true' +global_parallel_threads = int(global_config.get('general', 'parallel_threads')) +global_cookie_domain = global_config.get('general', 'cookie_domain') +global_cookie_login_domain = global_config.get('general', 'cookie_login_domain') +global_cookie_login_name = global_config.get('general', 'cookie_login_name') +global_cookie_login_value = global_config.get('general', 'cookie_login_value') + +# Colors. +blue = '\033[94m' +orange = '\033[33m' +red = '\033[91m' +end_color = '\033[0m' + +parser = argparse.ArgumentParser(description='Run screenshot tests!') +parser.add_argument('testfile', type=str, nargs='?', + help='a testfile to run') +parser.add_argument('test', metavar='test', type=str, nargs='?', + help='a particular test to run in the testfile') +parser.add_argument('-f', action='store_true', default=False, + help='run full tests: run all of the browsers in global.cfg, not just the first') +parser.add_argument('--nogui', action='store_true', default=False, + help='show results as pass/fail in stdout') +parser.add_argument('--nocolors', action='store_true', default=False, + help='no color formatting of stdout') +args = parser.parse_args() + +if args.nocolors: + blue = green = orange = red = end_color = '' + +# Remove test directory prefix. +if args.testfile: + testdir_with_prefix = os.path.join('tests', '') + args.testfile = args.testfile.replace(testdir_with_prefix, '') + +test_list = [args.testfile] if args.testfile else os.listdir(tests_dir) + +def run_test(driver, browser_size, cookie_domain, cookie_login_domain, cookie_login_name, + cookie_login_value, config, browser, main_test, is_mobile): + test_section = '' + + try: + try: + driver.set_window_position(0, 0) + driver.set_window_size(int(browser_size[0]), int(browser_size[1])) + driver.set_window_position(0, 0) + #driver.window_maximize() + except: + # Android doesn't like maximize. + pass + + if cookie_domain: + driver.get(cookie_domain) + driver.add_cookie({'domain': cookie_login_domain, + 'name': cookie_login_name, + 'expires': 2114380800000, + 'value': cookie_login_value}) + + # Run every test for this browser. + for section in config.sections(): + if section == 'general': + continue + if args.test and section != args.test: + continue + + test_section = section + print blue + browser + ': ' + orange + main_test + ': ' + end_color + \ + section + end_color + + # Retrieve test + url = config.get(section, 'url') + if config.has_option(section, 'js'): + js = config.get(section, 'js') + else: + js = '' + if config.has_option(section, 'wait'): + wait = config.get(section, 'wait') + else: + wait = None + + # Run the test! + driver.get(url) + try: + driver.execute_script(bilite_js + ';' + sendkeys_js + ';' + + hackpad_js + ';' + + '$.isReady ? (function() {' + js +'})() : $(function() {' + js + '});') + if wait: + driver.find_element_by_css_selector(wait) + except: + # If test fails, still take a screenshot of it. + pass + + # Take a screenshot. + time.sleep(3) + test_result_dir = os.path.join(screenshots_results_dir, browser) + if not os.path.exists(test_result_dir): + os.makedirs(test_result_dir) + screenshot_path = os.path.join(test_result_dir, + main_test + '_' + section + '.png') + driver.save_screenshot(screenshot_path) + + # Mobile browsers include the top notification bar as part of the + # screenshot (carrier, wifi, current time, etc.) This messes with + # the screenshot diff later on so we crop it out here. + # 25px does the trick for iPhone, 65px for iPad. + if is_mobile: + screenshot = Image.open(screenshot_path) + crop_length = 65 if browser.find('iPad') != -1 else 25 + cropped_image = screenshot.crop((0, crop_length, screenshot.size[0], + screenshot.size[1])) + cropped_image.save(screenshot_path, 'png') + except Exception as ex: + print ex + print >> sys.stderr, red + 'Error! Selenium failed completely: ' + \ + end_color + browser + ': ' + main_test + ': ' + test_section + pass + finally: + driver.quit() + +if global_async: + pool = Pool(processes=global_parallel_threads) + +for test in test_list: + if os.path.splitext(test)[1] != '.cfg': + continue + + main_test = os.path.splitext(test)[0] + + # Read tests. + config = ConfigParser.ConfigParser() + config.read(os.path.join(tests_dir, test)) + if config.has_option('general', 'browsers'): + browsers = config.get('general', 'browsers').split('\n') + else: + browsers = global_browsers + if config.has_option('general', 'browser_size'): + browser_size = config.get('general', 'browser_size') + else: + browser_size = global_browser_size + if config.has_option('general', 'cookie_domain'): + cookie_domain = config.get('general', 'cookie_domain') + else: + cookie_domain = global_cookie_domain + if config.has_option('general', 'cookie_login_domain'): + cookie_login_domain = config.get('general', 'cookie_login_domain') + else: + cookie_login_domain = global_cookie_login_domain + if config.has_option('general', 'cookie_login_name'): + cookie_login_name = config.get('general', 'cookie_login_name') + else: + cookie_login_name = global_cookie_login_name + if config.has_option('general', 'cookie_login_value'): + cookie_login_value = config.get('general', 'cookie_login_value') + else: + cookie_login_value = global_cookie_login_value + browser_size = browser_size.split('x') + + for browser in browsers: + browser = browser.strip() + browser_specs = browser.split('-') + + # Configure browser. + is_mobile = False + mobile_browser = None + for mobile_browser_test in mobile_browsers: + if browser_specs[2].lower().find(mobile_browser_test.lower()) != -1: + is_mobile = True + mobile_browser = mobile_browser_test + caps = {} + if is_mobile: + caps['platform'] = browser_specs[0] + ' ' + browser_specs[1] + caps['device'] = browser_specs[2] + ' Simulator' + caps['app'] = 'safari' + if len(browser_specs) > 3: + caps['version'] = browser_specs[3] + else: + caps['platform'] = browser_specs[0] + ' ' + browser_specs[1] + caps['os'] = browser_specs[0] + caps['os_version'] = browser_specs[1] + caps['browser'] = caps['browserName'] = browser_specs[2] + caps['screenshot'] = True + if len(browser_specs) > 3: + caps['browser_version'] = caps['version'] = browser_specs[3] + + caps['project'] = global_project + caps['screen-resolution'] = global_screen_resolution + git_describe = subprocess.check_output(["git", "describe", "--always"]) + caps['build'] = git_describe + caps['extra'] = git_describe + caps['groups'] = git_describe + caps['name'] = str(datetime.datetime.now()) + caps['ignoreProtectedModeSettings'] = 'true' + caps['browserstack.debug'] = 'true' + + try: + # Open browser. + driver = webdriver.Remote(command_executor=command_executor, + desired_capabilities=caps) + driver.implicitly_wait(10) # seconds + + if global_async: + pool.apply_async(run_test, [driver, browser_size, cookie_domain, + cookie_login_domain, cookie_login_name, cookie_login_value, + config, browser, main_test, is_mobile]) + else: + run_test(driver, browser_size, cookie_domain, + cookie_login_domain, cookie_login_name, cookie_login_value, + config, browser, main_test, is_mobile) + except Exception as ex: + print ex + print >> sys.stderr, red + 'Error! Startup of selenium failed completely: ' + \ + end_color + browser + ': ' + main_test + try: + driver.quit() + except: + pass + pass + + # Run smoke test - just one browser. + if not args.f: + break + +if global_async: + pool.close() + +cmd = "./compare.py" +if args.nogui: + cmd += " --nogui" +if args.nocolors: + cmd += " --nocolors" + +os.system(cmd) diff --git a/contrib/testing/tests/loggedout.cfg b/contrib/testing/tests/loggedout.cfg new file mode 100644 index 0000000..e492f06 --- /dev/null +++ b/contrib/testing/tests/loggedout.cfg @@ -0,0 +1,25 @@ +[general] +cookie_domain = + +[homepage] +url = https://stage.hackpad.com + +[static_pad] +url = https://stage.hackpad.com/vqZcebZtsND +js = $('#inviteLog-wrapper, #last-saved-timestamp').hide(); +wait = .ace-line + +[signup] +url = https://stage.hackpad.com +js = $('#top-right-signin-button, #hero-signin-button').click(); + $('#login-form [name=email]').val('testbot_signup@hackpad.com'); + $('#login-email-go').click(); + $('#login-submit').prop('disabled', false).focus(); + +[signin] +url = https://stage.hackpad.com/ep/account/sign-in +js = $('#login-form [name=email]').val('browserstack@mail.com'); + $('#login-email-go').click(); + $('#login-form [name=password]').val('gHOyhtl9'); + $('#login-form [name=cont]').val('/ep/account/settings/'); + $('#login-form').submit(); diff --git a/contrib/testing/tests/pad.cfg b/contrib/testing/tests/pad.cfg new file mode 100644 index 0000000..451d5b0 --- /dev/null +++ b/contrib/testing/tests/pad.cfg @@ -0,0 +1,28 @@ +[hello_world] +url = https://stage.hackpad.com/B7UfDAt5jXA +js = $('#editor').html(''); + $('#editor').sendkeys("hello, hackpad"); + $('#inviteLog-wrapper, #last-saved-timestamp').hide(); + $('#editor').blur(); +wait = .ace-line + +[functionality_static] +url = https://stage.hackpad.com/vqZcebZtsND +js = $('#inviteLog-wrapper, #last-saved-timestamp').hide(); +wait = .ace-line + +[homepage] +url = https://stage.hackpad.com/ +js = $('.segment-outer-wrapper[data-padid=PhF1MzEXWie], .segment-outer-wrapper[data-padid=PhF1MzEXWie] + div').detach().prependTo($('#padtable')); + $('.segment-outer-wrapper[data-padid=PhF1MzEXWie] .segment-content').hide(); + $('.segment-last-edited-date').hide(); + $('#createpadentry').blur(); + +[search] +url = https://stage.hackpad.com/ep/search/?q=browser%20stack&r=-1 +js = $('.segment-last-edited-date').hide() + +[collection] +url = https://stage.hackpad.com/ep/group/16 +js = $('.segment-last-edited-date').hide(); + diff --git a/contrib/testing/tests/pad_edit.cfg b/contrib/testing/tests/pad_edit.cfg new file mode 100644 index 0000000..15df8a4 --- /dev/null +++ b/contrib/testing/tests/pad_edit.cfg @@ -0,0 +1,64 @@ +[general] +browsers = Windows-7-chrome-27 + +[functionality_manual] +url = https://stage.hackpad.com/PhF1MzEXWie +js = $('#editor').html(''); + $('#editor').sendkeys("Test Functionality Manual{enter}{enter}"); + $('#editor').sendkeys("@Mime{enter}"); + $('#editor').sendkeys("@Paris{enter}"); + $('#editor').sendkeys("#test{enter}{enter} "); + + typeAndSelect('bold'); + $('#boldbutton').mousedown(); + + typeAndSelect(' italic'); + $('#boldbutton').mousedown(); + $('#italicsbutton').mousedown(); + + typeAndSelect(' underline'); + $('#underlinebutton').mousedown(); + $('#italicsbutton').mousedown(); + + typeAndSelect(' strike-through'); + $('#underlinebutton').mousedown(); + $('#strikebutton').mousedown(); + + typeAndSelect(' underline'); + $('#strikebutton').mousedown(); + + $('#editor').sendkeys('{enter}1'); + $('#listbutton').click(); + $('#editor').sendkeys('{enter}2{enter}3{enter}1'); + $('#indentbutton').click(); + $('#editor').sendkeys('{enter}2{enter}3{enter}1'); + $('#indentbutton').click(); + $('#editor').sendkeys('{enter}2{enter}3{enter}1'); + $('#outdentbutton').click(); + $('#outdentbutton').click(); + + $('#numberedlistbutton').click(); + $('#editor').sendkeys('{enter}2{enter}3{enter}1'); + $('#indentbutton').click(); + $('#editor').sendkeys('{enter}2{enter}3{enter}1'); + $('#indentbutton').click(); + $('#editor').sendkeys('{enter}2{enter}3{enter}1'); + $('#outdentbutton').click(); + $('#outdentbutton').click(); + + $('#editor').sendkeys('{enter}Checkbox'); + $('#taskbutton').click(); + $('#editor').sendkeys('{enter}Checkbox 123'); + $('#indentbutton').click(); + + $('#editor').sendkeys('{enter}Comment'); + $('#outdentbutton').click(); + $('#commentbutton').click(); + $('#editor').sendkeys('{enter}Comment 123'); + $('#indentbutton').click(); + + // TODO: Figure out way to send true keys to ace editor. + + $('#inviteLog-wrapper, #last-saved-timestamp').hide(); + $('#editor').blur(); +wait = .ace-line diff --git a/contrib/testing/tests/pad_extras.cfg b/contrib/testing/tests/pad_extras.cfg new file mode 100644 index 0000000..804be1d --- /dev/null +++ b/contrib/testing/tests/pad_extras.cfg @@ -0,0 +1,19 @@ +[history] +url = https://stage.hackpad.com/ep/pad/summary/vqZcebZtsND +js = $('.author-diff-header').hide(); +wait = .ace-line + +[embed] +url = https://stage.hackpad.com/vqZcebZtsND +js = $('#inviteLog-wrapper, #last-saved-timestamp').hide(); + pad.showEmbedDialog(); +wait = .ace-line + +[print] +url = https://stage.hackpad.com/ep/pad/static/vqZcebZtsND + +[embedded] +url = https://stage.hackpad.com/static/embed-test.html + +[ios] +url = https://stage.hackpad.com/ep/pad/editor diff --git a/contrib/testing/tests/pro.cfg b/contrib/testing/tests/pro.cfg new file mode 100644 index 0000000..73e3b0e --- /dev/null +++ b/contrib/testing/tests/pro.cfg @@ -0,0 +1,8 @@ +[signup] +url = https://stage.hackpad.com/ep/pro-signup/ + +[new_space] +url = https://stage.hackpad.com/ep/new-site/ + +[new_space_2] +url = https://stage.hackpad.com/ep/new-site/invite diff --git a/contrib/testing/tests/pro2.cfg b/contrib/testing/tests/pro2.cfg new file mode 100644 index 0000000..307c583 --- /dev/null +++ b/contrib/testing/tests/pro2.cfg @@ -0,0 +1,37 @@ +[general] +cookie_domain = https://testbot2.stage.hackpad.com +cookie_login_domain = testbot2.stage.hackpad.com +cookie_login_name = +cookie_login_value = + +[bs_site] +url = https://testbot2.stage.hackpad.com/ +js = $('.segment-last-edited-date').hide(); + $('#createpadentry').blur(); + +[sidebar] +url = https://testbot2.stage.hackpad.com/ +js = $('#site-toggle').click(); + $('.segment-last-edited-date').hide(); + $('#createpadentry').blur(); + +[acct_manager] +url = https://testbot2.stage.hackpad.com/ep/admin/account-manager/ +js = $('#accountlist td:nth-child(4)').text(''); + +[acct_manager_add] +url = https://testbot2.stage.hackpad.com/ep/admin/account-manager/ +js = $('#accountlist td:nth-child(4)').text(''); + modals.showModal('#create-account'); + setTimeout(function() { + $('input').blur(); + $('body').addClass('test-done'); + }, 1000); +wait = .test-done + +[config] +url = https://testbot2.stage.hackpad.com/ep/admin/pro-config/ + +[import_export] +url = https://testbot2.stage.hackpad.com/ep/admin/import-export +js = $('input').blur(); diff --git a/contrib/testing/tests/profile.cfg b/contrib/testing/tests/profile.cfg new file mode 100644 index 0000000..1b01faa --- /dev/null +++ b/contrib/testing/tests/profile.cfg @@ -0,0 +1,8 @@ +[profile] +url = https://stage.hackpad.com/ep/profile/ +js = $('.segment-outer-wrapper[data-padid=PhF1MzEXWie], .segment-outer-wrapper[data-padid=PhF1MzEXWie] + div').detach().prependTo($('#padtable')); + $('.segment-outer-wrapper[data-padid=PhF1MzEXWie] .segment-content').hide(); + $('.segment-last-edited-date').hide(); + +[account] +url = https://stage.hackpad.com/ep/account/settings/ diff --git a/contrib/testing/tests/search.cfg b/contrib/testing/tests/search.cfg new file mode 100644 index 0000000..e223591 --- /dev/null +++ b/contrib/testing/tests/search.cfg @@ -0,0 +1,27 @@ +[general] +cookie_domain = https://testbot2.stage.hackpad.com +cookie_login_domain = testbot2.stage.hackpad.com +cookie_login_name = +cookie_login_value = + +[search] +url = https://testbot2.stage.hackpad.com/ +js = $("#createpadentry").sendkeys("wel"); + $('#createpadentry').blur(); +wait = #listwrap-search + +[in_page_search] +url = https://testbot2.stage.hackpad.com/Welcome-to-hackpad-the-collaborative-notepad-4ZNNZEZoM2Y +js = $('#inviteLog-wrapper, #last-saved-timestamp').hide(); + $("#createpadentry").sendkeys("wel"); + $("#createpadentry").trigger('keyup'); + $("#createpadentry").prop('disabled', true); + +[in_pad_search] +url = https://testbot2.stage.hackpad.com/Welcome-to-hackpad-the-collaborative-notepad-4ZNNZEZoM2Y +js = $('#inviteLog-wrapper, #last-saved-timestamp').hide(); + $("#createpadentry").sendkeys("wel"); + $("#createpadentry").trigger('keyup'); + var e = $.Event("keyup"); + e.keyCode = e.which = e.charCode = 13; // Hrm. + $("#createpadentry").trigger(e); diff --git a/etherpad/.gitignore b/etherpad/.gitignore new file mode 100644 index 0000000..d6639d8 --- /dev/null +++ b/etherpad/.gitignore @@ -0,0 +1,8 @@ +data/ +build +derby.log +local +*.swp +etherpad-pne-*.jar + + diff --git a/etherpad/appjet-eth-dev.jar b/etherpad/appjet-eth-dev.jar new file mode 100644 index 0000000..62ee455 Binary files /dev/null and b/etherpad/appjet-eth-dev.jar differ diff --git a/etherpad/bin/.gitignore b/etherpad/bin/.gitignore new file mode 100644 index 0000000..00fd678 --- /dev/null +++ b/etherpad/bin/.gitignore @@ -0,0 +1 @@ +run-david.sh diff --git a/etherpad/bin/run-local.sh b/etherpad/bin/run-local.sh new file mode 100755 index 0000000..baac8b6 --- /dev/null +++ b/etherpad/bin/run-local.sh @@ -0,0 +1,121 @@ +#!/bin/bash -e + +# Copyright 2009 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS-IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +mkdir -p data/appjet + +# JVM heap memory limit (actually reserved during startup) +MXRAM="4G" +# maximum thread count for etherpad (should be roughly memory in MB / 4) +MAXTHREADS="2048" + +if [ -x "/usr/bin/perl" ]; then + if [ -e "/proc/meminfo" ]; then + # compute the MXRAM parameter: + # default it to half of the usable real free memory, + # but at least 100M and up to 1024M + # TODO: this should be rewritten in awk to always work (awk is part of coreutils, perl is not) + MXRAM=$(cat /proc/meminfo | perl -ne ' + BEGIN { + $free = 0; + $buffers = 0; + $cached = 0 + }; + + if (m/^MemFree:\s*(\d+)/) + { $free = $1/1024 }; + if (m/^Buffers:\s*(\d+)/) + { $buffers = $1/1024 }; + if (m/^Cached:\s*(\d+)/) + { $cached = $1/1024 }; + + END { + $usable_free = ($free + $buffers + $cached)/2; + $usable_free = 100 if ($usable_free < 100); +# $usable_free = 1024 if ($usable_free > 1024); + print int($usable_free)."M\n" + };') + + MAXTHREADS=$(echo "$MXRAM" | perl -ne ' + s/[^\d]//; + $maxthreads = int($_/6); + if ($maxthreads < 5) + { $maxthreads = 5 } + print $maxthreads; + ') + fi +fi + +if [ ! -z $1 ]; then + if [ ! '-' = `echo $1 | head -c 1` ]; then + MXRAM="$1"; + shift; + fi +fi + +CP="appjet-eth-dev.jar:data" +for f in lib/*.jar; do + CP="$CP:$f" +done + +if [ -z "$JAVA" ]; then + JAVA=java +fi + +# etherpad properties file +cfg_file=./etc/etherpad.local.properties +if [ ! -f $cfg_file ]; then + cfg_file=./etc/etherpad.localdev-default.properties +fi +if [[ $1 == "--cfg" ]]; then + cfg_file=${2} + shift; + shift; +fi + +echo "Maximum ram: $MXRAM" +echo "Maximum thread count: $MAXTHREADS" + +echo "Using config file: ${cfg_file}" + +exec $JAVA -classpath $CP \ + -server \ + -Xmx${MXRAM} \ + -Xms${MXRAM} \ + -XX:NewSize=768m \ + -XX:PermSize=256m \ + -XX:MaxPermSize=2048m \ + -Djava.awt.headless=true \ + -Djava.util.logging.config.file=../infrastructure/lib/logging.properties \ + -XX:MaxGCPauseMillis=500 \ + -XX:+UseConcMarkSweepGC \ + -XX:+UseParNewGC \ + -XX:+PrintHeapAtGC \ + -XX:+CMSIncrementalMode \ + -XX:+CMSClassUnloadingEnabled \ + -XX:CMSIncrementalSafetyFactor=50 \ + -XX:+PrintGCDetails \ + -XX:+PrintGCTimeStamps \ + -XX:OnOutOfMemoryError="killall -9 java" \ + -Xloggc:./data/logs/backend/jvm-gc.log \ + -Dappjet.jmxremote=true \ + -Djavax.net.ssl.trustStore=./etc/cacerts-rds \ + -Djavax.net.ssl.trustStorePassword=changeit \ + $JAVA_OPTS \ + net.appjet.oui.main \ + --configFile=${cfg_file} \ + --maxThreads=${MAXTHREADS} + "$@" + diff --git a/etherpad/etc/cacerts-rds b/etherpad/etc/cacerts-rds new file mode 100644 index 0000000..be06431 Binary files /dev/null and b/etherpad/etc/cacerts-rds differ diff --git a/etherpad/etc/etherpad.local.properties.tmpl b/etherpad/etc/etherpad.local.properties.tmpl new file mode 100644 index 0000000..c561959 --- /dev/null +++ b/etherpad/etc/etherpad.local.properties.tmpl @@ -0,0 +1,56 @@ +ajstdlibHome = ../infrastructure/framework-src/modules +appjetHome = ./data/appjet +devMode = false +etherpad.fakeProduction = false +etherpad.fakePNE = true +etherpad.isProduction = true +etherpad.proAccounts = true +etherpad.superUserEmailAddresses = __email_addresses_with_admin_access__ +etherpad.SQL_JDBC_DRIVER = com.mysql.jdbc.Driver +etherpad.SQL_JDBC_URL = jdbc:mysql://__dbc_dbserver__:__dbc_dbport__/__dbc_dbname__ +etherpad.SQL_PASSWORD = __dbc_dbpass__ +etherpad.SQL_USERNAME = __dbc_dbuser__ +etherpad.SQL_REQUIRE_SSL = false +etherpad.googleConsumerKey = __google_consumer_key__ +etherpad.googleConsumerSecret = __google_consumer_secret__ +hidePorts = false +listen = 9000 +logDir = /var/log/etherpad +modulePath = ./src +topdomains = localhost,localhost.localdomain +transportPrefix = /comet +transportUseWildcardSubdomains = true +useHttpsUrls = false +useVirtualFileRoot = ./src +theme = default +etherpad.soffice = /usr/bin/soffice +customBrandingName = Hackpad +customEmailAddress = noreply@example.com +facebookClientId = __fb_id__ +facebookClientSecret = __fb_secret__ +smtpUser = __smtp_user__ +smtpPass = __smtp_password__ +awsUser = __aws_key_id__ +awsPass = __aws_secret__ +s3Bucket = __aws_attachments_bucket__ +solrHostPort = 127.0.0.1:9000 +solrOnly = false +etherpad.syndicateChanges = true +etherpad.processInbox = true +secureCookieKey = __secure_cookie_key__ +requestSigningSecret = __request_signing_secret__ +apnsCert.appStore.certFile = __apns_p12_cert_file__ +apnsCert.appStore.certPass = __apns_p12_cert_password__ +apnsCert.beta.certFile = __apns_p12_cert_file__ +apnsCert.beta.certPass = __apns_p12_cert_password__ +apnsCert.debug.certFile = __apns_p12_cert_file__ +apnsCert.debug.certPass = __apns_p12_cert_password__ +cdnUrl = __cdn_url__ +mixpanelToken = __mixpanel_token__ +googleAnalyticsAccount = __google_analytics_account__ +googleAnalyticsDomainName = __google_analytics_domain_name__ +defaultIdEncryptionKey = __default_id_encryption_key__ +accountIdEncryptionKey = __account_id_encryption_key__ +collectionIdEncryptionKey = __collection_id_encryption_key__ +welcomePadSourceId = __welcome_pad_source_id__ +featureHelpPadId = __feature_help_pad_source_id__ diff --git a/etherpad/etc/etherpad.localdev-default.properties b/etherpad/etc/etherpad.localdev-default.properties new file mode 100644 index 0000000..ed73a07 --- /dev/null +++ b/etherpad/etc/etherpad.localdev-default.properties @@ -0,0 +1,56 @@ +ajstdlibHome = ../infrastructure/framework-src/modules +appjetHome = ./data/appjet +devMode = true +verbose = true +etherpad.fakeProduction = false +etherpad.isProduction = false +etherpad.proAccounts = true +etherpad.superUserEmailAddresses = __email_addresses_with_admin_access__ +etherpad.SQL_JDBC_DRIVER = com.mysql.jdbc.Driver +etherpad.SQL_JDBC_URL = jdbc:mysql://localhost:3306/hackpad +etherpad.SQL_PASSWORD = password +etherpad.SQL_USERNAME = hackpad +etherpad.SQL_REQUIRE_SSL = false +hidePorts = false +listen = 9000 +logDir = ./data/logs +modulePath = ./src +topdomains = localhost,localbox.info +transportPrefix = /comet +transportUseWildcardSubdomains = false +useHttpsUrls = false +useVirtualFileRoot = ./src +theme = default +etherpad.soffice = /usr/bin/soffice +customBrandingName = Hackpad +customEmailAddress = noreply@example.com +customEmailImapPassword = __imap_password__ +supportEmailAddress = support@example.com +etherpad.skipHostnameCheck = true +etherpad.canonicalDomain = localhost:9000 +facebookClientId = __fb_id__ +facebookClientSecret = __fb_secret__ +smtpServer = __smtp_server__ +smtpUser = __smtp_user__ +smtpPass = __smtp_password__ +awsUser = __aws_key_id__ +awsPass = __aws_secret__ +etherpad.googleConsumerKey = __google_consumer_key__ +etherpad.googleConsumerSecret = __google_consumer_secret__ +solrHostPort = 127.0.0.1:9000 +solrOnly = false +etherpad.syndicateChanges = false +etherpad.processInbox = false +secureCookieKey = __secure_cookie_key__ +requestSigningSecret = __request_signing_secret__ +apnsCert.debug.certFile = __apns_p12_cert_file__ +apnsCert.debug.certPass = __apns_p12_cert_password__ +cdnUrl = __cdn_url__ +mixpanelToken = __mixpanel_token__ +googleAnalyticsAccount = __google_analytics_account__ +googleAnalyticsDomainName = __google_analytics_domain_name__ +defaultIdEncryptionKey = 0123456789abcdef +accountIdEncryptionKey = 0123456789abcdef +collectionIdEncryptionKey = 0123456789abcdef +welcomePadSourceId = WELCOMEPAD +featureHelpPadId = FEATUREHELPPAD diff --git a/etherpad/etc/rds-combined-ca-bundle.pem b/etherpad/etc/rds-combined-ca-bundle.pem new file mode 100644 index 0000000..f1582f7 --- /dev/null +++ b/etherpad/etc/rds-combined-ca-bundle.pem @@ -0,0 +1,260 @@ +-----BEGIN CERTIFICATE----- +MIIDQzCCAqygAwIBAgIJAOd1tlfiGoEoMA0GCSqGSIb3DQEBBQUAMHUxCzAJBgNV +BAYTAlVTMRMwEQYDVQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdTZWF0dGxlMRMw +EQYDVQQKEwpBbWF6b24uY29tMQwwCgYDVQQLEwNSRFMxHDAaBgNVBAMTE2F3cy5h +bWF6b24uY29tL3Jkcy8wHhcNMTAwNDA1MjI0NDMxWhcNMTUwNDA0MjI0NDMxWjB1 +MQswCQYDVQQGEwJVUzETMBEGA1UECBMKV2FzaGluZ3RvbjEQMA4GA1UEBxMHU2Vh +dHRsZTETMBEGA1UEChMKQW1hem9uLmNvbTEMMAoGA1UECxMDUkRTMRwwGgYDVQQD +ExNhd3MuYW1hem9uLmNvbS9yZHMvMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB +gQDKhXGU7tizxUR5WaFoMTFcxNxa05PEjZaIOEN5ctkWrqYSRov0/nOMoZjqk8bC +med9vPFoQGD0OTakPs0jVe3wwmR735hyVwmKIPPsGlaBYj1O6llIpZeQVyupNx56 +UzqtiLaDzh1KcmfqP3qP2dInzBfJQKjiRudo1FWnpPt33QIDAQABo4HaMIHXMB0G +A1UdDgQWBBT/H3x+cqSkR/ePSIinPtc4yWKe3DCBpwYDVR0jBIGfMIGcgBT/H3x+ +cqSkR/ePSIinPtc4yWKe3KF5pHcwdTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCldh +c2hpbmd0b24xEDAOBgNVBAcTB1NlYXR0bGUxEzARBgNVBAoTCkFtYXpvbi5jb20x +DDAKBgNVBAsTA1JEUzEcMBoGA1UEAxMTYXdzLmFtYXpvbi5jb20vcmRzL4IJAOd1 +tlfiGoEoMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAvguZy/BDT66x +GfgnJlyQwnFSeVLQm9u/FIvz4huGjbq9dqnD6h/Gm56QPFdyMEyDiZWaqY6V08lY +LTBNb4kcIc9/6pc0/ojKciP5QJRm6OiZ4vgG05nF4fYjhU7WClUx7cxq1fKjNc2J +UCmmYqgiVkAGWRETVo+byOSDZ4swb10= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIID9DCCAtygAwIBAgIBQjANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx +EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM +GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx +GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUwOTExMzFaFw0y +MDAzMDUwOTExMzFaMIGKMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv +bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl +cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEbMBkGA1UEAwwSQW1hem9uIFJE +UyBSb290IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuD8nrZ8V +u+VA8yVlUipCZIKPTDcOILYpUe8Tct0YeQQr0uyl018StdBsa3CjBgvwpDRq1HgF +Ji2N3+39+shCNspQeE6aYU+BHXhKhIIStt3r7gl/4NqYiDDMWKHxHq0nsGDFfArf +AOcjZdJagOMqb3fF46flc8k2E7THTm9Sz4L7RY1WdABMuurpICLFE3oHcGdapOb9 +T53pQR+xpHW9atkcf3pf7gbO0rlKVSIoUenBlZipUlp1VZl/OD/E+TtRhDDNdI2J +P/DSMM3aEsq6ZQkfbz/Ilml+Lx3tJYXUDmp+ZjzMPLk/+3beT8EhrwtcG3VPpvwp +BIOqsqVVTvw/CwIDAQABo2MwYTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUw +AwEB/zAdBgNVHQ4EFgQUTgLurD72FchM7Sz1BcGPnIQISYMwHwYDVR0jBBgwFoAU +TgLurD72FchM7Sz1BcGPnIQISYMwDQYJKoZIhvcNAQEFBQADggEBAHZcgIio8pAm +MjHD5cl6wKjXxScXKtXygWH2BoDMYBJF9yfyKO2jEFxYKbHePpnXB1R04zJSWAw5 +2EUuDI1pSBh9BA82/5PkuNlNeSTB3dXDD2PEPdzVWbSKvUB8ZdooV+2vngL0Zm4r +47QPyd18yPHrRIbtBtHR/6CwKevLZ394zgExqhnekYKIqqEX41xsUV0Gm6x4vpjf +2u6O/+YE2U+qyyxHE5Wd5oqde0oo9UUpFETJPVb6Q2cEeQib8PBAyi0i6KnF+kIV +A9dY7IHSubtCK/i8wxMVqfd5GtbA8mmpeJFwnDvm9rBEsHybl08qlax9syEwsUYr +/40NawZfTUU= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIEATCCAumgAwIBAgIBRDANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx +EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM +GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx +GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzMDZaFw0y +MDAzMDUyMjAzMDZaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv +bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl +cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzElMCMGA1UEAwwcQW1hem9uIFJE +UyBhcC1ub3J0aGVhc3QtMSBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBAMmM2B4PfTXCZjbZMWiDPyxvk/eeNwIRJAhfzesiGUiLozX6CRy3rwC1ZOPV +AcQf0LB+O8wY88C/cV+d4Q2nBDmnk+Vx7o2MyMh343r5rR3Na+4izd89tkQVt0WW +vO21KRH5i8EuBjinboOwAwu6IJ+HyiQiM0VjgjrmEr/YzFPL8MgHD/YUHehqjACn +C0+B7/gu7W4qJzBL2DOf7ub2qszGtwPE+qQzkCRDwE1A4AJmVE++/FLH2Zx78Egg +fV1sUxPtYgjGH76VyyO6GNKM6rAUMD/q5mnPASQVIXgKbupr618bnH+SWHFjBqZq +HvDGPMtiiWII41EmGUypyt5AbysCAwEAAaNmMGQwDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFIiKM0Q6n1K4EmLxs3ZXxINbwEwR +MB8GA1UdIwQYMBaAFE4C7qw+9hXITO0s9QXBj5yECEmDMA0GCSqGSIb3DQEBBQUA +A4IBAQBezGbE9Rw/k2e25iGjj5n8r+M3dlye8ORfCE/dijHtxqAKasXHgKX8I9Tw +JkBiGWiuzqn7gO5MJ0nMMro1+gq29qjZnYX1pDHPgsRjUX8R+juRhgJ3JSHijRbf +4qNJrnwga7pj94MhcLq9u0f6dxH6dXbyMv21T4TZMTmcFduf1KgaiVx1PEyJjC6r +M+Ru+A0eM+jJ7uCjUoZKcpX8xkj4nmSnz9NMPog3wdOSB9cAW7XIc5mHa656wr7I +WJxVcYNHTXIjCcng2zMKd1aCcl2KSFfy56sRfT7J5Wp69QSr+jq8KM55gw8uqAwi +VPrXn2899T1rcTtFYFP16WXjGuc0 +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIEATCCAumgAwIBAgIBRTANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx +EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM +GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx +GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzMTlaFw0y +MDAzMDUyMjAzMTlaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv +bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl +cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzElMCMGA1UEAwwcQW1hem9uIFJE +UyBhcC1zb3V0aGVhc3QtMSBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBANaXElmSEYt/UtxHFsARFhSUahTf1KNJzR0Dmay6hqOXQuRVbKRwPd19u5vx +DdF1sLT7D69IK3VDnUiQScaCv2Dpu9foZt+rLx+cpx1qiQd1UHrvqq8xPzQOqCdC +RFStq6yVYZ69yfpfoI67AjclMOjl2Vph3ftVnqP0IgVKZdzeC7fd+umGgR9xY0Qr +Ubhd/lWdsbNvzK3f1TPWcfIKQnpvSt85PIEDJir6/nuJUKMtmJRwTymJf0i+JZ4x +7dJa341p2kHKcHMgOPW7nJQklGBA70ytjUV6/qebS3yIugr/28mwReflg3TJzVDl +EOvi6pqbqNbkMuEwGDCmEQIVqgkCAwEAAaNmMGQwDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFAu93/4k5xbWOsgdCdn+/KdiRuit +MB8GA1UdIwQYMBaAFE4C7qw+9hXITO0s9QXBj5yECEmDMA0GCSqGSIb3DQEBBQUA +A4IBAQBlcjSyscpPjf5+MgzMuAsCxByqUt+WFspwcMCpwdaBeHOPSQrXNqX2Sk6P +kth6oCivA64trWo8tFMvPYlUA1FYVD5WpN0kCK+P5pD4KHlaDsXhuhClJzp/OP8t +pOyUr5109RHLxqoKB5J5m1XA7rgcFjnMxwBSWFe3/4uMk/+4T53YfCVXuc6QV3i7 +I/2LAJwFf//pTtt6fZenYfCsahnr2nvrNRNyAxcfvGZ/4Opn/mJtR6R/AjvQZHiR +bkRNKF2GW0ueK5W4FkZVZVhhX9xh1Aj2Ollb+lbOqADaVj+AT3PoJPZ3MPQHKCXm +xwG0LOLlRr/TfD6li1AfOVTAJXv9 +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIEATCCAumgAwIBAgIBRjANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx +EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM +GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx +GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzMjRaFw0y +MDAzMDUyMjAzMjRaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv +bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl +cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzElMCMGA1UEAwwcQW1hem9uIFJE +UyBhcC1zb3V0aGVhc3QtMiBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBAJqBAJutz69hFOh3BtLHZTbwE8eejGGKayn9hu98YMDPzWzGXWCmW+ZYWELA +cY3cNWNF8K4FqKXFr2ssorBYim1UtYFX8yhydT2hMD5zgQ2sCGUpuidijuPA6zaq +Z3tdhVR94f0q8mpwpv2zqR9PcqaGDx2VR1x773FupRPRo7mEW1vC3IptHCQlP/zE +7jQiLl28bDIH2567xg7e7E9WnZToRnhlYdTaDaJsHTzi5mwILi4cihSok7Shv/ME +hnukvxeSPUpaVtFaBhfBqq055ePq9I+Ns4KGreTKMhU0O9fkkaBaBmPaFgmeX/XO +n2AX7gMouo3mtv34iDTZ0h6YCGkCAwEAAaNmMGQwDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFIlQnY0KHYWn1jYumSdJYfwj/Nfw +MB8GA1UdIwQYMBaAFE4C7qw+9hXITO0s9QXBj5yECEmDMA0GCSqGSIb3DQEBBQUA +A4IBAQA0wVU6/l41cTzHc4azc4CDYY2Wd90DFWiH9C/mw0SgToYfCJ/5Cfi0NT/Y +PRnk3GchychCJgoPA/k9d0//IhYEAIiIDjyFVgjbTkKV3sh4RbdldKVOUB9kumz/ +ZpShplsGt3z4QQiVnKfrAgqxWDjR0I0pQKkxXa6Sjkicos9LQxVtJ0XA4ieG1E7z +zJr+6t80wmzxvkInSaWP3xNJK9azVRTrgQZQlvkbpDbExl4mNTG66VD3bAp6t3Wa +B49//uDdfZmPkqqbX+hsxp160OH0rxJppwO3Bh869PkDnaPEd/Pxw7PawC+li0gi +NRV8iCEx85aFxcyOhqn0WZOasxee +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIID/zCCAuegAwIBAgIBRzANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx +EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM +GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx +GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzMzFaFw0y +MDAzMDUyMjAzMzFaMIGSMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv +bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl +cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEjMCEGA1UEAwwaQW1hem9uIFJE +UyBldS1jZW50cmFsLTEgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB +AQDFtP2dhSLuaPOI4ZrrPWsK4OY9ocQBp3yApH1KJYmI9wpQKZG/KCH2E6Oo7JAw +QORU519r033T+FO2Z7pFPlmz1yrxGXyHpJs8ySx3Yo5S8ncDCdZJCLmtPiq/hahg +5/0ffexMFUCQaYicFZsrJ/cStdxUV+tSw2JQLD7UxS9J97LQWUPyyG+ZrjYVTVq+ +zudnFmNSe4QoecXMhAFTGJFQXxP7nhSL9Ao5FGgdXy7/JWeWdQIAj8ku6cBDKPa6 +Y6kP+ak+In+Lye8z9qsCD/afUozfWjPR2aA4JoIZVF8dNRShIMo8l0XfgfM2q0+n +ApZWZ+BjhIO5XuoUgHS3D2YFAgMBAAGjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNV +HRMBAf8ECDAGAQH/AgEAMB0GA1UdDgQWBBRm4GsWIA/M6q+tK8WGHWDGh2gcyTAf +BgNVHSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQUFAAOC +AQEAHpMmeVQNqcxgfQdbDIi5UIy+E7zZykmtAygN1XQrvga9nXTis4kOTN6g5/+g +HCx7jIXeNJzAbvg8XFqBN84Quqgpl/tQkbpco9Jh1HDs558D5NnZQxNqH5qXQ3Mm +uPgCw0pYcPOa7bhs07i+MdVwPBsX27CFDtsgAIru8HvKxY1oTZrWnyIRo93tt/pk +WuItVMVHjaQZVfTCow0aDUbte6Vlw82KjUFq+n2NMSCJDiDKsDDHT6BJc4AJHIq3 +/4Z52MSC9KMr0yAaaoWfW/yMEj9LliQauAgwVjArF4q78rxpfKTG9Rfd8U1BZANP +7FrFMN0ThjfA1IvmOYcgskY5bQ== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIID/DCCAuSgAwIBAgIBSDANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx +EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM +GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx +GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzMzVaFw0y +MDAzMDUyMjAzMzVaMIGPMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv +bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl +cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJE +UyBldS13ZXN0LTEgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCx +PdbqQ0HKRj79Pmocxvjc+P6i4Ux24kgFIl+ckiir1vzkmesc3a58gjrMlCksEObt +Yihs5IhzEq1ePT0gbfS9GYFp34Uj/MtPwlrfCBWG4d2TcrsKRHr1/EXUYhWqmdrb +RhX8XqoRhVkbF/auzFSBhTzcGGvZpQ2KIaxRcQfcXlMVhj/pxxAjh8U4F350Fb0h +nX1jw4/KvEreBL0Xb2lnlGTkwVxaKGSgXEnOgIyOFdOQc61vdome0+eeZsP4jqeR +TGYJA9izJsRbe2YJxHuazD+548hsPlM3vFzKKEVURCha466rAaYAHy3rKur3HYQx +Yt+SoKcEz9PXuSGj96ejAgMBAAGjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMB +Af8ECDAGAQH/AgEAMB0GA1UdDgQWBBTebg//h2oeXbZjQ4uuoiuLYzuiPDAfBgNV +HSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQUFAAOCAQEA +TikPaGeZasTPw+4RBemlsyPAjtFFQLo7ddaFdORLgdEysVf8aBqndvbA6MT/v4lj +GtEtUdF59ZcbWOrVm+fBZ2h/jYJ59dYF/xzb09nyRbdMSzB9+mkSsnOMqluq5y8o +DY/PfP2vGhEg/2ZncRC7nlQU1Dm8F4lFWEiQ2fi7O1cW852Vmbq61RIfcYsH/9Ma +kpgk10VZ75b8m3UhmpZ/2uRY+JEHImH5WpcTJ7wNiPNJsciZMznGtrgOnPzYco8L +cDleOASIZifNMQi9PKOJKvi0ITz0B/imr8KBsW0YjZVJ54HMa7W1lwugSM7aMAs+ +E3Sd5lS+SHwWaOCHwhOEVA== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIID/DCCAuSgAwIBAgIBSTANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx +EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM +GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx +GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzNDBaFw0y +MDAzMDUyMjAzNDBaMIGPMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv +bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl +cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJE +UyBzYS1lYXN0LTEgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCU +X4OBnQ5xA6TLJAiFEI6l7bUWjoVJBa/VbMdCCSs2i2dOKmqUaXu2ix2zcPILj3lZ +GMk3d/2zvTK/cKhcFrewHUBamTeVHdEmynhMQamqNmkM4ptYzFcvEUw1TGxHT4pV +Q6gSN7+/AJewQvyHexHo8D0+LDN0/Wa9mRm4ixCYH2CyYYJNKaZt9+EZfNu+PPS4 +8iB0TWH0DgQkbWMBfCRgolLLitAZklZ4dvdlEBS7evN1/7ttBxUK6SvkeeSx3zBl +ww3BlXqc3bvTQL0A+RRysaVyFbvtp9domFaDKZCpMmDFAN/ntx215xmQdrSt+K3F +cXdGQYHx5q410CAclGnbAgMBAAGjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMB +Af8ECDAGAQH/AgEAMB0GA1UdDgQWBBT6iVWnm/uakS+tEX2mzIfw+8JL0zAfBgNV +HSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQUFAAOCAQEA +FmDD+QuDklXn2EgShwQxV13+txPRuVdOSrutHhoCgMwFWCMtPPtBAKs6KPY7Guvw +DpJoZSehDiOfsgMirjOWjvfkeWSNvKfjWTVneX7pZD9W5WPnsDBvTbCGezm+v87z +b+ZM2ZMo98m/wkMcIEAgdSKilR2fuw8rLkAjhYFfs0A7tDgZ9noKwgHvoE4dsrI0 +KZYco6DlP/brASfHTPa2puBLN9McK3v+h0JaSqqm5Ro2Bh56tZkQh8AWy/miuDuK +3+hNEVdxosxlkM1TPa1DGj0EzzK0yoeerXuH2HX7LlCrrxf6/wdKnjR12PMrLQ4A +pCqkcWw894z6bV9MAvKe6A== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIID/DCCAuSgAwIBAgIBQzANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx +EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM +GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx +GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMTU0MDRaFw0y +MDAzMDUyMTU0MDRaMIGPMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv +bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl +cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJE +UyB1cy1lYXN0LTEgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDI +UIuwh8NusKHk1SqPXcP7OqxY3S/M2ZyQWD3w7Bfihpyyy/fc1w0/suIpX3kbMhAV +2ESwged2/2zSx4pVnjp/493r4luhSqQYzru78TuPt9bhJIJ51WXunZW2SWkisSaf +USYUzVN9ezR/bjXTumSUQaLIouJt3OHLX49s+3NAbUyOI8EdvgBQWD68H1epsC0n +CI5s+pIktyOZ59c4DCDLQcXErQ+tNbDC++oct1ANd/q8p9URonYwGCGOBy7sbCYq +9eVHh1Iy2M+SNXddVOGw5EuruvHoCIQyOz5Lz4zSuZA9dRbrfztNOpezCNYu6NKM +n+hzcvdiyxv77uNm8EaxAgMBAAGjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMB +Af8ECDAGAQH/AgEAMB0GA1UdDgQWBBQSQG3TmMe6Sa3KufaPBa72v4QFDzAfBgNV +HSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQUFAAOCAQEA +L/mOZfB3187xTmjOHMqN2G2oSKHBKiQLM9uv8+97qT+XR+TVsBT6b3yoPpMAGhHA +Pc7nxAF5gPpuzatx0OTLPcmYucFmfqT/1qA5WlgCnMNtczyNMH97lKFTNV7Njtek +jWEzAEQSyEWrkNpNlC4j6kMYyPzVXQeXUeZTgJ9FNnVZqmvfjip2N22tawMjrCn5 +7KN/zN65EwY2oO9XsaTwwWmBu3NrDdMbzJnbxoWcFWj4RBwanR1XjQOVNhDwmCOl +/1Et13b8CPyj69PC8BOVU6cfTSx8WUVy0qvYOKHNY9Bqa5BDnIL3IVmUkeTlM1mt +enRpyBj+Bk9rh/ICdiRKmA== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIID/DCCAuSgAwIBAgIBSjANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx +EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM +GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx +GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzNDVaFw0y +MDAzMDUyMjAzNDVaMIGPMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv +bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl +cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJE +UyB1cy13ZXN0LTEgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDE +Dhw+uw/ycaiIhhyu2pXFRimq0DlB8cNtIe8hdqndH8TV/TFrljNgR8QdzOgZtZ9C +zzQ2GRpInN/qJF6slEd6wO+6TaDBQkPY+07TXNt52POFUhdVkhJXHpE2BS7Xn6J7 +7RFAOeG1IZmc2DDt+sR1BgXzUqHslQGfFYNS0/MBO4P+ya6W7IhruB1qfa4HiYQS +dbe4MvGWnv0UzwAqdR7OF8+8/5c58YXZIXCO9riYF2ql6KNSL5cyDPcYK5VK0+Q9 +VI6vuJHSMYcF7wLePw8jtBktqAFE/wbdZiIHhZvNyiNWPPNTGUmQbaJ+TzQEHDs5 +8en+/W7JKnPyBOkxxENbAgMBAAGjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMB +Af8ECDAGAQH/AgEAMB0GA1UdDgQWBBS0nw/tFR9bCjgqWTPJkyy4oOD8bzAfBgNV +HSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQUFAAOCAQEA +CXGAY3feAak6lHdqj6+YWjy6yyUnLK37bRxZDsyDVXrPRQaXRzPTzx79jvDwEb/H +Q/bdQ7zQRWqJcbivQlwhuPJ4kWPUZgSt3JUUuqkMsDzsvj/bwIjlrEFDOdHGh0mi +eVIngFEjUXjMh+5aHPEF9BlQnB8LfVtKj18e15UDTXFa+xJPFxUR7wDzCfo4WI1m +sUMG4q1FkGAZgsoyFPZfF8IVvgCuGdR8z30VWKklFxttlK0eGLlPAyIO0CQxPQlo +saNJrHf4tLOgZIWk+LpDhNd9Et5EzvJ3aURUsKY4pISPPF5WdvM9OE59bERwUErd +nuOuQWQeeadMceZnauRzJQ== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIID/DCCAuSgAwIBAgIBSzANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx +EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM +GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx +GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzNTBaFw0y +MDAzMDUyMjAzNTBaMIGPMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv +bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl +cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJE +UyB1cy13ZXN0LTIgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDM +H58SR48U6jyERC1vYTnub34smf5EQVXyzaTmspWGWGzT31NLNZGSDFaa7yef9kdO +mzJsgebR5tXq6LdwlIoWkKYQ7ycUaadtVKVYdI40QcI3cHn0qLFlg2iBXmWp/B+i +Z34VuVlCh31Uj5WmhaBoz8t/GRqh1V/aCsf3Wc6jCezH3QfuCjBpzxdOOHN6Ie2v +xX09O5qmZTvMoRBAvPkxdaPg/Mi7fxueWTbEVk78kuFbF1jHYw8U1BLILIAhcqlq +x4u8nl73t3O3l/soNUcIwUDK0/S+Kfqhwn9yQyPlhb4Wy3pfnZLJdkyHldktnQav +9TB9u7KH5Lk0aAYslMLxAgMBAAGjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMB +Af8ECDAGAQH/AgEAMB0GA1UdDgQWBBT8roM4lRnlFHWMPWRz0zkwFZog1jAfBgNV +HSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQUFAAOCAQEA +JwrxwgwmPtcdaU7O7WDdYa4hprpOMamI49NDzmE0s10oGrqmLwZygcWU0jT+fJ+Y +pJe1w0CVfKaeLYNsOBVW3X4ZPmffYfWBheZiaiEflq/P6t7/Eg81gaKYnZ/x1Dfa +sUYkzPvCkXe9wEz5zdUTOCptDt89rBR9CstL9vE7WYUgiVVmBJffWbHQLtfjv6OF +NMb0QME981kGRzc2WhgP71YS2hHd1kXtsoYP1yTu4vThSKsoN4bkiHsaC1cRkLoy +0fFA4wpB3WloMEvCDaUvvH1LZlBXTNlwi9KtcwD4tDxkkBt4tQczKLGpQ/nF/W9n +8YDWk3IIc1sd0bkZqoau2Q== +-----END CERTIFICATE----- diff --git a/etherpad/solr/collection1/conf/protwords.txt b/etherpad/solr/collection1/conf/protwords.txt new file mode 100644 index 0000000..1dfc0ab --- /dev/null +++ b/etherpad/solr/collection1/conf/protwords.txt @@ -0,0 +1,21 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#----------------------------------------------------------------------- +# Use a protected word file to protect against the stemmer reducing two +# unrelated words to the same base word. + +# Some non-words that normally won't be encountered, +# just to test that they won't be stemmed. +dontstems +zwhacky + diff --git a/etherpad/solr/collection1/conf/schema.xml b/etherpad/solr/collection1/conf/schema.xml new file mode 100644 index 0000000..b39ba6e --- /dev/null +++ b/etherpad/solr/collection1/conf/schema.xml @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id + + + contents + + + + + + + + + diff --git a/etherpad/solr/collection1/conf/solrconfig.xml b/etherpad/solr/collection1/conf/solrconfig.xml new file mode 100644 index 0000000..a4a8212 --- /dev/null +++ b/etherpad/solr/collection1/conf/solrconfig.xml @@ -0,0 +1,393 @@ + + + + LUCENE_40 + + + ./data/solr + + + + + + + true + + + + + + + + + + 10000 + 10000 + false + + + + + 1000 + + + + + + + + + + + + 1024 + + + + + + + + + + + + + true + + + + + + + + 10 + + + + + + + + + + + + + + + + + + true + + + 4 + + + + + + + + + + 100 + + + + + + + + 70 + + 0.5 + + [-\w ,/\n\"']{20,200} + + + + + + + ]]> + ]]> + + + + + + + + + + + + + + + + + explicit + + + + + + + + contents + + + + + + + + title,contents,authorId + 1 + + + + + + + + + + + application/json + + + + + application/csv + + + + + + + + + + + + + + + + + + solr + + + qt=standard&q=solrpingquery + + + + + diff --git a/etherpad/solr/collection1/conf/stopwords.txt b/etherpad/solr/collection1/conf/stopwords.txt new file mode 100644 index 0000000..8433c83 --- /dev/null +++ b/etherpad/solr/collection1/conf/stopwords.txt @@ -0,0 +1,57 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#----------------------------------------------------------------------- +# a couple of test stopwords to test that the words are really being +# configured from this file: +stopworda +stopwordb + +#Standard english stop words taken from Lucene's StopAnalyzer +an +and +are +as +at +be +but +by +for +if +in +into +is +it +no +not +of +on +or +s +such +t +that +the +their +then +there +these +they +this +to +was +will +with + diff --git a/etherpad/solr/collection1/conf/synonyms.txt b/etherpad/solr/collection1/conf/synonyms.txt new file mode 100644 index 0000000..b0e31cb --- /dev/null +++ b/etherpad/solr/collection1/conf/synonyms.txt @@ -0,0 +1,31 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#----------------------------------------------------------------------- +#some test synonym mappings unlikely to appear in real input text +aaa => aaaa +bbb => bbbb1 bbbb2 +ccc => cccc1,cccc2 +a\=>a => b\=>b +a\,a => b\,b +fooaaa,baraaa,bazaaa + +# Some synonym groups specific to this example +GB,gib,gigabyte,gigabytes +MB,mib,megabyte,megabytes +Television, Televisions, TV, TVs +#notice we use "gib" instead of "GiB" so any WordDelimiterFilter coming +#after us won't split it into two words. + +# Synonym mappings can be used for spelling correction too +pixima => pixma + diff --git a/etherpad/src/etherpad/admin/shell.js b/etherpad/src/etherpad/admin/shell.js new file mode 100644 index 0000000..86b8265 --- /dev/null +++ b/etherpad/src/etherpad/admin/shell.js @@ -0,0 +1,149 @@ +/** + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import("funhtml"); +import("funhtml.*"); +import("jsutils.cmp"); +import("jsutils.eachProperty"); +import("exceptionutils"); +import("execution"); +import("stringutils.trim"); + +import("etherpad.sessions.{getSession,saveSession}"); +import("etherpad.utils.*"); +import("etherpad.helpers"); + +function _splitCommand(cmd) { + var parts = [[], []]; + var importing = true; + cmd.split("\n").forEach(function(l) { + if ((trim(l).length > 0) && + (trim(l).indexOf("import") != 0)) { + importing = false; + } + + if (importing) { + parts[0].push(l); + } else { + parts[1].push(l); + } + }); + + parts[0] = parts[0].join("\n"); + parts[1] = parts[1].join("\n"); + return parts; +} + +function getResult(cmd) { + var resultString = (function() { + try { + var parts = _splitCommand(cmd); + result = execution.fancyAssEval(parts[0], parts[1]); + } catch (e) { + // if (e instanceof JavaException) { + // e = new net.appjet.bodylock.JSRuntimeException(e.getMessage(), e.javaException); + // } + if (appjet.config.devMode) { + (e.javaException || e.rhinoException || e).printStackTrace(); + } + result = exceptionutils.getStackTracePlain(e); + } + var resultString; + try { + resultString = ((result && result.toString) ? result.toString() : String(result)); + } catch (ex) { + resultString = "Error converting result to string: "+ex.toString(); + } + return resultString; + })(); + return resultString; +} + +function _renderCommandShell() { + // run command if necessary + if (request.params.cmd) { + var cmd = request.params.cmd; + var resultString = getResult(cmd); + + getSession().shellCommand = cmd; + getSession().shellResult = resultString; + saveSession(); + response.redirect(request.path+(request.query?'?'+request.query:'')); + } + + var div = DIV({style: "padding: 4px; margin: 4px; background: #eee; " + + "border: 1px solid #338"}); + // command div + var oldCmd = getSession().shellCommand || ""; + var commandDiv = DIV({style: "width: 100%; margin: 4px 0;"}); + commandDiv.push(FORM({style: "width: 100%;", + method: "POST", action: request.path + (request.query?'?'+request.query:'')}, + INPUT({type: "hidden", name: "xsrf", value:helpers.xsrfToken()}), + TEXTAREA({name: "cmd", + style: "border: 1px solid #555;" + + "width: 100%; height: 160px; font-family: monospace;"}, + html(oldCmd)), + INPUT({type: "submit"}))); + + // result div + var resultDiv = DIV({style: ""}); + var isResult = getSession().shellResult != null; + if (isResult) { + resultDiv.push(DIV( + PRE({style: 'border: 1px solid #555; font-family: monospace; margin: 4px 0; padding: 4px;'}, + getSession().shellResult))); + delete getSession().shellResult; + saveSession(); + resultDiv.push(DIV({style: "text-align: right;"}, + A({href: qpath({})}, "clear"))); + } else { + resultDiv.push(P("result will go here")); + } + + var t = TABLE({border: 0, cellspacing: 0, cellpadding: 0, width: "100%", + style: "width: 100%;"}); + t.push(TR(TH({width: "49%", align: "left"}, " Command:"), + TH({width: "49%", align: "left"}, " "+(isResult ? "Result:" : ""))), + TR(TD({valign: "top", style: 'padding: 4px;'}, commandDiv), + TD({valign: "top", style: 'padding: 4px;'}, resultDiv))); + div.push(t); + return div; +} + + +function render_main_post() { + // run command if necessary + if (request.params.cmd) { + var cmd = request.params.cmd; + var resultString = getResult(cmd); + + getSession().shellCommand = cmd; + getSession().shellResult = resultString; + response.redirect(request.path+(request.query ? '?' + request.query : '')); + } +} + + +function render_main_get() { + var body = funhtml.DIV(); + body.push(_renderCommandShell()); + renderHtml("admin/dynamic.ejs", { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Shell', + content: body + }); +} diff --git a/etherpad/src/etherpad/admin/sites.js b/etherpad/src/etherpad/admin/sites.js new file mode 100644 index 0000000..3acd05e --- /dev/null +++ b/etherpad/src/etherpad/admin/sites.js @@ -0,0 +1,60 @@ + +import("etherpad.utils.*"); +import("etherpad.pro.domains"); +import("sqlbase.sqlobj"); +import("etherpad.helpers"); + +function render_main_get() { + + // {subDomain, isPublic, accountCount, guestCount, adminCount, padCount} + sql = "select pro_domains.id, pro_domains.subDomain, count(*) as accountCount, count(CASE WHEN flags & 16 THEN 1 END) as guestCount from pro_accounts join pro_domains on pro_accounts.domainId = pro_domains.id group by pro_accounts.domainId;"; + var sites = sqlobj.executeRaw(sql, {}); + + sql = "select domainId, max(lastEditedDate) as lastEditedDate, count(*) as padCount from pro_padmeta group by domainId"; + var sitePadInfos = sqlobj.executeRaw(sql, {}); + + sql = "select domainId, jsonVal = '{\"x\":true}' as isPublic from pro_config where name = 'publicDomain'"; + var siteConfigInfos = sqlobj.executeRaw(sql, {}); + + var idToSiteInfo = {}; + sites.forEach(function(site) { + idToSiteInfo[site.id] = site; + }); + + sitePadInfos.forEach(function(sitePadInfo) { + // copy everything from the second query into the first + for (name in sitePadInfo){ + if (name != "domainId") { + if (idToSiteInfo[sitePadInfo.domainId]) { + idToSiteInfo[sitePadInfo.domainId][name] = sitePadInfo[name]; + } + } + } + }); + + siteConfigInfos.forEach(function(siteConfigInfo) { + // copy everything from the second query into the first + for (name in siteConfigInfo){ + if (name != "domainId") { + if (idToSiteInfo[siteConfigInfo.domainId]) { + idToSiteInfo[siteConfigInfo.domainId][name] = siteConfigInfo[name]; + } + } + } + }); + + sites.forEach(function(site) { + site.lastEditedDate = site.lastEditedDate ? helpers.prettyDate(site.lastEditedDate) : ""; + }); + + renderHtml("admin/dynamic.ejs", { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Sites', + content: renderTemplateAsString('admin/sites.ejs', { + sites: sites, + canonicalDomain: appjet.config['etherpad.canonicalDomain'], + }) + }); + +} \ No newline at end of file diff --git a/etherpad/src/etherpad/changes/changes.js b/etherpad/src/etherpad/changes/changes.js new file mode 100644 index 0000000..2b84dd0 --- /dev/null +++ b/etherpad/src/etherpad/changes/changes.js @@ -0,0 +1,889 @@ +import("execution"); +import("exceptionutils"); +import("stringutils"); +import("sqlbase.sqlobj"); +import("varz"); +import("jsutils.uniqueNumbers"); +import("crypto"); + +import("email.sendEmail"); + +import("etherpad.changes.follow.FOLLOW"); +import("etherpad.changes.follow.getUserFollowPrefsForPad"); + +import("etherpad.collab.ace.easysync2.Changeset"); +import("etherpad.collab.ace.linestylefilter.linestylefilter"); +import("etherpad.collab.ace.domline.domline"); + +import("etherpad.importexport.table.renderStaticTable"); + +import("etherpad.globals"); +import("etherpad.log"); +import("etherpad.pad.model"); +import("etherpad.pad.padusers"); +import("etherpad.pad.padutils"); +import("etherpad.pad.pad_security"); +import("etherpad.pro.domains"); +import("etherpad.pro.pro_apns"); +import("etherpad.pro.pro_utils"); +import("etherpad.pro.pro_padmeta"); +import("etherpad.pro.pro_accounts"); +import("etherpad.statistics.email_tracking"); + + +import("etherpad.utils"); +import("etherpad.utils.renderTemplateAsString"); +import("etherpad.collab.collab_server"); + +import("etherpad.helpers"); +import("etherpad.debug.dmesg"); + +import("funhtml"); +import("funhtml.*"); + + +function _getFollowers(globalPadId) { + var followers = sqlobj.selectMulti("PAD_FOLLOW", { 'id': globalPadId, 'followPref': FOLLOW.EVERY }); + return followers.map(function (r) { return r.userId; }); +} + +function _getColorsForEditors(historicalAuthorData) { + var colorIdForAuthor = {}; + for (var author in historicalAuthorData) { + var accountId = padusers.getAccountIdForProAuthor(author); + colorIdForAuthor[accountId] = historicalAuthorData[author].colorId; + } + return colorIdForAuthor; +} + +function accountIdsToNotifyTester (globalPadId, creatorId, guestPolicy) { + return _accountIdsToNotify(globalPadId, creatorId, guestPolicy); +} + +function _accountIdsToNotify(globalPadId, creatorId, guestPolicy) { + var peopleWithAccess = []; + + if (guestPolicy == "link") { + peopleWithAccess = pad_security.getInvitedUsers(globalPadId); + } else { + // people are only marked as having accessed if the pad is deny or friends + // when they visit. so it's *extremely* unreliable. + // still it's unsafe to not check for it or we'll spam a ton of people - + // especially in the "allow" case of public pads, but also for old school + // "friends" pads. + peopleWithAccess = pad_security.getInvitedUsersWhoAccessedPad(globalPadId); + } + + peopleWithAccess.push(creatorId); + + // filter etherpad admin and/or null creator id + peopleWithAccess = peopleWithAccess.filter(function(id) { return id; }); + + // don't send mail to invitees who don't want mail by default + var excludeList = {}; + pro_accounts.getAccountsByIds(peopleWithAccess).forEach(function(acct) { + if (pro_accounts.getAccountDoesNotWantFollowEmail(acct)) { + excludeList[acct.id] = true; + } + }); + peopleWithAccess = peopleWithAccess.filter(function(accountId){ return !excludeList[accountId] }); + + var followerPrefs = getUserFollowPrefsForPad(globalPadId, peopleWithAccess); + var authenticatedFollowers = peopleWithAccess.filter(function(accountId) { + return (followerPrefs[accountId] == FOLLOW.DEFAULT || + followerPrefs[accountId] == FOLLOW.EVERY); + }); + + // add all the followers who have access because the pad isn't invite only + if (guestPolicy != "deny") { + authenticatedFollowers = authenticatedFollowers.concat(_getFollowers(globalPadId)); + } + + return uniqueNumbers(authenticatedFollowers); +} + + +function _sendEmailsAboutChanges(globalPadId, padTitle, htmlParts, accountIdsOfChangeAuthors, mentionedUserIds, accountIds, revNum, optNotifyEditors) { + + for (var i=0; iTo stop receiving email about changes to this pad, unsubscribe.

"; + htmlPartsForSending.splice(htmlPartsForSending.length-1, 0, unsubText); + + var trackingId = email_tracking.trackEmailSent(acct.email, email_tracking.CHANGES, 1); + + // come up with email subject + var subj = "hackpad: " + padTitle + " edited"; + _sendEmail(globalPadId, revNum, subj, acct, htmlPartsForSending, trackingId); + } +} + + +function _sendEmailsAboutMentions(globalPadId, padTitle, htmlParts, changeAuthorIds, mentionedUserIds, revNum) { + for (var i=0; iApprove This Change

"; + var htmlParts = _getHTMLForChanges(pad, padTitle, segments, colorIdForAuthor, approveChangesHTML); + if (htmlParts && htmlParts.length) { + // come up with email subject + var authors = []; + for (var i=0; iemail settings"; + emailHeader = padLinkHtml + " (" +padEmailSettingsHtml +") - edited by "; + } + + var isTrivial = true; + for (var i=0; i"); + + if (opt_approveChangesHTML) { + htmlParts.push("

To reject this change, just ignore this email

"); + } else { + htmlParts.push("

Reply to this email directly or edit it live on hackpad: " + padTitle + "

"); + } + + htmlParts.push(""); + + return htmlParts; + +} + +function _getProAuthorIdsForChange(pad, segment) { + var proAuthorIds = []; + if (!segment[2]) { + return []; + } + for (var i=0; i 20) { + delayMinutes = 60; + } + dmesg("syndication delay is: " + delayMinutes); + + var now = new Date(); + var segmentsForSyndication = []; + for (var j=0; j delayMinutes * MINUTES) { + dmesg("segment is " + String(now.getTime() - segmentDate.getTime()) +"old"); + segmentsForSyndication = segments.slice(j); + break; + } + } + return segmentsForSyndication; +} + +function _sendEmail(globalPadId, revNum, subj, acct, html, trackingId) { + var localPadId = padutils.globalToLocalId(globalPadId); + var fromAddr = pro_utils.getEmailFromAddr(); + var body = html.join("\n"); + + // render the email with tracking ids filled out + body = body.replace(TRACKING_ID_GUID_RE, trackingId || "") + + var inReplyToId = "<" + localPadId + "@" + _domainForPadId(globalPadId) + ">"; + var referencesId = "<" + localPadId + '+' + revNum + "@" + _domainForPadId(globalPadId) + ">"; + var headers = { "In-Reply-To": inReplyToId, "References": referencesId, + "Content-Transfer-Encoding": "quoted-printable", + "Content-Type": "text/plain; charset=\"utf-8\"" }; + + try { + dmesg("SENDING EMAIL TO" + acct.id); + log.custom("changesemail", {userId: padusers.getUserIdForProUser(acct.id), toEmails: acct.email, padId: globalPadId}); + sendEmail(acct.email, fromAddr, subj, headers, body, "text/html; charset=utf-8"); + varz.incrementMetric("changes-mail-send-succeeded"); + } catch (ex) { + varz.incrementMetric("changes-mail-send-failed"); + log.logException("Failed to send email to: " + acct.email + "(" + ex + ")"); + } +} + + +function authorNames(authorNums, colorIdForAuthor, asHTML, relativeUrlPrefix, pad) { + var authors = []; + for (var i=0; i" + SPAN(authorName) + ""); + } else { + authors.push("" + SPAN(authorName) + ""); + } + } else { + authors.push(authorName); + } + } + } + + return authors; +} + +function getDiffHTML(pad, revNum, revisionIdTo, authorNums, colorIdForAuthor, includeTimestamps, byLineHeader, includeDeletes, optDiffCs, optNotEmail, optIncludeRevertLink) { + + var diffAndAuthors = getDiffAndAuthorsHTML(pad, revNum, revisionIdTo, authorNums, colorIdForAuthor, includeDeletes, optDiffCs, optNotEmail); + + var authorHTMLParts = []; + authorHTMLParts.push('
'); + var byLine = byLineHeader + diffAndAuthors.authorsHTML; + if (includeTimestamps) { + var revDate = helpers.prettyDate(pad.getRevisionDate(revNum)); + byLine += (" - " + revDate); + } + authorHTMLParts.push(byLine); + if (optIncludeRevertLink) { + var localPadId = padutils.globalToLocalId(pad.getId()); + authorHTMLParts.push(SPAN(" - ")); + + if (optNotEmail) { + // web + authorHTMLParts.push(funhtml.FORM({action: '/ep/pad/'+localPadId+'/revert-to/'+revNum, method: 'POST', + style: 'display: inline'}, + helpers.xsrfTokenElement(), + funhtml.INPUT({type: 'submit', name:'submit', value:'Revert this' }))); + } else { + // no revert links in email + authorHTMLParts.push(A({ href:'/ep/pad/summary/' + encodeURIComponent(localPadId)}, 'View history')); + } + + } + authorHTMLParts.push('
\n'); + + if (diffAndAuthors.diffHTML && diffAndAuthors.authorsHTML) { + return authorHTMLParts.join('') + diffAndAuthors.diffHTML; + } else { + return ''; + } +} + +/* +@returns {diffHTML:.., authorsHTML:} +*/ +function getDiffAndAuthorsHTML(pad, revNum, revisionIdTo, authorNums, colorIdForAuthor, includeDeletes, optDiffCs, optNotEmail, maxLines, optHideElipsis) { + + var relativeUrlPrefix = (appjet.config.useHttpsUrls ? "https://" : "http://") + _domainForPadId(pad.getId()); + + // authors html + var authorsHTMLParts = authorNames(authorNums, colorIdForAuthor, true/*asHTML*/, relativeUrlPrefix, pad); + var authorsHTML = authorsHTMLParts.join(", "); + + // diff html + var pieces = []; + var atextAndPool = null; + if (optDiffCs) { + atextAndPool = pad.getDiffATextForChangeset(optDiffCs, revNum, includeDeletes); + } else { + atextAndPool = pad.getDiffATextForChangeRange(revNum, revisionIdTo, includeDeletes); + } + + if (atextAndPool == null) { + // There are no changes in this range + return ''; + } + var atext = atextAndPool[0]; + var apool = atextAndPool[1]; + + var textlines = Changeset.splitTextLines(atext.text); + var alines = Changeset.splitAttributionLines(atext.attribs, + atext.text); + + function classToStyle (classes) { + var classes = classes.split(" "); + var styles = []; + + if (classes.indexOf("added") > -1) { + // fa-author-p-1 / author-p-1 -> 1 + // if it's fa-author, don't add color + if (classes[0].slice(0,2) == "fa") { + // + } else { + var userId = linestylefilter.className2Author(classes[0]); + if (!userId) { + // No author for added line + styles.push("color:#999"); // ignore for now + } else { + userId = padusers.getAccountIdForProAuthor(userId); + // look up author color + var colorId = colorIdForAuthor[userId]; + var color = globals.getPalette()[colorId % globals.getPalette().length]; + styles.push("border-bottom: 2px dotted " + color); + } + } + } else if (classes.indexOf("removed") >= 0) { + styles.push("color: #999"); + styles.push("text-decoration:line-through"); + } else { + styles.push("color: #999"); + } + + //log.info("Classes are " + classes.join(" ")); + //log.info("Styles are " + styles.join(";")); + + return styles.length ? styles.join(";") : ""; + } + + var browser = optNotEmail ? "stream" : "email"; + var atStart = true; + var i = 0; + var lastSeenShortName = ''; + var lastSeenCommentShortName = ''; + for(;i -1) { + if (shortName && shortName != lastSeenShortName) { + nameToShow = shortName; + lastSeenShortName = shortName; + } + } + + if (node.className.indexOf('line-list-type-comment') > -1) { + if (shortName && shortName != lastSeenCommentShortName) { + nameToShow = shortName; + lastSeenCommentShortName = shortName; + } + } + + pieces.push('
'); + var userId = _getLineUserId(pad, node); + if (userId && browser != 'email' && nameToShow) { + accountId = padusers.getAccountIdForProAuthor(userId); + var color = _getLineAuthorColor(domInfo.node, colorIdForAuthor); + var colorStyle = color ? 'color:' + color : ''; + pieces.push('' + SPAN(nameToShow) + ''); + } + if (browser == "email") { + pieces.push('', + node.innerHTML, ''); + } else { + pieces.push(node.innerHTML); + } + pieces.push('
\n'); + } + } + + if (i == maxLines && !optHideElipsis) { + pieces.push('
...
'); + } + + return {diffHTML: pieces.join(''), authorsHTML:authorsHTML}; +} + +function _getLineAuthorColor(node, colorIdForAuthor) { + var classes = node.className.split(" "); + for (var i=0; i p.1 + var userId = linestylefilter.className2Author(classes[i]); + if (userId) { + var accountId = padusers.getAccountIdForProAuthor(userId); + var colorId = colorIdForAuthor[accountId]; + var color = globals.getPalette()[colorId % globals.getPalette().length]; + if (color) { + return color; + } + return null; + } + } + return null; +} + +function _getLineUserId(pad, node) { + var classes = node.className.split(" "); + for (var i = 0; i < classes.length; i++) { + // fa-author-p-1 / author-p-1 -> p.1 + var userId = linestylefilter.className2Author(classes[i]); + if (userId) { + return userId; + } + } + return null; +} + +function _getLineAuthorName(pad, node) { + var userId = _getLineUserId(pad, node); + if (userId) { + return getAuthorName(userId, pad); + } + return null; +} + +function getAuthorName(authorNum, pad) { + var authorName; + if (pad) { + var authorInfo = pad.getAuthorData(authorNum); + if (authorInfo) { + authorName = authorInfo.name; + } else { + log.warn("Cannot find author data for author " + authorNum + " in pad " + pad.getId()); + authorName = null; + } + } + if (!authorName) { + authorName = padusers.getNameForUserId(authorNum); + } + return authorName || ""; +} + +function getShortNameFromFullName(fullName) { + if (fullName) { + var authorInitials = fullName.split(' '); + return authorInitials.length == 1 ? authorInitials[0] : + authorInitials[0] + ' ' + authorInitials[authorInitials.length - 1][0]; + } + + return ''; +} + +function _wholeLineStyleForNode(node, colorIdForAuthor) { + var color = _getLineAuthorColor(node, colorIdForAuthor); + + if (color && node.className.indexOf("allAdd") > -1) { + return "border-left-color:" + color + ";"; + } else { + return "border-left-color: white;"; + } +} + + +function _convertEmbedToAnchor(src) { + return '' + src + ''; +} + +serverhandlers.tasks.changeSyndicationTask = function() { + try { + syndicateChanges(); + } finally { + execution.scheduleTask('changes', "changeSyndicationTask", 2*60*1000, []); + } +} + +function onStartup() { + if (appjet.config['etherpad.syndicateChanges'] == "true") { + execution.initTaskThreadPool("changes", 1); + execution.scheduleTask('changes', "changeSyndicationTask", 60*1000, []); + } else { + dmesg("Not syndicating pad changes."); + } +} diff --git a/etherpad/src/etherpad/changes/digest.js b/etherpad/src/etherpad/changes/digest.js new file mode 100644 index 0000000..9a38d25 --- /dev/null +++ b/etherpad/src/etherpad/changes/digest.js @@ -0,0 +1,178 @@ +/* + Tell people about activity they may have missed in their workspace +*/ + +import("execution"); +import("jsutils"); +import("etherpad.log"); +import("etherpad.changes.follow"); +import("etherpad.pad.padutils"); +import("etherpad.pro.pro_accounts"); +import("etherpad.pro.pro_key_values"); +import("etherpad.pro.domains"); +import("etherpad.pro.pro_pad_db"); +import("etherpad.pro.pro_utils"); +import("etherpad.utils.renderTemplateAsString"); +import("etherpad.utils"); +import("email.sendEmail"); +import("etherpad.statistics.email_tracking"); + +function onStartup() { + if (appjet.config['etherpad.sendDigest']) { + execution.initTaskThreadPool("digest", 1); + _scheduleNextDailyBatch('digest', 'dailyActivityDigestBatch', {hour:15, minute:15}); + } else { + log.info("Not syndicating digest"); + } +} + +function _scheduleNextDailyBatch(threadPool, jobName, when) { + var now = +(new Date); + var tomorrow = new Date(now + 1000*60*60*24); + tomorrow.setHours(when.hour); + tomorrow.setMinutes(when.minute); + tomorrow.setMilliseconds(00); + log.info("Scheduling next daily batch for: " + tomorrow.toString()); + var delay = +tomorrow - (+(new Date)); + execution.scheduleTask(threadPool, jobName, delay, []); +} + +serverhandlers.tasks.dailyActivityDigestBatch = function() { + try { + sendDailyActivityDigestEmails(); + } catch (ex) { + log.warn("digest.dailyActivityDigestBatch() failed: "+ex.toString()); + } finally { + _scheduleNextDailyBatch('digest', 'dailyActivityDigestBatch', {hour:15, minute:15}); + } +} + +function _dayDiff(firstDate, secondDate) { + return (secondDate.getTime() - firstDate.getTime()) / (1000 * 60 * 60 * 24.0); +} + +function sendDailyActivityDigestEmails() { + var batchInfo = {batchSize: 100}; + var allDomains = domains.getAllDomains(); + var digestUsers = {/* email : accounts */}; + var digestPads = {/* email : newPads */}; + + for (var i=0; i -1) { + return; + } + // at most once per week + if (user.lastSentDigest && (_dayDiff(user.lastSentDigest, new Date()) < 6.5)){ + return; + } + + // exclude the pad if i'm a creator or follower (or have unfollowed) + followPrefs = follow.getUserIdsWithFollowPrefsForPads(newPads.map(function(row){return padutils.getGlobalPadId(row.localPadId, row.domainId) })); + newPads.forEach(function(newPad) { + var globalPadId = padutils.getGlobalPadId(newPad.localPadId, newPad.domainId); + if ((!user.lastSentDigest || newPad.lastEditedDate > user.lastSentDigest) && + newPad.guestPolicy in {'allow':1, 'domain':1} && + newPad.creator != null && + newPad.creatorId != user.id && + newPad.title != "Untitled" && + newPad.title != "" && + newPad.title != "Welcome to hackpad - the collaborative notepad" && + newPad.title != null && + (!followPrefs[globalPadId] || followPrefs[globalPadId].indexOf(user.id) == -1)) { + digestUsers[user.email] = digestUsers[user.email] || {}; + digestUsers[user.email][user.domainId] = user; + digestPads[user.email] = digestPads[user.email] || []; + digestPads[user.email].push(newPad); + } + }); + }); + } + for (email in digestUsers) { + sendDigestForUser(email, jsutils.values(digestUsers[email]), digestPads[email], dictByProperty(allDomains, 'id')); + } +} +function dictByProperty(array, propertyName) { + var dict = {} + array.forEach(function(item) { + dict[item[propertyName]] = item; + }); + return dict; +} + +function sendDigestForUser(email, accounts, pads, domainById) { + var accountIds = accounts.map(function(acct){ return acct.id }); + + pro_key_values.updateValueForAccounts(accountIds, 'lastSentDigest', new Date()); + + var fromAddr = pro_utils.getEmailFromAddr(); + var padsByDomainId = {/*domainId: pads*/}; + pads.forEach(function(row) { + padsByDomainId[row.domainId] = padsByDomainId[row.domainId] || []; + padsByDomainId[row.domainId].push(row); + }); + + + var domainNames = accounts.map(function(acct){ + return domainById[acct.domainId].subDomain; + }); + + var subject = "New pads added to " + domainNames.join(", "); + + var trackingId = email_tracking.trackEmailSent(email, email_tracking.NEW_PADS_DIGEST, 1); + + var unsubURL = utils.absoluteSignedURL("/ep/account/settings/unsub-new-pads", {accountId: pro_accounts.getEncryptedUserId(accounts[0].id)}) + + for (domainId in padsByDomainId) { + padsByDomainId[domainId] = padsByDomainId[domainId].reverse(); + } + + var body = renderTemplateAsString( + 'email/digest_new_pads.ejs', { + domainById:domainById, + accounts: accounts, + padsByDomainId: padsByDomainId, + fullName: accounts[0].fullName, + timeAgo: utils.timeAgo, + absolutePadURL: utils.absolutePadURL, + absoluteProfileURL: utils.absoluteProfileURL, + unsubURL: unsubURL, + trackingId: trackingId + } + ); + + log.custom("digest", {userIds: accountIds, fullName: accounts[0].fullName, email: email}); + + // send the email + try { + sendEmail(email, fromAddr, subject, {}, body, "text/html; charset=utf-8"); + } catch(e) { + log.logException("Failed to send email: " + email); + } + +} + + diff --git a/etherpad/src/etherpad/changes/email.js b/etherpad/src/etherpad/changes/email.js new file mode 100644 index 0000000..6583815 --- /dev/null +++ b/etherpad/src/etherpad/changes/email.js @@ -0,0 +1,564 @@ + +import("email.sendEmail"); +import("execution"); +import("sqlbase.sqlobj"); +import("stringutils.{startsWith,endsWith,trim}"); + +import("etherpad.debug.dmesg"); +import("etherpad.globals.isProduction"); +import("etherpad.log"); +import("etherpad.collab.collab_server"); +import("etherpad.collab.ace.easysync2.Changeset"); +import("etherpad.control.pad.pad_control"); +import("etherpad.pad.pad_access"); +import("etherpad.pad.padevents"); +import("etherpad.pad.model.accessPadGlobal"); +import("etherpad.pad.padutils.{makeGlobalId,globalToLocalId}"); +import("etherpad.pad.padusers"); +import("etherpad.pad.padusers.getUserIdForProUser"); +import("etherpad.pro.domains"); +import("etherpad.pro.pro_accounts"); +import("etherpad.pro.pro_invite"); + +import("etherpad.pro.pro_padmeta.accessProPad"); +import("etherpad.pro.pro_utils"); +import("etherpad.utils.{randomUniquePadId,renderTemplateAsString}"); + +jimport('java.lang.System'); +jimport("javax.mail.Session"); +jimport("javax.mail.Folder"); +jimport("javax.mail.Flags"); +jimport("javax.mail.Flags.Flag"); +jimport("javax.mail.search.FlagTerm"); +jimport("javax.mail.FolderClosedException"); + +var IMAP_STORE = null; + +function _insertResponseText(globalPadId, revNum, userId, userName, text, newParagraph) { + log.custom("inbox", "Email append to globalPadId: " + globalPadId + " at revNum:" + revNum); + dmesg("Appending email text:" + text); + + // Make the appended text a new paragraph + if (newParagraph) { + text = "\n\n" + text; + } + + var success = accessPadGlobal(globalPadId, function(pad) { + if (!pad.exists()) { + log.custom("inbox", "Reply email globalPadId " + globalPadId + " does not exist. Skipping."); + return false; + } + + if (pad.getIsModerated()) { + log.custom("inbox", "Reply email globalPadId " + globalPadId + " is moderated. Skipping."); + return false; + } + + userId = userId || userName; + + var authorData = null; + var authorId = null; + dmesg("User id " + userId ); + + if (padusers.isGuest(userId)) { + authorId = userId; + authorData = pad.getAuthorData(authorId); + } else if (userId) { + authorId = getUserIdForProUser(userId); + authorData = pad.getAuthorData(authorId); + } + + dmesg("Author id " + authorId ); + + if (!authorData) { + authorData = { colorId: pad_control.assignColorId(pad, userId), name: userName }; + dmesg("Author data " + authorData ); + + pad.setAuthorData(authorId, authorData); + } + + // append to end of revNum + revNum = revNum || pad.getHeadRevisionNumber(); + var oldText = pad.getInternalRevisionText(revNum); + var changeset = Changeset.makeSplice(oldText, oldText.length, 0, text, + [['author', authorId]], pad.pool()); + collab_server.applyUserChanges(pad, revNum, changeset, null, authorId); + + padevents.onEditPad(pad, authorId); + + return true; + }, "rw", true); + + if (success && userId) { + pad_access.updateUserIdLastAccessedDate(globalPadId, userId); + } + + return success; +} + +/* +Mail content type: multipart/MIXED; boundary=0016e6db29661b127504b777e454 +info: 2012-01-26 16:54:42.018-0800 Multipart message #2289no text/plain part. +*/ + +function _getPlainText(msg, recursing) { + // if this is called, the message is marked as read + var content = msg.getContent(); + + dmesg("Email content type: " + msg.getContentType()); + var text; + + if (startsWith(msg.getContentType().toLowerCase(), "text/plain")) { + text = msg.getContent(); + } else { + // Multipart multipart = (Multipart) msg[i].getContent(); + + // multipart content + if (content.getCount) { + for (var i = 0; i < content.getCount(); i++) { + var part = content.getBodyPart(i); + text = _getPlainText(part, true); + if (text) { + break; + } + } + } + + if (!text && !recursing) { + log.custom("inbox", "Multipart message #" + msg.getMessageNumber() + " no text/plain part."); + return ""; + } + } + + return text; +} + +function _parseResponseText(msg) { + var text = _getPlainText(msg); + + // arbitrarily complex + var newstuff = ""; + var lines = text.split("\n"); + for (var i in lines) { + var line = trim(lines[i]); + if (!line) { + newstuff += "\n\n"; + continue; + } else if (startsWith(line, ">") || + startsWith(line, "From: ") || + startsWith(line, "Subject: ") || + startsWith(line, "Date: ") || + startsWith(line, "Subject: ") || + startsWith(line, "To: ") || + startsWith(line, "Cc: ") || + line == "---------- Forwarded message ----------" || + (startsWith(line, "On ") && endsWith(line, "> wrote:"))) { + continue; + } + + newstuff += " " + line; + } + + return trim(newstuff); +} + +function authorForLine(content){ + var authorMatch = /On .*, ([^,]+)( <(.+@.+\..+)> )?\s?wrote:/.exec(content); + if (!authorMatch) { + authorMatch = /From: (.*) (<(.+@.+\..+)>)/.exec(content); + } + if (!authorMatch) { + authorMatch = /From: \*(.*)\* (<(.+@.+\..+)>)/.exec(content); + } + if (!authorMatch) { + authorMatch = /From: (.*) \[mailto:(.+@.+\..+)\]/.exec(content); + } + if (authorMatch) { + dmesg(authorMatch[1] + "10"); + return {name: authorMatch[1], email: authorMatch[3], confidence:10}; + } + + authorMatch = /[\d\/] (.*) (<(.+@.+\..+)>)\s*$/.exec(content); + if (authorMatch) { + dmesg(authorMatch[1] + "5"); + return {name: authorMatch[1], email: authorMatch[3], confidence:5}; + } + + authorMatch = /(.*) wrote:\s*$/.exec(content); + if (authorMatch) { + dmesg(authorMatch[1] + "1"); + return {name: authorMatch[1], email: authorMatch[1], confidence: 1}; + } + + dmesg(content + "no match"); + return null; +} + +function parseLine(line) { + line = trim(line.replace(/\*/g, "")); + var quotedMatch = /^([>\s]*)\s?(.*)/.exec(line); + var level = quotedMatch[1].replace(/\s/g, "").length; + var content = quotedMatch[2]; + return {text: content, level:level}; +} + + +function _parseCreateText(msg, author) { + var text = _getPlainText(msg); + if (!text) { + return []; + } + + var segments = []; + + var currentSegmentAuthor = author; + var currentSegmentLines = []; + + var lines = text.split("\n"); + var currentLevel = 0; + var ignoreRestOfLevel = false; + + var lineInfo; + var lastLineWasEmpty = false; + for (var i=0; i 5) { + // skip next line + i++; + author = altAuthor; + } + } + + // if so, end current segment, start next one + if (author) { + segments.push([currentSegmentAuthor, currentSegmentLines]); + currentSegmentAuthor = author.name; + currentSegmentLines = []; + ignoreRestOfLevel = false; + continue; + } + + // skip all following lines on the same level + if (ignoreRestOfLevel) { + if (lineInfo.level == currentLevel) { + continue; + } + ignoreRestOfLevel = false; + } + + + // ignore these lines: + if (startsWith(lineInfo.text, "Subject: ") || + startsWith(lineInfo.text, "Date: ") || + startsWith(lineInfo.text, "Subject: ") || + startsWith(lineInfo.text, "To: ") || + startsWith(lineInfo.text, "Cc: ") || + lineInfo.text == "---------- Forwarded message ----------"){ + continue; + } + + // now sure how general this is.. + if (lineInfo.text == "_______________________________________________" || + lineInfo.text == "--" || + lineInfo.text == "___") { + ignoreRestOfLevel = true; + continue; + } + + // trim leading whitespace lines + if (/^\s*$/.test(lineInfo.text) && !currentSegmentLines.length) { + continue; + } + + currentSegmentLines.push(lineInfo.text); + } + + // add the final segment + if (currentSegmentLines.length) { + segments.push([currentSegmentAuthor, currentSegmentLines]); + } + + segments = segments.reverse(); + + // trim whitespace lines in the other direction + for (var i=0; i/); + if (m) { + if (m[4]) { + var domain = domains.getDomainRecordFromSubdomain(m[4]); + if (!domain) { return null; } + domainId = domain.id; + } + + var acct = _getAccount(msg, domainId); + if (!acct) { return null; } + var globalPadId = makeGlobalId(domainId, m[1]); + + var revNum = (m[2] == "undefined" ? null : m[2]); + return { padId: globalPadId, revNum: revNum, acct: acct, type: 'reply' }; + } + } + + // creating a new pad + var msgId = msg.getHeader("Message-ID") || []; + var newMailReferences = msgId.join(" ") + " " + referencesIds.join(" "); + + domainId = _getDomainIdFromRecipientAddress(msg); + + var acct = _getAccount(msg, domainId); + if (!acct) { return null; } + + log.custom("inbox", "Message #" + msg.getMessageNumber() + " not a change reply. Creating new pad."); + return { acct: acct, type: 'create', references: newMailReferences }; +} + +function processInbox() { + if (!isProduction()) { + return; + } + + var inbox = _getInbox(); + try { + var msgs = _fetchUnreadMail(inbox); + + for (var i in msgs) { + var msg = msgs[i]; + + var ctx = _getMessageContext(msg); + if (!ctx) { continue; } + + if (ctx.acct && !domains.domainIsOnThisServer(ctx.acct.domainId)) { + log.custom("inbox", "Skipping an email for a different domain."); + // let the appropriate server handler it +// msg.setFlags(new Flags(Flag.SEEN), false); +// msg.saveChanges(); + continue; + } + + var txt = ""; + var segments = []; + if (ctx.type == "create") { + //(ctx.acct && ctx.acct.fullName) || "") + segments = _parseCreateText(msg, ctx.acct.fullName); + } else { + txt =_parseResponseText(msg); + } + + if (ctx.type == "reply") { + if (!txt) { + log.custom("inbox", "Skipping empty change reply email."); + continue; + } + var cleanSubject = msg.getSubject() || ""; + if (cleanSubject.indexOf("[Auto-Reply]") == 0 || + cleanSubject.indexOf("Automatic reply") == 0) { + + log.custom("inbox", "Skipping auto-reply change reply email."); + continue; + } + + _insertResponseText(ctx.padId, ctx.revNum, ctx.acct.id, ctx.acct.fullName, txt, true); + + } else if (ctx.type == "create") { + var newLocalPadId = randomUniquePadId(ctx.acct.domainId); + var newPadId = makeGlobalId(ctx.acct.domainId, newLocalPadId); + var cleanSubject = msg.getSubject() || ""; + if (startsWith(cleanSubject.toLowerCase(), "re: ")) { + cleanSubject = cleanSubject.substr(4); + } else if (startsWith(cleanSubject.toLowerCase(), "fwd: ")) { + cleanSubject = cleanSubject.substr(5); + } + + // future: if the cleanSubject start with ">", try to find a pad with that name to + // append to + + accessPadGlobal(newPadId, function(pad) { + pad.create(cleanSubject, cleanSubject); + accessProPad(newPadId, function(ppad) { + ppad.setCreatorId(ctx.acct.id); + ppad.setLastEditor(ctx.acct.id); + ppad.setLastEditedDate(new Date()); + }); + _insertResponseText(newPadId, pad.getHeadRevisionNumber(), ctx.acct.id, ctx.acct.fullName, "\n", false); + var guestAuthors = {}; + for (var j=0; j -1) { + // rate limited, try again later + } else { + log.logException(e); + } + } catch (e) { + log.logException(e); + } finally { + execution.scheduleTask('email', "processInbox", 10*1000, []); + } +} + +function onStartup() { + if (appjet.config['etherpad.processInbox'] == "true") { + execution.initTaskThreadPool("email", 1); + execution.scheduleTask('email', "processInbox", 60*1000, []); + } else { + dmesg("Not processing email inbox."); + } +} diff --git a/etherpad/src/etherpad/changes/follow.js b/etherpad/src/etherpad/changes/follow.js new file mode 100644 index 0000000..b39eabf --- /dev/null +++ b/etherpad/src/etherpad/changes/follow.js @@ -0,0 +1,193 @@ +import("sqlbase.sqlobj"); +import("etherpad.pad.pad_access"); +import("etherpad.pad.padusers"); +import("etherpad.pad.padutils"); +import("etherpad.pad.pad_security"); +import("etherpad.pad.model"); +import("etherpad.collab.collab_server"); +import("etherpad.pro.pro_accounts"); +import("etherpad.pro.pro_groups"); +import("etherpad.pro.pro_pad_db"); +import("etherpad.pro.pro_padmeta"); +import("etherpad.changes.follow") +import("etherpad.log"); + +// fix: send mail to folks invited, even if not editors +// fix: have a single thread per pad, don't group + +var FOLLOW = { + DEFAULT : 0, + IGNORE : 1, + EVERY : 2, + DAILY_PER_PAD : 3, + DAILY_OVERALL : 4, + NO_EMAIL: 5, +}; + +function getUserFollowPrefsForPad(padId, userIds) { + var followPrefs = sqlobj.selectMulti('PAD_FOLLOW', {id: padId, userId: ['in', userIds]}); + + var followPrefsByUserId = {}; + for (var i=0; i -1; }) + .map(function(groupId) { return pro_groups.getEncryptedGroupId(groupId) }); + + _getPadConnections(pad).forEach(function(connection) { + var userInfo = { + name: fullName, + userId: padusers.getUserIdForProUser(userId), + userLink: pro_accounts.getUserLinkById(userId), + userPic: pro_accounts.getPicById(userId), + status: "invited", + colorId: 1, + groups: userGroups + }; + _sendUserInfoMessage(connection.connectionId, "USER_NEWINFO", userInfo); + }); + }, 'r'); +} + +function announceNewUserInfo(globalPadId, userId, fullName, colorId) { + // requires that we somehow have permission on this pad + model.accessPadGlobal(globalPadId, function(pad) { + _getPadConnections(pad).forEach(function(connection) { + var userInfo = { + name: fullName, + userId: padusers.getUserIdForProUser(userId), + colorId: colorId, + }; + _sendUserInfoMessage(connection.connectionId, "EDITOR_NEWINFO", userInfo); + }); + }, 'r'); +} + +function announceGroupPadRemoval(globalPadId, groupId) { + // requires that we somehow have permission on this pad + model.accessPadGlobal(globalPadId, function(pad) { + _getPadConnections(pad).forEach(function(connection) { + var groupInfo = { + groupId: pro_groups.getEncryptedGroupId(groupId) + }; + _sendUserInfoMessage(connection.connectionId, "GROUP_REMOVEPAD", groupInfo); + }); + }, 'r'); +} + +function announceGroupInvite(globalPadId, groupId, name, userCnt) { + // requires that we somehow have permission on this pad + model.accessPadGlobal(globalPadId, function(pad) { + _getPadConnections(pad).forEach(function(connection) { + var groupInfo = { + name: toHTML(name), + groupId: pro_groups.getEncryptedGroupId(groupId), + userCnt: userCnt }; + _sendUserInfoMessage(connection.connectionId, "GROUP_NEWINFO", groupInfo); + }); + }, 'r'); +} + +function announceKillUser(globalPadId, userId) { + // requires that we somehow have permission on this pad + model.accessPadGlobal(globalPadId, function(pad) { + _getPadConnections(pad).forEach(function(connection) { + var userInfo = { userId: userId }; + _sendUserInfoMessage(connection.connectionId, "USER_KILL", userInfo); + }); + }, 'r'); +} + + +function _verifyUserId(userId) { + var result; + if (padusers.isGuest(userId)) { + // allow cookie-verified guest even if user has signed in + result = (userId == padusers.getGuestUserId()); + } + else { + result = (userId == padusers.getUserId()); + } + return result; +} + +function _checkChangesetAndPool(cs, pool) { + Changeset.checkRep(cs); + Changeset.eachAttribNumber(cs, function(n) { + if (! pool.getAttrib(n)) { + throw new Error("Attribute pool is missing attribute "+n+" for changeset "+cs); + } + }); +} + +function _doWarn(str) { + log.warn(appjet.executionId+": "+str); +} + +function _doInfo(str) { + log.info(appjet.executionId+": "+str); +} + +function _getPadRevisionSockets(pad) { + var revisionSockets = pad.tempObj().revisionSockets; + if (! revisionSockets) { + revisionSockets = {}; // rev# -> socket id + pad.tempObj().revisionSockets = revisionSockets; + } + return revisionSockets; +} + +function applyUserChanges(pad, baseRev, changeset, optSocketId, optAuthor) { + // changeset must be already adapted to the server's apool + + var apool = pad.pool(); + var r = baseRev; + while (r < pad.getHeadRevisionNumber()) { + r++; + var c = pad.getRevisionChangeset(r); + changeset = Changeset.follow(c, changeset, false, apool); + } + + var prevText = pad.text(); + if (Changeset.oldLen(changeset) != prevText.length) { + _doWarn("Can't apply USER_CHANGES "+changeset+" to document of length "+ + prevText.length + " (baseRev:" + baseRev + ", headRev:" + r + ", oldLen:" + Changeset.oldLen(changeset) + ")"); + return; + } + + + var thisAuthor = ''; + if (optSocketId) { + var connectionId = getSocketConnectionId(optSocketId); + if (connectionId) { + var connection = getConnection(connectionId); + if (connection) { + thisAuthor = connection.data.userInfo.userId; + } + } + } + if (optAuthor) { + thisAuthor = optAuthor; + } + + pad.appendRevision(changeset, thisAuthor); + var newRev = pad.getHeadRevisionNumber(); + if (optSocketId) { + _getPadRevisionSockets(pad)[newRev] = optSocketId; + } + + var correctionChangeset = _correctMarkersInPad(pad.atext(), pad.pool()); + if (correctionChangeset) { + pad.appendRevision(correctionChangeset); + } + + var newTitle = null; + + ///// make document end in blank line if it doesn't: + if (pad.text().lastIndexOf("\n\n") != pad.text().length-2) { + var nlChangeset = Changeset.makeSplice( + pad.text(), pad.text().length-1, 0, "\n"); + pad.appendRevision(nlChangeset); + } + + updatePadClients(pad); + + /* In the client, when editing first line, call pad.notifyChangeTitle instead of doing it here? */ + /* Need to trim text so we always have a title. Need to call cleanText here? */ + if (!pad.getTitleIsReadOnly()) { + var prevTitle = trim(prevText.substring(0, prevText.indexOf('\n'))); + var newText = pad.text(); + newTitle = trim(newText.substring(0, newText.indexOf('\n'))); + newTitle = newTitle.replace(/^\*/, ''); + newTitle = newTitle.substring(0, pro_padmeta.MAX_TITLE_LENGTH); + + if (prevTitle != newTitle) { + _getPadConnections(pad).forEach(function(connection) { + sendMessage(connection.connectionId, {type: "CLIENT_MESSAGE", payload: { + type: "padtitle", title: newTitle } }); + }); + // what he said ^ :) + /*pro_padmeta.accessProPad(pad.getId(), function(propad) { + propad.setTitle(newTitle); + });*/ + } + } + + activepads.touch(pad.getId()); + padevents.onEditPad(pad, thisAuthor, newTitle); +} + +function updateClient(pad, connectionId) { + var conn = getConnection(connectionId); + if (! conn) { + return; + } + var lastRev = conn.data.lastRev; + var userId = conn.data.userInfo.userId; + var socketId = conn.socketId; + while (lastRev < pad.getHeadRevisionNumber()) { + var r = ++lastRev; + var author = pad.getRevisionAuthor(r); + var revisionSockets = _getPadRevisionSockets(pad); + if (revisionSockets[r] === socketId) { + sendMessage(connectionId, {type:"ACCEPT_COMMIT", newRev:r}); + } + else { + var forWire = Changeset.prepareForWire(pad.getRevisionChangeset(r), pad.pool()); + var msg = {type:"NEW_CHANGES", newRev:r, + changeset: forWire.translated, + apool: forWire.pool, + author: author}; + sendMessage(connectionId, msg); + } + } + conn.data.lastRev = pad.getHeadRevisionNumber(); + updateRoomConnectionData(connectionId, conn.data); +} + +function updatePadClients(pad) { + _getPadConnections(pad).forEach(function(connection) { + updateClient(pad, connection.connectionId); + }); + + readonly_server.updatePadClients(pad); +} + +function _lookForCommitTheHardWay(pad, baseRev, changeset, apool) { + var r = baseRev; + while (r < pad.getHeadRevisionNumber()) { + r++; + var c = pad.getRevisionChangeset(r); + if (c == changeset) { + _doWarn("_lookForCommitTheHardWay: found existing commit!! " + r + ": " + changeset); + return r; + } + + dmesg("_lookForCommitTheHardWay: before follow " + r + ": " + changeset); + changeset = Changeset.follow(c, changeset, false, apool); + dmesg("_lookForCommitTheHardWay: after follow " + r + ": " + changeset); + } + return null; +} + +function applyMissedChanges(pad, missedChanges) { + var userInfo = missedChanges.userInfo; + var baseRev = missedChanges.baseRev; + var committedChangeset = missedChanges.committedChangeset; // may be falsy + var furtherChangeset = missedChanges.furtherChangeset; // may be falsy + var apool = pad.pool(); + + if (! _verifyUserId(userInfo.userId)) { + return; + } + + if (pad.getIsModerated()) { + var abortRequest = false; + var uid = padusers.getAccountIdForProAuthor(userInfo.userId); + var acct = uid && pro_accounts.getAccountById(uid, true /*skipDeleted*/); + pro_padmeta.accessProPad(pad.getId(), function(propad) { + if (!acct || (propad.getCreatorId() != uid && !acct.isAdmin)) { + abortRequest = true; + } + }); + if (abortRequest) { + return; + } + } + + _handlePadUserInfo(pad, userInfo); + + if (committedChangeset) { + var wireApool1 = (new AttribPool()).fromJsonable(missedChanges.committedChangesetAPool); + _checkChangesetAndPool(committedChangeset, wireApool1); + committedChangeset = pad.adoptChangesetAttribs(committedChangeset, wireApool1); + } + if (furtherChangeset) { + var wireApool2 = (new AttribPool()).fromJsonable(missedChanges.furtherChangesetAPool); + _checkChangesetAndPool(furtherChangeset, wireApool2); + furtherChangeset = pad.adoptChangesetAttribs(furtherChangeset, wireApool2); + } + + var commitWasMissed = !! committedChangeset; + if (commitWasMissed) { + var commitSocketId = missedChanges.committedChangesetSocketId; + var revisionSockets = _getPadRevisionSockets(pad); + // was the commit really missed, or did the client just not hear back? + // look for later changeset by this socket + var r = baseRev; + while (r < pad.getHeadRevisionNumber()) { + r++; + var s = revisionSockets[r]; + if (! s) { + var newBaseRev = _lookForCommitTheHardWay(pad, baseRev, committedChangeset, apool); + if (newBaseRev) { + baseRev = newBaseRev; + commitWasMissed = false; + } + break; + } + if (s == commitSocketId) { + baseRev = r; + commitWasMissed = false; + break; + } + } + } + if (! commitWasMissed) { + // commit already incorporated by the server + committedChangeset = null; + } + + var changeset; + if (committedChangeset && furtherChangeset) { + dmesg("applyMissedChanges composing committedChangeset + furtherChangeset"); + + changeset = Changeset.compose(committedChangeset, furtherChangeset, apool); + } + else { + changeset = (committedChangeset || furtherChangeset); + } + + if (changeset) { + var author = userInfo.userId; + + dmesg("applyMissedChanges calling applyUserChanges"); + + applyUserChanges(pad, baseRev, changeset, null, author); + } +} + +function getAllPadsWithConnections() { + // returns array of global pad id strings + return getAllRoomsOfType(PADPAGE_ROOMTYPE).map(_roomToPadId); +} + +function broadcastServerMessage(msgObj, globalPadId) { + var msg = {type: "SERVER_MESSAGE", payload: msgObj}; + var rooms = globalPadId ? [ _padIdToRoom(globalPadId) ] : getAllRoomsOfType(PADPAGE_ROOMTYPE); + rooms.forEach(function(roomName) { + getRoomConnections(roomName).forEach(function(connection) { + sendMessage(connection.connectionId, msg); + }); + }); +} + +function broadcastSiteToClientMessage(msgObj, userId) { + + var msg = {type: "SITE_TO_CLIENT_MESSAGE", payload: msgObj}; + var rooms = getAllRoomsOfType(PADPAGE_ROOMTYPE); + userId = padusers.getUserIdForProUser(userId); + rooms.forEach(function(roomName) { + getRoomConnections(roomName, userId).forEach(function(connection) { + sendMessage(connection.connectionId, msg); + }); + }); +} + +function broadcastClientMessage(pad, msgObj) { + _getPadConnections(pad).forEach(function(conn) { + sendMessage(conn.connectionId, + {type: "CLIENT_MESSAGE", payload: msgObj}); + }); +} + +function prependPadText(pad, txt, optAuthor) { + txt = model.cleanText(txt); + var oldFullText = pad.text(); + _applyChangesetToPad(pad, + Changeset.makeSplice(oldFullText, 0, 0, txt, optAuthor ? [['author', optAuthor]] : [], pad.pool()), + optAuthor); +} + +function appendPadText(pad, txt) { + txt = model.cleanText(txt); + var oldFullText = pad.text(); + _applyChangesetToPad(pad, Changeset.makeSplice(oldFullText, + oldFullText.length-1, 0, txt)); +} + +function setPadText(pad, txt) { + txt = model.cleanText(txt); + var oldFullText = pad.text(); + // replace text except for the existing final (virtual) newline + _applyChangesetToPad(pad, Changeset.makeSplice(oldFullText, 0, + oldFullText.length-1, txt)); +} + +// if passed an apool, migrates attributes from the apool to the pad +// otherwise assumes the atext is referencing existing attributes +function setPadAText(pad, atext, opt_apool, optAuthor) { + var oldFullText = pad.text(); + var deletion = Changeset.makeSplice(oldFullText, 0, oldFullText.length-1, ""); + + var assem = Changeset.smartOpAssembler(); + Changeset.appendATextToAssembler(atext, assem); + var charBank = atext.text.slice(0, -1); + var insertion = Changeset.checkRep(Changeset.pack(1, atext.text.length, + assem.toString(), charBank)); + + if (typeof(opt_apool) != "undefined") { + insertion = pad.adoptChangesetAttribs(insertion, opt_apool); + } + + var cs = Changeset.compose(deletion, insertion, pad.pool()); + Changeset.checkRep(cs); + + _applyChangesetToPad(pad, cs, optAuthor); +} + +function applyChangesetToPad(pad, changeset) { + Changeset.checkRep(changeset); + + _applyChangesetToPad(pad, changeset); +} + +function _applyChangesetToPad(pad, changeset, optAuthor) { + pad.appendRevision(changeset, optAuthor); + updatePadClients(pad); +} + +function getHistoricalAuthorData(pad, author) { + var authorData = pad.getAuthorData(author); + if (authorData) { + var data = {}; + if ((typeof authorData.colorId) == "number") { + data.colorId = authorData.colorId; + } + if (authorData.name) { + data.name = authorData.name.replace(/%20/g, " "); + } + else { + var uname = padusers.getNameForUserId(author); + if (uname) { + data.name = uname; + } + } + data.userLink = padusers.getLinkForUserId(author); + return data; + } + return null; +} + +function buildHistoricalAuthorDataMapFromAText(pad, atext) { + var map = {}; + pad.eachATextAuthor(atext, function(author, authorNum) { + var data = getHistoricalAuthorData(pad, author); + + if (data) { + map[author] = data; + } + }); + return map; +} + +/** Returns all editors who are currently attributed in the pad (port from Composer) */ +function getAllAuthorsFromAText(globalPadId) { + var userIds = model.accessPadGlobal(globalPadId, function (pad) { + return Object.keys(buildHistoricalAuthorDataMapFromAText(pad, pad.atext())); + }); + + return userIds.filter(function(userId) { + return startsWith(userId, "p."); + }).map(function (userId) { + return pro_accounts.getAccountById(parseInt(userId.substring(2), 10)) + }); +} + +function buildHistoricalAuthorDataMapForPadHistory(pad) { + var map = {}; + pad.pool().eachAttrib(function(key, value) { + if (key == 'author') { + var author = value; + var data = getHistoricalAuthorData(pad, author); + if (data) { + map[author] = data; + } + } + }); + return map; +} + +function getATextForWire(pad, optRev) { + var atext; + if ((optRev && ! isNaN(Number(optRev))) || (typeof optRev) == "number") { + atext = pad.getInternalRevisionAText(Number(optRev)); + } + else { + atext = pad.atext(); + } + + var historicalAuthorData = buildHistoricalAuthorDataMapFromAText(pad, atext); + + var attribsForWire = Changeset.prepareForWire(atext.attribs, pad.pool()); + var apool = attribsForWire.pool; + // mutate atext (translate attribs for wire): + atext.attribs = attribsForWire.translated; + + return {atext:atext, apool:apool.toJsonable(), + historicalAuthorData:historicalAuthorData }; +} + +function getCollabClientVars(pad) { + // construct object that is made available on the client + // as collab_client_vars + + var forWire = getATextForWire(pad); + + return { + initialAttributedText: { text: escape(forWire.atext.text), attribs: forWire.atext.attribs }, + rev: pad.getHeadRevisionNumber(), + padId: pad.getLocalId(), + globalPadId: pad.getId(), + historicalAuthorData: forWire.historicalAuthorData, + apool: forWire.apool, + clientIp: request.clientAddr, + clientAgent: request.headers["User-Agent"] + }; +} + +function getNumConnections(pad) { + return _getPadConnections(pad).length; +} + +function getNumConnectionsByPadId(padId) { + return getRoomConnections(_padIdToRoom(padId)).length; +} + +function getConnectedUsers(pad) { + var users = []; + _getPadConnections(pad).forEach(function(connection) { + users.push(connection.data.userInfo); + }); + return users; +} + + +function bootAllUsersFromPad(pad, reason) { + return bootUsersFromPad(pad, reason); +} + +function bootUsersFromPad(pad, reason, userInfoFilter) { + var connections = _getPadConnections(pad); + var bootedUserInfos = []; + connections.forEach(function(connection) { + if ((! userInfoFilter) || userInfoFilter(connection.data.userInfo)) { + bootedUserInfos.push(connection.data.userInfo); + bootConnection(connection.connectionId, reason); + } + }); + return bootedUserInfos; +} + +function dumpStorageToString(pad) { + var lines = []; + var errors = []; + var head = pad.getHeadRevisionNumber(); + try { + for(var i=0;i<=head;i++) { + lines.push("changeset "+i+" "+Changeset.toBaseTen(pad.getRevisionChangeset(i))); + } + } + catch (e) { + errors.push("!!!!! Error in changeset "+i+": "+e.message); + } + for(var i=0;i<=head;i++) { + lines.push("author "+i+" "+pad.getRevisionAuthor(i)); + } + for(var i=0;i<=head;i++) { + lines.push("time "+i+" "+pad.getRevisionDate(i)); + } + var revisionSockets = _getPadRevisionSockets(pad); + for(var k in revisionSockets) lines.push("socket "+k+" "+revisionSockets[k]); + return errors.concat(lines).join('\n'); +} + +function _getPadIdForSocket(socketId) { + var connectionId = getSocketConnectionId(socketId); + if (connectionId) { + var connection = getConnection(connectionId); + if (connection) { + return _roomToPadId(connection.roomName); + } + } + return null; +} + +function _getUserIdForSocket(socketId) { + var connectionId = getSocketConnectionId(socketId); + if (connectionId) { + var connection = getConnection(connectionId); + if (connection) { + return connection.data.userInfo.userId; + } + } + return null; +} + +function _serverDebug(msg) { /* nothing */ } + +function _accessSocketPad(socketId, accessType, padFunc, dontRequirePad) { + return _accessCollabPad(_getPadIdForSocket(socketId), accessType, + padFunc, dontRequirePad); +} + +function _accessConnectionPad(connection, accessType, padFunc, dontRequirePad) { + return _accessCollabPad(_roomToPadId(connection.roomName), accessType, + padFunc, dontRequirePad); +} + +function _accessCollabPad(padId, accessType, padFunc, dontRequirePad) { + if (! padId) { + if (! dontRequirePad) { + _doWarn("Collab operation \""+accessType+"\" aborted because socket "+socketId+" has no pad."); + } + return; + } + else { + return _accessExistingPad(padId, accessType, function(pad) { + return padFunc(pad); + }, dontRequirePad); + } +} + +function _accessExistingPad(padId, accessType, padFunc, dontRequireExist, rwMode) { + return model.accessPadGlobal(padId, function(pad) { + if (! pad.exists()) { + if (! dontRequireExist) { + _doWarn("Collab operation \""+accessType+"\" aborted because pad "+padId+" doesn't exist."); + } + return; + } + else { + return padFunc(pad); + } + }, rwMode); +} + +function _handlePadUserInfo(pad, userInfo) { + var author = userInfo.userId; + var colorId = Number(userInfo.colorId); + var name = userInfo.name; + + if (! author) return; + + // update map from author to that author's last known color and name + var data = {colorId: colorId}; + if (name) data.name = name; + if (userInfo && userInfo.userId && !padusers.isGuest(userInfo.userId)) { + pad.setAuthorData(author, data); + } +} + +function _sendUserInfoMessage(connectionId, type, userInfo) { + if (translateSpecialKey(userInfo.specialKey) != 'invisible') { + // Scrub out private information. + delete userInfo['ip']; + delete userInfo['userAgent']; + sendMessage(connectionId, {type: type, userInfo: userInfo }); + } +} + + +function getRoomCallbacks(roomName) { + var callbacks = {}; + callbacks.introduceUsers = + function (joiningConnection, existingConnection) { + // notify users of each other + _sendUserInfoMessage(existingConnection.connectionId, + "USER_NEWINFO", + joiningConnection.data.userInfo); + _sendUserInfoMessage(joiningConnection.connectionId, + "USER_NEWINFO", + existingConnection.data.userInfo); + }; + callbacks.extroduceUsers = + function (leavingConnection, existingConnection) { + _sendUserInfoMessage(existingConnection.connectionId, "USER_LEAVE", + leavingConnection.data.userInfo); + }; + callbacks.introduceSiteUsers = + function (connection, userInfo) { + _sendUserInfoMessage(connection.connectionId, + "USER_SITE_NEWINFO", + userInfo); + }; + callbacks.extroduceSiteUsers = + function (leavingConnection, existingConnection) { + _sendUserInfoMessage(existingConnection.connectionId, "USER_SITE_LEAVE", + leavingConnection.data.userInfo); + }; + callbacks.onAddConnection = + function (data) { + //var userCanWrite = data.userInfo && data.userInfo.userId && !padusers.isGuest(data.userInfo.userId); + // if the user can write to the pad, we'll actually commit to remembering their + // name & color, but for guests, we won't + // XXX: Don't write pad on connection. + // Instead connected userinfo will sit in pad's author cache and maybe be written + // if there are further changes, or discarded if not. + model.accessPadGlobal(_roomToPadId(roomName), function(pad) { + _handlePadUserInfo(pad, data.userInfo); + padevents.onUserJoin(pad, data.userInfo); + readonly_server.updateUserInfo(pad, data.userInfo); + }, 'r'); + }; + callbacks.onRemoveConnection = + function (data) { + model.accessPadGlobal(_roomToPadId(roomName), function(pad) { + padevents.onUserLeave(pad, data.userInfo); + }, 'r', true/*skip access control*/); + }; + callbacks.handleConnect = + function (data) { + if (roomName.indexOf("padpage/") != 0) { + return null; + } + if (! (data.userInfo && data.userInfo.userId && + _verifyUserId(data.userInfo.userId))) { + return null; + } + return data.userInfo; + }; + callbacks.clientReady = + function(newConnection, data) { + var padId = _roomToPadId(newConnection.roomName); + + if (data.stats) { + log.custom("padclientstats", {padId:padId, stats:data.stats}); + } + + var lastRev = data.lastRev; + var isReconnectOf = data.isReconnectOf; + var isCommitPending = !! data.isCommitPending; + var connectionId = newConnection.connectionId; + + newConnection.data.lastRev = lastRev; + updateRoomConnectionData(connectionId, newConnection.data); + + // This is unnecessary.. + /*if (padutils.isProPadId(padId) && false) { + pro_padmeta.accessProPad(padId, function(propad) { + // tell client about pad title + sendMessage(connectionId, {type: "CLIENT_MESSAGE", payload: { + type: "padtitle", title: propad.getDisplayTitle() } }); + sendMessage(connectionId, {type: "CLIENT_MESSAGE", payload: { + type: "padpassword", password: propad.getPassword() } }); + }); + }*/ + + var booted = false; + _accessExistingPad(padId, "CLIENT_READY", function(pad) { + if (pad.getHeadRevisionNumber() < lastRev) { + bootConnection(connectionId, 'invalidrev'); + booted = true; + return; + } + sendMessage(connectionId, {type: "CLIENT_MESSAGE", payload: { + type: "padoptions", options: pad.getPadOptionsObj() } }); + + updateClient(pad, connectionId); + + }, false, 'r'); + if (booted) { + return; + } + + if (isCommitPending) { + // tell client that if it hasn't received an ACCEPT_COMMIT by now, it isn't coming. + sendMessage(connectionId, {type:"NO_COMMIT_PENDING"}); + } + }; + callbacks.handleMessage = function(connection, msg) { + _handleCometMessage(connection, msg); + }; + return callbacks; +} + +var _specialKeys = [['x375b', 'invisible']]; + +function translateSpecialKey(specialKey) { + // code -> name + for(var i=0;i<_specialKeys.length;i++) { + if (_specialKeys[i][0] == specialKey) { + return _specialKeys[i][1]; + } + } + return null; +} + +function getSpecialKey(name) { + // name -> code + for(var i=0;i<_specialKeys.length;i++) { + if (_specialKeys[i][1] == name) { + return _specialKeys[i][0]; + } + } + return null; +} + +function _updateDocumentConnectionUserInfo(pad, socketId, userInfo) { + var connectionId = getSocketConnectionId(socketId); + if (connectionId) { + var updatingConnection = getConnection(connectionId); + updatingConnection.data.userInfo = userInfo; + updateRoomConnectionData(connectionId, updatingConnection.data); + _getPadConnections(pad).forEach(function(connection) { + if (connection.socketId != updatingConnection.socketId) { + _sendUserInfoMessage(connection.connectionId, + "USER_NEWINFO", userInfo); + } + }); + + _handlePadUserInfo(pad, userInfo); + padevents.onUserInfoChange(pad, userInfo); + readonly_server.updateUserInfo(pad, userInfo); + } +} + +function _handleCometMessage(connection, msg) { + var socketUserId = connection.data.userInfo.userId; + if (! (socketUserId && _verifyUserId(socketUserId))) { + // reverting https://github.com/orph/pad/commit/5265fcb70c75d2bd515e78cec575bf19aa0c9918 + // can't be worse than what was here before (a render404 which would ISE) + // user has signed out or cleared cookies, no longer auth'ed + log.warn("Booting unautharized user"); + bootConnection(connection.connectionId, "unauth"); + return; + } + + if (msg.type == "USER_CHANGES") { + try { + var abortRequest = false; + _accessConnectionPad(connection, "USER_CHANGES", function(pad) { + if (pad.getIsModerated()) { + var uid = padusers.getAccountIdForProAuthor(connection.data.userInfo.userId); + var acct = uid && pro_accounts.getAccountById(uid, true /*skipDeleted*/); + pro_padmeta.accessProPad(pad.getId(), function(propad) { + if (!acct || (propad.getCreatorId() != uid && !acct.isAdmin)) { + sendMessage(connection.connectionId, + {type: "MODERATION_MESSAGE", payload: "moderated"}); + abortRequest = true; + } + }); + } + if (abortRequest) { + return; + } + + var baseRev = msg.baseRev; + var wireApool = (new AttribPool()).fromJsonable(msg.apool); + var changeset = msg.changeset; + if (changeset) { + _checkChangesetAndPool(changeset, wireApool); + changeset = pad.adoptChangesetAttribs(changeset, wireApool); + applyUserChanges(pad, baseRev, changeset, connection.socketId); + } + }); + } + catch (e if e.easysync) { + _doWarn("Changeset error handling USER_CHANGES " + msg.changeset + " (baseRev:" + msg.baseRev + "): "+e); + } + } else if (msg.type == "USERINFO_UPDATE") { + _accessConnectionPad(connection, "USERINFO_UPDATE", function(pad) { + var userInfo = msg.userInfo; + // security check + if (userInfo.userId == connection.data.userInfo.userId) { + _updateDocumentConnectionUserInfo(pad, + connection.socketId, userInfo); + } + else { + // drop on the floor + } + }); + } else if (msg.type == "CLIENT_MESSAGE") { + // drop caret updates from guests on the floor + var isCaretMsg = msg.payload.type == 'caret'; + var isChatMsg = msg.payload.type == 'chat'; + if ((isCaretMsg && msg.payload.changedBy.indexOf("g.") == 0) || + (isChatMsg && msg.payload.userId.indexOf("g.") == 0)) { + return; + } + _accessConnectionPad(connection, "CLIENT_MESSAGE", function(pad) { + var payload = msg.payload; + if (payload.authId && + payload.authId != connection.data.userInfo.userId) { + // authId, if present, must actually be the sender's userId; + // here it wasn't + } + else { + if (isDogfood() && isChatMsg && payload.chatroom_to != 'pad') { + var site = pro_utils.getFullProDomain(); + var rooms = getAllRoomsOfType(PADPAGE_ROOMTYPE); + rooms.forEach(function(roomName) { + getRoomConnections(roomName, + payload.chatroom_to == 'site' ? undefined : + payload.chatroom_to /* userId */, + site). + forEach(function(conn) { + if (conn.socketId != connection.socketId || + payload.chatroom_to != 'site') { + sendMessage(conn.connectionId, + {type: "SITE_MESSAGE", payload: payload}); + } + }); + }); + padevents.onClientMessage(pad, connection.data.userInfo, payload); + } else { + getRoomConnections(connection.roomName).forEach( + function(conn) { + if (conn.socketId != connection.socketId) { + sendMessage(conn.connectionId, + {type: "CLIENT_MESSAGE", payload: payload}); + } + }); + padevents.onClientMessage(pad, connection.data.userInfo, payload); + } + } + }); + } +} + +function _correctMarkersInPad(atext, apool) { + var text = atext.text; + + // collect char positions of line markers (e.g. bullets) in new atext + // that aren't at the start of a line + var badMarkers = []; + var iter = Changeset.opIterator(atext.attribs); + var offset = 0; + while (iter.hasNext()) { + var op = iter.next(); + var listValue = Changeset.opAttributeValue(op, 'list', apool); + if (listValue) { + for(var i=0;i 0 && text.charAt(offset-1) != '\n') { + badMarkers.push(offset); + } + offset++; + } + } + else { + offset += op.chars; + } + } + + if (badMarkers.length == 0) { + return null; + } + + // create changeset that removes these bad markers + offset = 0; + var builder = Changeset.builder(text.length); + badMarkers.forEach(function(pos) { + builder.keepText(text.substring(offset, pos)); + builder.remove(1); + offset = pos+1; + }); + return builder.toString(); +} diff --git a/etherpad/src/etherpad/collab/collabroom_server.js b/etherpad/src/etherpad/collab/collabroom_server.js new file mode 100644 index 0000000..2ad2ea6 --- /dev/null +++ b/etherpad/src/etherpad/collab/collabroom_server.js @@ -0,0 +1,484 @@ +/** + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import("execution"); +import("comet"); +import("fastJSON"); +import("cache_utils.syncedWithCache"); +import("etherpad.collab.collab_server"); +import("etherpad.collab.readonly_server"); +import("etherpad.globals.isDogfood"); +import("etherpad.globals.isProduction"); +import("etherpad.log"); +import("etherpad.pro.domains"); +import("etherpad.pro.pro_utils"); +jimport("java.util.concurrent.ConcurrentSkipListMap"); +jimport("java.util.concurrent.CopyOnWriteArraySet"); + +function onStartup() { + execution.initTaskThreadPool("collabroom_async", 1); +} + +function _doWarn(str) { + log.warn(appjet.executionId+": "+str); +} + +// deep-copies (recursively clones) an object (or value) +function _deepCopy(obj) { + if ((typeof obj) != 'object' || !obj) { + return obj; + } + var o = obj instanceof Array ? [] : {}; + for(var k in obj) { + if (obj.hasOwnProperty(k)) { + var v = obj[k]; + if ((typeof v) == 'object' && v) { + o[k] = _deepCopy(v); + } + else { + o[k] = v; + } + } + } + return o; +} + +// calls func inside a global lock on the cache +function _withCache(func) { + return syncedWithCache("collabroom_server", function(cache) { + if (! cache.rooms) { + // roomName -> { connections: CopyOnWriteArraySet, + // type: } + cache.rooms = new ConcurrentSkipListMap(); + } + if (! cache.allConnections) { + // connectionId -> connection object + cache.allConnections = new ConcurrentSkipListMap(); + } + if (! cache.sites) { + // site (e.g. bar.hackpad.com) -> + // { connections: CopyOnWriteArraySet } + cache.sites = new ConcurrentSkipListMap(); + } + return func(cache); + }); +} + +// accesses cache without lock +function _getCache() { + return _withCache(function(cache) { return cache; }); +} + +// if roomType is null, will only update an existing connection +// (otherwise will insert or update as appropriate) +function _putConnection(connection, roomType) { + var roomName = connection.roomName; + var connectionId = connection.connectionId; + var socketId = connection.socketId; + var data = connection.data; + + _withCache(function(cache) { + var rooms = cache.rooms; + if (! rooms.containsKey(roomName)) { + // connection refers to room that doesn't exist / is empty + if (roomType) { + rooms.put(roomName, {connections: new CopyOnWriteArraySet(), + type: roomType}); + } + else { + return; + } + } + if (roomType) { + rooms.get(roomName).connections.add(connectionId); + cache.allConnections.put(connectionId, connection); + } + else { + cache.allConnections.replace(connectionId, connection); + } + + if (isDogfood() && data.site && !_isGuest(connection)) { + var sites = cache.sites; + if (!sites.containsKey(data.site)) { + // connection refers to a site that doesn't exist / is empty + sites.put(data.site, { connections: new CopyOnWriteArraySet() }); + } + sites.get(data.site).connections.add(connectionId); + } + }); +} + +function _removeConnection(connection) { + _withCache(function(cache) { + var rooms = cache.rooms; + var thisRoom = connection.roomName; + var thisConnectionId = connection.connectionId; + if (rooms.containsKey(thisRoom)) { + var roomConnections = rooms.get(thisRoom).connections; + roomConnections.remove(thisConnectionId); + if (roomConnections.isEmpty()) { + rooms.remove(thisRoom); + } + } + + if (connection.data.site) { + var sites = cache.sites; + var thisSite = connection.data.site; + if (sites.containsKey(thisSite)) { + var siteConnections = sites.get(thisSite).connections; + siteConnections.remove(thisConnectionId); + if (siteConnections.isEmpty()) { + sites.remove(thisSite); + } + } + } + + cache.allConnections.remove(thisConnectionId); + }); +} + +function _getConnection(connectionId) { + // return a copy of the connection object + return _deepCopy(_getCache().allConnections.get(connectionId) || null); +} + +function _getConnections(roomName, opt_userId, opt_site) { + var array = []; + + var roomObj = _getCache().rooms.get(roomName); + if (roomObj) { + var roomConnections = roomObj.connections; + var iter = roomConnections.iterator(); + while (iter.hasNext()) { + var cid = iter.next(); + var conn = _getConnection(cid); + if (conn && (!opt_userId || opt_userId == conn.data.userInfo.userId) && + (!opt_site || opt_site == conn.data.site)) { + array.push(conn); + } + } + } + return array; +} + +function _getSiteConnections(siteName) { + var array = []; + + var siteObj = _getCache().sites.get(siteName); + if (siteObj) { + var siteConnections = siteObj.connections; + var iter = siteConnections.iterator(); + while (iter.hasNext()) { + var cid = iter.next(); + var conn = _getConnection(cid); + if (conn) { + array.push(conn); + } + } + } + return array; +} + +function sendMessage(connectionId, msg) { + var connection = _getConnection(connectionId); + if (connection) { + _sendMessageToSocket(connection.socketId, msg); + if (! comet.isConnected(connection.socketId)) { + // defunct socket, disconnect (later) + execution.scheduleTask("collabroom_async", + "collabRoomDisconnectSocket", + 0, [connection.connectionId, + connection.socketId]); + } + } +} + +function _sendMessageToSocket(socketId, msg) { + var msgString = fastJSON.stringify({type: "COLLABROOM", data: msg}); + comet.sendMessage(socketId, msgString); +} + +function disconnectDefunctSocket(connectionId, socketId) { + var connection = _getConnection(connectionId); + if (connection && connection.socketId == socketId) { + removeRoomConnection(connectionId); + } +} + +function _bootSocket(socketId, reason) { + if (reason) { + _sendMessageToSocket(socketId, + {type: "DISCONNECT_REASON", reason: reason}); + } + comet.disconnect(socketId); +} + +function bootConnection(connectionId, reason) { + var connection = _getConnection(connectionId); + if (connection) { + _bootSocket(connection.socketId, reason); + removeRoomConnection(connectionId); + } +} + +function getCallbacksForRoom(roomName, roomType) { + if (! roomType) { + var room = _getCache().rooms.get(roomName); + if (room) { + roomType = room.type; + } + } + + var emptyCallbacks = {}; + emptyCallbacks.introduceUsers = + function (joiningConnection, existingConnection) {}; + emptyCallbacks.extroduceUsers = + function extroduceUsers(leavingConnection, existingConnection) {}; + emptyCallbacks.introduceSiteUsers = + function (connection, userInfo) {}; + emptyCallbacks.extroduceSiteUsers = + function extroduceUsers(leavingConnection, existingConnection) {}; + emptyCallbacks.onAddConnection = function (joiningData) {}; + emptyCallbacks.onRemoveConnection = function (leavingData) {}; + emptyCallbacks.handleConnect = + function(data) { return /*userInfo or */null; }; + emptyCallbacks.clientReady = function(newConnection, data) {}; + emptyCallbacks.handleMessage = function(connection, msg) {}; + + if (roomType == collab_server.PADPAGE_ROOMTYPE) { + return collab_server.getRoomCallbacks(roomName, emptyCallbacks); + } + else if (roomType == readonly_server.PADVIEW_ROOMTYPE) { + return readonly_server.getRoomCallbacks(roomName, emptyCallbacks); + } + else { + //java.lang.System.out.println("UNKNOWN ROOMTYPE: "+roomType); + return emptyCallbacks; + } +} + +// roomName must be globally unique, just within roomType; +// data must have a userInfo.userId +function addRoomConnection(roomName, roomType, + connectionId, socketId, data) { + var callbacks = getCallbacksForRoom(roomName, roomType); + + comet.setAttribute(socketId, "connectionId", connectionId); + + bootConnection(connectionId, "userdup"); + var joiningConnection = {roomName:roomName, + connectionId:connectionId, socketId:socketId, + data:data}; + + var siteConnections; + var firstIntroduction = true; + var uniqueUsers = {}; + if (isDogfood() && data.site) { + // check here first before _putConnection where our connection gets added. + siteConnections = _getSiteConnections(data.site); + siteConnections.forEach(function(connection) { + var userInfo = connection.data.userInfo; + if (userInfo.userId == joiningConnection.data.userInfo.userId) { + firstIntroduction = false; + } + uniqueUsers[userInfo.userId] = userInfo; + }); + } + + _putConnection(joiningConnection, roomType); + var connections = _getConnections(roomName); + var joiningUser = data.userInfo.userId; + + connections.forEach(function(connection) { + if (connection.socketId != socketId) { + var user = connection.data.userInfo.userId; + callbacks.introduceUsers(joiningConnection, connection); + + /*if (user == joiningUser) { + bootConnection(connection.connectionId, "userdup"); + } + else { + callbacks.introduceUsers(joiningConnection, connection); + }*/ + + } + }); + + // Joining a site - don't send to all if you are already connected somewhere else, + // but do get all other site members sent to your new connection. + if (isDogfood() && data.site && !_isGuest(joiningConnection)) { + for (var user in uniqueUsers) { + var userInfo = uniqueUsers[user]; + callbacks.introduceSiteUsers(joiningConnection, userInfo); + } + + if (firstIntroduction) { + siteConnections.forEach(function(connection) { + callbacks.introduceSiteUsers(connection, joiningConnection.data.userInfo); + }); + } + } + + callbacks.onAddConnection(data); + + return joiningConnection; +} + +function _isGuest(connection) { + return connection.data.userInfo.userId.indexOf('g.') == 0; +} + +function removeRoomConnection(connectionId) { + var leavingConnection = _getConnection(connectionId); + if (leavingConnection) { + var roomName = leavingConnection.roomName; + var callbacks = getCallbacksForRoom(roomName); + + _removeConnection(leavingConnection); + + // only announce the departure if this is the last connectino for this user + var departingUserId = leavingConnection.data.userInfo.userId; + var lastConnectionForUser = true; + _getConnections(roomName).forEach(function(connection) { + var userId = connection.data.userInfo.userId; + if (userId == departingUserId) { + lastConnectionForUser = false; + } + }); + + if (lastConnectionForUser) { + _getConnections(roomName).forEach(function (connection) { + callbacks.extroduceUsers(leavingConnection, connection); + }); + } + + // Leaving a site: if it's your last connection - then tell everyone. + if (isDogfood() && leavingConnection.data.site && !_isGuest(leavingConnection)) { + var lastSiteConnectionForUser = true; + _getSiteConnections(leavingConnection.data.site).forEach(function(connection) { + var userId = connection.data.userInfo.userId; + if (userId == departingUserId) { + lastSiteConnectionForUser = false; + } + }); + + if (lastSiteConnectionForUser) { + _getSiteConnections(leavingConnection.data.site).forEach(function(connection) { + callbacks.extroduceSiteUsers(leavingConnection, connection); + }); + } + } + + callbacks.onRemoveConnection(leavingConnection.data); + } +} + +function getConnection(connectionId) { + return _getConnection(connectionId); +} + +function updateRoomConnectionData(connectionId, data) { + var connection = _getConnection(connectionId); + if (connection) { + connection.data = data; + _putConnection(connection); + } +} + +function getRoomConnections(roomName, opt_userId, opt_site) { + return _getConnections(roomName, opt_userId, opt_site); +} + +function getAllRoomsOfType(roomType) { + var rooms = _getCache().rooms; + var roomsIter = rooms.entrySet().iterator(); + var array = []; + while (roomsIter.hasNext()) { + var entry = roomsIter.next(); + var roomName = entry.getKey(); + var roomStruct = entry.getValue(); + if (roomStruct.type == roomType) { + array.push(roomName); + } + } + return array; +} + +function getSocketConnectionId(socketId) { + var result = comet.getAttribute(socketId, "connectionId"); + return result && String(result); +} + +function handleComet(cometOp, cometId, msg) { + var cometEvent = cometOp; + + function requireTruthy(x, id) { + if (!x) { + _doWarn("Collab operation rejected due to missing value, case "+id); + if (messageSocketId) { + comet.disconnect(messageSocketId); + } + response.stop(); + } + return x; + } + + if (cometEvent != "disconnect" && cometEvent != "message") { + response.stop(); + } + + var messageSocketId = requireTruthy(cometId, 2); + var messageConnectionId = getSocketConnectionId(messageSocketId); + + if (cometEvent == "disconnect") { + if (messageConnectionId) { + removeRoomConnection(messageConnectionId); + } + } + else if (cometEvent == "message") { + if (msg.type == "CLIENT_READY") { + var roomType = requireTruthy(msg.roomType, 4); + var roomName = requireTruthy(msg.roomName, 11); + + var socketId = messageSocketId; + var connectionId = messageSocketId; + var clientReadyData = requireTruthy(msg.data, 12); + + var callbacks = getCallbacksForRoom(roomName, roomType); + var userInfo = + requireTruthy(callbacks.handleConnect(clientReadyData), 13); + var data = {userInfo: userInfo}; + if (isDogfood() && (!domains.isPrimaryDomainRequest() || !isProduction())) { + data.site = pro_utils.getFullProDomain(); + } + + var newConnection = addRoomConnection(roomName, roomType, + connectionId, socketId, + data); + + callbacks.clientReady(newConnection, clientReadyData); + } + else { + if (messageConnectionId) { + var connection = getConnection(messageConnectionId); + if (connection) { + var callbacks = getCallbacksForRoom(connection.roomName); + callbacks.handleMessage(connection, msg); + } + } + } + } +} diff --git a/etherpad/src/etherpad/collab/json_sans_eval.js b/etherpad/src/etherpad/collab/json_sans_eval.js new file mode 100644 index 0000000..6cbd497 --- /dev/null +++ b/etherpad/src/etherpad/collab/json_sans_eval.js @@ -0,0 +1,178 @@ +// Copyright (C) 2008 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * Parses a string of well-formed JSON text. + * + * If the input is not well-formed, then behavior is undefined, but it is + * deterministic and is guaranteed not to modify any object other than its + * return value. + * + * This does not use `eval` so is less likely to have obscure security bugs than + * json2.js. + * It is optimized for speed, so is much faster than json_parse.js. + * + * This library should be used whenever security is a concern (when JSON may + * come from an untrusted source), speed is a concern, and erroring on malformed + * JSON is *not* a concern. + * + * Pros Cons + * +-----------------------+-----------------------+ + * json_sans_eval.js | Fast, secure | Not validating | + * +-----------------------+-----------------------+ + * json_parse.js | Validating, secure | Slow | + * +-----------------------+-----------------------+ + * json2.js | Fast, some validation | Potentially insecure | + * +-----------------------+-----------------------+ + * + * json2.js is very fast, but potentially insecure since it calls `eval` to + * parse JSON data, so an attacker might be able to supply strange JS that + * looks like JSON, but that executes arbitrary javascript. + * If you do have to use json2.js with untrusted data, make sure you keep + * your version of json2.js up to date so that you get patches as they're + * released. + * + * @param {string} json per RFC 4627 + * @return {Object|Array} + * @author Mike Samuel + */ +var jsonParse = (function () { + var number + = '(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)'; + var oneChar = '(?:[^\\0-\\x08\\x0a-\\x1f\"\\\\]' + + '|\\\\(?:[\"/\\\\bfnrt]|u[0-9A-Fa-f]{4}|x7c))'; + var string = '(?:\"' + oneChar + '*\")'; + + // Will match a value in a well-formed JSON file. + // If the input is not well-formed, may match strangely, but not in an unsafe + // way. + // Since this only matches value tokens, it does not match whitespace, colons, + // or commas. + var jsonToken = new RegExp( + '(?:false|true|null|[\\{\\}\\[\\]]' + + '|' + number + + '|' + string + + ')', 'g'); + + // Matches escape sequences in a string literal + var escapeSequence = new RegExp('\\\\(?:([^ux]|x7c)|u(.{4}))', 'g'); + + // Decodes escape sequences in object literals + var escapes = { + '"': '"', + '/': '/', + '\\': '\\', + 'b': '\b', + 'f': '\f', + 'n': '\n', + 'r': '\r', + 't': '\t', + 'x7c': '|' + }; + function unescapeOne(_, ch, hex) { + return ch ? escapes[ch] : String.fromCharCode(parseInt(hex, 16)); + } + + // A non-falsy value that coerces to the empty string when used as a key. + var EMPTY_STRING = new String(''); + var SLASH = '\\'; + + // Constructor to use based on an open token. + var firstTokenCtors = { '{': Object, '[': Array }; + + return function (json) { + // Split into tokens + var toks = json.match(jsonToken); + // Construct the object to return + var result; + var tok = toks[0]; + if ('{' === tok) { + result = {}; + } else if ('[' === tok) { + result = []; + } else { + throw new Error(tok); + } + + // If undefined, the key in an object key/value record to use for the next + // value parsed. + var key; + // Loop over remaining tokens maintaining a stack of uncompleted objects and + // arrays. + var stack = [result]; + for (var i = 1, n = toks.length; i < n; ++i) { + tok = toks[i]; + + var cont; + switch (tok.charCodeAt(0)) { + default: // sign or digit + cont = stack[0]; + cont[key || cont.length] = +(tok); + key = void 0; + break; + case 0x22: // '"' + tok = tok.substring(1, tok.length - 1); + if (tok.indexOf(SLASH) !== -1) { + tok = tok.replace(escapeSequence, unescapeOne); + } + cont = stack[0]; + if (!key) { + if (cont instanceof Array) { + key = cont.length; + } else { + key = tok || EMPTY_STRING; // Use as key for next value seen. + break; + } + } + cont[key] = tok; + key = void 0; + break; + case 0x5b: // '[' + cont = stack[0]; + stack.unshift(cont[key || cont.length] = []); + key = void 0; + break; + case 0x5d: // ']' + stack.shift(); + break; + case 0x66: // 'f' + cont = stack[0]; + cont[key || cont.length] = false; + key = void 0; + break; + case 0x6e: // 'n' + cont = stack[0]; + cont[key || cont.length] = null; + key = void 0; + break; + case 0x74: // 't' + cont = stack[0]; + cont[key || cont.length] = true; + key = void 0; + break; + case 0x7b: // '{' + cont = stack[0]; + stack.unshift(cont[key || cont.length] = {}); + key = void 0; + break; + case 0x7d: // '}' + stack.shift(); + break; + } + } + // Fail if we've got an uncompleted object. + if (stack.length) { throw new Error(); } + return result; + }; +})(); diff --git a/etherpad/src/etherpad/collab/readonly_server.js b/etherpad/src/etherpad/collab/readonly_server.js new file mode 100644 index 0000000..13561f4 --- /dev/null +++ b/etherpad/src/etherpad/collab/readonly_server.js @@ -0,0 +1,172 @@ +/** + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import("comet"); +import("ejs"); +import("etherpad.collab.ace.easysync2.{AttribPool,Changeset}"); +import("etherpad.log"); +import("etherpad.pad.activepads"); +import("etherpad.pad.model"); +import("etherpad.pad.padutils"); +import("etherpad.pad.padevents"); +import("etherpad.pro.pro_padmeta"); +import("fastJSON"); +import("fileutils.readFile"); +import("jsutils.eachProperty"); +import("etherpad.collab.server_utils.*"); +import("etherpad.collab.collabroom_server"); + +jimport("java.lang.System.out.println"); + +var PADVIEW_ROOMTYPE = 'padview'; + +var _serverDebug = println;//function(x) {}; + +// "view id" is either a padId or an ro.id +function _viewIdToRoom(padId) { + return "padview/"+padId; +} + +function _roomToViewId(roomName) { + return roomName.substring(roomName.indexOf("/")+1); +} + +function getRoomCallbacks(roomName, emptyCallbacks) { + var callbacks = emptyCallbacks; + + var viewId = _roomToViewId(roomName); + + callbacks.handleConnect = function(data) { + if (data.userInfo && data.userInfo.userId) { + return data.userInfo; + } + return null; + }; + callbacks.clientReady = + function(newConnection, data) { + newConnection.data.lastRev = data.lastRev; + collabroom_server.updateRoomConnectionData(newConnection.connectionId, + newConnection.data); + }; + + return callbacks; +} + +function updatePadClients(pad) { + var padId = pad.getId(); + var roId = padIdToReadonly(padId); + + function update(connection) { + updateClient(pad, connection.connectionId); + } + + collabroom_server.getRoomConnections(_viewIdToRoom(padId)).forEach(update); + collabroom_server.getRoomConnections(_viewIdToRoom(roId)).forEach(update); +} + +// Get arrays of text lines and attribute lines for a revision +// of a pad. +function _getPadLines(pad, revNum) { + var atext; + if (revNum >= 0) { + atext = pad.getInternalRevisionAText(revNum); + } else { + atext = Changeset.makeAText("\n"); + } + + var result = {}; + result.textlines = Changeset.splitTextLines(atext.text); + result.alines = Changeset.splitAttributionLines(atext.attribs, + atext.text); + return result; +} + +function updateClient(pad, connectionId) { + var conn = collabroom_server.getConnection(connectionId); + if (! conn) { + return; + } + var lastRev = conn.data.lastRev; + while (lastRev < pad.getHeadRevisionNumber()) { + var r = ++lastRev; + var author = pad.getRevisionAuthor(r); + var lines = _getPadLines(pad, r-1); + var wirePool = new AttribPool(); + var forwards = pad.getRevisionChangeset(r); + var backwards = Changeset.inverse(forwards, lines.textlines, + lines.alines, pad.pool()); + var forwards2 = Changeset.moveOpsToNewPool(forwards, pad.pool(), + wirePool); + var backwards2 = Changeset.moveOpsToNewPool(backwards, pad.pool(), + wirePool); + + function revTime(r) { + var date = pad.getRevisionDate(r); + var s = Math.floor((+date)/1000); + //java.lang.System.out.println("time "+r+": "+s); + return s; + } + + var msg = {type:"NEW_CHANGES", newRev:r, + changeset: forwards2, + changesetBack: backwards2, + apool: wirePool.toJsonable(), + author: author, + timeDelta: revTime(r) - revTime(r-1) }; + collabroom_server.sendMessage(connectionId, msg); + } + conn.data.lastRev = pad.getHeadRevisionNumber(); + collabroom_server.updateRoomConnectionData(connectionId, conn.data); +} + +function sendMessageToPadConnections(pad, msg) { + var padId = pad.getId(); + var roId = padIdToReadonly(padId); + + function update(connection) { + collabroom_server.sendMessage(connection.connectionId, msg); + } + + collabroom_server.getRoomConnections(_viewIdToRoom(padId)).forEach(update); + collabroom_server.getRoomConnections(_viewIdToRoom(roId)).forEach(update); +} + +function updateUserInfo(pad, userInfo) { + var msg = { type:"NEW_AUTHORDATA", + author: userInfo.userId, + data: {} }; + var hasData = false; + if ((typeof (userInfo.colorId)) == "number") { + msg.data.colorId = userInfo.colorId; + hasData = true; + } + if (userInfo.name) { + msg.data.name = userInfo.name; + hasData = true; + } + if (hasData) { + sendMessageToPadConnections(pad, msg); + } +} + +function broadcastNewRevision(pad, revObj) { + var msg = { type:"NEW_SAVEDREV", + savedRev: revObj }; + + delete revObj.ip; // we try not to share info like IP addresses on slider + + sendMessageToPadConnections(pad, msg); +} diff --git a/etherpad/src/etherpad/collab/server_utils.js b/etherpad/src/etherpad/collab/server_utils.js new file mode 100644 index 0000000..386967f --- /dev/null +++ b/etherpad/src/etherpad/collab/server_utils.js @@ -0,0 +1,203 @@ +/** + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import("comet"); +import("ejs"); +import("etherpad.log"); +import("etherpad.pad.activepads"); +import("etherpad.pad.model"); +import("etherpad.pad.padutils"); +import("etherpad.pad.padevents"); +import("etherpad.pro.pro_padmeta"); +import("fastJSON"); +import("fileutils.readFile"); +import("jsutils.eachProperty"); + +jimport("java.util.Random"); +jimport("java.lang.System"); + +import("etherpad.collab.collab_server"); +// importClass(java.util.Random); +// importClass(java.lang.System); + +var _serverDebug = function() {}; +var _dmesg = function() { System.out.println(arguments[0]+""); }; + +/// Begin readonly/padId conversion code +/// TODO: refactor into new file? +var _baseRandomNumber = 0x123123; // keep this number seekrit + +function _map(array, func) { + for(var i=0; i 1) { + for(var i=0; i= start && charcode <= end; +} + +/* a short little testing function, converts back and forth */ +// function _testEncrypt(str) { +// var encrypted = padIdToReadonly(str); +// var decrypted = readonlyToPadId(encrypted); +// _dmesg(str + " " + encrypted + " " + decrypted); +// if(decrypted != str) { +// _dmesg("ERROR: " + str + " and " + decrypted + " do not match"); +// } +// } + +// _testEncrypt("testing$"); diff --git a/etherpad/src/etherpad/control/admin/admin_download_user_data.js b/etherpad/src/etherpad/control/admin/admin_download_user_data.js new file mode 100644 index 0000000..27ff782 --- /dev/null +++ b/etherpad/src/etherpad/control/admin/admin_download_user_data.js @@ -0,0 +1,67 @@ +import("jsutils") +import("underscore._"); +import ("funhtml.*"); + +import("etherpad.sessions.{isAnEtherpadAdmin}"); +import ("etherpad.utils.*"); +import ("etherpad.pad.padutils"); +import ("etherpad.pad.model"); +import("etherpad.pad.exporthtml"); +import('etherpad.pro.pro_padmeta'); +import('etherpad.control.pro.pro_padlist_control'); +import('etherpad.pro.pro_accounts'); +import("etherpad.pro.pro_utils"); +import("etherpad.log"); +import("sqlbase.sqlobj"); +import ("etherpad.utils"); +import ("etherpad.statistics.email_tracking"); + +function render_main_get() { + var body = renderTemplateAsString("admin/download_user_data.ejs"); + + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Download User Data', + content: body + }); +} + +function render_main_post() { + if (!isAnEtherpadAdmin()) { + response.redirect("/"); + } + var addresses = requireParam("addresses"); + var destination = requireParam("destination"); + + addresses = _.compact(addresses.split(/\r\n|\r|\n/g)); + + // Make sure everything's an e-mail. + var invalids = findInvalidEmails(addresses.concat(destination)); + if (invalids.length > 0) { + response.write("The following are not valid e-mails: " + invalids.join(", ")); + response.stop(); + return; + } + + pro_padlist_control.sendPadsToZip(addresses, destination, "txt") + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Send Email', + content: ["

Success!

", "

You should receive an e-mail shortly.

"].join("") + }); +} + +function findInvalidEmails(emails) { + return _.reject(emails, function(email) { + var parts = email.split("@"); + + // A pretty simple check -- two parts (one before and the after the @), and neither can be empty. + return (parts.length == 2 && !_.any(parts, function(part) { + return part.length == 0; + })); + }); +} diff --git a/etherpad/src/etherpad/control/admin/admin_email_control.js b/etherpad/src/etherpad/control/admin/admin_email_control.js new file mode 100644 index 0000000..f6a8b77 --- /dev/null +++ b/etherpad/src/etherpad/control/admin/admin_email_control.js @@ -0,0 +1,135 @@ +import("jsutils") +import ("funhtml.*"); +import ("etherpad.utils.*"); +import ("etherpad.pad.padutils"); +import ("etherpad.pad.model"); +import("etherpad.pad.exporthtml"); +import('etherpad.pro.pro_padmeta'); +import('etherpad.pro.pro_accounts'); +import("etherpad.pro.pro_utils"); +import("etherpad.log"); +import("sqlbase.sqlobj"); +import ("etherpad.utils"); +import ("etherpad.statistics.email_tracking"); + +function render_stats_get() { + var stats = sqlobj.executeRaw("SELECT globalPadId, sum(clicks>0) as clicks, sum(timeOpened is not NULL) as opens, count(*) as sent from email_tracking where globalPadId != '' group by globalPadId", {}); + stats.forEach(function(s){ + pro_padmeta.accessProPad(s.globalPadId, function(ppad) { + s.title = ppad.getDisplayTitle(); + s.url = absolutePadURL(ppad.getLocalPadId()); + }); + }) + + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Email Stats', + content: renderTemplateAsString("admin/emailstats.ejs", {stats:stats}) + }); +} + +function render_main_get() { + var body = renderTemplateAsString("admin/sendemail.ejs"); + + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Send Email', + content: body + }); +} + +function render_main_post() { + var addresses = request.params.addresses; + var sqladdresses = request.params.sqladdresses; + var emailType = request.params.emailtype; + var emailVersion = request.params.emailversion; + var campaignId = request.params.campaignid; + var count = request.params.count; + var really = request.params.really; + var globalPadId = parsePadURL(request.params.pad); + + + if (!(globalPadId && (sqladdresses || addresses))) { + response.write("No mesage text or addresses specified."); + response.stop(); + return; + } + addresses = addresses.split("\n"); + + if (sqladdresses) { + var r = sqlobj.executeRaw(sqladdresses, []); + for (i in r) { + if (r[i].email) { + addresses.push(r[i].email); + } + } + } + + var body; + var padId; + model.accessPadGlobal(globalPadId, function (pad) { + body = exporthtml.getPadHTMLDocument(pad, pad.getHeadRevisionNumber(), false/*noDoctype*/, true /*removeTitleLine*/, true/*unescapeCodeFragment*/); + padId = pad.getId(); + }); + var title; + pro_padmeta.accessProPad(padId, function(propad) { + title = propad.getDisplayTitle(); + }); + body = body.replace(/"); + atext = pad.getRecoveredAText(); + } + var newText = ""; + + var iter = Changeset.opIterator(atext.attribs); + var charIter = Changeset.stringIterator(atext.text); + while (iter.hasNext()) { + var op = iter.next(); + var newOp = Changeset.newOp(); + Changeset.copyOp(op, newOp); + + var chars = ""; + if (charIter.remaining() >= op.chars) { + chars = charIter.take(op.chars); + } else { + chars = charIter.take(charIter.remaining()); + for (var i=chars.length; i"); + } + + if ((newOp.lines || newlines ) && (chars.charAt(chars.length-1) != "\n")) { + chars = chars + "\n"; + newOp.chars++; + newOp.lines++; + content += ("fixed op terminal newline
"); + } + newOp.opcode = "+"; + newText += chars; + assem.append(newOp); + } + + // Rescue any final text if our attribs are mis-aligned + if (charIter.remaining()) { + var newOp = Changeset.newOp(); + chars = charIter.take(charIter.remaining()); + if (chars.charAt(chars.length-1) != "\n") { + chars = chars + "\n"; + } + newOp.opcode = "+"; + newOp.lines = chars.split("\n").length-1; + newOp.chars = chars.length; + newText += chars; + assem.append(newOp); + } + + + assem.endDocument(); + var newAttribs = assem.toString(); + atext.attribs = newAttribs; + atext.text = newText; + + content += ("
"); + content += (helpers.escapeHtml(atext.text).replace(/\n/g,"")); + content += (helpers.escapeHtml(atext.attribs)); + + if (apply) { + content += "

Recovered!"; + //atext = pad.getRecoveredAText(); + model.rollbackToRevNum(globalPadId, 0); + // flush the model cache + model.flushModelCacheForPad(globalPadId, 10000); + + } + }); + + if (apply) { + var headRev = null; + var refresh = false; + model.accessPadGlobal(globalPadId, function(pad) { + collab_server.setPadAText(pad, atext, pad.pool()); + headRev = pad.getHeadRevisionNumber(); + refresh = collab_server.getConnectedUsers(pad).length; + }); + + var title = ""; + pro_padmeta.accessProPad(globalPadId, function(propad) { + title = propad.getDisplayTitle(); + }); + var domainId = padutils.getDomainId(globalPadId); + var domainRecord = domains.getDomainRecord(domainId); + var subDomain = domainRecord.orgName != null ? domainRecord.subDomain : ""; + sqlobj.update('PAD_SQLMETA', {id:globalPadId}, {lastSyndicatedRev: headRev}); + + var padUrl = utils.absolutePadURL(padutils.globalToLocalId(globalPadId), + {}, subDomain, title); + + if (refresh) { + collab_server.broadcastServerMessage({ + type: 'RELOAD', + padUrl: padUrl + }, globalPadId); + } + } + + content += BR(); + content += BR(); + + content += funhtml.FORM({action: '/ep/admin/recover/recover', method: 'POST'}, + helpers.xsrfTokenElement(), + funhtml.INPUT({type: 'hidden', name:'globalPadId', value:globalPadId}), + funhtml.INPUT({type: 'submit', name:'submit', value:'Recover'})); + + + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Analyze', + content: content + }); + + return true; +} +import("execution"); +import("funhtml.*"); +import("etherpad.utils.renderHtml"); + +function render_pad_checker_get() { + var status = DIV(SPAN("Pads checked: "), SPAN(appjet.cache.padsChecked)); + var start = A({'href': '/admin/recover/start-checker', 'style': 'padding:10px;'}, 'start'); + var stop = A({'href': '/admin/recover/stop-checker', 'style': 'padding:10px;'}, 'stop'); + var body = DIV({'style': 'padding-left:148px'}, status, start, stop); + + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Send Email', + content: body + }); + + return true; +} + +function onStartup() { + appjet.cache.padsChecked = 0; + execution.initTaskThreadPool("recoverer", 1); +} + +function render_start_checker_both () { + appjet.cache.padsChecked = 0; + execution.scheduleTask('recoverer', 'checkNextBatch', 0, + [parseInt(request.params.start || 0), parseInt(request.params.count || 100)]); + response.redirect('/admin/recover/pad-checker'); +} + +function render_stop_checker_both () { + appjet.cache.padsChecked = -1; + response.redirect('/admin/recover/pad-checker'); +} + +serverhandlers.tasks.checkNextBatch = function (firstPadId, count) { + if (appjet.cache.padsChecked == -1) { + return; + } + + _check_pads(firstPadId, count); + + // Have we been asked to stop? + if (appjet.cache.padsChecked == -1) { + return; + } + + appjet.cache.padsChecked += count; + execution.scheduleTask('recoverer', 'checkNextBatch', 1000, [firstPadId+count, count]); +} + +function _check_pads(firstPadId, count) { + // re-index count pads and schedule the next batch + var rows = sqlobj.selectMulti('pro_padmeta', {id: ['between', [firstPadId, firstPadId+count-1]], isDeleted: false, isArchived: false}); + + if (!rows.length) { + return; + } + + for (var i=0; i 0) { + // don't mess with active pads. + return null; + } + + if (!pad._meta) { + return "no meta"; + } + + head = pad._meta.head; + + // traverse the attribs. when finding something that doesn't match the reality + try { + atext = pad.atext(); + } catch(e) { + return "no atext"; + } + + try { + var replayAText = pad.getReconstructedAText(); + if (replayAText) { + if (replayAText.text != atext.text || + replayAText.attribs != atext.attribs) { + return "atext doesn't match up"; + } + } + } catch(e) { + return "atext replaying failed"; + } + + // look for invalid sequences in the atext + + var atextCheckResult = _check_atext(pad.atext()); + if (atextCheckResult) { + return atextCheckResult; + } + + // check the segment cache against the head rev + try { + var segments = pad.getMostRecentEditSegments(1); + } catch (e) { + return "failure getting segments"; + } + if (segments && segments.length) { + var segment = segments[0]; + var endRev = segment[1]; + if (endRev > head) { + return "segment exists ahead of head rev" + } + } + + // flush the pad if it's freshly loaded + if (!pad._meta.status.lastAccess) { + try { + dbwriter.writePadNow(pad, true/*and flush*/); + model.flushModelCacheForPad(globalPadId, pad.getHeadRevisionNumber()); + } catch(e) { + return "write failed"; + } + } + + return null; + }, 'r'); + +} + +function _check_atext(atext) { + var logMessage = null; + + var iter = Changeset.opIterator(atext.attribs); + var charIter = Changeset.stringIterator(atext.text); + + while (iter.hasNext()) { + var op = iter.next(); + var newOp = Changeset.newOp(); + Changeset.copyOp(op, newOp); + + var chars = ""; + if (charIter.remaining() >= op.chars) { + chars = charIter.take(op.chars); + } else { + chars = charIter.take(charIter.remaining()); + for (var i=chars.length; i"; + } + + if ((newOp.lines || newlines ) && (chars.charAt(chars.length-1) != "\n")) { + chars = chars + "\n"; + newOp.chars++; + newOp.lines++; + logMessage = (logMessage || "") + "missing terminal newline
"; + } + newOp.opcode = "+"; + } + + return logMessage; +} + + diff --git a/etherpad/src/etherpad/control/admincontrol.js b/etherpad/src/etherpad/control/admincontrol.js new file mode 100644 index 0000000..6ff077b --- /dev/null +++ b/etherpad/src/etherpad/control/admincontrol.js @@ -0,0 +1,915 @@ +/** + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import("fastJSON"); +import("netutils"); +import("funhtml"); +import("funhtml.*"); +import("stringutils.{html,sprintf,startsWith,md5,trim}"); +import("jsutils.*"); +import("sqlbase.sqlbase"); +import("sqlbase.sqlcommon"); +import("sqlbase.sqlobj"); +import("varz"); +import("comet"); +import("email.sendEmail"); +import("dispatch.{Dispatcher,PrefixMatcher,DirMatcher,forward}"); + +import("etherpad.globals.*"); +import("etherpad.helpers"); +import("etherpad.utils.*"); +import("etherpad.sessions.getSession"); +import("etherpad.sessions"); +import("etherpad.statistics.statistics"); +import("etherpad.log"); +import("etherpad.admin.shell"); +import("etherpad.admin.sites"); +import("etherpad.usage_stats.usage_stats"); +import("etherpad.control.pro_beta_control"); +import("etherpad.control.statscontrol"); +import("etherpad.changes.follow"); +import("etherpad.statistics.clientside_errors"); +import("etherpad.statistics.exceptions"); + +import("etherpad.pad.activepads"); +import("etherpad.pad.model"); +import("etherpad.pad.padutils"); +import("etherpad.pad.pad_access"); +import("etherpad.pad.dbwriter"); +import("etherpad.collab.collab_server"); + +import("etherpad.pro.pro_accounts"); +import("etherpad.pro.pro_accounts.getSessionProAccount"); +import("etherpad.pro.pro_apns"); +import("etherpad.pro.pro_pad_db"); +import("etherpad.pro.pro_padmeta.accessProPad"); +import("etherpad.pro.pro_utils"); +import("etherpad.pro.domains"); +import("etherpad.pro.domain_migration"); +import("etherpad.control.admin.recovercontrol"); +import("etherpad.control.admin.admin_email_control"); +import("etherpad.control.admin.admin_download_user_data"); +import("etherpad.control.pro.admin.account_manager_control"); + + +import("etherpad.pad.padutils"); +import('etherpad.pro.pro_padmeta'); +import("etherpad.pad.exporthtml"); + +jimport("java.lang.System.out.println"); + +jimport("net.appjet.oui.cometlatencies"); +jimport("net.appjet.oui.appstats"); +jimport("org.mindrot.BCrypt"); + + +//---------------------------------------------------------------- + +function onRequest(name) { + pro_accounts.requireSuperAdminAccount(); + + var disp = new Dispatcher(); + + disp.addLocations([ + [PrefixMatcher('/admin/email/'), forward(admin_email_control)], + [PrefixMatcher('/admin/download-user-data/'), forward(admin_download_user_data)], + [PrefixMatcher('/admin/recover/'), forward(recovercontrol)], + [PrefixMatcher('/admin/shell'), forward(shell)], + [PrefixMatcher('/admin/usagestats/'), forward(statscontrol)], + [DirMatcher('/admin/account-manager/'), forward(account_manager_control)], + [DirMatcher('/admin/sites/'), forward(sites)], + ]); + + return disp.dispatch(); +} + +function _commonHead() { + return HEAD(STYLE( + "html {font-family:Verdana,Helvetica,sans-serif;}", + "body {padding: 2em;}" + )); +} + +//---------------------------------------------------------------- + +function render_main_get() { + renderHtml("admin/page.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + }); +} + +//---------------------------------------------------------------- + +function render_config_get() { + + vars = []; + eachProperty(appjet.config, function(k,v) { + vars.push(k); + }); + + vars.sort(); + + body = PRE() + vars.forEach(function(v) { + body.push("appjet.config."+v+" = "+appjet.config[v]+"\n"); + }); + + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Config', + content: body + }); +} + +//---------------------------------------------------------------- + + +function render_dashboard_get() { + var body = BODY(); + body.push(H1({style: "border-bottom: 1px solid black;"}, "Dashboard")); + + body.push(H2({style: "color: #226; font-size: 1em;"}, "Uptime")); + body.push(P({style: "margin-left: 25px;"}, "Server running for "+renderServerUptime()+".")) + + body.push(H2({style: "color: #226; font-size: 1em;"}, "Response codes")); + body.push(renderResponseCodes()); + + body.push(H2({style: "color: #226; font-size: 1em;"}, "Comet Connections")); + body.push(renderPadConnections()); + + body.push(H2({style: "color: #226; font-size: 1em;"}, "Comet Stats")); + body.push(renderCometStats()); + + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Dashboard', + content: body + }); +} + +// Note: This function is called by the PNE dashboard (pro_admin_control.js)! Be careful. +function renderPadConnections() { + var d = DIV(); + var lastCount = cometlatencies.lastCount(); + + if (lastCount.isDefined()) { + var countMap = {}; + lastCount.get().foreach(scalaF1(function(x) { + countMap[x._1()] = x._2(); + })); + + var totalConnected = 0; + var ul = UL(); + eachProperty(countMap, function(k,v) { + ul.push(LI(k+": "+v)); + if (/^\d+$/.test(v)) { + totalConnected += Number(v); + } + }); + ul.push(LI(B("Total: ", totalConnected))); + d.push(ul); + } else { + d.push("Still collecting data... check back in a minute."); + } + return d; +} + +// Note: This function is called by the PNE dashboard (pro_admin_control.js)! Be careful. +function renderCometStats() { + var d = DIV(); + var lastStats = cometlatencies.lastStats(); + var lastCount = cometlatencies.lastCount(); + + + if (lastStats.isDefined()) { + d.push(P("Realtime transport latency percentiles (microseconds):")); + var ul = UL(); + lastStats.map(scalaF1(function(s) { + ['50', '90', '95', '99', 'max'].forEach(function(id) { + var fn = id; + if (id != "max") { + fn = ("p"+fn); + id = id+"%"; + } + ul.push(LI(id, ": <", s[fn](), html("µ"), "s")); + }); + })); + d.push(ul); + } else { + d.push(P("Still collecting data... check back in a minutes.")); + } + + /* ["p50", "p90", "p95", "p99", "max"].forEach(function(id) { + ul.push(LI(B( + + return DIV(P(sprintf("50%% %d\t90%% %d\t95%% %d\t99%% %d\tmax %d", + s.p50(), s.p90(), s.p95(), s.p99(), s.max())), + P(sprintf("%d total messages", s.count()))); + }})).get();*/ + + + return d; +} + +// Note: This function is called by the PNE dashboard (pro_admin_control.js)! Be careful. +function renderResponseCodes() { + var statusCodeFrequencyNames = ["minute", "hour", "day", "week"]; + var data = { }; + var statusCodes = appstats.stati(); + for (var i = 0; i < statusCodes.length; ++i) { + var name = statusCodeFrequencyNames[i]; + var map = statusCodes[i]; + map.foreach(scalaF1(function(pair) { + if (! (pair._1() in data)) data[pair._1()] = {}; + var scmap = data[pair._1()]; + scmap[name] = pair._2().count(); + })); + }; + var stats = TABLE({id: "responsecodes-table", style: "margin-left: 25px;", + border: 1, cellspacing: 0, cellpadding: 4}, + TR.apply(TR, statusCodeFrequencyNames.map(function(name) { + return TH({colspan: 2}, "Last", html(" "), name); + }))); + var sortedStati = []; + eachProperty(data, function(k) { + sortedStati.push(k); + }); + sortedStati.sort(); + sortedStati.forEach(function(k, i) { // k is status code. + var row = TR(); + statusCodeFrequencyNames.forEach(function(name) { + row.push(TD({style: 'width: 2em;'}, data[k][name] ? k+":" : "")); + row.push(TD(data[k][name] ? data[k][name] : "")); + }); + stats.push(row); + }); + return stats; +} + +// Note: This function is called by the PNE dashboard (pro_admin_control.js)! Be careful. +function renderServerUptime() { + var labels = ["seconds", "minutes", "hours", "days"]; + var ratios = [60, 60, 24]; + var time = appjet.uptime / 1000; + var pos = 0; + while (pos < ratios.length && time / ratios[pos] > 1.1) { + time = time / ratios[pos]; + pos++; + } + return sprintf("%.1f %s", time, labels[pos]); +} + +//---------------------------------------------------------------- +// Broadcasting Messages +//---------------------------------------------------------------- + +function render_broadcast_message_get() { + var body = FORM({action: request.path, method: 'post'}, + H3('Broadcast Message to All Active Pad Clients:'), + INPUT({type:'hidden', name:'xsrf', value: helpers.xsrfToken()}), + TEXTAREA({name: 'msgtext', style: 'width: 100%; height: 100px;'}), + H3('JavaScript code to be eval()ed on client (optional, be careful!): '), + TEXTAREA({name: 'jscode', style: 'width: 100%; height: 100px;'}), + INPUT({type: 'submit', value: 'Broadcast Now'})); + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Broadcast message', + content: body + }); +} + +function render_broadcast_message_post() { + var msgText = request.params.msgtext; + var jsCode = request.params.jscode; + if (!(msgText || jsCode)) { + response.write("No mesage text or jscode specified."); + response.stop(); + return; + } + collab_server.broadcastServerMessage({ + type: 'NOTICE', + text: msgText, + js: jsCode + }); + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Broadcast message', + content: P("OK") + }); +} + + +//---------------------------------------------------------------- +// pad inspector +//---------------------------------------------------------------- + +function _getPadUrl(globalPadId) { + var superdomain = pro_utils.getRequestSuperdomain(); + var domain; + if (padutils.isProPadId(globalPadId)) { + var domainId = padutils.getDomainId(globalPadId); + domain = domains.getDomainRecord(domainId).subDomain + + '.' + superdomain; + } + else { + domain = superdomain; + } + var localId = padutils.globalToLocalId(globalPadId); + return "http://"+httpHost(domain)+"/"+localId; +} + +function render_revert_post() { + var padId = request.params.padId; + var revNum = request.params.revNum; + + model.rollbackToRevNum(padId, revNum); + response.redirect('/admin/padinspector?padId='+padId+"&revtext=HEAD"); +} + +function render_padinspector_get() { + var padId = request.params.padId; + if (!padId) { + var div = DIV(); + div.push(FORM({action: request.path, method: 'get', style: 'border: 1px solid #ccc; background-color: #eee; padding: .2em 1em;'}, + P("Pad Lookup: ", + INPUT({name: 'padId', value: ''}), + INPUT({type: 'submit'})))); + + // show recently active pads; the number of them may vary; lots of + // activity in a pad will push others off the list + div.push(H3("Recently Active Pads:")); + var recentlyActiveTable = TABLE({cellspacing: 0, cellpadding: 6, border: 1 }); + var recentPads = activepads.getActivePads(); + recentPads.forEach(function (info) { + var time = info.timestamp; // number + var pid = info.padId; + model.accessPadGlobal(pid, function(pad) { + if (pad.exists()) { + var numRevisions = pad.getHeadRevisionNumber(); + var connected = collab_server.getNumConnections(pad); + recentlyActiveTable.push( + TR(TD(B(pid)), + TD({style: 'font-style: italic;'}, timeAgo(time)), + TD(connected+" connected"), + TD(numRevisions+" revisions"), + TD(A({href: qpath({padId: pid, revtext: "HEAD"})}, "HEAD")), + TD(A({href: qpath({padId: pid})}, "inspect")) + )); + } + }, "r"); + }); + div.push(recentlyActiveTable); + renderHtml("admin/dynamic.ejs", { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Pad inspector', + content: div + }); + return; + } + if (startsWith(padId, '/')) { + padId = padId.substr(1); + } + if (request.params.setsupportstimeslider) { + var v = (String(request.params.setsupportstimeslider).toLowerCase() == + 'true'); + model.accessPadGlobal(padId, function(pad) { + pad.setSupportsTimeSlider(v); + }); + response.write("on pad "+padId+": setSupportsTimeSlider("+v+")"); + response.stop(); + } + model.accessPadGlobal(padId, function(pad) { + if (! pad.exists()) { + response.write("Pad not found: /"+padId); + response.stop(); + } + + var headRev = pad.getHeadRevisionNumber(); + var div = DIV(); + + if (request.params.revtext) { + var i; + if (request.params.revtext == "HEAD") { + i = headRev; + } else { + i = Number(request.params.revtext); + } + var infoObj = {}; + div.push(H3(A({href: request.path}, "PadInspector"), + ' > ', A({href: request.path+'?padId='+padId}, "/"+padId), + ' > ', "Revision ", i, "/", headRev, + SPAN({style: 'color: #949;'}, ' ', pad.getRevisionDate(i).toLocaleDateString() + pad.getRevisionDate(i).toLocaleTimeString()))); + div.push(H3("Browse Revisions: ", + ((i > 0) ? A({id: 'previous', href: qpath({revtext: (i-1)})}, '<< previous') : ''), + ' ', + ((i < pad.getHeadRevisionNumber()) ? A({id: 'next', href: qpath({revtext:(i+1)})}, 'next >>') : '')), + funhtml.FORM({action: '/admin/revert', method: 'POST'}, + helpers.xsrfTokenElement(), + funhtml.INPUT({type: 'hidden', name:'padId', value:padId}), + funhtml.INPUT({type: 'hidden', name:'revNum', value:i}), + funhtml.INPUT({type: 'submit', name:'submit', value:'Revert to here' })), + + DIV({style: 'padding: 1em; border: 1px solid #ccc;'}, + pad.getRevisionText(i, infoObj))); + + if (infoObj.badLastChar) { + div.push(P("Bad last character of text (not newline): "+infoObj.badLastChar)); + } + } else if (request.params.dumpstorage) { + div.push(P(collab_server.dumpStorageToString(pad))); + } else if (request.params.showlatest) { + div.push(P(pad.text())); + } else { + div.push(H2(A({href: request.path}, "PadInspector"), ' > ', "/"+padId)); + // no action + div.push(P(A({href: qpath({revtext: 'HEAD'})}, 'HEAD='+headRev))); + div.push(P(A({href: qpath({dumpstorage: 1})}, 'dumpstorage'))); + div.push(P(A({href: '/admin/recover/analyze?globalPadiId=' + pad.getId()}, 'analyze'))); + var supportsTimeSlider = pad.getSupportsTimeSlider(); + if (supportsTimeSlider) { + div.push(P(A({href: qpath({setsupportstimeslider: 'false'})}, 'hide slider'))); + } + else { + div.push(P(A({href: qpath({setsupportstimeslider: 'true'})}, 'show slider'))); + } + } + + var script = SCRIPT({type: 'text/javascript', nonce: helpers.cspNonce() }, html([ + '$(document).keydown(function(e) {', + ' var h = undefined;', + ' if (e.keyCode == 37) { h = $("#previous").attr("href"); }', + ' if (e.keyCode == 39) { h = $("#next").attr("href"); }', + ' if (h) { window.location.href = h; }', + '});' + ].join('\n'))); + + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Pad inspector', + content: DIV(div, script) + }); + }, "r"); +} + + +//---------------------------------------------------------------- +// eepnet license display +//---------------------------------------------------------------- + +function render_eepnet_licenses_get() { + var data = sqlobj.selectMulti('eepnet_signups', {}, {orderBy: 'date'}); + var t = TABLE({border: 1, cellspacing: 0, cellpadding: 2}); + var cols = ['date','email','orgName','firstName','lastName', 'jobTitle','phone','estUsers']; + data.forEach(function(x) { + var tr = TR(); + cols.forEach(function(colname) { + tr.push(TD(x[colname])); + }); + t.push(tr); + }); + response.write(HTML(BODY({style: 'font-family: monospace;'}, t))); +} + +//---------------------------------------------------------------- +// pad integrity +//---------------------------------------------------------------- + +/*function render_changesettest_get() { + var nums = [0, 1, 2, 3, 0xfffffff, 0x02345678, 4]; + var str = Changeset.numberArrayToString(nums); + var result = Changeset.numberArrayFromString(str); + var resultArray = result[0]; + var remainingString = result[1]; + var bad = false; + if (remainingString) { + response.write(P("remaining string length is: "+remainingString.length)); + bad = true; + } + if (nums.length != resultArray.length) { + response.write(P("length mismatch: "+nums.length+" / "+resultArray.length)); + bad = true; + } + response.write(P(nums[2])); + for(var i=0;i 0 ? makeLink("Show previous "+count+".", [], [], start-count) : ""), + (diagnostic_entries.length == count ? makeLink("Show next "+count+".", [], [], start+count) : ""))); + body.push(t); + + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Diagnostics', + content: body + }); +} + +//---------------------------------------------------------------- + +import("etherpad.pad.pad_migrations"); + +function render_padmigrations_both() { + var residue = (request.params.r || 0); + var modulus = (request.params.m || 1); + var name = (request.params.n || (residue+"%"+modulus)); + pad_migrations.runBackgroundMigration(residue, modulus, name); + response.write("done"); + return true; +} + +// TODO: show sizes? +function render_cachebrowser_get() { + var path = request.params.path; + if (path && path.charAt(0) == ',') { + path = path.substr(1); + } + var pathArg = (path || ""); + var c = appjet.cache; + if (path) { + var cparent, cpart; + path.split(",").forEach(function(part) { + cparent = c; + cpart = part; + c = c[part]; + }); + + if (c && request.params["delete"]) { + delete cparent[cpart]; + response.redirect(qpath({"delete": null, path: pathArg.substr(0, pathArg.lastIndexOf(","))})); + } + } + + var d = DIV({style: 'font-family: monospace; text-decoration: none;'}); + + d.push(H3("appjet.cache --> "+pathArg.split(",").join(" --> "))); + d.push(FORM({method: "GET"}, + INPUT({name: "path", type: "hidden", "value": pathArg}), + INPUT({name: "delete", type: "submit", "value": "Delete"}))); + + var t = TABLE({border: 1}); + keys(c).sort().forEach(function(k) { + var v = c[k]; + if (v && (typeof(v) == 'object') && (!v.getDate)) { + t.push(TR(TD(A({style: 'text-decoration: none;', + href: request.path+"?path="+pathArg+","+k}, k)))); + } else { + t.push(TR(TD(k), TD(v))); + } + }); + + d.push(t); + response.write(d); +} + +function render_send_missed_get() { + response.write("
") +} + +function render_send_missed_post() { + var missedInvites = JSON.parse(request.params.data); + var doSend = Boolean(request.params.send); + + var emailToPadsMap = {}; + for (var i=0; i"); + } + + for (var toEmail in emailToPadsMap) { + body = "Hey there,

"; + body += "Our sincere apologies. Due to a bug in Hackpad, some invites were not properly delivered.

"; + body += "Here are the invites you missed:

"; + var padListForLog = []; + + for (var globalPadId in emailToPadsMap[toEmail]) { + var missedInvite = emailToPadsMap[toEmail][globalPadId]; + var title = "Untitled"; + accessProPad(globalPadId, function(ppad) { + title = ppad.getDisplayTitle(); + }); + var name = null; + if (missedInvite.hostId) { + name = pro_accounts.getAccountById(missedInvite.hostId).fullName; + } + padListForLog.push(title) + if (name) { + body += name + " invited you to edit "; + body += ""+title+"
"; + } else { + body += "You were invited to edit "; + body += ""+title+"
"; + } + } + + body += "
We have taken steps to make sure this doesn't happen again,
"; + body += "The Hackpad Team"; + response.write("Sent mail to " + toEmail + " about " + padListForLog.join(",") + "
"); + if (doSend) { + sendEmail(toEmail, pro_utils.getEmailFromAddr(), "You've been invited to edit on Hackpad", {}, body, "text/html; charset=utf-8"); + } + } +} + + +function render_pro_domain_accounts_get() { + var accounts = sqlobj.selectMulti('pro_accounts', {}, {}); + var domains = sqlobj.selectMulti('pro_domains', {}, {}); + + // build domain map + var domainMap = {}; + domains.forEach(function(d) { domainMap[d.id] = d; }); + accounts.sort(function(a,b) { return cmp(b.lastLoginDate, a.lastLoginDate); }); + + var b = DIV({style: "font-family: monospace;"}); + b.push(accounts.length + " pro accounts."); + var t = TABLE({border: 1}); + t.push(TR(TH("email"), + TH("domain"), + TH("lastLogin"), + TH("password"))); + accounts.forEach(function(u) { + t.push(TR(TD(u.email), + TD(domainMap[u.domainId].subDomain+"."+request.domain), + TD(u.lastLoginDate), + TD(INPUT({type: "password", name: "password_" + u.email})))); + }); + + b.push(t); + b.push(INPUT({type: "submit", value: "Save"})); + + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Pro accounts', + content: FORM({method: "POST", action: request.path}, b) + }); + +} + +function render_usagestats_get() { + response.redirect("/ep/admin/usagestats/"); +} + +function render_exceptions_get() { + exceptions.render(); +} + +function render_clientside_errors_get() { + clientside_errors.render(); +} + +function render_apns_post() { + var body = H2('Apple Push Notification Service Tester'); + + + body += H3({style: 'margin-top:20px;'}, "Send Simple Notification"); + + if (request.params.deviceToken && request.params.appId) { + pro_apns.sendPushNotification(request.params.appId, request.params.deviceToken, request.params.message, { + hp: { + u: request.params.padUrl, + a: request.params.accountId, + t: request.params.eventType + } + }, !!request.params.padUrl); + body += H4({style: "color: green; margin-top:20px;"}, "Pushed to device " + request.params.deviceToken); + } + + body += FORM( + P("App ID"), P(INPUT({type: "text", name: "appId", value: request.params.appId || pro_apns.DEBUG_APP_ID, size: 64})), + P("Device Token"), P(INPUT({type: "text", name: "deviceToken", value: request.params.deviceToken, size: 64})), + P("Alert Message"), P(INPUT({type: "text", name: "message", value: request.params.message, size: 64})), + P("Pad URL"), P(INPUT({type: "text", name: "padUrl", value: request.params.padUrl, size: 64})), + P("Account ID"), P(INPUT({type: "text", name: "accountId", value: request.params.accountId, size: 64})), + P("Event Type"), P(SELECT({name: "eventType"}, + OPTION({value: "c"}, "Created"), + OPTION({value: "d"}, "Deleted"), + OPTION({value: "e"}, "Edited"), + OPTION({value: "f"}, "Follow"), + OPTION({value: "u"}, "Unfollow"), + OPTION({value: "i"}, "Invite"), + OPTION({value: "m"}, "Mention"))), + P(INPUT({type: "submit"}))); + + + body += H3({style: 'margin-top:20px;'}, "Send Pad Notification"); + + if (request.params.globalPadId && request.params.accountId && request.params.eventType) { + var userId = pro_accounts.getUserIdByEncryptedId(request.params.accountId); + if (userId) { + pro_apns.sendPushNotificationForPad(request.params.globalPadId, request.params.message, userId, request.params.eventType); + body += H4({style: "color: green; margin-top:20px;"}, "Pushed to account " + request.params.accountId); + } else { + body += H4({style: "color: red; margin-top:20px;"}, "Could not find accountId " + request.params.accountId); + } + } + + body += FORM( + P("Global Pad Id"), P(INPUT({type: "text", name: "globalPadId", value: request.params.globalPadId})), + P("Account Id"), P(INPUT({type: "text", name: "accountId", value: request.params.accountId})), + P("Alert Message"), P(INPUT({type: "text", name: "message", value: request.params.message})), + P("Event Type"), P(SELECT({name: "eventType"}, + OPTION({value: "c"}, "Created"), + OPTION({value: "d"}, "Deleted"), + OPTION({value: "e"}, "Edited"), + OPTION({value: "f"}, "Follow"), + OPTION({value: "u"}, "Unfollow"), + OPTION({value: "i"}, "Invite"), + OPTION({value: "m"}, "Mention"))), + P(INPUT({type: "submit"}))); + + + body += H3({style: 'margin-top:20px;'}, "Process Notification Feedback"); + if (request.params.processFeedback) { + pro_apns.processFeedback(); + body += H4({style: "color: green; margin-top:20px;"}, "Processed feedback"); + } + body += FORM( + P(INPUT({type: 'hidden', name: 'processFeedback', value: '1'})), + P(INPUT({type: "submit"}))); + + renderHtml("admin/dynamic.ejs", + { + config: appjet.config, + bodyClass: 'nonpropad', + title: 'Apple Push Notification Service', + content: body + }); +} + + +function render_setadminmode_post() { + var sudoAcctIds = [ 0 /* etherpad admin */ ]; + + var sudoEmailStr = appjet.config['superUserEmailAddresses']; + if (sudoEmailStr) { + // parse the list of super user email addresses, and normalize them + var sudoEmailList = sudoEmails.split(",").map(function(email) { + return trim(email).toLowerCase(); + }); + sudoEmailList = sudoEmailList.filter(function(email) { + return email && email.indexOf('@') > -1; + }); + + // collect all account ids with a super user email + sudoEmailList.forEach(function(email) { + sudoAcctIds = sudoAcctIds.concat(pro_accounts.getAllAccountsWithEmail(email)); + }); + } + + if (isProduction() && + sudoAcctIds.indexOf(pro_accounts.getSessionProAccount().id) == -1) { + render401("Unauthorized: Sudo Required"); + } + + sessions.setIsAnEtherpadAdmin( + String(request.params.v).toLowerCase() == "true"); + response.redirect("/admin/"); +} diff --git a/etherpad/src/etherpad/control/api_v1_control.js b/etherpad/src/etherpad/control/api_v1_control.js new file mode 100644 index 0000000..683ea96 --- /dev/null +++ b/etherpad/src/etherpad/control/api_v1_control.js @@ -0,0 +1,766 @@ + +import("dispatch.{Dispatcher,PrefixMatcher}"); +import("stringutils.trim"); +import("sqlbase.sqlobj"); + +import("etherpad.control.searchcontrol"); +import("etherpad.collab.collab_server"); +import("etherpad.importexport.importexport") +import("etherpad.pad.exporthtml"); +import("etherpad.pad.importhtml"); +import("etherpad.pad.model"); +import("etherpad.pad.pad_access"); +import("etherpad.pad.padevents"); +import("etherpad.pad.padusers"); +import("etherpad.pad.padutils"); +import("etherpad.pad.pad_security"); +import("etherpad.pro.domains"); +import("etherpad.pro.pro_config"); +import("etherpad.pro.pro_groups"); +import("etherpad.pro.pro_groups_key_values"); +import("etherpad.pro.pro_padmeta"); +import("etherpad.pro.pro_pad_db"); +import("etherpad.pro.pro_accounts"); +import("etherpad.pro.pro_oauth"); +import("etherpad.pro.pro_settings"); +import("etherpad.changes.follow"); +import("etherpad.changes.changes.getDiffHTML"); +import("etherpad.control.apicontrol.emailToAPIEmail"); +import("etherpad.control.invitecontrol.autocompleteContacts"); +import("etherpad.control.pad.pad_view_control"); +import("etherpad.control.pad.pad_control"); +import("etherpad.globals.*"); +import("etherpad.log"); +import("etherpad.utils.*"); + +import("etherpad.importexport.Markdown.Markdown"); +import("etherpad.importexport.toMarkdown.toMarkdown"); + + +function onRequest() { + var disp = new Dispatcher(); + disp.addLocations([ + [/^\/api\/1\.0\/edited\-since\/(\d+)$/, render_v1_edited_since_get], + + [/^\/api\/1\.0\/group\/([^\/]+)\/options$/, render_v1_group_options_both], + + ['/api/1.0/options', render_v1_options_get], + + ['/api/1.0/pad/create', render_v1_create_pad_post], + + [/^\/api\/1\.0\/pad\/([^\/]+)\/title$/, render_v1_get_title_get], + [/^\/api\/1\.0\/pad\/([^\/]+)\/permissions$/, render_v1_get_permissions_get], + [/^\/api\/1\.0\/pad\/([^\/]+)\/groups$/, render_v1_get_groups_get], + [/^\/api\/1\.0\/pad\/([^\/]+)\/content$/, render_v1_set_content_post], + [/^\/api\/1\.0\/pad\/([^\/]+)\/content\/(\d+|latest)\.(html|md|txt|native)$/, render_v1_get_content_get], + [/^\/api\/1\.0\/pad\/([^\/]+)\/content\.(html|md|txt|native)$/, render_v1_get_latest_content_get], + [/^\/api\/1\.0\/pad\/([^\/]+)\/invitees$/, render_v1_pad_invitees_get], + [/^\/api\/1\.0\/pad\/([^\/]+)\/options$/, render_v1_pad_options_get], + [/^\/api\/1\.0\/pad\/([^\/]+)\/metadata/, render_v1_pad_metadata_get], + [/^\/api\/1\.0\/pad\/([^\/]+)\/revert\-to\/(\d+)$/, render_v1_pad_revert_post], + [/^\/api\/1\.0\/pad\/([^\/]+)\/revisions$/, render_v1_pad_revisions_get], + [/^\/api\/1\.0\/pad\/([^\/]+)\/revoke-access\/(.+)$/, render_v1_pad_revoke_access_post], + [/^\/api\/1\.0\/pad\/([^\/]+)\/export-info$/, render_v1_pad_export_info_get], + + + [/^\/api\/1\.0\/am-i-an-admin$/, render_v1_am_i_workspace_admin_get], + [/^\/api\/1\.0\/all-pads-in-domain$/, render_v1_get_all_pads_in_domain_get], + [/^\/api\/1\.0\/all-users-in-domain$/, render_v1_get_all_users_in_domain_get], + + ['/api/1.0/pads/all', render_v1_list_all_pads_get], + + ['/api/1.0/search', render_v1_search_get], + + // Current user + ['/api/1.0/user/contacts', render_v1_user_contacts_get], + ['/api/1.0/user/create', render_v1_create_user_post], + ['/api/1.0/user/sites', render_v1_user_sites_get], + + // By (encrypted) user id + [/^\/api\/1\.0\/user\/([^\/]+)\/profile$/, render_v1_user_profile_get], + + // By email address + [/^\/api\/1\.0\/user\/([^\/]+)\/remove$/, render_v1_remove_user_post], + [/^\/api\/1\.0\/user\/([^\/]+)\/settings$/, render_v1_user_settings_get], + + // This one must be last, otherwise they get redirected to the sign-in page. + [PrefixMatcher('/api/1.0/'), render_v1_default_get], + ]); + + return disp.dispatch(); +} + +function render_v1_default_get() { + renderJSONError(404, "Not Found"); +} + +function _setPadContentFromRequest(pad) { + switch (request.headers["Content-Type"]) { + case "text/html": + // let's wait for someone to ask before turning on authorship preservation + // we need a better scheme for preventing blatant impersonation and datamining + // this makes it the *tiniest* bit harder + importhtml.setPadHTML(pad, request.content, false /*preserve authorship*/); + break; + case "text/x-web-markdown": + var md = new Markdown.Converter(); + var html = md.makeHtml(request.content); + importhtml.setPadHTML(pad, html); + break; + case "text/plain": + default: + collab_server.setPadText(pad, request.content); + break; + } +} + +function render_v1_create_pad_post() { + + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + + var padId = randomUniquePadId(); + padutils.accessPadLocal(padId, function(pad) { + if (pad.exists()){ + renderJSONError(401, "Create pad failed."); // XXX: just try another id + } + if (request.content && request.content.length) { + try { + pad.create(null, request.content.split("\n")[0]); + _setPadContentFromRequest(pad); + } catch (ex) { + log.logException(ex); + renderJSONError(400, "Invalid pad content"); + } + } else { + pad.create(); + } + }); + + var globalId = padutils.getGlobalPadId(padId); + var userAccount = pro_accounts.getApiProAccount(); + pro_padmeta.accessProPad(globalId, function(ppad) { + ppad.setCreatorId(userAccount.id); + ppad.setLastEditor(userAccount.id); + ppad.setLastEditedDate(new Date()); + }); + + return renderJSON({padId:padId, globalPadId:globalId}); +} + +function render_v1_set_content_post(padId) { + + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + var setCreatorId = false; + padutils.accessPadLocal(padId, function(pad) { + if (!pad.exists()){ + pad.create(); + setCreatorId = true; + } + _setPadContentFromRequest(pad); + }); + + var globalId = padutils.getGlobalPadId(padId); + var userAccount = pro_accounts.getApiProAccount(); + pro_padmeta.accessProPad(globalId, function(ppad) { + if (setCreatorId) { + ppad.setCreatorId(userAccount.id); + } + ppad.setLastEditor(userAccount.id); + ppad.setLastEditedDate(new Date()); + }); + return renderJSON({ success: true }); +} + + +function _getColorsForEditors(historicalAuthorData) { + var colorIdForAuthor = {}; + for (var author in historicalAuthorData) { + var accountId = padusers.getAccountIdForProAuthor(author); + colorIdForAuthor[accountId] = historicalAuthorData[author].colorId; + } + return colorIdForAuthor; +} + +function render_v1_get_title_get(padId) { + + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + var title; + padutils.accessPadLocal(padId, function(pad) { + title = pro_padmeta.accessProPadLocal(padId, function(propad) { + return propad.getDisplayTitle(); + }); + }); + + return renderJSON({title: title}); +} + +function render_v1_pad_revisions_get(padId) { + + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + + var padDiffs = []; + var limit = Math.min(request.params.limit || 100); + + var historicalAuthorData = padutils.accessPadLocal(padId, function(pad) { + return collab_server.buildHistoricalAuthorDataMapForPadHistory(pad); + }, 'r', true /*skip access control!*/); + var colorIdForAuthor = _getColorsForEditors(historicalAuthorData); + var emailByAcctId = {}; + + padutils.accessPadLocal(padId, function(pad) { + if (!pad.exists()) { + renderJSONError(404, "Pad not found"); + } + var segments = pad.getMostRecentEditSegments(limit); + for (var i=0; i 0 && !emailByAcctId[acctId]) { + newAcctIds.push(acctId); + } + }); + + pro_accounts.getAccountsByIds(newAcctIds).forEach(function(acct) { + emailByAcctId[acct.id] = acct.email; + }); + + segments[i][2].map(padusers.getAccountIdForProAuthor).forEach(function(acctId) { + if (acctId>0) { + emails.push(emailByAcctId[acctId]); + } + }); + } + + if (!authors.length) { + pro_padmeta.accessProPadLocal(padId, function (propad) { + if (!propad.exists()) { + return; + } + var creatorId = propad.getCreatorId(); + authorPics.push(pro_accounts.getPicById(creatorId)); + authors.push(pro_accounts.getFullNameById(creatorId)); + }); + } + + padDiffs.push({ + htmlDiff: + getDiffHTML(pad, segments[i][0], segments[i][1], segments[i][2], colorIdForAuthor, true/*timestamps*/, "Edited by ", true/*includeDeletes*/, segments[i][4]), + snippet: padutils.truncatedPadText(pad), + timestamp:segments[i][3] / 1000, + startRev: segments[i][0], + endRev:segments[i][1], + authors: authors, + emails: emails, + authorPics: authorPics, + }); + } + }, 'r'); + + return renderJSON(padDiffs); +} + +/* + revert + POST /api/v1/pad/padId/content/revert-to/revisionId +*/ + +function render_v1_pad_revert_post(padId, revisionId) { + + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + if (revisionId < 0) { + renderJSONError(403, "Invalid revision"); + } + + padutils.accessPadLocal(padId, function(pad) { + if (revisionId > pad.getHeadRevisionNumber()) { + renderJSONError(403, "Invalid revision"); + } + + var atext = pad.getInternalRevisionAText(revisionId); + collab_server.setPadAText(pad, atext); + }); + + return renderJSON({ success: true }); +} + + +/* + get-content + GET /api/v1/pad/padId/content/revisionId.{format} + + revisionId: "latest" or numeric revision id + format: "html", "markdown", "text" +*/ + +function render_v1_get_latest_content_get(localPadId, format) { + return render_v1_get_content(localPadId, null, format) +} + +function render_v1_get_all_users_in_domain_get() { + if (!request.isGet) { + return false; + } + + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + if (!apiAccount || !apiAccount.isAdmin) { + return false; + } + + var userIdToProfile = {}; + pro_accounts.listAllDomainAccounts(apiAccount.domainId).map(function (r) { + userIdToProfile[pro_accounts.getEncryptedUserId(r.id)] = { + email: r.email, + fullName: r.fullName, + isGuest: Boolean(pro_accounts.getIsDomainGuest(r)), + }; + }); + + return renderJSON({userIdToProfile: userIdToProfile}); +} + +function render_v1_get_all_pads_in_domain_get() { + if (!request.isGet) { + return false; + } + + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + if (!apiAccount || !apiAccount.isAdmin) { + return false; + } + + var localPadIds = sqlobj.selectMulti('pro_padmeta', {domainId: apiAccount.domainId, isDeleted:false, isArchived:false, lastEditorId: ["IS NOT", null]}).map(function (row) { + return row.localPadId; + }); + return renderJSON({pads: localPadIds}); +} + +function render_v1_pad_metadata_get(localPadId) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + if (!apiAccount || !apiAccount.isAdmin) { + return false; + } + + return renderJSON(sqlobj.selectSingle('pro_padmeta', {localPadId: localPadId})); +} + +function render_v1_get_groups_get(localPadId) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + var globalPadId = padutils.getGlobalPadId(localPadId); + + return renderJSON({groups: pro_groups.getGroupInfos(pro_groups.getPadGroupIds(globalPadId))}) +} + +function render_v1_get_permissions_get(localPadId) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + + var out; + + // Must have access to the pad + padutils.accessPadLocal(localPadId, function(pad) { + out = _getPadPermissions(localPadId); + }); + + return renderJSON(out); +} + +function _getPadPermissions(localPadId) { + var globalPadId = padutils.getGlobalPadId(localPadId); + var accessIds = pad_access.getUserIdsWithAccess(globalPadId).map(function (uid) { return pro_accounts.getEncryptedUserId(uid)}); + + var rawFollowerMap = follow.getUserIdsAndFollowPrefsForPad(globalPadId); + var encryptedFollowerMap = {}; + Object.keys(rawFollowerMap).map(function (uid) { + encryptedFollowerMap[pro_accounts.getEncryptedUserId(uid)] = rawFollowerMap[uid]; + }); + + var creatorId; + pro_padmeta.accessProPad(globalPadId, function(ppad) { + creatorId = pro_accounts.getEncryptedUserId(ppad.getCreatorId()); + }); + + return {permissioned: accessIds, followers: encryptedFollowerMap, creatorId: creatorId}; +} + +function render_v1_get_content_get(localPadId, revisionId, format) { + var out; + + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + + padutils.accessPadLocal(localPadId, function(pad) { + if (!revisionId || revisionId == 'latest') { + revisionId = pad.getHeadRevisionNumber(); + } + response.addHeader('X-Hackpad-Revision', revisionId); + + if (!(format in importexport.formats)) { + renderJSONError(400, "missing or unknown format"); + } + + out = importexport.exportPadContent(pad, revisionId, format); + response.setContentType(importexport.contentTypeForFormat(format)); + + }, 'r'); + + response.write(out); + return true; +} + +function render_v1_edited_since_get(timestamp) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(true); + var pads = pro_pad_db.listPadsEditedSince(timestamp, 1000); + pads = pads.map(function (pad) { return pad.localPadId }); + return renderJSON(pads); +} + +function render_v1_pad_revoke_access_post(localPadId, email) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + + var account = pro_oauth.getFullOrApiAccountByEmail(email.toLowerCase(), apiAccount.domainId); + if (!account) { + renderJSONError(400, "Not Allowed"); + } + + var userId = pro_accounts.getEncryptedUserId(account.id); + + var err = pad_control.revokePadUserAccess(localPadId, userId); + if (err) { + renderJSONError(403, err); + } + return renderJSON({ success: true }); +} + +function render_v1_create_user_post() { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + + if (!apiAccount || !apiAccount.isAdmin || domains.isPrimaryDomainRequest()) { + render401("Domain Admin Required"); + } + + var isDomainGuest = !(request.params.isFullMember == "1"); + + var account = pro_oauth.getFullOrApiAccountByEmail(emailToAPIEmail(requireEmailParam()), apiAccount.domainId); + if (!account) { + var accountId = pro_accounts.createNewAccount(apiAccount.domainId, request.params.name, emailToAPIEmail(requireEmailParam()), null, false, true, null, isDomainGuest/*isDomainGuest*/, false/*linked*/); + pro_accounts.setAccountDoesNotWantWhatsNew(accountId); + pro_accounts.setAccountDoesNotWantFollowEmail(accountId); + account = pro_accounts.getAccountById(accountId); + } else { + renderJSONError(403, "Account already exists"); + } + + return renderJSON({ success: true }); +} + + +function render_v1_remove_user_post(email) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(true); + + var userAccount = pro_oauth.getFullOrApiAccountByEmail(email.toLowerCase()); + if (!userAccount) { + renderJSONError(403, "User does not exist"); + } + + pro_accounts.setDeleted(userAccount); + return renderJSON({ success: true }); +} + +function render_v1_user_settings_get(email) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + + var userAccount; + email = email.toLowerCase(); + + if (apiAccount.isAdmin) { + userAccount = pro_oauth.getFullOrApiAccountByEmail(email); + if (!userAccount) { + renderJSONError(403, "User does not exist"); + } + } else { + userAccount = pro_accounts.getSessionProAccount(); + if (userAccount.email != email) { + renderJSONError(403, "Domain admin required"); + } + } + + if (request.isPost) { + for (var key in request.params) { + switch (key) { + case 'send-email': + pro_settings.setAccountGetsFollowEmails(userAccount.id, request.params[key].toLowerCase() == 'true'); + break; + } + } + return renderJSON({ success: true }); + } else { + var currentEmailSetting = pro_settings.getAccountGetsFollowEmails(userAccount); + return renderJSON({ success: true, 'send-email': currentEmailSetting}); + } +} + +function render_v1_user_profile_get(encryptedUserId) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + + var userId = pro_accounts.getUserIdByEncryptedId(encryptedUserId); + if (!userId) { + renderJSONError(404, "User does not exist"); + } + + var userAccount = pro_accounts.getAccountById(userId, true); + if (!userAccount) { + renderJSONError(404, "User does not exist"); + } + + var outputDict = { + success: true, + profile: { + fullName: userAccount.fullName, + photoUrl: pro_accounts.getPicById(userId), + largePhotoUrl: pro_accounts.getPicById(userId, true) + } + }; + + if (request.params.showEmail && apiAccount.isAdmin) { + outputDict.profile.email = userAccount.email; + } + + return renderJSON(outputDict); +} + +function render_v1_search_get() { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + var data = []; + if (request.params.q && trim(request.params.q)) { + data = searchcontrol.searchPads(request.params.q, request.params.start, request.params.limit).list; + } + return renderJSON(data); +} + +function render_v1_list_all_pads_get() { + + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + + var pads = pro_pad_db.listAccessiblePads(); + pads = pads.map(function (pad) { return pad.localPadId }); + + return renderJSON(pads) +} + +function render_v1_pad_invitees_get(padId) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + var userInfos; + var creatorId; + + pro_padmeta.accessProPadLocal(padId, function(propad) { + if (propad.exists()) { + creatorId = propad.getCreatorId(); + } + }); + + if (!creatorId) { + renderJSONError(404, "Pad not found"); + } + + padutils.accessPadLocal(padId, function(pad) { + userInfos = pad_control.getUsersForUserList(pad, creatorId); + }); + + for (var i = 0; i < userInfos.length; i++) { + userInfos[i].userId = pro_accounts.getEncryptedUserId(userInfos[i].userId); + } + + return renderJSON({ success: true, invitees: userInfos }); +} + +function render_v1_options_get() { + if (!domains.getRequestDomainRecord()) { + renderJSONError(404, 'Domain not found'); + } + var methods = [ 'password', 'google' ]; + if (domains.supportsFacebookSignin()) { + methods.push('facebook'); + } + return renderJSON({ success: true, options: { + siteName: pro_config.getConfig().siteName, + signInMethods: methods, + }}); +} + +function render_v1_pad_options_get(encryptedPadId) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + var retval = false; + padutils.accessPadLocal(encryptedPadId, function(pad) { + if (request.isGet) { + var padOptions = pad.getPadOptionsObj(); + var siteOptions = { guestPolicies: pad.getGuestPolicies(), + isSubdomain: !domains.isPrimaryDomainRequest() }; + if (siteOptions.isSubdomain) { + siteOptions.isPublic = domains.isPublicDomain(); + } + retval = renderJSON({ success: true, options: padOptions, + siteOptions: siteOptions }); + } else if (request.isPost) { + var msg = { + type: 'padoptions', + options: {}, + changedBy: padusers.getUserName() + }; + for (var key in request.params) { + var val = request.params[key]; + switch (key) { + case 'guestPolicy': + if (pad.getGuestPolicies().indexOf(val) == -1) { + renderJSONError(403, 'Invalid guestPolicy specified.'); + } + msg.options[key] = val; + break; + case 'isModerated': + msg.options[key] = (/^true$/i).test(val); + break; + default: + renderJSONError(403, 'Invalid pad option specified.'); + return; + } + } + padevents.onClientMessage(pad, { userId: padusers.getUserId() }, msg); + // This sends correct values regardless of whether the above succeeds. + msg.options = pad.getPadOptionsObj(); + collab_server.broadcastClientMessage(pad, msg); + // Unfortunately we don't actually know if this is true! + retval = renderJSON({ success: true }); + } + }); + return retval; +} + +/** + * A quick way to get all the things needed to export a pad + */ +function render_v1_pad_export_info_get(localPadId) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + if (!apiAccount || !apiAccount.isAdmin) { + return false; + } + + var info = {}; + var globalPadId = padutils.getGlobalPadId(localPadId); + + // Include other-domain accounts attributed in this document to avoid "unknown editor"s. + var nonDomainAccounts = []; + + try { + nonDomainAccounts = collab_server.getAllAuthorsFromAText(globalPadId) + .filter(function (account) { + return account.domainId != padutils.getDomainId(globalPadId); + }) + .map(function (account) { + return { + id: pro_accounts.getEncryptedUserId(account.id), + domainId: account.domainId, + fullName: account.fullName, + email: account.email, + isDeleted: account.isDeleted, + isGuest: Boolean(pro_accounts.getIsDomainGuest(account)), + isForeignUser: true, + } + }); + } catch (e) { + log.warn({ + message: "Exception during /export_info collab_server.getAllAuthorsFromAText", + e: e + }) + } + + var groupInfos = pro_groups.getGroupInfos(pro_groups.getPadGroupIds(globalPadId)); + pro_groups_key_values.decorateWithValues(groupInfos, 'pinnedPads'); + + padutils.accessPadLocal(localPadId, function(pad) { + var rev = pad.getHeadRevisionNumber(); + info['metadata'] = sqlobj.selectSingle('pro_padmeta', {localPadId: localPadId}); + info['options'] = pad.getPadOptionsObj(); + info['permissions'] = _getPadPermissions(localPadId); + info['contents'] = importexport.exportPadContent(pad, rev, "native"); + info['groups'] = groupInfos; + info['rev'] = rev; + info['nonDomainAccounts'] = nonDomainAccounts; + }); + + renderJSON({ success: true, info: info }); + return true; +} + +function render_v1_am_i_workspace_admin_get() { + + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + if (!apiAccount) { + return false; + } + + return renderJSON({ result: apiAccount.isAdmin }); +} + +function render_v1_group_options_both(encryptedGroupId) { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + var retval = false; + var groupId = pro_groups.getGroupIdByEncryptedId(encryptedGroupId); + if (request.isGet) { + var siteOptions = { guestPolicies: [ 'deny', 'allow' ], + isSubdomain: !domains.isPrimaryDomainRequest() }; + if (siteOptions.isSubdomain) { + siteOptions.isPublic = domains.isPublicDomain(); + } + retval = renderJSON({ success: true, options: { guestPolicy: pro_groups.getGroupIsPublic(groupId) ? "allow" : "deny" }, siteOptions: siteOptions }); + } else if (request.isPost) { + var isPublic = requireParam('guestPolicy') == 'allow'; + if (!pro_accounts.isAdminSignedIn()) { + var creatorId = pro_groups.getGroupCreatorId(groupId); + if (creatorId != apiAccount.id) { + renderJSONError(403, "Only " + pro_accounts.getFullNameById(creatorId) + " can change the group access."); + } + } + pro_groups.setGroupIsPublic(groupId, apiAccount.id, isPublic); + retval = renderJSON({success:true}); + } + return retval; +} + +function render_v1_user_sites_get() { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + return renderJSON({ + success: true, + sites: pro_accounts.getSessionSpaces().map(function(site) { + return { + siteName: site.orgName, + url: site.url + }; + }) + }); +} + +function render_v1_user_contacts_get() { + var apiAccount = pro_oauth.getAuthorizedRequestApiAccount(); + var contacts = autocompleteContacts(request.params.q); + return renderJSON({ + success:true, + contacts:contacts.list.map(function(contact) { + return { + name:contact.name, + userId:contact.hackpadUserId ? pro_accounts.getEncryptedUserId(contact.hackpadUserId) : null, + email:contact.visibleEmail, + fbid:contact.fbid + }; + }) + }); +} diff --git a/etherpad/src/etherpad/control/apicontrol.js b/etherpad/src/etherpad/control/apicontrol.js new file mode 100644 index 0000000..d3cb3e4 --- /dev/null +++ b/etherpad/src/etherpad/control/apicontrol.js @@ -0,0 +1,606 @@ + +import("sqlbase.sqlobj"); +import("fastJSON"); +import("jsutils"); +import("netutils.{urlGet,urlPost}"); +import("stringutils.{startsWith,trim}"); +import("s3"); + +import("etherpad.changes.changes.getDiffHTML"); +import("etherpad.collab.collab_server"); +import("etherpad.globals.isProduction"); +import("etherpad.helpers"); +import("etherpad.log"); +import("etherpad.pad.pad_access"); +import("etherpad.pad.pad_security"); +import("etherpad.pad.padutils"); +import("etherpad.pad.padutils.globalToLocalId"); +import("etherpad.pad.padutils.getGlobalPadId"); +import("etherpad.pro.domains"); +import("etherpad.pro.pro_accounts"); +import("etherpad.pro.pro_facebook"); +import("etherpad.pro.pro_pad_db"); +import("etherpad.pro.pro_padmeta"); +import("etherpad.pro.pro_groups"); +import("etherpad.pro.pro_oauth"); +import("etherpad.pro.pro_accounts.getSessionProAccount"); +import("etherpad.pro.pro_tokens"); +import("etherpad.control.pad.pad_render_control"); +import("etherpad.control.pro.pro_main_control.decorateWithSegments"); +import("etherpad.pad.padusers"); + +import("etherpad.sessions.{getSession,saveSession,destroySession}"); +import("etherpad.utils.*"); +import("jsutils.*"); + +jimport("org.apache.commons.fileupload"); + + +function checkAuthentication() { + if (!pro_accounts.getSessionProAccount()) { + if (request.params.token) { + // login via token + var u = pro_oauth.getUserForToken(request.params.token); + if (!u || u.id == 0 /*no super admin api access*/ || u.isDeleted) { + render401("Invalid oAuth token sent"); + } + if (u.domainId != domains.getRequestDomainId()) { + var host = domains.getDomainRecord(u.domainId).subDomain +"."+ appjet.config['etherpad.canonicalDomain']; + response.redirect((isProduction() ? "https://" : "http://") + host + request.path + "?" + request.query); + } + pro_accounts.signInSession(u, true/*skipLastLoginUpdate*/); + } else { + render401("No oAuth token sent"); + } + } +} + +function emailToAPIEmail(email) { + return email + "|API"; +} +function APIEmailToEmail(email) { + return email.replace("|API", ""); +} + +/* + Iff your are a subdomain admin, we will let you auto-create / switch to user. + + Otherwise the embed happens as the currently active browser sessions and may require login. +*/ +function render_embed_pad_get() { + response.allowFraming(); + + var clientId; + if (request.params.oauth_signature || request.params.email || request.params.name) { + clientId = pro_oauth.clientIdFromSignature(); + if (!clientId) { + render401("Invalid request signature."); + } + } + + var localPadId = requireParam("padId"); + var apiAccount; + + if (clientId) { + var userId = pro_accounts.getUserIdByEncryptedId(clientId); + apiAccount = pro_accounts.getAccountById(userId); + if (!apiAccount) { + render401("Invalid client id.") + } + + if (apiAccount.domainId != domains.getRequestDomainId()) { + render401("Domain id does not match request."); + } + } + + //var apiTokenInfo = pro_tokens.getToken(getSessionProAccount().id, pro_tokens.HACKPAD_API_TOKEN); + + // create the pad if not exist + getSession().instantCreate = request.params.padId; + saveSession(); + + // switch accounts if needed + // Note that request.params.email forces a signature check above. + if (request.params.email) { + if (!apiAccount || !apiAccount.isAdmin || domains.isPrimaryDomainRequest()) { + render401("Domain Admin Required"); + } + + var account = pro_accounts.getAccountByEmail(emailToAPIEmail(requireEmailParam()), apiAccount.domainId); + + if (!account) { + var accountId = pro_accounts.createNewAccount(null, request.params.name, emailToAPIEmail(requireEmailParam()), null, false, true, null, true/*isDomainGuest*/, false/*linked*/, true/*apiAccount*/); + pro_accounts.setAccountDoesNotWantWhatsNew(accountId); + pro_accounts.setAccountDoesNotWantFollowEmail(accountId); + account = pro_accounts.getAccountById(accountId); + } + + if (account.isAdmin) { + // as a precaution, we'll forbid this - as this is probably not what + // the user wants (letting anyone who embeds become an admin) + render401("Woah there, you're requesting to impersonate and admin user. This is prohibited as a precaution. Please contact support."); + } + + // ensure user has access + var globalPadId = getGlobalPadId(localPadId) + pad_access.grantUserIdAccess(globalPadId, account.id, userId); + + pro_accounts.signInSession(account); + } + + request.cache.isEmbed = true; + + pad_render_control.renderPadWithTemplate(localPadId, "pad/editor_embed.ejs", + {cont:request.url, googleButtonTarget:"_blank"}, + {isEmbed: true}, true /*isEmbed*/); +} + +/* Returns the most recently changed pads for the current user */ +function render_pad_list_get() { + var origAccount = pro_accounts.getSessionProAccount(); + checkAuthentication(); + + var myPads = pro_pad_db.listMyPads(); + var accessiblePads = pro_pad_db.listFollowedPads(myPads); + + if (!origAccount && request.params.token) { + destroySession(); + } + + return renderJSON(accessiblePads.map(function(p) { + return { + localPadId: p.localPadId, + title: p.title, + createdDate: p.createdDate.getTime() / 1000, + lastEditedDate: p.lastEditedDate ? p.lastEditedDate.getTime() / 1000 : 0, + }; + })); +} + + +function _get_collection_info(padsOut) { + // get a list of all the collections this user has access to + var userCollectionIds = pro_groups.getUserAccessibleCollectionIds(getSessionProAccount()); + + // get the ids of all the pads in each collection + var collectionPadIdLists = pad_access.getPadIdsInCollections(userCollectionIds); + + // get the ids of all the unique pads + var localPadIds = {}; + var globalPadIds = []; + userCollectionIds = jsutils.keys(collectionPadIdLists); // should be the same, but just in case + userCollectionIds.forEach(function(k) { + collectionPadIdLists[k].forEach(function(globalPadId){ + var localPadId = padutils.globalToLocalId(globalPadId); + if (localPadId in padsOut) { + return; + } + localPadIds[localPadId] = true; + globalPadIds[globalPadId] = true; + }); + }); + localPadIds = jsutils.keys(localPadIds); + globalPadIds = jsutils.keys(globalPadIds); + + // load the pad metas + var pads = sqlobj.selectMulti('pro_padmeta', {domainId: domains.getRequestDomainId(), localPadId:['IN', localPadIds], isDeleted:false, isArchived:false}); + + // pre-compute creatorIds for all the pads and make a pad lookup dict for later + var creatorForPadId = {}; + var padsByGlobalPadIds = {}; + pads.forEach(function(p) { + var globalPadId = padutils.getGlobalPadId(p.localPadId); + creatorForPadId[globalPadId] = p.creatorId; + padsByGlobalPadIds[globalPadId] = p; + }); + + // filter out any pads we don't have access to + var padIds = pad_security.padIdsUserCanSee(getSessionProAccount().id, globalPadIds, creatorForPadId); + var padIdsUserCanSee = jsutils.arrayToSet(padIds); + + // load full collection info + var collectionInfos = pro_groups.getGroupInfos(userCollectionIds); + collectionInfos.forEach(function(collectionInfo) { + collectionInfo.pads = collectionPadIdLists[collectionInfo.groupId].filter(function(globalPadId){ + var localPadId = padutils.globalToLocalId(globalPadId); + if (localPadId in padsOut) { + return true; + } + if (globalPadId in padsByGlobalPadIds && globalPadId in padIdsUserCanSee) { + padsOut[localPadId] = padsByGlobalPadIds[globalPadId]; + return true; + } + return false; + }).map(padutils.globalToLocalId); + }); + return collectionInfos; +} + +/* + Return a list of user collections and their contained pads +*/ +function render_collection_info_get() { + var origAccount = pro_accounts.getSessionProAccount(); + checkAuthentication(); + + var pads = {}; + var collectionInfos = _get_collection_info(pads); + + if (!origAccount && request.params.token) { + destroySession(); + } + + // render response + return renderJSON(collectionInfos.map(function(collectionInfo) { + return { + groupId: pro_groups.getEncryptedGroupId(collectionInfo.groupId), + title: collectionInfo.name, + pads: collectionInfo.pads.map(function(localPadId) { + var p = pads[localPadId]; + return { + localPadId: p.localPadId, + title: p.title, + lastEditedDate: p.lastEditedDate ? p.lastEditedDate.getTime() / 1000 : 0, + }; + }), + }; + })); +} + +function render_pads_get() { + checkAuthentication(); + + var pads = {}; + pro_pad_db.listFollowedPads(pro_pad_db.listMyPads()).forEach(function(p) { + p.followed = true; + pads[p.localPadId] = p; + }); + + var collections = _get_collection_info(pads); + var editorNames = []; + var editorPics = []; + var editors = {}; + + return renderJSON({ + success: true, + pads: jsutils.values(pads).map(function(pad) { + if (pad.lastEditorId && !(pad.lastEditorId in editors)) { + editors[pad.lastEditorId] = editorNames.length; + editorNames.push(pro_accounts.getFullNameById(pad.lastEditorId)); + editorPics.push(pro_accounts.getPicById(pad.lastEditorId)); + } + return { + localPadId: pad.localPadId, + title: pad.title, + lastEditedDate: pad.lastEditedDate ? pad.lastEditedDate.getTime() / 1000 : 0, + editor: editors[pad.lastEditorId], + followed: pad.followed, + }; + }), + collections: collections.map(function (collection) { + return { + groupId: pro_groups.getEncryptedGroupId(collection.groupId), + title: collection.name, + localPadIds: collection.pads, + }; + }), + editorNames: editorNames, + editorPics: editorPics, + }); +} + +function render_edited_pads_get() { + checkAuthentication(); + + var myAuthorID = getSessionProAccount().id; + + var lastCheckTimestamp = getParamIfExists("lastCheckTimestamp") || "0"; + + var myPads = pro_pad_db.listMyPads(); + var followedPads = pro_pad_db.listFollowedPads(myPads,0,null,null,lastCheckTimestamp); + + // Filter out all pads where I am the last editor + followedPads = followedPads.filter(function(pad) { + return pad.lastEditorId != myAuthorID; + }); + + // Get all the segments associated with the pads we are checking. These segments are the + // individual changes to the pad. + decorateWithSegments(followedPads); + + //Build an array of pad, segment + var segmentList = []; + followedPads.forEach(function(p) { + p.segments.forEach(function(s) { + segmentList.push([p, s]); + }) + }); + + // Filter the segments array in each pad to contain only segments newer than the timestamp argument + // and to contain only segments not edited by me + segmentList = segmentList.filter(function(segment) { + return (segment[1][3] > lastCheckTimestamp) && (padusers.getAccountIdForProAuthor(segment[1][2]) != myAuthorID); + }); + + // Iterate through each segment and create the response object + + var changes = segmentList.map(function(s) { + var pad = s[0]; + var segment = s[1]; + var segmentAuthors = segment[2]; + + return { 'localPadId' : pad.localPadId, 'title' : pad.title, 'editors' : segmentAuthors.map(function(author) { + return padusers.getNameForUserId(author); + })}; + + }); + + var editedPads = { 'timestamp' : new Date().getTime(), 'changes' : changes }; + + + + return renderJSON(editedPads); +} + + +function _embedUrlCache() { + if (!appjet.cache.embedUrlCache) { + appjet.cache.embedUrlCache = {}; + } + return appjet.cache.embedUrlCache; +} + +function render_connection_count_get() { + var padId = requireParam("padId"); + var callback = requireParam("callback"); + if (!callback.match(/^[\w\d_]+$/)) { + render400("callback must match [\w\d_]+"); + } + + response.setContentType('application/javascript; charset=utf-8'); + + var connections = collab_server.getNumConnectionsByPadId(getGlobalPadId(padId, 1)); + response.write(callback + "(" + connections + ");" ); + return true; +} + +function render_errors_get() { + var context = getParamIfExists("context") || ''; + var message = getParamIfExists("message") || ''; + var file = getParamIfExists("file") || ''; + var line = getParamIfExists("line") || ''; + var column = getParamIfExists("column") || ''; + var url = getParamIfExists("url") || ''; + var errorObj = getParamIfExists("errorObj") || ''; + + log.custom('clientside-errors', JSON.stringify({ + context: context, + message: message, + file: file, + line: line, + column: column, + url: url, + errorObj: errorObj + })); + + response.setStatusCode(204); + return true; +} + +function render_tweet_get() { + var url = requireParam("url"); + renderTemplate('pad/tweet.ejs', { url: url }); + return true; +} + +function render_oembed_script_get() { + render_embed_get(true /* rendered with iframe */); + return true; +} + +function render_embed_get(opt_iframeOuter) { + var url = requireParam("url"); + var maxwidth = requireParam("maxwidth"); + var cachekey = url + ":" + maxwidth; + + var scriptRe = new RegExp("http(s)?://gist\\.github\\.com"); + var scriptMatch = url.match(scriptRe); + + if (scriptMatch && !opt_iframeOuter) { + response.setContentType('application/json; charset=utf-8'); + // Generate an iframe first around the script. + response.write('{"html": ' + + JSON.stringify(renderTemplateAsString('pad/oembed_script_outer.ejs', + { url: url, maxwidth: maxwidth })) + + '}'); + return true; + } + + var linkRe = new RegExp("(.*)(https?://(\\w+\\.)?twitter.com/.*/status[\\w/]+)(.*)"); + var linkMatch = url.match(linkRe); + if (linkMatch) { + response.setContentType('application/json; charset=utf-8'); + response.write('{"html": ' + + JSON.stringify(renderTemplateAsString('pad/tweet_outer.ejs', + { url: url }).replace(/\n/g, '').replace(/\W$/, '')) + + ', "provider_name": "twitter"}'); + return true; + } + + var embedJson = _embedUrlCache()[cachekey]; + if (!embedJson) { + var args = { + 'url': url, + 'maxwidth': maxwidth, + 'key': 'fbf31da098f011e0928c4040d3dc5c07', + 'secure': 'true', + 'frame': 'true' + } + if (url.indexOf("speakerdeck.com") > -1 || scriptMatch) { + // embedly bug when using frame=true + delete args['frame']; + } + var res = urlGet('https://api.embed.ly/1/oembed', args, {}, 30, true /*acceptErrorCodes*/); + + //log.info("embedly", { 'embedlyContent': res.content, 'embedlyStatus': res.status }); + + if (res.status == 200) { + _embedUrlCache()[cachekey] = embedJson = String(res.content); + } else { + log.custom("embedly", { 'target': url, 'embedlyStatus': res.status }); + } + } + + if (opt_iframeOuter) { + response.write(helpers.documentDomain() + '\n'); + response.write(JSON.parse(embedJson).html); + return true; + } + + response.setContentType('application/json; charset=utf-8'); + response.write(embedJson || "{}"); + return true; +} + + +function render_latex_get() { + var formula = requireParam("formula"); + + formula = formula.replace(/%/g,"%25"); + formula = formula.replace(/&/g,"%26"); + + var preamble = "\\usepackage{amsmath} \\usepackage{amsfonts} \\usepackage{amssymb}"; + preamble = preamble.replace(/%/g,"%25"); + preamble = preamble.replace(/&/g,"%26"); + + var body = 'formula=' +formula; + body = body + '&fsize=' +'14px'; + body = body + '&fcolor=' +'000000'; + body = body + '&mode=0'; + body = body + '&out=1'; + body = body + '&preamble='+preamble; + + var res = urlPost("http://quicklatex.com/latex3.f", body); + if (res.status == 200) { + response.setContentType('text/plain; charset=utf-8'); + response.write(String(new java.lang.String(res.content))); + } + + return true; +} + + +function render_attach_post() { + var tag = requireParam("tag"); + + if (!getSessionProAccount()) { + response.sendError(403, "Please sign in"); + return true; + } + + var itemFactory = new fileupload.disk.DiskFileItemFactory(); + var handler = new fileupload.servlet.ServletFileUpload(itemFactory); + var items = handler.parseRequest(request.underlying).toArray(); + for (var i = 0; i < items.length; i++) { + if (items[i].isFormField()) { + continue; + } + + var file = items[i]; + var key = domains.getRequestDomainId() + "$" + tag + "_" + getSessionProAccount().id + "_" + (+new Date()) + "_" + file.name; + var uploadedStream = file.getInputStream(); + + s3.put(appjet.config.s3Bucket, key, uploadedStream, true, file.getContentType()); + uploadedStream.close(); + + return renderJSON({ + url: s3.getURL(appjet.config.s3Bucket, key), + key: key, + size: file.getSize() }); + } +} + + +function render_spaces_info_get() { + var domainInfos = pro_accounts.getSessionSpaces(); + return renderJSON(domainInfos); +} + + +function render_lookup_session_get() { + return renderJSON(getSession()); +} + +function render_pad_invite_info_get() { + var padId = requireParam("padId"); + + function _getUserInfo(id) { + var acct = pro_accounts.getAccountById(id, true /* skipDeleted */); + if (!acct) { return null; } + return { + name: acct.fullName, + userLink: pro_accounts.getUserLinkById(acct.id), + userPic: pro_accounts.getPicById(acct.id) + }; + } + + function _getGroupInfo(groupId) { + if (!pro_groups.currentUserHasAccess(groupId)) { + return null; + } + return { + groupId: pro_groups.getEncryptedGroupId(groupId), + name: pro_groups.getGroupName(groupId) + }; + } + + var globalPadId = getGlobalPadId(padId); + var rows = pad_access.getAccessRowsRaw({ globalPadId: globalPadId }).sort(function(a, b) { + return (b.lastAccessedDate || b.createdDate) - (a.lastAccessedDate || a.createdDate); + }).map(function(r) { + var row = { + host: _getUserInfo(r.hostUserId), + timestamp: toISOString(r.createdDate) + }; + if (r.userId) { + row.user = _getUserInfo(r.userId); + if (r.lastAccessedDate) { + row.lastAccessedTimestamp = toISOString(r.lastAccessedDate); + } + } + if (r.groupId) { + row.group = _getGroupInfo(r.groupId); + } + return row.host && (row.user || row.group) && row; + }).filter(function(r) { return r; }); + + // created by + pro_padmeta.accessProPad(globalPadId, function(propad) { + rows.push({ + host: _getUserInfo(propad.getCreatorId()), + timestamp: toISOString(propad.getCreatedDate()) + }); + }); + + return renderJSON(rows); +} + + +function render_subdomain_check_get() { + var subdomain = requireParam("subdomain"); + return renderJSON({ exists: domains.doesSubdomainExist(subdomain) }); +} + + +function render_device_notify_both() { + checkAuthentication(); + + var deviceToken = requireParam("iosDeviceToken"); + var appId = requireParam('iosAppId'); + if (!pro_tokens.addIOSDeviceToken(getSessionProAccount().id, deviceToken, appId)) { + log.info('Possible invalid app id: ' + appId); + } + + return renderJSON({success: true}); +} + diff --git a/etherpad/src/etherpad/control/connection_diagnostics_control.js b/etherpad/src/etherpad/control/connection_diagnostics_control.js new file mode 100644 index 0000000..aaa1bb3 --- /dev/null +++ b/etherpad/src/etherpad/control/connection_diagnostics_control.js @@ -0,0 +1,87 @@ +/** + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import("etherpad.utils.*"); +import("etherpad.helpers.*"); + +//---------------------------------------------------------------- +// Connection diagnostics +//---------------------------------------------------------------- + +/* +function _getDiagnosticsCollection() { + var db = storage.getRoot("connection_diagnostics"); + if (!db.diagnostics) { + db.diagnostics = new StorableCollection(); + } + return db.diagnostics; +} +*/ + +function render_main_get() { + /* + var diagnostics = _getDiagnosticsCollection(); + + var data = new StorableObject({ + ip: request.clientAddr, + userAgent: request.headers['User-Agent'] + }); + + diagnostics.add(data); + + helpers.addClientVars({ + diagnosticStorableId: data.id + }); +*/ + renderFramed("main/connection_diagnostics_body.ejs"); +} + +function render_submitdata_post() { + response.setContentType('text/plain; charset=utf-8'); + /* + var id = request.params.diagnosticStorableId; + var storedData = storage.getStorable(id); + if (!storedData) { + response.write("Error retreiving diagnostics record."); + response.stop(); + } + var diagnosticData = JSON.parse(request.params.dataJson); + eachProperty(diagnosticData, function(k,v) { + storedData[k] = v; + }); +*/ + response.write("OK"); +} + +function render_submitemail_post() { + response.setContentType('text/plain; charset=utf-8'); + /* + var id = request.params.diagnosticStorableId; + var data = storage.getStorable(id); + if (!data) { + response.write("Error retreiving diagnostics record."); + response.stop(); + } + var email = request.params.email; + if (!isValidEmail(email)) { + response.write("Invalid email address."); + response.stop(); + } + data.email = email; +*/ + response.write("OK"); +} + diff --git a/etherpad/src/etherpad/control/healthz_control.js b/etherpad/src/etherpad/control/healthz_control.js new file mode 100644 index 0000000..849c5fd --- /dev/null +++ b/etherpad/src/etherpad/control/healthz_control.js @@ -0,0 +1,21 @@ + +import("varz"); +import("etherpad.utils.*"); +import("etherpad.log"); +import("cache_utils.syncedWithCache"); + +function onRequest() { + var count = 0; + syncedWithCache('exception-counts', function (c) { + var hourId = log.currentHourId(); + count = c[hourId] || 0; + }); + + // if more than 20 exceptions have happened in the last hour return unhealthy + if (count > 20) { + render400("FAILED"); + } + + response.write("OK"); + return true; +} \ No newline at end of file diff --git a/etherpad/src/etherpad/control/invitecontrol.js b/etherpad/src/etherpad/control/invitecontrol.js new file mode 100644 index 0000000..f038d59 --- /dev/null +++ b/etherpad/src/etherpad/control/invitecontrol.js @@ -0,0 +1,631 @@ +import("crypto"); +import("sqlbase.sqlobj"); +import("stringutils"); +import("underscore._"); +import("jsutils.{uniqueBy,keys,sortBy,reverseSortBy}"); + +import("etherpad.control.pad.pad_control"); +import("etherpad.helpers"); +import("etherpad.log"); +import("etherpad.sessions.getSession"); +import("etherpad.pad.padutils"); +import("etherpad.pro.domains"); +import("etherpad.pro.pro_facebook"); +import("etherpad.pro.pro_invite"); +import("etherpad.pro.pro_friends"); +import("etherpad.pro.pro_groups"); +import("etherpad.pro.pro_accounts.getSessionProAccount"); +import("etherpad.pro.pro_accounts"); +import("etherpad.pro.google_account"); +import("etherpad.pro.pro_config"); +import("etherpad.pro.pro_padmeta"); +import("etherpad.control.pro.admin.account_manager_control.sendWelcomeEmail"); +import("etherpad.control.pro.account_control"); +import("etherpad.statistics.mixpanel"); +import("cache_utils.syncedWithCache"); +import("etherpad.utils.*"); +import("jsutils"); +import("etherpad.utils"); + +var INVITE_BLACKLIST_DOMAINS = ['reply.github.com', 'sale.craigslist.org']; + +function ContactList () { + this.list = []; + this.emailToContact = {}; + this.fbidToContact = {}; + this.addContact = function (name, email, hackpadUserId, fbid, lastLoginDate) { + var uniqueId = name + "::" + email + "::" + hackpadUserId; + var ts = lastLoginDate ? lastLoginDate.getTime() : null; + var contact = {name: name, email: email, hackpadUserId: hackpadUserId, fbid: fbid, uniqueId: uniqueId, lastLoginDate: ts}; + this.list.push(contact); + + if (contact.email) { + this.emailToContact[contact.email] = contact; + } + if (contact.fbid) { + this.fbidToContact[contact.fbid] = contact; + } + } + + this.indexOfContact = function (contact){ + var contactIndex = -1; + for (var i = 0; contactIndex < 0 && i b.lastLoginDate){ + return -1; + } + if (a.lastLoginDate < b.lastLoginDate){ + return 1; + } + } + + var aDisplayName = a.name || a.email; + var bDisplayName = b.name || b.email; + return aDisplayName.localeCompare(bDisplayName); + }); + + // add self or move self to front if already there + var me = getSessionProAccount(); + if (!options.emailOnly && _hackpadUserMatchesQuery(me, lowercaseQuery)) { + var meContact = { + name: me.fullName, + email: me.email, + hackpadUserId: me.id, + lastLoginDate: me.lastLoginDate + }; + var index = contacts.indexOfContact(meContact); + if (index > -1) { + meContact = contacts.list.splice(index, 1)[0]; + } + contacts.list.unshift(meContact); + } + return contacts; +} + +function _hackpadUserMatchesQuery(u, lowercaseQuery) { + return lowercaseQuery == '' || u.fullName.toLowerCase().search("\\b" + lowercaseQuery) >= 0 || + u.email.toLowerCase().search(lowercaseQuery) >= 0; +} + +// The following users are added here: +// 1. Invitees +// 2. Followers +// 3. Creator +// 4. Editors +function updateWithUsersWithPadAccess(contacts, lowercaseQuery, pad, creatorId, editorIds) { + var userIdsWithStatus = pad_control.getUserIdsWithStatusForPad(pad, creatorId, 1000/*optLimit*/); + + editorIds && editorIds.forEach(function(editorId) { + if (!userIdsWithStatus[editorId]) { + userIdsWithStatus[editorId] = "editor"; + } + }); + + var userIds = keys(userIdsWithStatus); + + updateWithUserIds(contacts, lowercaseQuery, userIds); +} + +function updateWithHackpadContacts(contacts, lowercaseQuery) { + var userIds = pro_accounts.getLoggedInUserFriendIds(); + updateWithUserIds(contacts, lowercaseQuery, userIds); +} + +function updateWithSiteMembers(contacts, lowercaseQuery, domainId) { + var siteMembers = pro_accounts.listAllDomainAccounts(domainId); + siteMembers = siteMembers.filter( + function(a) { return !pro_accounts.getIsDomainGuest(a); } // no guests + ); + + updateWithUserAccounts(contacts, lowercaseQuery, siteMembers); +} + +function updateWithUserIds(contacts, lowercaseQuery, userIds) { + var userAccounts = pro_accounts.getAccountsByIds(userIds, true/*skipDeleted*/); + updateWithUserAccounts(contacts, lowercaseQuery, userAccounts); +} + +function updateWithUserAccounts(contacts, lowercaseQuery, userAccounts){ + if (!userAccounts) { + return; + } + var userIdsWithKnownEmails = pro_friends.getFriendsInvitedByMeUserIds(getSessionProAccount().id); + + for (var i=0; i -1) { + contacts.emailToContact[u.email].visibleEmail = u.email; + } + } + } +} + + +function updateWithFacebookContacts(contacts, lowercaseQuery) { + + var fbUserId = getSession().facebookInfo.user.id; + var fbToken = getSession().facebookInfo.accessToken; + var friends = pro_facebook.getFacebookFriends(fbUserId, fbToken); + + for (var i in friends) { + if (!friends[i]['name']) { + // fix live exception (i guess it's a privacy setting?) + continue; + } + + if (friends[i]['name'].toLowerCase().search("\\b"+lowercaseQuery) >= 0) { + if (contacts.fbidToContact[friends[i].id] > -1) { + continue; // we've already included this contact + } else { + contacts.addContact(friends[i]['name'], null, null/*hackpadUserId*/, friends[i].id /*fbid*/); + } + } + } + +} + +function updateWithGoogleContacts(contacts, lowercaseQuery) { + var googleContacts = google_account.contactsForAccount(getSessionProAccount()); + + if (!googleContacts) { + google_account.reloadGoogleContactsAsync(getSessionProAccount()); + return; + } + + for (var i=0; i -1) { continue;} + + // XXX: only match on word start, not middle of email addresses + if (email.toLowerCase().search(lowercaseQuery) >= 0 || + (name && name.toLowerCase().search("\\b"+lowercaseQuery) >= 0)) { + contacts.addContact(name, email, null /*hackpadUserId*/); + // Not all google contacts have email addresses + if (email){ + var contact = contacts.emailToContact[email]; + if (contact) { + contact.visibleEmail = email; + } + } + } + } +} + +function render_autocomplete_get() { + if (!request.params.q || !request.params.q.length) { + return; + } + + // pop up a dialog if the user is logged out + if (!getSessionProAccount()) { + var html = renderTemplateAsString("pro/account/signed_out_modal.ejs", {}); + renderJSON({success:false, html:html}); + response.stop(); + } + + var options = { + emailOnly: request.params.emailonly, + excludeFacebook: request.params.excludefacebook, + isAtless: request.params.isatless == 'true', + isMention: request.params.ismention + }; + + if (!domains.isPrimaryDomainRequest()){ + var domainId = domains.getRequestDomainId(); + options.siteMembersOnly = true; + options.domainId = domainId; + } + + var contacts = autocompleteContacts(request.params.q, request.params.padid, options); + + var userlink = request.params.userlink; + var limit = request.params.limit; + + var list = []; + for (var i=0; i