diff options
56 files changed, 7676 insertions, 0 deletions
@@ -0,0 +1,680 @@ +COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + +1. Definitions. + +1.1. Contributor means each individual or entity that creates or +contributes to the creation of Modifications. + +1.2. Contributor Version means the combination of the Original +Software, prior Modifications used by a Contributor (if any), +and the Modifications made by that particular Contributor. + +1.3. Covered Software means (a) the Original Software, or (b) +Modifications, or (c) the combination of files containing +Original Software with files containing Modifications, in each +case including portions thereof. + +1.4. Executable means the Covered Software in any form other +than Source Code. + +1.5. Initial Developer means the individual or entity that first +makes Original Software available under this License. + +1.6. Larger Workmeans a work which combines Covered Software or +portions thereof with code not governed by the terms of this +License. + +1.7. License means this document. + +1.8. Licensable means having the right to grant, to the maximum +extent possible, whether at the time of the initial grant or +subsequently acquired, any and all of the rights conveyed herein. + +1.9. Modifications means the Source Code and Executable form of +any of the following: A. Any file that results from an addition +to, deletion from or modification of the contents of a file +containing Original Software or previous Modifications; B. Any +new file that contains any part of the Original Software or +previous Modification; or C. Any new file that is contributed or +otherwise made available under the terms of this License. + +1.10. Original Software means the Source Code and Executable +form of computer software code that is originally released under +this License. + +1.11. Patent Claims means any patent claim(s), now owned or +hereafter acquired, including without limitation, method, +process, and apparatus claims, in any patent Licensable by +grantor. + +1.12. Source Code means (a) the common form of computer software +code in which modifications are made and (b) associated +documentation included in or with such code. + +1.13. You (or Your) means an individual or a legal entity +exercising rights under, and complying with all of the terms of, +this License. For legal entities, You includes any entity which +controls, is controlled by, or is under common control with You. +For purposes of this definition, control means (a) the power, +direct or indirect, to cause the direction or management of such +entity, whether by contract or otherwise, or (b) ownership of +more than fifty percent (50%) of the outstanding shares or +beneficial ownership of such entity. + +2. License Grants. + +2.1. The Initial Developer Grant. Conditioned upon Your +compliance with Section 3.1 below and subject to third party +intellectual property claims, the Initial Developer hereby +grants You a world-wide, royalty-free, non-exclusive license: + +(a) under intellectual property rights (other than patent or +trademark) Licensable by Initial Developer, to use, reproduce, +modify, display, perform, sublicense and distribute the Original +Software (or portions thereof), with or without Modifications, +and/or as part of a Larger Work; and + +(b) under Patent Claims infringed by the making, using or +selling of Original Software, to make, have made, use, practice, +sell, and offer for sale, and/or otherwise dispose of the +Original Software (or portions thereof); + +(c) The licenses granted in Sections 2.1(a) and (b) are +effective on the date Initial Developer first distributes or +otherwise makes the Original Software available to a third party +under the terms of this License; + +(d) Notwithstanding Section 2.1(b) above, no patent license is +granted: (1) for code that You delete from the Original +Software, or (2) for infringements caused by: (i) the +modification of the Original Software, or (ii) the combination +of the Original Software with other software or devices. + +2.2. Contributor Grant. Conditioned upon Your compliance with +Section 3.1 below and subject to third party intellectual +property claims, each Contributor hereby grants You a +world-wide, royalty-free, non-exclusive license: + +(a) under intellectual property rights (other than patent or +trademark) Licensable by Contributor to use, reproduce, modify, +display, perform, sublicense and distribute the Modifications +created by such Contributor (or portions thereof), either on an +unmodified basis, with other Modifications, as Covered Software +and/or as part of a Larger Work; and + +(b) under Patent Claims infringed by the making, using, or +selling of Modifications made by that Contributor either alone +and/or in combination with its Contributor Version (or portions +of such combination), to make, use, sell, offer for sale, have +made, and/or otherwise dispose of: (1) Modifications made by +that Contributor (or portions thereof); and (2) the combination +of Modifications made by that Contributor with its Contributor +Version (or portions of such combination). + +(c) The licenses granted in Sections 2.2(a) and 2.2(b) +areeffective on the date Contributor first distributes or +otherwise makes the Modifications available to a third party. + +(d) Notwithstanding Section 2.2(b) above, no patent license is +granted: (1) for any code that Contributor has deleted from the +Contributor Version; (2) for infringements caused by: (i) third +party modifications of Contributor Version, or (ii) the +combination of Modifications made by that Contributor with other +software (except as part of the Contributor Version) or other +devices; or (3) under Patent Claims infringed by Covered +Software in the absence of Modifications made by that +Contributor. + +3. Distribution Obligations. + +3.1. Availability of Source Code. Any Covered Software that You +distribute or otherwise make available in Executable form must +also be made available in Source Code form and that Source Code +form must be distributed only under the terms of this License. +You must include a copy of this License with every copy of the +Source Code form of the Covered Software You distribute or +otherwise make available. You must inform recipients of any such +Covered Software in Executable form as to how they can obtain +such Covered Software in Source Code form in a reasonable manner +on or through a medium customarily used for software exchange. + +3.2. Modifications. The Modifications that You create or to +which You contribute are governed by the terms of this License. +You represent that You believe Your Modifications are Your +original creation(s) and/or You have sufficient rights to grant +the rights conveyed by this License. + +3.3. Required Notices. You must include a notice in each of Your +Modifications that identifies You as the Contributor of the +Modification. You may not remove or alter any copyright, patent +or trademark notices contained within the Covered Software, or +any notices of licensing or any descriptive text giving +attribution to any Contributor or the Initial Developer. + +3.4. Application of Additional Terms. You may not offer or +impose any terms on any Covered Software in Source Code form +that alters or restricts the applicable version of this License +or the recipients rights hereunder. You may choose to offer, and +to charge a fee for, warranty, support, indemnity or liability +obligations to one or more recipients of Covered +Software. However, you may do so only on Your own behalf, and +not on behalf of the Initial Developer or any Contributor. You +must make it absolutely clear that any such warranty, support, +indemnity or liability obligation is offered by You alone, and +You hereby agree to indemnify the Initial Developer and every +Contributor for any liability incurred by the Initial Developer +or such Contributor as a result of warranty, support, indemnity +or liability terms You offer. + +3.5. Distribution of Executable Versions. You may distribute the +Executable form of the Covered Software under the terms of this +License or under the terms of a license of Your choice, which +may contain terms different from this License, provided that You +are in compliance with the terms of this License and that the +license for the Executable form does not attempt to limit or +alter the recipients rights in the Source Code form from the +rights set forth in this License. If You distribute the Covered +Software in Executable form under a different license, You must +make it absolutely clear that any terms which differ from this +License are offered by You alone, not by the Initial Developer +or Contributor. You hereby agree to indemnify the Initial +Developer and every Contributor for any liability incurred by +the Initial Developer or such Contributor as a result of any +such terms You offer. + +3.6. Larger Works. You may create a Larger Work by combining +Covered Software with other code not governed by the terms of +this License and distribute the Larger Work as a single product. +In such a case, You must make sure the requirements of this +License are fulfilled for the Covered Software. + +4. Versions of the License. + +4.1. New Versions. Sun Microsystems, Inc. is the initial license +steward and may publish revised and/or new versions of this +License from time to time. Each version will be given a +distinguishing version number. Except as provided in Section +4.3, no one other than the license steward has the right to +modify this License. + +4.2. Effect of New Versions. You may always continue to use, +distribute or otherwise make the Covered Software available +under the terms of the version of the License under which You +originally received the Covered Software. If the Initial +Developer includes a notice in the Original Software prohibiting +it from being distributed or otherwise made available under any +subsequent version of the License, You must distribute and make +the Covered Software available under the terms of the version of +the License under which You originally received the Covered +Software. Otherwise, You may also choose to use, distribute or +otherwise make the Covered Software available under the terms of +any subsequent version of the License published by the license +steward. + +4.3. Modified Versions. When You are an Initial Developer and +You want to create a new license for Your Original Software, You +may create and use a modified version of this License if You: +(a) rename the license and remove any references to the name of +the license steward (except to note that the license differs +from this License); and (b) otherwise make it clear that the +license contains terms which differ from this License. + +5. DISCLAIMER OF WARRANTY. COVERED SOFTWARE IS PROVIDED UNDER +THIS LICENSE ON AN AS IS BASIS, WITHOUT WARRANTY OF ANY KIND, +EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, +WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, +MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. +THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE +DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY +OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, +REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN +ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE +IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +6. TERMINATION. + +6.1. This License and the rights granted hereunder will +terminate automatically if You fail to comply with terms herein +and fail to cure such breach within 30 days of becoming aware of +the breach. Provisions which, by their nature, must remain in +effect beyond the termination of this License shall survive. + +6.2. If You assert a patent infringement claim (excluding +declaratory judgment actions) against Initial Developer or a +Contributor (the Initial Developer or Contributor against whom +You assert such claim is referred to as Participant) alleging +that the Participant Software (meaning the Contributor Version +where the Participant is a Contributor or the Original Software +where the Participant is the Initial Developer) directly or +indirectly infringes any patent, then any and all rights granted +directly or indirectly to You by such Participant, the Initial +Developer (if the Initial Developer is not the Participant) and +all Contributors under Sections 2.1 and/or 2.2 of this License +shall, upon 60 days notice from Participant terminate +prospectively and automatically at the expiration of such 60 day +notice period, unless if within such 60 day period You withdraw +Your claim with respect to the Participant Software against such +Participant either unilaterally or pursuant to a written +agreement with Participant. + +6.3. In the event of termination under Sections 6.1 or 6.2 +above, all end user licenses that have been validly granted by +You or any distributor hereunder prior to termination (excluding +licenses granted to You by any distributor) shall survive +termination. + +7. LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES AND UNDER NO +LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR +OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER +CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY +SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY +INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY +CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST +PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR +MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, +EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY +OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO +LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH +PARTYS NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH +LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR +LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS +EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +8. U.S. GOVERNMENT END USERS. The Covered Software is a +commercial item, as that term is defined in 48 C.F.R. 2.101 +(Oct. 1995), consisting of commercial computer software (as that +term is defined at 48 C.F.R. 252.227-7014(a)(1)) and commercial +computer software documentation as such terms are used in 48 +C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and +48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all +U.S. Government End Users acquire Covered Software with only +those rights set forth herein. This U.S. Government Rights +clause is in lieu of, and supersedes, any other FAR, DFAR, or +other clause or provision that addresses Government rights in +computer software under this License. + +9. MISCELLANEOUS. This License represents the complete agreement +concerning subject matter hereof. If any provision of this +License is held to be unenforceable, such provision shall be +reformed only to the extent necessary to make it enforceable. +This License shall be governed by the law of the jurisdiction +specified in a notice contained within the Original Software +(except to the extent applicable law, if any, provides +otherwise), excluding such jurisdictions conflict-of-law +provisions. Any litigation relating to this License shall be +subject to the jurisdiction of the courts located in the +jurisdiction and venue specified in a notice contained within +the Original Software, with the losing party responsible for +costs, including, without limitation, court costs and reasonable +attorneys fees and expenses. The application of the United +Nations Convention on Contracts for the International Sale of +Goods is expressly excluded. Any law or regulation which +provides that the language of a contract shall be construed +against the drafter shall not apply to this License. You agree +that You alone are responsible for compliance with the United +States export administration regulations (and the export control +laws and regulation of any other countries) when You use, +distribute or otherwise make available any Covered Software. + +10. RESPONSIBILITY FOR CLAIMS. As between Initial Developer and +the Contributors, each party is responsible for claims and +damages arising, directly or indirectly, out of its utilization +of rights under this License and You agree to work with Initial +Developer and Contributors to distribute such responsibility on +an equitable basis. Nothing herein is intended or shall be +deemed to constitute any admission of liability. + +---------------------------------------------------------------- + +NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND +DISTRIBUTION LICENSE (CDDL): This code is released under the +CDDL and shall be governed by the laws of the State of +California (excluding conflict-of-law provisions). Any +litigation relating to this License shall be subject to the +jurisdiction of the Federal Courts of the Northern District of +California and the state courts of the State of California, with +venue lying in Santa Clara County, California. + +---------------------------------------------------------------- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..c6ce5bc --- /dev/null +++ b/ChangeLog @@ -0,0 +1,2 @@ +2008-20-02 Alberto Ruiz <alberto.ruiz@sun.com> + * Initial commit. diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..af437a6 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..1401045 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,77 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +ORIGDIR=`pwd` +cd $srcdir +PROJECT=FIREFOX-APOC-ADAPTER + +DIE=0 + +(autoconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have autoconf installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnu.org/gnu/autoconf/" + DIE=1 +} + + +if test -x "`which automake-1.9`" +then + AUTOMAKE=`which automake-1.9` + ACLOCAL=`which aclocal-1.9` + ACLOCAL_FLAGS="" +elif test -x "`which automake-1.10`" +then + AUTOMAKE=`which automake-1.10` + ACLOCAL=`which aclocal-1.10` + ACLOCAL_FLAGS="" +else + echo + echo "You must have automake 1.10.x or 1.9.x installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/" + DIE=1 +fi + +if test -x "`which libtoolize`" +then + LIBTOOLIZE=`which libtoolize` + LIBTOOLIZEFLAGS="--force" +else + echo + echo "You must have libtoolize installed to comopile $PROJECT." + echo "Install the appropriate package for your operating system." + DIE=1 +fi + + +if test "$DIE" -eq 1; then + exit 1 +fi + +if test -z "$AUTOGEN_SUBDIR_MODE"; then + if test -z "$*"; then + echo "I am going to run ./configure with no arguments - if you wish " + echo "to pass any to it, please specify them on the $0 command line." + fi +fi + +rm -rf autom4te.cache + + +$ACLOCAL $ACLOCAL_FLAGS || exit $? +$LIBTOOLIZE $LIBTOOLIZEFLAGS || exit $? +$AUTOMAKE --add-missing || exit $? +autoconf || exit $? +cd $ORIGDIR || exit $? + +if test -z "$AUTOGEN_SUBDIR_MODE"; then + $srcdir/configure --enable-maintainer-mode $AUTOGEN_CONFIGURE_ARGS "$@" || exit $? + + echo + echo "Now type 'make' to compile $PROJECT." +fi diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..7325baf --- /dev/null +++ b/configure.ac @@ -0,0 +1,47 @@ +AC_INIT(firefox-apoc-adapter, 1.0) + +AM_INIT_AUTOMAKE + +AC_PROG_CXX +AC_PROG_LIBTOOL + +#Checking and including XPCOM +PKG_CHECK_MODULES(XPCOM, firefox-xpcom, +[ + FIREFOX="yes" + CXXFLAGS="$CXXFLAGS $XPCOM_CFLAGS -DMOZILLA_INTERNAL_API" + LIBS="$LIBS $XPCOM_LIBS" +]) + +XPCOM_LIBDIR=`pkg-config --variable=libdir firefox-xpcom` +COMPONENT_DIR=$XPCOM_LIBDIR/components + +#Checking NSPR headers +NSPR_INCLUDEDIR="" +AC_ARG_WITH(nspr-includes, +AC_HELP_STRING( [--with-nspr-includes=DIR], + [specify the Netscape Portable Runtime include path]), +[ + if test "$withval" != "no" + then + CFLAGS="$CFLAGS -I$withval" + CXXFLAGS="$CXXFLAGS -I$withval" + fi +]) + +AC_CHECK_HEADERS([nspr.h], [], +AC_MSG_ERROR(Netscape Portable Runtime headers not found. +If you have it already installed please use --with-nspr-includes option to specify the correct include path.) +) +AC_CHECK_HEADERS([prtypes.h], [], +AC_MSG_ERROR(Netscape Portable Runtime headers not found. +If you have it already installed please use --with-nspr-includes option to specify the correct include path.) +) + +AC_SUBST(XPCOM_LIBDIR) +AC_SUBST(COMPONENT_DIR) + +AC_OUTPUT([ +Makefile +src/Makefile +]) diff --git a/contrib/Makefile.in.extension b/contrib/Makefile.in.extension new file mode 100644 index 0000000..8398c82 --- /dev/null +++ b/contrib/Makefile.in.extension @@ -0,0 +1,63 @@ +#************************************************************************* +#* +#* $RCSfile: Makefile.in,v $ +#* +#* Description: +#* +#* Last change: $Date: 2006/10/30 03:23:52 $ $Revision: 1.1.1.1 $ +#* +#* Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use of this +#* product is subject to license terms. +#* +#************************************************************************* + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = apoc +LIBRARY_NAME = mozapoc +SHORT_LIBNAME = mozapoc +EXPORT_LIBRARY = 1 +IS_COMPONENT = 1 +MODULE_NAME = mozApocModule +MOZILLA_INTERNAL_API = 1 +REQUIRES = xpcom \ + string \ + expat \ + pref \ + $(NULL) + +CPPSRCS = \ + mozApocModule.cpp \ + mozApocPrefService.cpp \ + mozApocPrefBranch.cpp \ + mozApocPolicyData.cpp \ + mozApocPolicyModel.cpp \ + mozApocPolicyModelBuilder.cpp \ + mozApocPolicyModelFromDOM.cpp \ + mozApocPolicyNodeData.cpp \ + mozApocPolicyNodeDOMData.cpp \ + mozApocPolicyModelFromXML.cpp \ + mozApocPolicyComponentData.cpp \ + mozApocPolicyComponentDOMData.cpp \ + mozApocSaxWrapper.cpp \ + mozApocPolicyBackend.cpp \ + mozApocNotificationImpl.cpp \ + mozApocPathParser.cpp \ + mozApocStringList.cpp \ + mozApocPAPI.cpp \ + $(NULL) + +DEFINES += -DXML_DTD -DXML_UNICODE + +SHARED_LIBRARY_LIBS = \ + $(DIST)/lib/$(LIB_PREFIX)expat_s.$(LIB_SUFFIX) \ + $(NULL) + +EXTRA_DSO_LDOPTS = $(MOZ_COMPONENT_LIBS) \ + +include $(topsrcdir)/config/rules.mk diff --git a/contrib/mozApoc.spec b/contrib/mozApoc.spec new file mode 100644 index 0000000..68ee5a7 --- /dev/null +++ b/contrib/mozApoc.spec @@ -0,0 +1,70 @@ +# +# Copyright (c) 2003 Sun Microsystems Inc. +# This file and all modifications and additions to the pristine +# package are under the same license as the package itself. +# +%define ADAPTER_VERSION 0.3 +%define ADAPTER_RELEASE 2 +%define MOZILLA_VERSION 1.4 +%define MOZILLA_LOCATION /usr/lib +%define MOZILLA_ROOT %{MOZILLA_LOCATION}/mozilla-%{MOZILLA_VERSION} +%define _prefix %{MOZILLA_ROOT} +Summary: APOC adapter for Mozilla +Name: apoc-adapter-mozilla +Group: Applications/Internet +Version: %{ADAPTER_VERSION} +Release: %{ADAPTER_RELEASE} +Distribution: Sun Java Desktop System +Vendor: Sun Microsystems Inc. +License: Sun Microsystems Binary Code License (BCL) +Autoreqprov: on +Requires: mozilla = %{MOZILLA_VERSION} +Prefix: %{_prefix} +BuildRoot: %{_tmppath}/%{name}-%{version}-root + +%description +APOC adapter for Mozilla 1.4. + +Provides mandatory and default preference values +for mozilla from APOC policies. + +Part of the Sun Java Desktop System + +Property of Sun Microsystems Inc., 2003 + +%prep + +%build +if test "$MOZ_OBJDIR" ; then + cd $MOZ_OBJDIR/extensions/apoc + make +fi + +%install +if test "$MOZ_OBJDIR" ; then + mkdir -p ${RPM_BUILD_ROOT}%{MOZILLA_ROOT}/components + cp $MOZ_OBJDIR/dist/bin/components/libmozapoc.so ${RPM_BUILD_ROOT}%{MOZILLA_ROOT}/components/ +fi + +%clean +if test "$MOZ_OBJDIR" ; then + rm -rf ${RPM_BUILD_ROOT}%MOZILLA_ROOT/components/libmozapoc.so +fi + +%post +# Register our component for XPCOM on each install/update +MOZILLA_ROOT=$RPM_INSTALL_PREFIX +$MOZILLA_ROOT/regxpcom -x $MOZILLA_ROOT $MOZILLA_ROOT/components/libmozapoc.so + +%postun +# Is this the last uninstall -> recreate registry from scratch +if [ $1 = 0 ] ; then + MOZILLA_ROOT=$RPM_INSTALL_PREFIX + $MOZILLA_ROOT/mozilla-rebuild-databases.pl +fi + +%files +%defattr (-, root, root) +%{_prefix}/components/libmozapoc.so + +%changelog diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..cd05f57 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,28 @@ +lib_LTLIBRARIES = libmozapoc.la + +libdir=@COMPONENT_DIR@ + +AM_LDFLAGS=-R @XPCOM_LIBDIR@ + +libmozapoc_la_SOURCES = \ + mozApocModule.cpp \ + mozApocPrefService.cpp \ + mozApocPrefBranch.cpp \ + mozApocPolicyData.cpp \ + mozApocPolicyModel.cpp \ + mozApocPolicyModelBuilder.cpp \ + mozApocPolicyModelFromDOM.cpp \ + mozApocPolicyNodeData.cpp \ + mozApocPolicyNodeDOMData.cpp \ + mozApocPolicyModelFromXML.cpp \ + mozApocPolicyComponentData.cpp \ + mozApocPolicyComponentDOMData.cpp \ + mozApocSaxWrapper.cpp \ + mozApocPolicyBackend.cpp \ + mozApocNotificationImpl.cpp \ + mozApocPathParser.cpp \ + mozApocStringList.cpp \ + mozApocPAPI.cpp + +install-local-data: + echo $(AM_LDFLAGS) diff --git a/src/mozApocModule.cpp b/src/mozApocModule.cpp new file mode 100644 index 0000000..8f776ec --- /dev/null +++ b/src/mozApocModule.cpp @@ -0,0 +1,54 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#include "mozApocPrefService.h" + +#include "nsIGenericFactory.h" + +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozApocPrefServiceWrapper,Init); + +static const nsModuleComponentInfo components[] = +{ + { + "Preference Policy Adapter for APOC", + MOZAPOC_PREFSERVICEWRAPPER_CID, + NS_PREFSERVICE_CONTRACTID, + mozApocPrefServiceWrapperConstructor + } +}; + +NS_IMPL_NSGETMODULE(mozApocModule, components) + diff --git a/src/mozApocNotificationDispatch.h b/src/mozApocNotificationDispatch.h new file mode 100644 index 0000000..fe093a3 --- /dev/null +++ b/src/mozApocNotificationDispatch.h @@ -0,0 +1,91 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_NOTIFICATIONDISPATCH_H_INCLUDED +#define MOZAPOC_NOTIFICATIONDISPATCH_H_INCLUDED + +#include "nsString.h" + +typedef struct mozApocNativeSettingsData const * mozApocNativeSettingsMemento; +extern void mozApocDiscardNativeSettings(mozApocNativeSettingsMemento aMemento); + +struct mozApocNotifier +{ + // dispatch a notification + virtual void NotifyValueChange(const char * aPath, nsAString const & aValue, PRBool bLocked) = 0; + virtual void NotifyLockChange(const char * aPath, PRBool bLocked) = 0; + + // help for remembering/restoring the native value + virtual mozApocNativeSettingsMemento RememberNativeValue(const char * aPath) const = 0; + virtual void RestoreAndNotifyNativeValue(const char * aPath, mozApocNativeSettingsMemento aMemento)= 0; + +protected: + // to silence warnings + virtual ~mozApocNotifier() {} +}; + +class mozApocNotificationDispatcher +{ + nsCString Path; + mozApocNotifier * Notifier; +public: + mozApocNotificationDispatcher(nsACString const & aPath, mozApocNotifier * pNotifier) + : Path(aPath) + , Notifier(pNotifier) + {} + + mozApocNotificationDispatcher(mozApocNotificationDispatcher const & aParent, nsACString const & aChildName); + + mozApocNotificationDispatcher GetChildNotifier(nsACString const & aChildName) const + { return mozApocNotificationDispatcher(*this,aChildName); } + + void NotifyValueChange(nsAString const & aValue, PRBool bLocked) const + { if (Notifier) Notifier->NotifyValueChange(Path.get(),aValue,bLocked); } + + void NotifyLockChange(PRBool bLocked) const + { if (Notifier) Notifier->NotifyLockChange(Path.get(),bLocked); } + + // help for remembering/restoring the native value + mozApocNativeSettingsMemento RememberNativeValue() const + { return Notifier ? Notifier->RememberNativeValue(Path.get()) : nsnull; } + + void RestoreAndNotifyNativeValue(mozApocNativeSettingsMemento aMemento) const + { if (Notifier && aMemento) Notifier->RestoreAndNotifyNativeValue(Path.get(),aMemento); } + +}; + +#endif + diff --git a/src/mozApocNotificationImpl.cpp b/src/mozApocNotificationImpl.cpp new file mode 100644 index 0000000..57e14a7 --- /dev/null +++ b/src/mozApocNotificationImpl.cpp @@ -0,0 +1,351 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+
+#include "mozApocNotificationImpl.h"
+#include "mozApocPathParser.h" // for BuildPath
+
+//Brian++ #include "nsIServiceManagerUtils.h"
+#include "nsServiceManagerUtils.h"
+#include "nsIProxyObjectManager.h"
+
+#ifdef DEBUG
+#define NOTIFICATION_TRACE ::fprintf
+#else
+#define NOTIFICATION_TRACE if (1) ; else ::fprintf
+#endif
+
+struct mozApocNativeSettingsData
+{
+ mozApocNativeSettingsData() : PrefType(nsIPrefBranch::PREF_INVALID), Locked(PR_FALSE) {}
+ ~mozApocNativeSettingsData() { Clear(); }
+
+ nsresult Read(const nsCOMPtr<nsIPrefBranch> & aBranch, const char * aPath);
+ nsresult Restore(const nsCOMPtr<nsIPrefBranch> & aBranch, const char * aPath) const;
+ nsresult Clear();
+
+ PRInt32 PrefType;
+ PRBool Locked;
+ union
+ {
+ char * CharValue;
+ PRInt32 IntValue;
+ PRBool BoolValue;
+ };
+};
+
+nsresult mozApocNativeSettingsData::Read(const nsCOMPtr<nsIPrefBranch> & aBranch, const char * aPath)
+{
+ NS_PRECONDITION( PrefType == nsIPrefBranch::PREF_INVALID, "apoc - Native Settings not cleared before reading (may leak memory)");
+ NS_PRECONDITION( aBranch, "apoc - Native Settings operation on NULL branch");
+ NS_PRECONDITION( aPath, "apoc - Native Settings operation on NULL path");
+
+ nsresult rv = aBranch->GetPrefType(aPath, &PrefType);
+ if (NS_FAILED(rv))
+ {
+ NS_ASSERTION( PrefType == nsIPrefBranch::PREF_INVALID, "apoc - Failed GetPrefType has returned unexpected type" );
+ return rv;
+ }
+
+ switch (PrefType)
+ {
+ case nsIPrefBranch::PREF_STRING:
+ CharValue = nsnull;
+ rv = aBranch->GetCharPref(aPath, &CharValue);
+ break;
+
+ case nsIPrefBranch::PREF_INT:
+ rv = aBranch->GetIntPref(aPath, &IntValue);
+ break;
+
+ case nsIPrefBranch::PREF_BOOL:
+ rv = aBranch->GetBoolPref(aPath, &BoolValue);
+ break;
+
+ default:
+ NS_WARNING("apoc - Unknown PrefType returned by GetPrefType !?");
+ rv = NS_ERROR_UNEXPECTED;
+ // fall through
+
+ case nsIPrefBranch::PREF_INVALID:
+ // no data
+ break;
+ }
+
+ if (NS_FAILED(rv))
+ {
+ NS_WARNING("apoc - Could not get native value for later restore");
+ PrefType = nsIPrefBranch::PREF_INVALID;
+ }
+
+ if (PrefType != nsIPrefBranch::PREF_INVALID)
+ {
+ nsresult rv2 = aBranch->PrefIsLocked(aPath,&Locked);
+ if ( NS_FAILED(rv2) )
+ {
+ NS_WARNING("apoc - Could not determine native lock state for later restore");
+ Locked = PR_FALSE;
+ }
+ }
+
+ return rv;
+}
+
+nsresult mozApocNativeSettingsData::Restore(const nsCOMPtr<nsIPrefBranch> & aBranch, const char * aPath) const
+{
+ NS_PRECONDITION( aBranch, "apoc - Native Settings operation on NULL branch");
+ NS_PRECONDITION( aPath, "apoc - Native Settings operation on NULL path");
+
+ nsresult rv = Locked ? rv = aBranch->LockPref(aPath) : rv = aBranch->UnlockPref(aPath);
+ if (NS_FAILED(rv) && PrefType != nsIPrefBranch::PREF_INVALID)
+ NS_WARNING("apoc - Could not restore native lock state");
+
+ switch (PrefType)
+ {
+ case nsIPrefBranch::PREF_STRING:
+ rv = aBranch->SetCharPref(aPath, CharValue);
+ break;
+
+ case nsIPrefBranch::PREF_INT:
+ rv = aBranch->SetIntPref(aPath, IntValue);
+ break;
+
+ case nsIPrefBranch::PREF_BOOL:
+ rv = aBranch->SetBoolPref(aPath, BoolValue);
+ break;
+
+ default:
+ NS_WARNING("apoc - Unknown PrefType returned by GetPrefType !?");
+ rv = NS_ERROR_UNEXPECTED;
+ break;
+
+ case nsIPrefBranch::PREF_INVALID:
+ aBranch->DeleteBranch(aPath);
+ rv = NS_OK;
+ break;
+ }
+
+ NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),"apoc - Could not restore native value");
+ return rv;
+}
+
+nsresult mozApocNativeSettingsData::Clear()
+{
+ nsresult rv = NS_OK;
+ switch (PrefType)
+ {
+ case nsIPrefBranch::PREF_STRING:
+ nsMemory::Free(CharValue);
+ break;
+
+ case nsIPrefBranch::PREF_INT:
+ case nsIPrefBranch::PREF_BOOL:
+ // nothing to do
+ break;
+
+ default:
+ NS_WARNING("apoc - Illegal PrefType found in native settings data !?");
+ rv = NS_ERROR_UNEXPECTED;
+ // fall through
+ case nsIPrefBranch::PREF_INVALID:
+ // no data
+ break;
+ }
+ NS_WARN_IF_FALSE( NS_SUCCEEDED(rv), "apoc - error discarding settings data");
+
+ PrefType = nsIPrefBranch::PREF_INVALID;
+ Locked = PR_FALSE;
+
+ return rv;
+}
+
+void mozApocDiscardNativeSettings(mozApocNativeSettingsMemento aMemento)
+{
+ delete aMemento;
+}
+
+mozApocNotificationDispatcher::mozApocNotificationDispatcher(mozApocNotificationDispatcher const & aParent,
+ nsACString const & aChildName)
+: Path( mozApocBuildPath(aParent.Path,aChildName) )
+, Notifier(aParent.Notifier)
+{}
+
+// This function is used to lazyly set up mDispatchBranch as UI-Thread proxy for mNativeBranch
+// This is needed to ensure that non-threadsafe components (e.g. XPConnect objects) are notfied on the UI thread
+//
+// Creation of the proxy requires that the event queue of the UI thread is created
+// If a notification is dispatched before that time, we simply use mNativeBranch directly
+// This is valid, as clients that exist before the UI thread, can operate outside it...
+nsCOMPtr< nsIPrefBranch > const & mozApocBranchNotifier::getTargetBranch()
+{
+ // TODO: use a mutex to protect mDispatchBranch manipulation
+ if (!mDispatchBranch.get())
+ {
+ // no proxy yet - attempt to create it
+ static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
+
+ nsresult rv = NS_OK;
+ nsCOMPtr<nsIPrefBranch> aBranchProxy;
+
+ nsCOMPtr<nsIProxyObjectManager> proxyObjectManager(do_GetService(kProxyObjectManagerCID, &rv));
+ if (NS_SUCCEEDED(rv))
+ {
+ rv = proxyObjectManager->GetProxyForObject(NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIPrefBranch),
+ mNativeBranch, PROXY_SYNC | PROXY_ALWAYS,
+ getter_AddRefs(aBranchProxy));
+ }
+ if (NS_FAILED(rv)) // cannot create proxy (yet)
+ {
+ if (rv == NS_ERROR_NOT_AVAILABLE)
+ NS_WARNING("apoc: Cannot create proxy for notifcation: UI thread event queue is not available");
+ else
+ NS_WARNING("apoc: Cannot create proxy for notifcation: Unexpected failure");
+
+ // .. so using the non-proxied branch object instead
+ return mNativeBranch;
+ }
+ NS_ASSERTION(aBranchProxy.get() != nsnull, "apoc: GetProxyForObject succeeded, but still no proxy available ?");
+ mDispatchBranch = aBranchProxy;
+ }
+ return mDispatchBranch;
+}
+
+void mozApocBranchNotifier::NotifyValueChange(const char * aPath, nsAString const & aValue, PRBool bLocked)
+{
+ NS_PRECONDITION(aPath,"apoc - Notifying for NULL path");
+
+ NOTIFICATION_TRACE(stderr, "Notifying change of value at %s: Value = '%s', State=%s\n",
+ aPath, NS_ConvertUCS2toUTF8(aValue).get(), bLocked ? "LOCKED" : "NOT LOCKED");
+
+ PRInt32 aPrefType = nsIPrefBranch::PREF_INVALID;
+
+ // read access (to determine the type) does not need to be proxied ..
+ nsresult rv = mNativeBranch->GetPrefType(aPath, &aPrefType);
+ if (NS_FAILED(rv))
+ NS_ASSERTION( aPrefType == nsIPrefBranch::PREF_INVALID, "apoc - Failed GetPrefType has returned unexpected type" );
+
+ // ... but write access (causing notifications) does
+ nsCOMPtr< nsIPrefBranch > const & aTargetBranch = this->getTargetBranch();
+ switch (aPrefType)
+ {
+ case nsIPrefBranch::PREF_INVALID:
+ // TODO: pass attributes into here, for typing
+ NS_WARNING("apoc - No native data for entry being notified: assuming type STRING");
+ // fall through
+
+ case nsIPrefBranch::PREF_STRING:
+ rv = aTargetBranch->SetCharPref(aPath, NS_ConvertUCS2toUTF8(aValue).get());
+ break;
+
+ case nsIPrefBranch::PREF_INT:
+ {
+ nsAutoString aHelperValue(aValue); // need this for ToInteger
+
+ PRInt32 Errcode = NS_OK;
+ PRInt32 IntVal = aHelperValue.ToInteger(&Errcode,kRadix10);
+
+ rv = NS_STATIC_CAST(nsresult,Errcode);
+ if (NS_SUCCEEDED(rv))
+ rv = aTargetBranch->SetIntPref(aPath, IntVal);
+ else
+ NS_WARNING("apoc - Cannot notify value change - not a numeric value for Int pref");
+ }
+ break;
+
+ case nsIPrefBranch::PREF_BOOL:
+ if (aValue.Equals(NS_LITERAL_STRING("false")))
+ rv = aTargetBranch->SetBoolPref(aPath, PR_FALSE);
+
+ else if (aValue.Equals(NS_LITERAL_STRING("true")))
+ rv = aTargetBranch->SetBoolPref(aPath, PR_TRUE);
+
+ else
+ {
+ NS_WARNING("apoc - Cannot notify value change - not a boolean value for Bool pref");
+ rv = NS_ERROR_UNEXPECTED;
+ }
+ break;
+
+ default:
+ NS_WARNING("apoc - Unknown PrefType returned by GetPrefType !?");
+ rv = NS_ERROR_UNEXPECTED;
+ break;
+ }
+
+}
+
+void mozApocBranchNotifier:: NotifyLockChange(const char * aPath, PRBool bLocked)
+{
+ NS_PRECONDITION(aPath,"apoc - Notifying for NULL path");
+
+ NOTIFICATION_TRACE(stderr, "Notifying change of lock state at %s: New State=%s\n",
+ aPath, bLocked ? "LOCKED" : "NOT LOCKED");
+
+ nsCOMPtr< nsIPrefBranch > const & aTargetBranch = this->getTargetBranch();
+
+ nsresult rv = bLocked ? aTargetBranch->LockPref(aPath) : aTargetBranch->UnlockPref(aPath);
+ if (NS_FAILED(rv))
+ NS_WARNING("apoc - Could not notify lock change");
+}
+
+mozApocNativeSettingsMemento mozApocBranchNotifier::RememberNativeValue(const char * aPath) const
+{
+ mozApocNativeSettingsData * aSettings = new mozApocNativeSettingsData();
+ if (aSettings)
+ {
+ // read access does not need to be proxied
+ nsresult rv = aSettings->Read(mNativeBranch, aPath);
+ if (NS_FAILED(rv))
+ {
+ delete aSettings, aSettings = nsnull;
+ }
+ }
+ else
+ NS_WARNING("apoc - Could not remember native value for later restore: OUT OF MEMORY");
+
+ return aSettings;
+}
+
+void mozApocBranchNotifier::RestoreAndNotifyNativeValue(const char * aPath, mozApocNativeSettingsMemento aMemento)
+{
+ if (aMemento)
+ {
+ NOTIFICATION_TRACE(stderr, "Notifying restore of value at %s\n", aPath);
+ // write access must be proxied, if possible
+ aMemento->Restore(this->getTargetBranch(), aPath);
+ }
+}
+
+
diff --git a/src/mozApocNotificationImpl.h b/src/mozApocNotificationImpl.h new file mode 100644 index 0000000..f815c0b --- /dev/null +++ b/src/mozApocNotificationImpl.h @@ -0,0 +1,69 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_NOTIFICATIONIMPL_H_INCLUDED +#define MOZAPOC_NOTIFICATIONIMPL_H_INCLUDED + +#include "mozApocNotificationDispatch.h" +#include "nsCOMPtr.h" +#include "nsIPrefBranch.h" + +class mozApocBranchNotifier : public mozApocNotifier +{ + nsCOMPtr< nsIPrefBranch > mNativeBranch; + nsCOMPtr< nsIPrefBranch > mDispatchBranch; + +public: + explicit + mozApocBranchNotifier( nsCOMPtr< nsIPrefBranch > const & aNativeBranch ) + : mNativeBranch(aNativeBranch) + , mDispatchBranch() + { + } + + // dispatch a notification + virtual void NotifyValueChange(const char * aPath, nsAString const & aValue, PRBool bLocked); + virtual void NotifyLockChange(const char * aPath, PRBool bLocked); + + // help for remembering/restoring the native value + virtual mozApocNativeSettingsMemento RememberNativeValue(const char * aPath) const; + virtual void RestoreAndNotifyNativeValue(const char * aPath, mozApocNativeSettingsMemento aMemento); +private: + nsCOMPtr< nsIPrefBranch > const & getTargetBranch(); +}; + +#endif + diff --git a/src/mozApocPAPI.cpp b/src/mozApocPAPI.cpp new file mode 100644 index 0000000..275fe53 --- /dev/null +++ b/src/mozApocPAPI.cpp @@ -0,0 +1,174 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+
+#include "mozApocPAPI.h"
+#include "nsDebug.h"
+#include "prenv.h"
+
+extern "C"
+{
+static
+void mozApocPAPIListenerDispatch( const PAPIEvent * inEvent, void * inUserData )
+{
+ NS_ASSERTION(inUserData, "apoc - NULL user data passed to listener");
+ NS_ASSERTION(inEvent, "apoc - NULL event passed to listener");
+ NS_ASSERTION(inEvent->componentName, "apoc - NULL component name passed to listener");
+
+ mozApocPAPIListener * listener = NS_STATIC_CAST(mozApocPAPIListener *, inUserData);
+ switch (inEvent->eventType)
+ {
+ case PAPIComponentAdd:
+ listener->componentAdded(inEvent->componentName);
+ break;
+ case PAPIComponentModify:
+ listener->componentModified(inEvent->componentName);
+ break;
+ case PAPIComponentRemove:
+ listener->componentRemoved(inEvent->componentName);
+ break;
+ default:
+ NS_NOTREACHED("apoc - Unknown event type in PAPI notification");
+ }
+}
+}
+
+nsresult mozApocPAPI::ReadComponentLayers( const char * inComponentName, mozApocPAPILayerList & outList) const
+{
+ NS_ENSURE_STATE(mPAPI);
+
+ PAPIStatus status = PAPISuccess;
+ outList.SetData( gPAPILib.papiReadComponentLayers( mPAPI, inComponentName, &status ) );
+ if (status == PAPINoSuchComponentFailure)
+ return NS_OK;
+ else
+ return ConvertResult(status);
+}
+
+nsresult mozApocPAPI::ListComponentNames( const char * inFilter, mozApocPAPIStringList& outList ) const
+{
+ NS_ENSURE_STATE(mPAPI);
+
+ PAPIStatus status = PAPISuccess;
+ outList.SetData( gPAPILib.papiListComponentNames( mPAPI, inFilter, &status ) );
+ return ConvertResult(status);
+}
+
+nsresult mozApocPAPI::AddListener(const char * inComponentName, mozApocPAPIListener * inListener, mozApocPAPIListenerId & outId)
+{
+ PAPIStatus status = PAPISuccess;
+ outId = gPAPILib.papiAddListener( mPAPI, inComponentName, mozApocPAPIListenerDispatch, (void*)inListener, &status);
+ return ConvertResult(status);
+}
+
+nsresult mozApocPAPI::RemoveListener(mozApocPAPIListenerId inListenerId)
+{
+ PAPIStatus status = PAPISuccess;
+ gPAPILib.papiRemoveListener( mPAPI, inListenerId, &status);
+ return ConvertResult(status);
+}
+
+nsresult mozApocPAPI::ConvertResult(PAPIStatus eStatus)
+{
+ switch (eStatus)
+ {
+ case PAPISuccess:
+ return NS_OK;
+
+ case PAPIConnectionFailure:
+ return NS_ERROR_NOT_AVAILABLE;
+
+ case PAPIInvalidArg:
+ case PAPINoSuchComponentFailure:
+ return NS_ERROR_INVALID_ARG;
+
+ case PAPIAuthenticationFailure:
+ case PAPILDBFailure:
+ case PAPIUnknownFailure:
+ return NS_ERROR_FAILURE;
+
+ case PAPIOutOfMemoryFailure:
+ return NS_ERROR_OUT_OF_MEMORY;
+
+ default:
+ NS_WARNING("apoc - Unknown PAPI status code");
+ return NS_ERROR_UNEXPECTED;
+ }
+}
+
+// implement support for dynamically loading PAPI
+#include "prlink.h"
+
+// todo: adjust for porting
+static const char kPAPILib_LibName[] = "libapoc.so";
+
+static int PAPILib_loadLibrary(struct PAPILib * libdata)
+{
+ char* moz_in_install = PR_GetEnv("MOZ_IN_INSTALL");
+
+ if (moz_in_install)
+ return 0; // this is during the quick silver installation
+ // don't load apoc library now.
+
+
+ if (libdata->module_)
+ return 0; // we have a module which failed before
+
+ PRLibrary * libpapi = PR_LoadLibrary(kPAPILib_LibName);
+ if (!libpapi)
+ return 0;
+
+ libdata->module_ = libpapi;
+
+ int success = 1;
+
+ // find the symbols for all interface functions in libpapi
+#define PAPI_DECLARATION( resulttype, functionname, parameterlist ) \
+ if (PRFuncPtr func = PR_FindFunctionSymbol( libpapi, #functionname)) \
+ libdata->functionname = reinterpret_cast<functionname ## Ptr>(func); \
+ else { \
+ NS_WARNING("apoc - libpapi.so is missing function \"" #functionname "\""); \
+ success = 0; \
+ }
+
+#include "papi/papidecl.h"
+#undef PAPI_DECLARATION
+
+ return success;
+}
+
+// implement the PAPI stub functionality here
+#include "papi/papilib.c"
+
diff --git a/src/mozApocPAPI.h b/src/mozApocPAPI.h new file mode 100644 index 0000000..702cb52 --- /dev/null +++ b/src/mozApocPAPI.h @@ -0,0 +1,187 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+
+#include "papi/papilib.h"
+#include "nsError.h"
+
+class mozApocPAPILayer
+{
+ PAPILayerList * layer_;
+public:
+ mozApocPAPILayer(PAPILayerList * layer)
+ : layer_(layer)
+ {}
+
+ PRBool Is() const { return layer_ != nsnull; }
+ PRBool HasData() const { return layer_ && layer_->data; }
+
+ const unsigned char * GetData() const
+ { return layer_ ? layer_->data : nsnull; }
+
+ PRInt32 GetLength() const
+ { return layer_ ? layer_->size : 0; }
+};
+
+class mozApocPAPILayerListEnumerator
+{
+ PAPILayerList * next_;
+public:
+ mozApocPAPILayerListEnumerator(PAPILayerList * start)
+ : next_(start)
+ {}
+
+ PRBool HasMore() const { return next_ != nsnull; }
+
+ mozApocPAPILayer Next()
+ {
+ PAPILayerList * data = next_;
+ if (next_) next_ = next_->next;
+ return data;
+ }
+};
+
+class mozApocPAPILayerList
+{
+ PAPILayerList * list_;
+public:
+ mozApocPAPILayerList()
+ : list_(nsnull)
+ {}
+
+ ~mozApocPAPILayerList()
+ { Free(); }
+
+ PRBool IsEmpty() const { return list_ == nsnull; }
+
+ mozApocPAPILayerListEnumerator Enum() const { return list_; }
+private:
+ friend class mozApocPAPI;
+ void SetData(PAPILayerList * list) { Free(); list_ = list; }
+ void Free() { if (list_) gPAPILib.papiFreeLayerList(list_); }
+private:
+ mozApocPAPILayerList(const mozApocPAPILayerList &); // not implemented
+ void operator=(const mozApocPAPILayerList &); // not implemented
+};
+
+class mozApocPAPIStringListEnumerator
+{
+ PAPIStringList * next_;
+public:
+ mozApocPAPIStringListEnumerator(PAPIStringList * start)
+ : next_(start)
+ {}
+
+ PRBool HasMore() const { return next_ != nsnull; }
+
+ const char * Next()
+ {
+ if (!next_) return nsnull;
+
+ const char * data = next_->data;
+ next_ = next_->next;
+ return data;
+ }
+};
+
+class mozApocPAPIStringList
+{
+ PAPIStringList * list_;
+public:
+ mozApocPAPIStringList()
+ : list_(nsnull)
+ {}
+
+ ~mozApocPAPIStringList()
+ { Free(); }
+
+ PRBool IsEmpty() const { return list_ == nsnull; }
+
+ mozApocPAPIStringListEnumerator Enum() const { return list_; }
+private:
+ friend class mozApocPAPI;
+ void SetData(PAPIStringList * list) { Free(); list_ = list; }
+ void Free() { if (list_) gPAPILib.papiFreeStringList(list_); }
+private:
+ mozApocPAPIStringList(const mozApocPAPIStringList &); // not implemented
+ void operator=(const mozApocPAPIStringList &); // not implemented
+};
+
+struct mozApocPAPIListener
+{
+ virtual void componentAdded(const char * component) = 0;
+ virtual void componentModified(const char * component) = 0;
+ virtual void componentRemoved(const char * component) = 0;
+};
+
+typedef PAPIListenerId mozApocPAPIListenerId;
+
+class mozApocPAPI
+{
+ PAPI * mPAPI;
+public:
+ explicit
+ mozApocPAPI(PAPIStatus * outStatus = nsnull)
+ : mPAPI( gPAPILib.papiInitialise(nsnull, outStatus) )
+ {}
+
+ explicit
+ mozApocPAPI(const char * inEntityId, PAPIStatus * outStatus = nsnull)
+ : mPAPI( gPAPILib.papiInitialise(inEntityId, outStatus) )
+ {}
+
+ ~mozApocPAPI()
+ {
+ if (mPAPI) gPAPILib.papiDeinitialise(mPAPI,nsnull);
+ }
+
+ PRBool IsConnected() const { return mPAPI != nsnull; }
+
+ nsresult ReadComponentLayers( const char * inComponentName, mozApocPAPILayerList & outList) const;
+
+ nsresult ListComponentNames( const char * inFilter, mozApocPAPIStringList & outList ) const;
+
+ nsresult AddListener(const char * inComponentName, mozApocPAPIListener * inListener, mozApocPAPIListenerId & outId);
+ nsresult RemoveListener(mozApocPAPIListenerId inListenerId);
+
+ // NYI: SetOffline, IsOffline
+
+ static nsresult ConvertResult(PAPIStatus eStatus);
+
+private:
+ mozApocPAPI(const mozApocPAPI&); // not implemented
+ void operator=(const mozApocPAPI&); // not implemented
+};
+
diff --git a/src/mozApocPathParser.cpp b/src/mozApocPathParser.cpp new file mode 100644 index 0000000..55dacb8 --- /dev/null +++ b/src/mozApocPathParser.cpp @@ -0,0 +1,102 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+
+#include "mozApocPathParser.h"
+
+nsCAutoString mozApocPathParser::GetComponent() const
+{
+ NS_ASSERTION(mPosition == 0, "apoc - Requesting component from path parser while not at start of path");
+ nsCAutoString aResult (GetCurrentPart());
+ return aResult;
+}
+
+PRBool mozApocPathParser::MoveNext()
+{
+ NS_PRECONDITION(HasData(), "apoc - Calling PathParser::MoveNext, when no components are left");
+
+ PRUint32 oldPosition = NS_STATIC_CAST(PRUint32,mPosition);
+ mPosition = mPathString.FindChar(k_mozApocPathDelimiter, oldPosition);
+
+ if (mPosition < 0)
+ return PR_FALSE;
+
+ PRUint32 newPosition = NS_STATIC_CAST(PRUint32,mPosition);
+ if (newPosition >= mPathString.Length())
+ {
+ mPosition = -1;
+ return PR_FALSE;
+ }
+
+ ++mPosition; // move after the dot
+
+ return PR_TRUE;
+}
+
+//brian nsDependentSingleFragmentCSubstring mozApocPathParser::GetCurrentPart() const
+nsDependentCSubstring mozApocPathParser::GetCurrentPart() const
+{
+ NS_PRECONDITION(HasData(), "apoc - Calling PathParser::GetCurrentPart, when no components are left");
+
+ PRUint32 curPosition = NS_STATIC_CAST(PRUint32,mPosition);
+
+ PRInt32 nextPosition = mPathString.FindChar(k_mozApocPathDelimiter, curPosition);
+ if (nextPosition < 0)
+ nextPosition = mPathString.Length();
+
+ PRUint32 curLength = NS_STATIC_CAST(PRUint32,nextPosition)-curPosition;
+
+ return Substring(mPathString,curPosition,curLength);
+}
+
+//brian nsDependentSingleFragmentCSubstring mozApocPathParser::GetRemainingPath() const
+nsDependentCSubstring mozApocPathParser::GetRemainingPath() const
+{
+ PRUint32 endPosition = mPathString.Length();
+ PRUint32 curPosition = this->HasData() ? NS_STATIC_CAST(PRUint32,mPosition) : endPosition;
+
+ return Substring(mPathString,curPosition,endPosition-curPosition);
+}
+
+nsCAutoString mozApocBuildPath(const nsACString & aPrefix, const nsACString & aLocalName)
+{
+ nsCAutoString aResult( aPrefix );
+ if (!aPrefix.IsEmpty())
+ aResult.Append(k_mozApocPathDelimiter);
+
+ aResult.Append(aLocalName);
+ return aResult;
+}
+
diff --git a/src/mozApocPathParser.h b/src/mozApocPathParser.h new file mode 100644 index 0000000..8f47733 --- /dev/null +++ b/src/mozApocPathParser.h @@ -0,0 +1,84 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_PATHPARSER_H_INCLUDED +#define MOZAPOC_PATHPARSER_H_INCLUDED + +#include "nsString.h" +#include "nsDependentString.h" +#include "nsDependentSubstring.h" + +//brian +#include "nsStringFwd.h" + +const char k_mozApocPathDelimiter = '.'; + +class mozApocPathParser +{ + nsDependentCString mPathString; + PRInt32 mPosition; +public: + mozApocPathParser(const char * aPath) + : mPathString(aPath) + , mPosition(0) + { + if (mPathString.IsEmpty()) + mPosition = -1; + } + + PRBool HasData() const { return mPosition >= 0; } + + PRUint32 TotalDepth() const + { + return mPathString.IsEmpty() ? 0 : + mPathString.CountChar(k_mozApocPathDelimiter) + 1u; + } + + PRBool MoveNext(); + void Reset() { if (!mPathString.IsEmpty()) mPosition = 0; } + +// typedef nsDependentSingleFragmentCSubstring partString; + typedef nsDependentCSubstring partString; + + nsCAutoString GetComponent() const; + partString GetCurrentPart() const; + partString GetRemainingPath() const; +}; + +nsCAutoString mozApocBuildPath(const nsACString & aPrefix, const nsACString & aLocalName); + +#endif + diff --git a/src/mozApocPolicyBackend.cpp b/src/mozApocPolicyBackend.cpp new file mode 100644 index 0000000..5b37eae --- /dev/null +++ b/src/mozApocPolicyBackend.cpp @@ -0,0 +1,309 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#include "mozApocPolicyBackend.h" +#include "mozApocPolicyComponentDOMData.h" +#include "mozApocPolicyModelFromDOM.h" +#include "mozApocPolicyModelFromXML.h" +#include "prthread.h" + +#ifndef MOZAPOC_DEBUGSUPPORT +#define MOZAPOC_DEBUGSUPPORT 0 +#endif + +#ifndef MOZAPOC_BACKEND_TRACE +#ifdef DEBUG +#define MOZAPOC_BACKEND_TRACE 2 +#else +#define MOZAPOC_BACKEND_TRACE MOZAPOC_DEBUGSUPPORT +#endif +#endif + +#define BETRACE(lvl) if ((lvl) > (MOZAPOC_BACKEND_TRACE)); else ::fprintf +#define BACKENDTRACE BETRACE(1) +#define REQUESTTRACE BETRACE(2) +#define DETAILTRACE BETRACE(3) + +#define k_mozApocPackagePrefix "org.mozilla." + +mozApocPolicyBackend::mozApocPolicyBackend() +: mPolicyStore() +, mGlobalListenerId(nsnull) +, mCache() +, mEnableCache(PR_FALSE) +, mUpdateLock(PR_NewMonitor()) +, mNotifier(nsnull) +{ + mEnableCache = mCache.Init(PL_DHASH_MIN_SIZE); + + NS_WARN_IF_FALSE(mPolicyStore.IsConnected(),"apoc - Backend: Connecting to PAPI failed - no policy data available"); + NS_WARN_IF_FALSE(mUpdateLock,"apoc - Backend: Could not create lock for cache - will not run threadsafe"); + if (mEnableCache && mPolicyStore.IsConnected()) + { + mPolicyStore.AddListener(k_mozApocPackagePrefix, + this, + mGlobalListenerId) ; + } +} + +mozApocPolicyBackend::~mozApocPolicyBackend() +{ + if (mGlobalListenerId != nsnull) + { + mPolicyStore.RemoveListener(mGlobalListenerId) ; + } + if (mUpdateLock) PR_DestroyMonitor(mUpdateLock); +} + +// tracks currently active parse(s) to prevent reentrant calls +class mozApoc_ActiveComponent +{ + nsACString const & name; + mozApoc_ActiveComponent * next; + + static mozApoc_ActiveComponent * top; +public: + explicit + mozApoc_ActiveComponent(nsACString const * name_) + : name(*name_) + , next(top) + { top = this; } + + ~mozApoc_ActiveComponent() + { top = next; } + + static PRBool findAny() { return top != nsnull; } + static PRBool find(nsACString const & name_) + { + for (mozApoc_ActiveComponent* entry = top; entry; entry = entry->next) + { + if (name_.Equals(entry->name)) + return PR_TRUE; + } + return PR_FALSE; + } +}; +mozApoc_ActiveComponent * mozApoc_ActiveComponent::top = nsnull; + +// ------------------------------------------------------------------------------------------- + +mozApocPolicyComponentData const * +mozApocPolicyBackend::GetComponentData(const nsACString & aComponentName, nsresult * _rv) +{ + ComponentInfo * pInfo = nsnull; + nsCAutoString aFullComponentName( NS_LITERAL_CSTRING(k_mozApocPackagePrefix) + aComponentName); + + nsresult rv = NS_OK; + if (!mEnableCache || !mCache.Get(aFullComponentName,&pInfo)) + { + if (mUpdateLock) PR_EnterMonitor(mUpdateLock); + + if (!mCache.Get(aFullComponentName,&pInfo)) + { + REQUESTTRACE(stderr,"\napoc: Request to read component '%s' from backend.\n", + PromiseFlatCString(aComponentName).get()); + + // Prevent infinite recursion for reentrant use of parser + PRBool isComponentAlreadyBeingParsed = mozApoc_ActiveComponent::find(aFullComponentName); + if (isComponentAlreadyBeingParsed) + { + NS_WARNING("apoc: Component is already being parsed - aborting recursive access\n"); + rv = NS_ERROR_UNEXPECTED; + } + else + { + mozApoc_ActiveComponent nowActive(&aFullComponentName); + + pInfo = new ComponentInfo(aComponentName); + if (pInfo) + { + if (mEnableCache) + mCache.Put(aFullComponentName,pInfo); + + rv = ReadComponent(aFullComponentName,*pInfo); + if (NS_FAILED(rv)) + { + if (mEnableCache) + mCache.Remove(aFullComponentName); + else + delete pInfo; + pInfo = nsnull; + } + } + else + rv = NS_ERROR_OUT_OF_MEMORY; + } + } + + if (mUpdateLock) PR_ExitMonitor(mUpdateLock); + } + + if (_rv) *_rv = rv; + + return pInfo; +} + +void mozApocPolicyBackend::Reset() +{ + // TODO: Unregister listeners + if (mEnableCache) + mCache.Clear(); +} + +nsresult mozApocPolicyBackend::ReadComponent(const nsAFlatCString & aFullComponentName, mozApocPolicyComponentData & aData, PRBool bClear) +{ + nsresult rv = NS_OK; + + mozApocPolicyComponentDOMData * pDOMData = nsnull; + if (!bClear) rv = ReadComponentDOM(aFullComponentName, aData.GetComponentName(), pDOMData); + + if (NS_SUCCEEDED(rv)) + { + mozApocBuildPolicyModelFromDOM aBuilder(pDOMData); + rv = aData.UpdateData(aBuilder, mNotifier); + } + else + NS_WARNING("apoc - Refreshing component data failed: parser error"); + + delete pDOMData; + + return rv; +} + +nsresult mozApocPolicyBackend::RefreshComponent(const char * component, PRBool bClear) +{ + NS_PRECONDITION(component, "apoc - Received PAPI notification with NULL component name"); + + if (mUpdateLock) PR_EnterMonitor(mUpdateLock); + + NS_ASSERTION(mEnableCache, "apoc - Notification is being invoked altough cache is not in use."); + NS_ASSERTION(!mozApoc_ActiveComponent::findAny(), "apoc - component refresh being executed while a request is in progress" + " (Locking problem ?)"); + + nsresult rv = NS_OK; + + nsCAutoString aFullComponentName(component); + + ComponentInfo * pInfo = nsnull; + if (mCache.Get(aFullComponentName,&pInfo)) + { + NS_ASSERTION(pInfo,"apoc - error: Found NULL cache entry"); + + REQUESTTRACE(stderr,"\napoc: Refreshing to component '%s' from backend for notification.\n", + aFullComponentName.get()); + + mozApoc_ActiveComponent nowActive(&aFullComponentName); + + rv = ReadComponent(aFullComponentName,*pInfo,bClear); + } + + if (mUpdateLock) PR_ExitMonitor(mUpdateLock); + + return rv; +} + +nsresult mozApocPolicyBackend::ReadComponentDOM(const nsAFlatCString & aFullComponentName, const nsAFlatCString & aShortComponentName, mozApocPolicyComponentDOMData *& newData) +{ + if (!mPolicyStore.IsConnected()) + { + DETAILTRACE(stderr,"apoc DEBUG: No data - not connected"); + return NS_OK; + } + + mozApocPAPILayerList aList; + + nsresult rv = mPolicyStore.ReadComponentLayers(aFullComponentName.get(),aList); + if (aList.IsEmpty()) + { + DETAILTRACE(stderr,"apoc DEBUG: No data in PAPI (rv = %0#8x)",unsigned(rv)); + return rv; + } + + BACKENDTRACE(stderr,"\napoc: Processing policy data for component '%s': ", aFullComponentName.get()); + + nsAutoPtr<mozApocPolicyComponentDOMData> apData( new mozApocPolicyComponentDOMData(aShortComponentName) ); + if (!apData) + return NS_ERROR_OUT_OF_MEMORY; + + mozApocPAPILayerListEnumerator aIterator = aList.Enum(); + while (aIterator.HasMore()) + { + BACKENDTRACE(stderr,"."); + mozApocPAPILayer aData = aIterator.Next(); + + mozApocBuildPolicyModelFromXML aParser(aData.GetData(), aData.GetLength()); + mozApocParsedLayerData aLayerData; + aParser.UpdateModel(aShortComponentName, nsnull, aLayerData); + + if (NS_SUCCEEDED(rv)) + { + apData->AddLayer(aLayerData); + BACKENDTRACE(stderr,"+"); + } + else + NS_WARNING("apoc - Parsing a layer failed: layer is ignored"); + } + BACKENDTRACE(stderr," - done. %d layers added.\n", int(apData->GetLayerCount())); + + newData = apData.forget(); + return NS_OK; +} + +nsresult mozApocPolicyBackend::RegisterForNotfication(const nsAFlatCString & aFullComponentName, ComponentInfo * data) +{ + NS_PRECONDITION(data,"apoc - error: trying to register a notification for a NULL component info"); + + nsresult rv = mPolicyStore.AddListener(aFullComponentName .get(), this, data->ListenerId); + + return rv; +} + +void mozApocPolicyBackend::componentAdded(const char * component) +{ + this->RefreshComponent(component); +} + +void mozApocPolicyBackend::componentModified(const char * component) +{ + this->RefreshComponent(component); +} + +void mozApocPolicyBackend::componentRemoved(const char * component) +{ + this->RefreshComponent(component,PR_TRUE); +} + + diff --git a/src/mozApocPolicyBackend.h b/src/mozApocPolicyBackend.h new file mode 100644 index 0000000..be98e02 --- /dev/null +++ b/src/mozApocPolicyBackend.h @@ -0,0 +1,94 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_POLICYBACKEND_H_INCLUDED +#define MOZAPOC_POLICYBACKEND_H_INCLUDED + +#include "mozApocPolicyComponentData.h" +#include "nsClassHashtable.h" +#include "nsHashKeys.h" +#include "mozApocPAPI.h" +#include "prmon.h" + +class mozApocPolicyComponentDOMData; +class mozApocNotifier; + +class mozApocPolicyBackend : private mozApocPAPIListener +{ + struct ComponentInfo : mozApocPolicyComponentData + { + ComponentInfo(const nsACString & aComponent) + : mozApocPolicyComponentData(aComponent) + , ListenerId() + {} + + mozApocPAPIListenerId ListenerId; + }; + typedef nsClassHashtable< nsCStringHashKey, ComponentInfo > ComponentCache; +private: + mozApocPAPI mPolicyStore; + mozApocPAPIListenerId mGlobalListenerId ; + ComponentCache mCache; + PRBool mEnableCache; + PRMonitor * mUpdateLock; + mozApocNotifier * mNotifier; +public: + mozApocPolicyBackend(); + virtual ~mozApocPolicyBackend(); + + mozApocPolicyComponentData const * GetComponentData(const nsACString & aComponentName, nsresult * _rv = nsnull); + + void Reset(); + + void SetNotifier(mozApocNotifier * pNotifier) { mNotifier = pNotifier; } +private: + nsresult RegisterForNotfication(const nsAFlatCString & aFullComponentName, ComponentInfo * data); + + nsresult ReadComponent(const nsAFlatCString & aFullComponentName, mozApocPolicyComponentData & pData, PRBool bClear = PR_FALSE); + nsresult ReadComponentDOM(const nsAFlatCString & aFullComponentName, const nsAFlatCString & aShortComponentName, + mozApocPolicyComponentDOMData *& newData); + nsresult RefreshComponent(const char * aFullComponentName, PRBool bClear = PR_FALSE); +private: + virtual void componentAdded(const char * component); + virtual void componentModified(const char * component); + virtual void componentRemoved(const char * component); +private: + mozApocPolicyBackend(const mozApocPolicyBackend &); // not implemented + void operator=(const mozApocPolicyBackend &); // not implemented +}; + +#endif + diff --git a/src/mozApocPolicyComponentDOMData.cpp b/src/mozApocPolicyComponentDOMData.cpp new file mode 100644 index 0000000..475c601 --- /dev/null +++ b/src/mozApocPolicyComponentDOMData.cpp @@ -0,0 +1,57 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+
+#include "mozApocPolicyComponentDOMData.h"
+
+mozApocPolicyComponentDOMData::mozApocPolicyComponentDOMData(const nsACString & aComponent)
+: mLayers()
+, mComponent(aComponent)
+{
+}
+
+void mozApocPolicyComponentDOMData::AddLayer(const mozApocParsedLayerData & aLayerData)
+{
+ mozApocPolicyModelNode::AppendToNodeList(mLayers,aLayerData);
+}
+
+PRInt32 mozApocPolicyComponentDOMData::GetLayerCount() const
+{
+ PRInt32 nResult = 0;
+ for (mozApocPolicyModelNode const * layer = mLayers.Get(); layer; layer = layer->GetNextSibling())
+ ++nResult;
+ return nResult;
+}
+
diff --git a/src/mozApocPolicyComponentDOMData.h b/src/mozApocPolicyComponentDOMData.h new file mode 100644 index 0000000..3906823 --- /dev/null +++ b/src/mozApocPolicyComponentDOMData.h @@ -0,0 +1,62 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_POLICYCOMPONENTDOMDATA_H_INCLUDED +#define MOZAPOC_POLICYCOMPONENTDOMDATA_H_INCLUDED + +#include "mozApocPolicyModel.h" + +typedef mozApocPolicyModelNodeRef mozApocParsedLayerData; +typedef mozApocPolicyModelNodeRef mozApocParsedLayerDataList; + +class mozApocPolicyComponentDOMData +{ + mozApocParsedLayerDataList mLayers; + nsCString mComponent; +public: + explicit + mozApocPolicyComponentDOMData(const nsACString & aComponent); + + const nsAFlatCString & GetComponentName() const { return mComponent; } + + mozApocParsedLayerDataList GetLayers() const { return mLayers; } + PRInt32 GetLayerCount() const; + + void AddLayer(const mozApocParsedLayerData & aLayerData); +}; + +#endif + diff --git a/src/mozApocPolicyComponentData.cpp b/src/mozApocPolicyComponentData.cpp new file mode 100644 index 0000000..7ed6635 --- /dev/null +++ b/src/mozApocPolicyComponentData.cpp @@ -0,0 +1,50 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+
+#include "mozApocPolicyComponentData.h"
+#include "mozApocPolicyModelBuilder.h"
+
+mozApocPolicyComponentData::mozApocPolicyComponentData(const nsACString & aComponent)
+: mData(nsnull)
+, mComponentName(aComponent)
+{
+}
+
+nsresult mozApocPolicyComponentData::UpdateData(mozApocPolicyModelBuilder & aUpdater, mozApocNotifier * pNotifier)
+{
+ return aUpdater.UpdateModel(mComponentName,pNotifier,mData);
+}
+
diff --git a/src/mozApocPolicyComponentData.h b/src/mozApocPolicyComponentData.h new file mode 100644 index 0000000..a46c23a --- /dev/null +++ b/src/mozApocPolicyComponentData.h @@ -0,0 +1,62 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_POLICYCOMPONENTDATA_H_INCLUDED +#define MOZAPOC_POLICYCOMPONENTDATA_H_INCLUDED + +#include "mozApocPolicyModel.h" +#include "nsString.h" + +class mozApocPolicyModelBuilder; +class mozApocNotifier; + +class mozApocPolicyComponentData +{ + mozApocPolicyModelNodeRef mData; + nsCString mComponentName; +public: + explicit + mozApocPolicyComponentData(const nsACString & aComponent); + + const nsAFlatCString & GetComponentName() const { return mComponentName; } + + const mozApocPolicyModelNode * getRootNode() const { return mData.Get(); } + + nsresult UpdateData(mozApocPolicyModelBuilder & aUpdater, mozApocNotifier * pNotifier); +}; + +#endif + diff --git a/src/mozApocPolicyData.cpp b/src/mozApocPolicyData.cpp new file mode 100644 index 0000000..053605c --- /dev/null +++ b/src/mozApocPolicyData.cpp @@ -0,0 +1,463 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#include "mozApocPolicyData.h" +#include "mozApocPolicyBackend.h" +#include "mozApocPathParser.h" +#include "nsReadableUtils.h" +#include "nsISupportsPrimitives.h" +#include "nsILocalFile.h" +#include "pref/nsIRelativeFilePref.h" +#include "nsIPrefLocalizedString.h" + +static +nsresult +ParseComplexValue(const nsString & aData, mozApocEntryAttributes aAttributes, + const nsIID & anID, /* [out, iid_is(anID)] */void * * aResult); + +mozApocPolicyEntry::mozApocPolicyEntry() +: mData() +, mErrCode(NS_ERROR_NOT_INITIALIZED) +{ +} + +mozApocPolicyEntry::mozApocPolicyEntry(mozApocPolicyBackend & aBackend, char const * aPath, PRBool bPreferProp) +: mData() +, mErrCode(NS_OK) +{ + if (aPath == 0) + { + NS_WARNING("apoc - Policy Entry constructed on NULL path"); + mErrCode = NS_ERROR_INVALID_POINTER; + return; + } + mozApocPathParser aParser(aPath); + if (!aParser.HasData()) + { + NS_WARNING("apoc - Policy Entry constructed on empty path"); + NS_WARNING(aPath ? aPath : "<null>"); + mErrCode = NS_ERROR_INVALID_ARG; + return; + } + mData = mozApocPolicyNodeData(aBackend.GetComponentData(aParser.GetComponent(), &mErrCode)); + if (HasError()) NS_WARNING("apoc - Error in GetComponentData - Policy Entry is invalid"); + FollowPath(aParser, bPreferProp); +} + +mozApocPolicyEntry::mozApocPolicyEntry(mozApocPolicyComponentData const * aComponent, char const * aPath, PRBool bPreferProp) +: mData() +, mErrCode(NS_OK) +{ + mozApocPathParser aParser(aPath); + if (aParser.HasData() && aParser.GetComponent().Equals(aComponent->GetComponentName())) + { + mData = mozApocPolicyNodeData(aComponent); + } + else + { + NS_WARNING("apoc - Component data does not match path"); + mErrCode = NS_ERROR_INVALID_ARG; + } + FollowPath(aParser, bPreferProp); +} + +mozApocPolicyEntry::mozApocPolicyEntry(mozApocPolicyEntry const & aEntry, char const * aRelativePath, PRBool bPreferProp) +: mData(aEntry.mData) +, mErrCode(aEntry.mErrCode) +{ + if (NS_FAILED(mErrCode)) return; + + if (aRelativePath == 0) + { + NS_WARNING("apoc - Policy Entry constructed on NULL path"); + SetError(NS_ERROR_INVALID_POINTER); + return; + } + + mozApocPathParser aParser(aRelativePath); + if (!aParser.HasData()) + { + NS_WARNING("apoc - Policy Entry constructed on empty path"); + SetError(NS_ERROR_INVALID_ARG); + return; + } + + FollowPath(aParser, bPreferProp); +} + +void mozApocPolicyEntry::SetError(nsresult aErrCode) +{ + mErrCode = aErrCode; + mData = mozApocPolicyNodeData(); +} + +static +PRBool GotoFallbackChild(mozApocPolicyNodeData & aData, mozApocPathParser::partString const & aFallbackName) +{ + if (!aData.HasRealChild(aFallbackName)) + { + return PR_FALSE; + } + + nsresult result = aData.GotoChild(aFallbackName); + if (NS_FAILED(result)) + { + NS_WARNING("apoc - GotoChild failed for fallback"); + return PR_FALSE; + } + + return PR_TRUE; +} + +void mozApocPolicyEntry::FollowPath(mozApocPathParser & aParser, PRBool bPreferProp) +{ + while (mData.IsReal() && aParser.MoveNext() && NS_SUCCEEDED(mErrCode)) + { + mozApocPathParser::partString aNextPart = aParser.GetCurrentPart(); + + // prefer fallback, if the result should preferably be a Property + // (rather than a node with a conflicting name) + if (bPreferProp || !mData.HasRealChild(aNextPart)) + { + if (GotoFallbackChild(mData,aParser.GetRemainingPath())) + break; + } + + nsresult result = mData.GotoChild(aNextPart); + + if (NS_FAILED(result)) + { + if (GotoFallbackChild(mData,aParser.GetRemainingPath())) + break; + + NS_WARNING("apoc - GotoChild failed: Setting PolicyEntry to error state"); + SetError(result); + } + } +} + +nsresult mozApocPolicyEntry::GetBoolValue(PRBool * _retval) const +{ + NS_ENSURE_ARG_POINTER(_retval); + + NS_ENSURE_FALSE(HasError(), NS_ERROR_UNEXPECTED); + + // to do: check and handle type issues + nsAutoString value; + nsresult rv = mData.GetValue(value); + if (NS_SUCCEEDED(rv)) + { + if (value.Equals(NS_LITERAL_STRING("false"))) + *_retval = PR_FALSE; + + else if (value.Equals(NS_LITERAL_STRING("true"))) + *_retval = PR_TRUE; + + else + { + NS_WARNING("apoc - GetBoolValue: Invalid data - not a boolean value"); + rv = NS_ERROR_UNEXPECTED; + } + } + + return rv; +} + +nsresult mozApocPolicyEntry::GetIntValue(PRInt32 * _retval) const +{ + NS_ENSURE_ARG_POINTER(_retval); + + NS_ENSURE_FALSE(HasError(), NS_ERROR_UNEXPECTED); + + // to do: check and handle type issues + nsAutoString value; + nsresult rv = mData.GetValue(value); + if (NS_SUCCEEDED(rv)) + { + PRInt32 errcode = NS_OK; + PRInt32 intVal = value.ToInteger(&errcode,kRadix10); + + rv = NS_STATIC_CAST(nsresult,errcode); + if (NS_SUCCEEDED(rv)) + *_retval = intVal; + else + NS_WARNING("apoc - - GetIntValue: Invalid data - not a numeric value"); + } + + return rv; +} + +nsresult mozApocPolicyEntry::GetCharValue(char **_retval) const +{ + NS_ENSURE_ARG_POINTER(_retval); + + NS_ENSURE_FALSE(HasError(), NS_ERROR_UNEXPECTED); + + // to do: check and handle type issues + nsAutoString value; + nsresult rv = mData.GetValue(value); + if (NS_SUCCEEDED(rv)) + { + *_retval = ToNewUTF8String(value); + if (!*_retval) + rv = NS_ERROR_OUT_OF_MEMORY; + } + + return rv; +} + +nsresult mozApocPolicyEntry::GetUnicodeValue(PRUnichar **_retval) const +{ + NS_ENSURE_ARG_POINTER(_retval); + + NS_ENSURE_FALSE(HasError(), NS_ERROR_UNEXPECTED); + + // to do: check and handle type issues + nsAutoString value; + nsresult rv = mData.GetValue(value); + if (NS_SUCCEEDED(rv)) + { + *_retval = ToNewUnicode(value); + if (!*_retval) + rv = NS_ERROR_OUT_OF_MEMORY; + } + + return rv; +} + +nsresult mozApocPolicyEntry::GetComplexValue(const nsIID & aType, void * *aValue) const +{ + NS_ENSURE_ARG_POINTER(aValue); + + NS_ENSURE_FALSE(HasError(), NS_ERROR_UNEXPECTED); + + // to do: check and handle type issues + nsAutoString value; + nsresult rv = mData.GetValue(value); + if (NS_SUCCEEDED(rv)) + { + rv = ParseComplexValue(value, mData.GetAttributes(), aType, aValue); + NS_WARN_IF_FALSE( NS_SUCCEEDED(rv), "apoc - - GetComplexValue: " + "Invalid data or request - could not create object of expected type from data."); + } + + return rv; +} + + +static const char k_mozApocFlatSettingComponent[] = "ooc"; + +mozApocPolicyData::mozApocPolicyData() +: mBackend(NULL) +, mRootEntry() +{ +} + +mozApocPolicyData::mozApocPolicyData(mozApocPolicyBackend & aBackend) +: mBackend(&aBackend) +, mRootEntry() // to be initialized later +{ +} + +mozApocPolicyData::mozApocPolicyData(mozApocPolicyEntry const & aRootEntry) +: mBackend(NULL) +, mRootEntry(aRootEntry) +{ +} + +mozApocPolicyData::~mozApocPolicyData() +{ +} + +PRBool mozApocPolicyData::HasError() const +{ + // support lazy init + if (mBackend && mRootEntry.GetError() == NS_ERROR_NOT_INITIALIZED) + return PR_FALSE; + + return mRootEntry.HasError(); +} + +nsresult mozApocPolicyData::GetError() const +{ + // support lazy init + if (mBackend && mRootEntry.GetError() == NS_ERROR_NOT_INITIALIZED) + return NS_OK; + + return mRootEntry.GetError(); +} + +mozApocPolicyEntry mozApocPolicyData::GetEntry(char const * path, PRBool bPreferProp) const +{ + if (mBackend) + { + mozApocPolicyEntry aResult(*mBackend,path,bPreferProp); + + bool bUseOOC = !aResult.IsReal() && path && + mozApocPathParser(path).TotalDepth() == 1; + if (!bUseOOC) + return aResult; + + // do lazy initialization + if (mRootEntry.GetError() == NS_ERROR_NOT_INITIALIZED) + mRootEntry = mozApocPolicyEntry(*mBackend,k_mozApocFlatSettingComponent,PR_FALSE); + + NS_ASSERTION(mRootEntry.GetError() != NS_ERROR_NOT_INITIALIZED, + "apoc - Unexpected error from reading policy data: change lazy initialisation"); + } + return mozApocPolicyEntry(mRootEntry,path,bPreferProp); +} + +static +nsresult ParseComplexValue(const nsString & aData, mozApocEntryAttributes aAttributes, + const nsIID & aType, void * * aResult) +{ + NS_WARN_IF_FALSE(mozApocGetEntryType(aAttributes) != MOZAPOC_ENTRY_TYPE_BINARY, + "apoc - ParseComplexValue: support for binary (serialized) data is not yet available"); + + if (aType.Equals(NS_GET_IID(nsISupportsString))) + { + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr<nsISupportsString> theString(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv,rv); + + rv = theString->SetData(aData); + NS_ENSURE_SUCCESS(rv,rv); + + nsISupportsString * temp = theString; + + NS_ADDREF(temp); + *aResult = temp; + return rv; + } + + if (aType.Equals(NS_GET_IID(nsIPrefLocalizedString))) + { + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr<nsIPrefLocalizedString> theString(do_CreateInstance(NS_PREFLOCALIZEDSTRING_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv,rv); + + rv = theString->SetDataWithLength(aData.Length(),aData.get()); + NS_ENSURE_SUCCESS(rv,rv); + + nsIPrefLocalizedString * temp = theString; + + NS_ADDREF(temp); + *aResult = temp; + return rv; + } + + if (aType.Equals(NS_GET_IID(nsILocalFile))) + { + // rv = file->SetPersistentDescriptor(utf8String); //--> to be used for binary data + + nsCOMPtr<nsILocalFile> file; + nsresult rv = NS_NewLocalFile(aData, PR_FALSE, getter_AddRefs(file)); + NS_ENSURE_SUCCESS(rv,rv); + + nsILocalFile * temp = file; + + NS_ADDREF(temp); + *aResult = temp; + return rv; + } + + if (aType.Equals(NS_GET_IID(nsIRelativeFilePref))) + { + nsresult rv = NS_ERROR_FAILURE; + + nsAString::const_iterator keyBegin, strEnd; + aData.BeginReading(keyBegin); + aData.EndReading(strEnd); + + // The pref has the format: [fromKey]a/b/c + NS_ENSURE_TRUE(*keyBegin++ == PRUnichar('['), rv); + + nsAString::const_iterator keyEnd(keyBegin); + NS_ENSURE_TRUE( FindCharInReadable(PRUnichar(']'), keyEnd, strEnd), rv); + + // assumption: directory key will only ever be ASCII + NS_LossyConvertUCS2toASCII key(Substring(keyBegin, keyEnd)); + + nsCOMPtr<nsIProperties> directoryService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv,rv); + + nsCOMPtr<nsILocalFile> theFile; + rv = directoryService->Get(key.get(), NS_GET_IID(nsILocalFile), getter_AddRefs(theFile)); + NS_ENSURE_SUCCESS(rv,rv); + + rv = theFile->AppendRelativePath(Substring(++keyEnd, strEnd)); + NS_ENSURE_SUCCESS(rv,rv); + + nsCOMPtr<nsIRelativeFilePref> relativePref; + rv = NS_NewRelativeFilePref(theFile, key, getter_AddRefs(relativePref)); + NS_ENSURE_SUCCESS(rv,rv); + + nsIRelativeFilePref * temp = relativePref; + + NS_ADDREF(temp); + *aResult = temp; + return rv; + } + +#if 0 // No support for this with unicode strings + // This is deprecated and you should not be using it + if (aType.Equals(NS_GET_IID(nsIFileSpec))) + { + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr<nsIFileSpec> file(do_CreateInstance(NS_FILESPEC_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv,rv); + + PRBool valid; + file->SetPersistentDescriptorString(utf8String); // only returns NS_OK + file->IsValid(&valid); + if (!valid) { + /* if the string wasn't a valid persistent descriptor, it might be a valid native path */ + file->SetNativePath(utf8String); + } + + nsIFileSpec *temp = file; + + NS_ADDREF(temp); + *aResult = temp; + return rv; + } +#endif + + NS_WARNING("apoc - ParseComplexValue - Unsupported interface type"); + return NS_NOINTERFACE; +} + diff --git a/src/mozApocPolicyData.h b/src/mozApocPolicyData.h new file mode 100644 index 0000000..b81df09 --- /dev/null +++ b/src/mozApocPolicyData.h @@ -0,0 +1,101 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_POLICYDATA_H_INCLUDED +#define MOZAPOC_POLICYDATA_H_INCLUDED + +#include "mozApocPolicyNodeData.h" +#include "nsID.h" + +class mozApocPolicyBackend; +class mozApocPolicyComponentData; +class mozApocPathParser; + +class mozApocPolicyEntry +{ + mozApocPolicyNodeData mData; + nsresult mErrCode; +public: + mozApocPolicyEntry(); + mozApocPolicyEntry(mozApocPolicyBackend & aBackend, char const * aPath, PRBool bPreferProp=PR_FALSE); + mozApocPolicyEntry(mozApocPolicyComponentData const * aComponent, char const * aPath, PRBool bPreferProp); + mozApocPolicyEntry(mozApocPolicyEntry const & aEntry, char const * aRelativePath, PRBool bPreferProp); + + PRBool HasError() const { return NS_FAILED(mErrCode); } + nsresult GetError() const { return mErrCode; } + + PRBool IsNothing() const { return mData.GetAttributes() == 0; } + PRBool IsReal() const { return mozApocExistsInPolicy(mData.GetAttributes()); } + PRBool IsProtected() const { return mozApocAreAnyFlagsSet(mData.GetAttributes(),MOZAPOC_ENTRY_PROTECTED_FLAGS); } + PRBool IsMandatory() const { return mozApocAreAnyFlagsSet(mData.GetAttributes(),MOZAPOC_ENTRY_MANDATORY_FLAGS); } + PRBool HasValue() const { return mozApocHasValue(mData.GetAttributes()); } + PRBool IsProperty() const { return mozApocIsProperty(mData.GetAttributes()); } + PRBool IsInnerNode() const { return mozApocIsNode(mData.GetAttributes()); } + + mozApocEntryFlagValues GetValueType() const { return mozApocGetEntryType(mData.GetAttributes()); } + + nsresult GetBoolValue(PRBool * _retval) const; + nsresult GetIntValue(PRInt32 * _retval) const; + nsresult GetCharValue(char **_retval) const; + nsresult GetUnicodeValue(PRUnichar **_retval) const; + nsresult GetComplexValue(const nsIID & aType, void * *aValue) const; +private: + void SetError(nsresult aErrCode); + void FollowPath(mozApocPathParser & aParser, PRBool bPreferProp); +}; + +class mozApocPolicyData +{ +public: + mozApocPolicyData(); + explicit + mozApocPolicyData(mozApocPolicyBackend & aBackend); + explicit + mozApocPolicyData(mozApocPolicyEntry const & aComponentRootEntry); + ~mozApocPolicyData(); + + mozApocPolicyEntry GetEntry(char const * path, PRBool bPreferProp) const; + + PRBool HasError() const; + nsresult GetError() const; +private: + mozApocPolicyBackend * mBackend; + mutable mozApocPolicyEntry mRootEntry; +}; + + +#endif + diff --git a/src/mozApocPolicyModel.cpp b/src/mozApocPolicyModel.cpp new file mode 100644 index 0000000..db7e48e --- /dev/null +++ b/src/mozApocPolicyModel.cpp @@ -0,0 +1,303 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+
+#include "mozApocPolicyModel.h"
+
+#include "mozApocPolicyComponentData.h"
+#include "mozApocNotificationDispatch.h"
+
+#include "pratom.h"
+
+#ifndef MOZAPOC_TRACE_MODEL
+#define MOZAPOC_TRACE_MODEL 0
+#endif
+
+#define MODEL_TRACE if (!(MOZAPOC_TRACE_MODEL )) ; else ::fprintf
+
+struct mozApocPolicyModelNode::ValueData
+{
+ ValueData(nsAString const & aValue, mozApocNotificationDispatcher const & aNotifier)
+ : PolicyValue(aValue)
+ , HasValue(PR_TRUE)
+ , NativeValue(aNotifier.RememberNativeValue())
+ {
+ }
+
+ ValueData(PRBool /*bLockState*/, mozApocNotificationDispatcher const & aNotifier)
+ : PolicyValue()
+ , HasValue(PR_FALSE)
+ , NativeValue(aNotifier.RememberNativeValue())
+ {
+ }
+
+ nsString PolicyValue;
+ PRBool HasValue;
+ const mozApocNativeSettingsMemento NativeValue;
+};
+
+mozApocPolicyModelNode::mozApocPolicyModelNode(const nsACString & aName)
+: mRefCount(0)
+, mNext()
+, mChildren()
+, mName(aName)
+, mAttributes(0)
+, mValue(nsnull)
+{
+ MODEL_TRACE(stderr, "apoc data model: Created Node '%s' at %p\n",
+ PromiseFlatCString(aName).get(), (void*)this);
+}
+
+mozApocPolicyModelNodeRef mozApocPolicyModelNode::New(const nsACString & aName,
+ mozApocEntryAttributes aAttributes,
+ mozApocNotificationDispatcher const & aNotifier)
+{
+ typedef mozApocPolicyModelNode node;
+ node * Node = new node(aName);
+ if (Node) Node->UpdateAttributes(aAttributes,aNotifier);
+ return Node;
+}
+
+
+mozApocPolicyModelNode::~mozApocPolicyModelNode()
+{
+ MODEL_TRACE(stderr, "apoc data model: Destroyed Node '%s' at %p\n", PromiseFlatCString(mName).get(), (void*)this);
+ if (mValue && mValue->NativeValue)
+ mozApocDiscardNativeSettings(mValue->NativeValue);
+ delete mValue;
+}
+
+void mozApocPolicyModelNode::AcquireReference() const
+{
+ PR_AtomicIncrement(&mRefCount);
+}
+
+void mozApocPolicyModelNode::ReleaseReference() const
+{
+ if (0 == PR_AtomicDecrement(&mRefCount))
+ delete this;
+}
+
+mozApocPolicyModelNode * mozApocPolicyModelNode::ImplGetChild(const nsACString & aName) const
+{
+ typedef mozApocPolicyModelNode Node;
+ for (Node * child = mChildren.Get(); child; child = child->mNext.Get())
+ {
+ if (child->IsNamed(aName))
+ return child;
+ }
+ return nsnull;
+}
+
+const mozApocPolicyModelNode * mozApocPolicyModelNode::GetChild(const nsACString & aName, nsresult * _rv) const
+{
+ mozApocPolicyModelNode * result;
+ nsresult rv;
+
+ if (!mozApocIsProperty(mAttributes))
+ {
+ result = ImplGetChild(aName);
+ rv = NS_OK;
+ }
+
+ else
+ {
+ NS_ASSERTION(!mChildren,"apoc - Found children in property");
+ result = nsnull;
+ rv = NS_ERROR_UNEXPECTED;
+ }
+
+
+ if (_rv) *_rv = rv;
+ return result;
+}
+
+nsresult mozApocPolicyModelNode::GetValue(nsAString & _retval) const
+{
+ nsresult rv;
+ if (mValue && mValue->HasValue)
+ {
+ _retval = mValue->PolicyValue;
+ rv = NS_OK;
+ }
+ else
+ rv = NS_ERROR_UNEXPECTED;
+
+ return rv;
+}
+
+nsresult mozApocPolicyModelNode::UpdateValue(const nsAString & aNewValue, mozApocNotificationDispatcher const & aNotifier)
+{
+ MODEL_TRACE(stderr, "apoc data model: Setting value of node '%s' at %p to '%s'\n",
+ PromiseFlatCString(mName).get(), (void*)this, NS_ConvertUCS2toUTF8(aNewValue).get());
+
+ NS_ENSURE_TRUE(mozApocHasValue(mAttributes), NS_ERROR_UNEXPECTED);
+ if (!mValue)
+ mValue = new ValueData(aNewValue,aNotifier);
+ else if (mValue->HasValue)
+ mValue->PolicyValue = aNewValue;
+ else
+ {
+ mValue->PolicyValue = aNewValue;
+ mValue->HasValue = PR_TRUE;
+ // remove the original lock-only notification
+ aNotifier.NotifyLockChange(PR_FALSE);
+ }
+
+ if (!mValue)
+ return NS_ERROR_OUT_OF_MEMORY;
+
+ aNotifier.NotifyValueChange(mValue->PolicyValue,this->IsProtected());
+
+ return NS_OK;
+}
+
+void mozApocPolicyModelNode::UpdateAttributes(mozApocEntryAttributes aNewAttributes, mozApocNotificationDispatcher const & aNotifier)
+{
+ MODEL_TRACE(stderr, "apoc data model: Updating attributes of Node '%s' at %p to %#.8x\n",
+ PromiseFlatCString(mName).get(), (void*)this, unsigned(aNewAttributes));
+
+ // get protected state before attribute change
+ PRBool bWasProtected = this->IsProtected();
+
+ mAttributes = aNewAttributes;
+
+ PRBool bProtectionChanged = (this->IsProtected() != bWasProtected);
+
+ if (!mozApocHasValue(aNewAttributes))
+ {
+ // check if this is a property that is being discarded -> restore native data
+ if (mValue)
+ {
+ if (mValue->HasValue || bProtectionChanged)
+ {
+ aNotifier.RestoreAndNotifyNativeValue(mValue->NativeValue);
+ delete mValue, mValue = nsnull;
+ }
+ }
+ // check, if this is a lock-only property
+ if (bProtectionChanged && mozApocIsProperty(aNewAttributes))
+ {
+ PRBool bLocked = this->IsProtected();
+ if (bLocked)
+ {
+ NS_ASSERTION(!mValue, "Logic error: Leaking ValueData object");
+
+ mValue = new ValueData(bLocked,aNotifier);
+ aNotifier.NotifyLockChange(bLocked);
+ }
+ }
+ }
+}
+
+nsresult mozApocPolicyModelNode::AddChild(Ref const & aNode)
+{
+ NS_PRECONDITION(aNode, "apoc - Trying to add a NULL node as child");
+ NS_PRECONDITION(!aNode->mNext, "apoc - Trying to add an entire list as child");
+ NS_PRECONDITION(! ImplGetChild(aNode->mName), "apoc - Child being added already exists");
+
+ MODEL_TRACE(stderr, "apoc data model: Adding Node '%s' at %p as new child to Node '%s' at %p\n",
+ PromiseFlatCString(aNode->mName).get(), (void*)aNode.Get(),
+ PromiseFlatCString(mName).get(), (void*)this );
+
+ aNode->mNext = mChildren;
+ mChildren = aNode;
+
+ return NS_OK;
+}
+
+mozApocPolicyModelNodeRef mozApocPolicyModelNode::ReleaseChildren()
+{
+ MODEL_TRACE(stderr, "apoc data model: Releasing children of Node '%s' at %p (first child was at %p)\n",
+ PromiseFlatCString(mName).get(), (void*)this, (void*)mChildren.Get() );
+
+ return mChildren.Release();
+}
+
+void mozApocPolicyModelNode::AppendToNodeList(Ref & aList, Ref const & aElement)
+{
+ Ref * pNode = &aList;
+ while (*pNode)
+ pNode = &(*pNode)->mNext;
+ *pNode = aElement;
+}
+
+mozApocPolicyModelNodeRef mozApocPolicyModelNode::ExtractFromNodeList(mozApocPolicyModelNodeRef & aList, const nsACString & aName)
+{
+ mozApocPolicyModelNodeRef * ppNode = &aList;
+ while (*ppNode)
+ {
+ mozApocPolicyModelNodeRef pNode = *ppNode;
+ if (pNode->IsNamed(aName))
+ {
+ // unlink, but don't release pNode
+ *ppNode = pNode->mNext.Release();
+
+ return pNode;
+ }
+
+ ppNode = &pNode->mNext;
+ }
+ return Ref();
+}
+
+mozApocPolicyModelNodeRef mozApocPolicyModelNode::ImplDisposeAndGetNext(mozApocNotificationDispatcher const & aNotifier)
+{
+ MODEL_TRACE(stderr, "apoc data model: Disposing Node '%s' at %p \n",
+ PromiseFlatCString(mName).get(), (void*)this );
+
+ UpdateAttributes(0, aNotifier);
+ NS_ASSERTION(!mValue, "apoc - Value not disposed properly");
+
+ DisposeNodeList(mChildren, aNotifier);
+
+ MODEL_TRACE(stderr, "apoc data model: Done disposing Node '%s' at %p \n",
+ PromiseFlatCString(mName).get(), (void*)this );
+
+ return mNext.Release();
+}
+
+void mozApocPolicyModelNode::DisposeNodeList(mozApocPolicyModelNodeRef & aList, mozApocNotificationDispatcher const & aParentNotifier)
+{
+ MODEL_TRACE(stderr, "apoc data model: Disposing list of nodes starting at %p\n", (void*)aList.Get());
+
+ Ref aNode = aList.Release();
+ while (aNode)
+ {
+ // first dispose, then release
+ aNode = aNode->ImplDisposeAndGetNext(aParentNotifier.GetChildNotifier(aNode->mName));
+ }
+}
+
diff --git a/src/mozApocPolicyModel.h b/src/mozApocPolicyModel.h new file mode 100644 index 0000000..3288d13 --- /dev/null +++ b/src/mozApocPolicyModel.h @@ -0,0 +1,177 @@ + + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_POLICYMODEL_H_INCLUDED +#define MOZAPOC_POLICYMODEL_H_INCLUDED + +#include "mozApocPolicyNodeAttributes.h" +#include "nsString.h" + +class mozApocPolicyModelNode; +class mozApocPolicyModelNodeRef +{ + struct NoAcquire {}; + + mozApocPolicyModelNode * mPtr; +public: + mozApocPolicyModelNodeRef() + : mPtr(nsnull) + {} + + mozApocPolicyModelNodeRef(mozApocPolicyModelNode * aPtr) + : mPtr(aPtr) + { Acquire_(); } + + mozApocPolicyModelNodeRef(mozApocPolicyModelNode * aPtr, NoAcquire) + : mPtr(aPtr) + {} + + mozApocPolicyModelNodeRef(const mozApocPolicyModelNodeRef& aOther) + : mPtr(aOther.mPtr) + { Acquire_(); } + + mozApocPolicyModelNodeRef & operator=(const mozApocPolicyModelNodeRef& aOther) + { + aOther.Acquire_(); + this->Release_(); + mPtr = aOther.mPtr; + return *this; + } + + ~mozApocPolicyModelNodeRef() + { Release_(); } + + // support for NULL check and comparison + struct OpaqueValue_; + operator OpaqueValue_ const * () const + { return NS_REINTERPRET_CAST(OpaqueValue_ const *,mPtr); } + + mozApocPolicyModelNode * Get() const { return mPtr; } + + mozApocPolicyModelNode & operator * () const { return *mPtr; } + mozApocPolicyModelNode * operator -> () const { return mPtr; } + + mozApocPolicyModelNodeRef Release() + { + mozApocPolicyModelNode * aPtr = mPtr; + mPtr = 0; + return mozApocPolicyModelNodeRef(aPtr, NoAcquire()); + } +private: + void Acquire_() const; + void Release_() const; +}; + +class mozApocNotificationDispatcher; +class mozApocPolicyModelNode +{ +private: + mozApocPolicyModelNode(const nsACString & aName); + +public: + void AcquireReference() const; + void ReleaseReference() const; + +public: + typedef mozApocPolicyModelNodeRef Ref; + static Ref New(const nsACString & aName, mozApocEntryAttributes aAttributes, + mozApocNotificationDispatcher const & aNotifier); + + // explicit mozApocPolicyModelNode(rawData aRawData); + ~mozApocPolicyModelNode(); + + PRBool HasChildren() const { return mChildren != nsnull; } + PRBool HasSiblings() const { return mNext != nsnull; } + PRBool IsNamed(const nsACString & aName) const { return mName.Equals(aName); } + + nsAFlatCString const & GetName() const { return mName; } + mozApocEntryAttributes GetAttributes() const { return mAttributes; } + PRBool IsProtected() const { return mozApocAreAnyFlagsSet(mAttributes,MOZAPOC_ENTRY_PROTECTED_FLAGS); } + + // TODO: Add support for localized values + nsresult GetValue(nsAString & _retval) const; + PRBool HasValue() const { return mValue != nsnull; } + + const mozApocPolicyModelNode * GetChild(const nsACString & aName, nsresult * _rv) const; + + Ref GetChild(const nsACString & aName) { return ImplGetChild(aName); } + + const mozApocPolicyModelNode * GetFirstChild() const { return mChildren.Get(); } + const mozApocPolicyModelNode * GetNextSibling() const { return mNext.Get(); } + + nsresult UpdateValue(const nsAString & aNewValue, mozApocNotificationDispatcher const & aNotifier); + void UpdateAttributes(mozApocEntryAttributes aNewAttributes, mozApocNotificationDispatcher const & aNotifier); + + nsresult AddChild(Ref const & aNode); + Ref ReleaseChildren(); + + static void NextInList(Ref & aListPosition) { aListPosition = aListPosition->mNext; } + static void AppendToNodeList(Ref & aList, Ref const & aElement); + static mozApocPolicyModelNodeRef ExtractFromNodeList(Ref & aList, const nsACString & aName); + static void DisposeNodeList(mozApocPolicyModelNodeRef & aList, mozApocNotificationDispatcher const & aNotifier); +private: + mozApocPolicyModelNode * ImplGetChild(const nsACString & aName) const; + + mozApocPolicyModelNodeRef ImplDisposeAndGetNext(mozApocNotificationDispatcher const & aNotifier); +private: + mutable PRInt32 mRefCount; + + mozApocPolicyModelNodeRef mNext; + mozApocPolicyModelNodeRef mChildren; + + nsCString mName; + mozApocEntryAttributes mAttributes; + + struct ValueData; + ValueData * mValue; +private: + // not implemented: + mozApocPolicyModelNode(const mozApocPolicyModelNode & aOther); + mozApocPolicyModelNode & operator=(const mozApocPolicyModelNode & aOther); +}; + +inline +void mozApocPolicyModelNodeRef::Acquire_() const +{ if (mPtr) mPtr->AcquireReference(); } + +inline +void mozApocPolicyModelNodeRef::Release_() const +{ if (mPtr) mPtr->ReleaseReference(); } + +#endif + diff --git a/src/mozApocPolicyModelBuilder.cpp b/src/mozApocPolicyModelBuilder.cpp new file mode 100644 index 0000000..81989a5 --- /dev/null +++ b/src/mozApocPolicyModelBuilder.cpp @@ -0,0 +1,205 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+
+#include "mozApocPolicyModelBuilder.h"
+#include "mozApocPolicyModel.h"
+#include "mozApocNotificationDispatch.h"
+
+#ifndef MOZAPOC_TRACE_MODEL
+#define MOZAPOC_TRACE_MODEL 0
+#endif
+#define BUILDER_TRACE if (!(MOZAPOC_TRACE_MODEL)) ; else ::fprintf
+
+struct mozApocPolicyModelBuilderData
+{
+ typedef mozApocPolicyModelBuilderData Data;
+ typedef mozApocPolicyModelNode Node;
+ typedef mozApocPolicyModelNodeRef NodeRef;
+
+ explicit
+ mozApocPolicyModelBuilderData(NodeRef const & aRootNode, mozApocNotifier * pNotifier)
+ : mParent(nsnull)
+ , mNotifier(NS_LITERAL_CSTRING(""),pNotifier)
+ , mNode()
+ , mUnmatchedChildren(aRootNode)
+ {
+ NS_ASSERTION(!aRootNode || !aRootNode->HasSiblings(),
+ "apoc - Component root actually is a list");
+ }
+
+ mozApocPolicyModelBuilderData(Data & aParent, const nsACString & aName,
+ mozApocEntryAttributes aAttributes)
+ : mParent(&aParent)
+ , mNotifier(aParent.mNotifier,aName)
+ , mNode( Node::ExtractFromNodeList(aParent.mUnmatchedChildren,aName) )
+ , mUnmatchedChildren()
+ {
+ if (mNode)
+ {
+ mUnmatchedChildren = mNode->ReleaseChildren();
+ mNode->UpdateAttributes(aAttributes, mNotifier);
+ }
+ else
+ mNode = mozApocPolicyModelNode::New(aName,aAttributes,mNotifier);
+ }
+
+ ~mozApocPolicyModelBuilderData()
+ {
+ Node::DisposeNodeList(mUnmatchedChildren,mNotifier);
+ }
+
+ Data * mParent;
+
+ mozApocNotificationDispatcher mNotifier;
+
+ NodeRef mNode;
+ NodeRef mUnmatchedChildren;
+
+};
+
+mozApocPolicyModelBuilder::mozApocPolicyModelBuilder()
+: mData(nsnull)
+{
+}
+
+mozApocPolicyModelBuilder::~mozApocPolicyModelBuilder()
+{
+ NS_PRECONDITION(mData == nsnull, "apoc - Destroying policy model builder that is still in use");
+}
+
+nsresult mozApocPolicyModelBuilder::UpdateModel(const nsACString & aComponent, mozApocNotifier * pNotifier, mozApocPolicyModelNodeRef & aModel)
+{
+ NS_PRECONDITION(mData == nsnull, "apoc - Reusing policy model builder that is still in use");
+ NS_PRECONDITION(!aModel || aModel->IsNamed(aComponent),
+ "apoc - Existing model does not match component being requested");
+
+ mData = new Data(aModel,pNotifier);
+ if (!mData) return NS_ERROR_OUT_OF_MEMORY;
+
+ nsresult rv = this->DoBuildModel(aComponent);
+ if (NS_FAILED(rv))
+ {
+ // unwind Data stack
+ while (Data * pParent = mData->mParent)
+ {
+ // this data was abandoned due to error processing
+ delete mData;
+ mData = pParent;
+ }
+ }
+
+ NS_ASSERTION(!mData->mParent, "apoc - Policy model builder: Unmatched Enter()");
+ NS_ASSERTION(!(mData->mNode && mData->mUnmatchedChildren), "apoc - Policy model builder: Orphaned old node found");
+
+ aModel = mData->mNode;
+ delete mData,mData = nsnull;
+
+ NS_POSTCONDITION(!aModel || aModel->IsNamed(aComponent),
+ "apoc - Newly built model does not match component being requested");
+
+ return rv;
+}
+
+nsresult mozApocPolicyModelBuilder::Enter(const nsACString & aName, mozApocEntryAttributes aNewAttributes)
+{
+ NS_PRECONDITION(mData, "apoc - Illegal use of policy model builder - not in update");
+
+ Data * newData = new Data(*mData, aName, aNewAttributes);
+ NS_ENSURE_TRUE(newData && newData->mNode, NS_ERROR_OUT_OF_MEMORY);
+ mData = newData;
+
+ NS_POSTCONDITION(!mData->mNode->HasSiblings(), "apoc - Node being processed has siblings.");
+ NS_POSTCONDITION( mData->mNode->IsNamed(aName), "apoc - Not using correct node");
+ NS_POSTCONDITION( mData->mNode->GetAttributes() == aNewAttributes, "apoc - Not using correct node");
+ BUILDER_TRACE(stderr, "apoc model builder - Entered Node %s, attributes = %#.8x \n",
+ PromiseFlatCString(aName).get(), unsigned(aNewAttributes));
+ return NS_OK;
+}
+
+nsresult mozApocPolicyModelBuilder::AddPropertyValue(const nsAString & aValue)
+{
+ NS_PRECONDITION(mData, "apoc - Illegal use of policy model builder - not in update");
+ NS_PRECONDITION(mData->mNode, "apoc - Policy model builder: AddPropertyValue() called without a node");
+
+ mozApocEntryAttributes attributes = mData->mNode->GetAttributes();
+
+ NS_WARN_IF_FALSE(!mozApocHasValue(attributes), "apoc - Policy model builder: multiple values for a node; ignoring all but last");
+
+ mozApocSetFlags( attributes, MOZAPOC_ENTRY_HASVALUE );
+ mData->mNode->UpdateAttributes(attributes, mData->mNotifier);
+
+ return this->SetPropertyValue(aValue);
+}
+
+nsresult mozApocPolicyModelBuilder::SetPropertyValue(const nsAString & aValue)
+{
+ NS_PRECONDITION(mData, "apoc - Illegal use of policy model builder - not in update");
+ NS_PRECONDITION(mData->mNode, "apoc - Policy model builder: SetPropertyValue() called without a node");
+
+ BUILDER_TRACE(stderr, "apoc model builder - Setting property value %s \n",
+ NS_ConvertUCS2toUTF8(aValue).get());
+
+ nsresult rv = mData->mNode->UpdateValue(aValue, mData->mNotifier);
+ return rv;
+}
+
+nsresult mozApocPolicyModelBuilder::Leave()
+{
+ NS_PRECONDITION(mData, "apoc - Illegal use of policy model builder - not in update");
+ NS_PRECONDITION(mData->mParent, "apoc - Policy model builder: Unmatched Leave()");
+ NS_PRECONDITION(mData->mNode, "apoc - Policy model builder: Leave() called without a node");
+
+ nsresult rv = NS_OK;
+
+ Data * aCompletedData = mData;
+ mData = mData->mParent;
+
+ BUILDER_TRACE(stderr, "apoc model builder - Left current node \n");
+ if (mData->mNode)
+ {
+ NS_ASSERTION(mData->mParent,"apoc - Found node within the root data element");
+ rv = mData->mNode->AddChild(aCompletedData->mNode);
+ }
+ else // set result to the root non-node
+ {
+ NS_ASSERTION(!mData->mParent,"apoc - Found non-node that is not root");
+ mData->mNode = aCompletedData->mNode;
+ BUILDER_TRACE(stderr, "apoc model builder - That was the root node: Building the model completed \n");
+ }
+ delete aCompletedData;
+ return rv;
+}
+
diff --git a/src/mozApocPolicyModelBuilder.h b/src/mozApocPolicyModelBuilder.h new file mode 100644 index 0000000..f2b5b91 --- /dev/null +++ b/src/mozApocPolicyModelBuilder.h @@ -0,0 +1,73 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_POLICYMODELBUILDER_H_INCLUDED +#define MOZAPOC_POLICYMODELBUILDER_H_INCLUDED + +#include "mozApocPolicyNodeAttributes.h" +#include "nsAString.h" + +class mozApocPolicyModelNodeRef; +class mozApocPolicyModelBuilderData; +class mozApocNotifier; + +class mozApocPolicyModelBuilder +{ + typedef mozApocPolicyModelBuilderData Data; + Data * mData; +public: + mozApocPolicyModelBuilder(); + virtual ~mozApocPolicyModelBuilder(); + + nsresult UpdateModel(const nsACString & aComponent, mozApocNotifier * pNotifier, /* inout */ mozApocPolicyModelNodeRef & aModel); + +protected: + nsresult Enter(const nsACString & aName, mozApocEntryAttributes aNewAttributes); + nsresult SetPropertyValue(const nsAString & aValue); + nsresult AddPropertyValue(const nsAString & aValue); + nsresult Leave(); + +private: + virtual nsresult DoBuildModel(const nsACString & aComponent) = 0; + +private: + // not implemented + mozApocPolicyModelBuilder(const mozApocPolicyModelBuilder & ); + void operator=(const mozApocPolicyModelBuilder & ); +}; + +#endif + diff --git a/src/mozApocPolicyModelFromDOM.cpp b/src/mozApocPolicyModelFromDOM.cpp new file mode 100644 index 0000000..eccd9a2 --- /dev/null +++ b/src/mozApocPolicyModelFromDOM.cpp @@ -0,0 +1,109 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+/* vim:expandtab:shiftwidth=4:tabstop=4:
+ */
+/*
+ *******************************************************************************
+ * $RCSfile: mozApocPolicyModelFromDOM.cpp,v $
+ *
+ * Description:
+ *
+ * Last change: $Date: 2006/10/30 03:23:53 $ $Revision: 1.1.1.1 $
+ *
+ * Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use of this
+ * product is subject to license terms.
+ *
+ *******************************************************************************
+ * Source Code Control System - Header
+ *
+ * $Header: /export/src/cvs/firefox-apoc-adapter/mozApocPolicyModelFromDOM.cpp,v 1.1.1.1 2006/10/30 03:23:53 sunop Exp $
+ *******************************************************************************
+ */
+
+#include "mozApocPolicyModelFromDOM.h"
+#include "mozApocPolicyComponentDOMData.h"
+#include "mozApocPolicyNodeDOMData.h"
+#include "mozApocStringList.h"
+
+nsresult mozApocBuildPolicyModelFromDOM::BuildModelForNode(const nsACString & aNodeName, mozApocPolicyNodeDOMData const & aDOMNode)
+{
+ NS_PRECONDITION(aDOMNode.IsReal(),"apoc - Unexpected attempt to build model for non-existing node");
+
+ nsresult rv = this->Enter(aNodeName, aDOMNode.GetAttributes());
+ NS_ENSURE_SUCCESS(rv,rv);
+
+ if (aDOMNode.HasValue())
+ {
+ nsAutoString aValue;
+ rv = aDOMNode.GetValue(aValue);
+ NS_ENSURE_SUCCESS(rv,rv);
+
+ rv = this->SetPropertyValue(aValue);
+ NS_ENSURE_SUCCESS(rv,rv);
+ }
+ if (aDOMNode.IsNode())
+ {
+ mozApocUniqueCStringList aChildList;
+ rv = aDOMNode.ListChildren(aChildList);
+
+ for (mozApocUniqueCStringList::iterator it = aChildList.Iterate(); it; it = it->Next())
+ {
+ mozApocPolicyNodeDOMData aChildNode(aDOMNode);
+ nsresult rv2 = aChildNode.GotoChild(it->Value());
+ if (NS_SUCCEEDED(rv2))
+ rv2 = BuildModelForNode(it->Value(),aChildNode);
+
+ if (NS_SUCCEEDED(rv)) rv = rv2;
+ }
+ NS_ENSURE_SUCCESS(rv,rv);
+ }
+ rv = this->Leave();
+
+ return rv;
+}
+
+nsresult mozApocBuildPolicyModelFromDOM::DoBuildModel(const nsACString & aComponent)
+{
+ if (! mDOMData)
+ return NS_OK;
+
+ NS_ASSERTION(mDOMData->GetComponentName().Equals(aComponent), "apoc - Component To Build does not match DOM data");
+
+ mozApocPolicyNodeDOMData aRootNode(mDOMData);
+ return BuildModelForNode(aComponent, aRootNode);
+}
+
+
diff --git a/src/mozApocPolicyModelFromDOM.h b/src/mozApocPolicyModelFromDOM.h new file mode 100644 index 0000000..684f730 --- /dev/null +++ b/src/mozApocPolicyModelFromDOM.h @@ -0,0 +1,63 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_POLICYMODELFROMDOM_H_INCLUDED +#define MOZAPOC_POLICYMODELFROMDOM_H_INCLUDED + +#include "mozApocPolicyModelBuilder.h" + +class mozApocPolicyComponentDOMData; +class mozApocPolicyNodeDOMData; + +class mozApocBuildPolicyModelFromDOM : public mozApocPolicyModelBuilder +{ + mozApocPolicyComponentDOMData * mDOMData; +public: + explicit + mozApocBuildPolicyModelFromDOM(mozApocPolicyComponentDOMData * aDOMData) + : mDOMData(aDOMData) + {} + + virtual ~mozApocBuildPolicyModelFromDOM() {} + +private: + virtual nsresult DoBuildModel(const nsACString & aComponent); + + nsresult BuildModelForNode(const nsACString & aNodeName, mozApocPolicyNodeDOMData const & aDOMNode); +}; + +#endif + diff --git a/src/mozApocPolicyModelFromXML.cpp b/src/mozApocPolicyModelFromXML.cpp new file mode 100644 index 0000000..ec1f5e1 --- /dev/null +++ b/src/mozApocPolicyModelFromXML.cpp @@ -0,0 +1,457 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+/* vim:expandtab:shiftwidth=4:tabstop=4:
+ */
+/*
+ *******************************************************************************
+ * $RCSfile: mozApocPolicyModelFromXML.cpp,v $
+ *
+ * Description:
+ *
+ * Last change: $Date: 2006/10/30 03:23:53 $ $Revision: 1.1.1.1 $
+ *
+ * Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use of this
+ * product is subject to license terms.
+ *
+ *******************************************************************************
+ * Source Code Control System - Header
+ *
+ * $Header: /export/src/cvs/firefox-apoc-adapter/mozApocPolicyModelFromXML.cpp,v 1.1.1.1 2006/10/30 03:23:53 sunop Exp $
+ *******************************************************************************
+ */
+
+#include "mozApocPolicyModelFromXML.h"
+#include "mozApocSaxWrapper.h"
+#include "mozApocXML.h"
+#include "nsString.h"
+
+class mozApocBuildPolicyModelFromXML::ParserState
+{
+public:
+ enum ParseContext
+ {
+ PARSE_FAILED,
+ ROOT_ELEMENT,
+ NODE_ELEMENT,
+ PROP_ELEMENT,
+ VALUE_ELEMENT,
+ SKIPPED_ELEMENT,
+ UNKNOWN_ELEMENT = SKIPPED_ELEMENT
+ };
+public:
+ ParserState(nsACString const & aComponent);
+ ~ParserState();
+
+ void SetErrorState(nsresult errcode);
+ nsresult GetParseResult() const;
+
+ nsACString const & GetElementName() const { return m_name; }
+ mozApocEntryAttributes GetElementAttributes() const { return m_attributes; }
+
+ nsAString const & GetLastValue() const { return m_value; }
+ void AddToCurrentValue(const nsAString & Data) { m_value += Data; }
+
+ ParseContext StartElement(nsAString const & Name, nsAString const * NamespaceURI,
+ mozApocSaxAttributeIterator Attributes);
+
+ ParseContext EndElement(nsAString const & Name, nsAString const * NamespaceURI);
+private:
+ void CollectAttributes(mozApocSaxAttributeIterator attributes, nsCString & outName);
+
+ ParseContext IdentifyElement(nsAString const & Name, nsAString const * NamespaceURI);
+
+ PRBool IsInProperty() const { return mozApocIsProperty(m_attributes); }
+ PRBool IsInValue() const { return mozApocHasValue(m_attributes); }
+
+ void EnterRoot() { mozApocSetFlags(m_attributes, MOZAPOC_ENTRY_EXISTS_IN_POLICY); }
+ void LeaveRoot() { mozApocResetFlags(m_attributes, MOZAPOC_ENTRY_EXISTS_IN_POLICY); }
+
+ void EnterProp() { mozApocSetFlags(m_attributes, MOZAPOC_ENTRY_PROPERTY); }
+ void LeaveProp()
+ {
+ mozApocResetFlags(m_attributes, MOZAPOC_ENTRY_PROPERTY);
+ mozApocResetFlags(m_attributes, MOZAPOC_ENTRY_TYPE_MASK);
+ }
+
+ void EnterValue() { mozApocSetFlags(m_attributes, MOZAPOC_ENTRY_HASVALUE); }
+ void LeaveValue() { mozApocResetFlags(m_attributes, MOZAPOC_ENTRY_HASVALUE); }
+
+ ParseContext StartElement(ParseContext NewContext,mozApocSaxAttributeIterator attributes);
+ ParseContext EndElement(ParseContext OldContext);
+ ParseContext Fail() { SetErrorState(NS_ERROR_UNEXPECTED); return PARSE_FAILED; }
+private:
+ nsCString m_name;
+ nsString m_value;
+ PRUint32 m_depth;
+ PRUint32 m_skipped;
+ nsresult m_errcode;
+ mozApocEntryAttributes m_attributes;
+};
+
+nsresult mozApocBuildPolicyModelFromXML::DoBuildModel(const nsACString & aComponent)
+{
+ if (!m_DataLength) // allow empty data
+ return NS_OK;
+
+ NS_ENSURE_TRUE(m_RawData, NS_ERROR_NULL_POINTER);
+
+ // Prevent signed integer overflow
+ PRInt32 SignedDataLength = PRInt32(m_DataLength);
+ NS_ENSURE_TRUE(SignedDataLength > 0, NS_ERROR_FAILURE);
+
+ NS_ENSURE_TRUE(!m_ParserState, NS_ERROR_UNEXPECTED);
+
+ m_ParserState = new ParserState(aComponent);
+
+ NS_ENSURE_TRUE(m_ParserState, NS_ERROR_OUT_OF_MEMORY);
+
+ mozApocSaxParser aParser(PR_TRUE);
+
+ nsresult rv = aParser.Parse(*this, NS_STATIC_CAST(const char *, m_RawData), SignedDataLength);
+
+ if (NS_SUCCEEDED(rv))
+ rv = m_ParserState->GetParseResult();
+
+ delete m_ParserState;
+
+ return rv;
+}
+
+void mozApocBuildPolicyModelFromXML::StartElement(XML_String const & Name, XML_String const * NamespaceURI,
+ mozApocSaxAttributeIterator Attributes)
+{
+ NS_ASSERTION(m_ParserState,"apoc - Policy DOM Builder called without active parser");
+
+ switch (m_ParserState->StartElement(Name, NamespaceURI, Attributes))
+ {
+ case ParserState::ROOT_ELEMENT:
+ case ParserState::NODE_ELEMENT:
+ case ParserState::PROP_ELEMENT:
+ m_ParserState->SetErrorState( this->Enter( m_ParserState->GetElementName(), m_ParserState->GetElementAttributes() ) );
+ break;
+
+ default:
+ break;
+ }
+}
+
+void mozApocBuildPolicyModelFromXML::EndElement(XML_String const & Name, XML_String const * NamespaceURI)
+{
+ NS_ASSERTION(m_ParserState,"apoc - Policy DOM Builder called without active parser");
+
+ switch (m_ParserState->EndElement(Name, NamespaceURI))
+ {
+ case ParserState::ROOT_ELEMENT:
+ case ParserState::NODE_ELEMENT:
+ case ParserState::PROP_ELEMENT:
+ m_ParserState->SetErrorState( this->Leave() );
+ break;
+
+ case ParserState::VALUE_ELEMENT:
+ m_ParserState->SetErrorState( this->AddPropertyValue(m_ParserState->GetLastValue()) );
+ break;
+
+ default:
+ break;
+ }
+}
+
+void mozApocBuildPolicyModelFromXML::CharacterData(XML_String const & Characters)
+{
+ NS_ASSERTION(m_ParserState,"apoc - Policy DOM Builder called without active parser");
+
+ m_ParserState->AddToCurrentValue(Characters);
+}
+
+mozApocBuildPolicyModelFromXML::ParserState::ParserState(nsACString const & aComponent)
+: m_name(aComponent)
+, m_value()
+, m_depth(0)
+, m_skipped(0)
+, m_errcode()
+, m_attributes()
+{
+}
+
+
+mozApocBuildPolicyModelFromXML::ParserState::~ParserState()
+{
+}
+
+
+void mozApocBuildPolicyModelFromXML::ParserState::SetErrorState(nsresult errcode)
+{
+ if (NS_SUCCEEDED(m_errcode)) m_errcode = errcode;
+}
+
+
+nsresult mozApocBuildPolicyModelFromXML::ParserState::GetParseResult() const
+{
+ if (NS_SUCCEEDED(m_errcode))
+ {
+ // check, if parse finished successfully
+ NS_ENSURE_TRUE(m_depth == 0 && m_skipped == 0, NS_ERROR_FAILURE);
+ }
+ return m_errcode;
+}
+
+mozApocBuildPolicyModelFromXML::ParserState::ParseContext
+ mozApocBuildPolicyModelFromXML::ParserState::
+ StartElement(ParseContext NewContext, mozApocSaxAttributeIterator Attributes)
+{
+ NS_ASSERTION(mozApocExistsInPolicy(m_attributes),"apoc - SAX builder: attributes were not prepared properly");
+
+ NS_ENSURE_TRUE(!IsInValue(), Fail());
+
+ nsCAutoString NewName;
+ CollectAttributes(Attributes,NewName);
+
+ NS_ENSURE_TRUE(!NewName.IsEmpty(),Fail());
+
+ if (NewContext == ROOT_ELEMENT)
+ NS_ENSURE_TRUE( m_name.Equals(NewName), Fail() );
+
+ m_name = NewName;
+
+ ++m_depth;
+ return NewContext;
+}
+
+mozApocBuildPolicyModelFromXML::ParserState::ParseContext
+ mozApocBuildPolicyModelFromXML::ParserState::
+ StartElement(nsAString const & Name, nsAString const * NamespaceURI, mozApocSaxAttributeIterator Attributes)
+{
+ ParseContext NewContext = IdentifyElement(Name, NamespaceURI);
+ switch (NewContext)
+ {
+ case ROOT_ELEMENT:
+ NS_ENSURE_TRUE(m_depth == 0, Fail());
+ EnterRoot();
+ return StartElement(NewContext, Attributes);
+
+ case NODE_ELEMENT:
+ NS_ENSURE_TRUE(m_depth != 0, Fail());
+ NS_ENSURE_TRUE(!IsInProperty(), Fail());
+ return StartElement(NewContext, Attributes);
+
+ case PROP_ELEMENT:
+ NS_ENSURE_TRUE(m_depth != 0, Fail());
+ NS_ENSURE_TRUE(!IsInProperty(), Fail());
+ EnterProp();
+ return StartElement(NewContext, Attributes);
+
+ case VALUE_ELEMENT:
+ NS_ENSURE_TRUE(IsInProperty(), Fail());
+ NS_ENSURE_TRUE(!IsInValue(), Fail());
+ EnterValue();
+ m_value.Truncate();
+ break;
+
+ case SKIPPED_ELEMENT:
+ if (!m_skipped) NS_WARNING("apoc - SAX parser: Skipping unknown element");
+ ++m_skipped;
+ break;
+
+ case PARSE_FAILED:
+ break;
+
+ default:
+ NS_NOTREACHED("apoc - Illegal Parser Context");
+ return Fail();
+ }
+ return NewContext;
+}
+
+
+mozApocBuildPolicyModelFromXML::ParserState::ParseContext
+ mozApocBuildPolicyModelFromXML::ParserState::
+ EndElement(ParseContext OldContext)
+{
+ NS_ENSURE_TRUE(!IsInProperty(), Fail());
+ NS_ENSURE_TRUE(m_depth > 0, Fail());
+ --m_depth;
+
+ m_value.Truncate(); // prevent accumulation of lots of whitespace
+ mozApocResetFlags(m_attributes, MOZAPOC_LOCAL_PROTECTION_FLAGS);
+
+ return OldContext;
+}
+
+mozApocBuildPolicyModelFromXML::ParserState::ParseContext
+ mozApocBuildPolicyModelFromXML::ParserState::
+ EndElement(nsAString const & Name, nsAString const * NamespaceURI)
+{
+ ParseContext OldContext = IdentifyElement(Name, NamespaceURI);
+ switch (OldContext)
+ {
+ case ROOT_ELEMENT:
+ NS_ENSURE_TRUE(m_depth == 1, Fail());
+ LeaveRoot();
+ return EndElement(OldContext);
+
+ case NODE_ELEMENT:
+ NS_ENSURE_TRUE(m_depth > 1, Fail());
+ return EndElement(OldContext);
+
+ case PROP_ELEMENT:
+ NS_ENSURE_TRUE(IsInProperty(), Fail());
+ NS_ENSURE_TRUE(!IsInValue(), Fail());
+ LeaveProp();
+ return EndElement(OldContext);
+
+ case VALUE_ELEMENT:
+ NS_ENSURE_TRUE(IsInValue(), Fail());
+ LeaveValue();
+ break;
+
+ case SKIPPED_ELEMENT:
+ NS_ENSURE_TRUE(m_skipped > 0, Fail());
+ --m_skipped;
+ break;
+
+ case PARSE_FAILED:
+ break;
+
+ default:
+ NS_NOTREACHED("apoc - Illegal Parser Context");
+ return Fail();
+ }
+ return OldContext;
+}
+
+
+static PRBool BooleanAttributeValue(const PRUnichar * aAttributeValue)
+{
+ if (NS_LITERAL_STRING("true").Equals(aAttributeValue))
+ return PR_TRUE;
+
+ return PR_FALSE;
+}
+static mozApocEntryFlagValues TypeAttributeValue(const PRUnichar * aAttributeValue)
+{
+ if (NS_LITERAL_STRING(k_mozApocXMLTypeValueString).Equals(aAttributeValue))
+ return MOZAPOC_ENTRY_TYPE_STRING;
+ if (NS_LITERAL_STRING(k_mozApocXMLTypeValueBool).Equals(aAttributeValue))
+ return MOZAPOC_ENTRY_TYPE_BOOL;
+ if (NS_LITERAL_STRING(k_mozApocXMLTypeValueInt).Equals(aAttributeValue))
+ return MOZAPOC_ENTRY_TYPE_INT;
+ if (NS_LITERAL_STRING(k_mozApocXMLTypeValueShort).Equals(aAttributeValue))
+ return MOZAPOC_ENTRY_TYPE_INT;
+ if (NS_LITERAL_STRING(k_mozApocXMLTypeValueBinary).Equals(aAttributeValue))
+ return MOZAPOC_ENTRY_TYPE_BINARY;
+ return MOZAPOC_ENTRY_TYPE_OTHER;
+}
+
+void mozApocBuildPolicyModelFromXML::ParserState::
+ CollectAttributes(mozApocSaxAttributeIterator attributes, nsCString & outName)
+{
+ mozApocResetFlags(m_attributes, MOZAPOC_LOCAL_PROTECTION_FLAGS);
+ NS_ASSERTION(!mozApocAreAnyFlagsSet(m_attributes,MOZAPOC_ENTRY_PROTECTED_FLAGS),
+ "apoc - Inherited protection flag found in SAX Node builder");
+ NS_ASSERTION(!mozApocAreAnyFlagsSet(m_attributes,MOZAPOC_ENTRY_TYPE_MASK),
+ "apoc - Attributes have a type when starting node");
+
+ //Brian++ const NS_NAMED_LITERAL_STRING( OORNamespaceURI, k_mozApocXMLNamespaceOOR );
+ NS_NAMED_LITERAL_STRING( OORNamespaceURI, k_mozApocXMLNamespaceOOR );
+ //Brian++ const NS_NAMED_LITERAL_STRING( AttributeName, k_mozApocXMLAttributeName );
+ NS_NAMED_LITERAL_STRING( AttributeName, k_mozApocXMLAttributeName );
+ //Brian++ const NS_NAMED_LITERAL_STRING( AttributeFinalized, k_mozApocXMLAttributeFinalized );
+ NS_NAMED_LITERAL_STRING( AttributeFinalized, k_mozApocXMLAttributeFinalized );
+ //Brian++ const NS_NAMED_LITERAL_STRING( AttributeMandatory, k_mozApocXMLAttributeMandatory );
+ NS_NAMED_LITERAL_STRING( AttributeMandatory, k_mozApocXMLAttributeMandatory );
+
+ for (mozApocSaxAttributeIterator CurrentAttribute = attributes; CurrentAttribute.Is(); CurrentAttribute.Next())
+ {
+ if (CurrentAttribute.IsNamed(AttributeName, &OORNamespaceURI, PR_TRUE))
+ {
+ outName.AssignWithConversion( CurrentAttribute.GetAttributeValue() );
+ }
+ else if (CurrentAttribute.IsNamed(AttributeFinalized, &OORNamespaceURI, PR_TRUE))
+ {
+ if ( BooleanAttributeValue(CurrentAttribute.GetAttributeValue()) )
+ mozApocSetFlags(m_attributes,MOZAPOC_ENTRY_FINALIZED);
+ }
+ else if (CurrentAttribute.IsNamed(AttributeMandatory, &OORNamespaceURI, PR_TRUE))
+ {
+ if ( BooleanAttributeValue(CurrentAttribute.GetAttributeValue()) )
+ mozApocSetFlags(m_attributes,MOZAPOC_ENTRY_MANDATORY);
+ }
+
+ else if (mozApocIsProperty(m_attributes))
+ {
+ if (CurrentAttribute.IsNamed(NS_LITERAL_STRING(k_mozApocXMLAttributeType), &OORNamespaceURI, PR_TRUE))
+ mozApocSetFlags(m_attributes,TypeAttributeValue(CurrentAttribute.GetAttributeValue()));
+ }
+ }
+}
+
+
+mozApocBuildPolicyModelFromXML::ParserState::ParseContext
+ mozApocBuildPolicyModelFromXML::ParserState::
+ IdentifyElement(nsAString const & Name, nsAString const * NamespaceURI)
+{
+ if (NS_FAILED(m_errcode)) return PARSE_FAILED;
+
+ if (m_skipped) return SKIPPED_ELEMENT;
+
+ if (NamespaceURI)
+ {
+ //Brian++ const NS_NAMED_LITERAL_STRING( OORNamespaceURI, k_mozApocXMLNamespaceOOR );
+ NS_NAMED_LITERAL_STRING( OORNamespaceURI, k_mozApocXMLNamespaceOOR );
+ if (!NamespaceURI->Equals(OORNamespaceURI))
+ return UNKNOWN_ELEMENT;
+ }
+
+ //Brian++ const NS_NAMED_LITERAL_STRING( OORTagRoot, k_mozApocXMLTagRoot );
+ NS_NAMED_LITERAL_STRING( OORTagRoot, k_mozApocXMLTagRoot );
+ if (Name.Equals(OORTagRoot)) return ROOT_ELEMENT;
+
+ //Brian++ const NS_NAMED_LITERAL_STRING( OORTagNode, k_mozApocXMLTagNode );
+ NS_NAMED_LITERAL_STRING( OORTagNode, k_mozApocXMLTagNode );
+ if (Name.Equals(OORTagNode)) return NODE_ELEMENT;
+
+ //Brian++ const NS_NAMED_LITERAL_STRING( OORTagProp, k_mozApocXMLTagProp );
+ NS_NAMED_LITERAL_STRING( OORTagProp, k_mozApocXMLTagProp );
+ if (Name.Equals(OORTagProp)) return PROP_ELEMENT;
+
+ //Brian++ const NS_NAMED_LITERAL_STRING( OORTagValue, k_mozApocXMLTagValue );
+ NS_NAMED_LITERAL_STRING( OORTagValue, k_mozApocXMLTagValue );
+ if (Name.Equals(OORTagValue)) return VALUE_ELEMENT;
+
+ return UNKNOWN_ELEMENT;
+}
+
+
diff --git a/src/mozApocPolicyModelFromXML.h b/src/mozApocPolicyModelFromXML.h new file mode 100644 index 0000000..9221804 --- /dev/null +++ b/src/mozApocPolicyModelFromXML.h @@ -0,0 +1,76 @@ + + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_POLICYMODELFROMXML_H_INCLUDED +#define MOZAPOC_POLICYMODELFROMXML_H_INCLUDED + +#include "mozApocPolicyModelBuilder.h" +#include "mozApocSaxHandler.h" + +class mozApocBuildPolicyModelFromXML +: public mozApocPolicyModelBuilder // inhibits copying +, private mozApocSaxHandler +{ +public: + explicit + mozApocBuildPolicyModelFromXML(const void * pRawData, PRUint32 nRawDataLength) + : m_RawData(pRawData) + , m_DataLength(nRawDataLength) + , m_ParserState(0) + {} + + virtual ~mozApocBuildPolicyModelFromXML() {} + +private: + virtual nsresult DoBuildModel(const nsACString & aComponent); + +private: + virtual void StartElement(XML_String const & Name, XML_String const * NamespaceURI, mozApocSaxAttributeIterator Attributes); + virtual void EndElement(XML_String const & Name, XML_String const * NamespaceURI); + virtual void CharacterData(XML_String const & Characters); + +private: + const void * m_RawData; + PRUint32 m_DataLength; + + struct ParserState; + ParserState * m_ParserState; +}; + +#endif + diff --git a/src/mozApocPolicyNodeAttributes.h b/src/mozApocPolicyNodeAttributes.h new file mode 100644 index 0000000..792ef9f --- /dev/null +++ b/src/mozApocPolicyNodeAttributes.h @@ -0,0 +1,108 @@ + + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_POLICYNODEATTRIBUTES_H_INCLUDED +#define MOZAPOC_POLICYNODEATTRIBUTES_H_INCLUDED + +#include "prtypes.h" + +enum mozApocEntryFlagValues +{ + MOZAPOC_ENTRY_TYPE_NONE = 0, + MOZAPOC_ENTRY_TYPE_STRING, + MOZAPOC_ENTRY_TYPE_INT, + MOZAPOC_ENTRY_TYPE_BOOL, + MOZAPOC_ENTRY_TYPE_BINARY, + MOZAPOC_ENTRY_TYPE_OTHER, + + MOZAPOC_ENTRY_TYPE_ERROR, + MOZAPOC_ENTRY_TYPE_MASK = 0x00FF, + + MOZAPOC_ENTRY_EXISTS_IN_POLICY = 0x0100, + MOZAPOC_ENTRY_FINALIZED = 0x0200, + MOZAPOC_ENTRY_MANDATORY = 0x0400, + MOZAPOC_ENTRY_PROTECTED = 0x0800, + MOZAPOC_ENTRY_PROPERTY = 0x1000, + MOZAPOC_ENTRY_HASVALUE = 0x2000, + + MOZAPOC_ENTRY_IS_NOT_EMPTY = MOZAPOC_ENTRY_EXISTS_IN_POLICY | + MOZAPOC_ENTRY_PROPERTY | + MOZAPOC_ENTRY_HASVALUE , + MOZAPOC_ENTRY_IS_PROPERTY = MOZAPOC_ENTRY_EXISTS_IN_POLICY | + MOZAPOC_ENTRY_PROPERTY , + MOZAPOC_ENTRY_PROTECTED_FLAGS = MOZAPOC_ENTRY_PROTECTED | + MOZAPOC_ENTRY_FINALIZED, + MOZAPOC_ENTRY_MANDATORY_FLAGS = MOZAPOC_ENTRY_PROTECTED | + MOZAPOC_ENTRY_MANDATORY, + MOZAPOC_LOCAL_PROTECTION_FLAGS= MOZAPOC_ENTRY_FINALIZED | + MOZAPOC_ENTRY_MANDATORY, + + MOZAPOC_ENTRY_FLAGS_MASK = 0xFF00 +}; +typedef PRUint16 mozApocEntryAttributes; + +inline mozApocEntryFlagValues mozApocGetEntryType(mozApocEntryAttributes attr) +{ return mozApocEntryFlagValues(attr & MOZAPOC_ENTRY_TYPE_MASK); } + +inline PRBool mozApocAreAnyFlagsSet(mozApocEntryAttributes attr, mozApocEntryFlagValues flags) +{ return (attr & flags) != 0; } + +inline PRBool mozApocAreAllFlagsSet(mozApocEntryAttributes attr, mozApocEntryFlagValues flags) +{ return (attr & flags) == flags; } + +inline void mozApocSetFlags(mozApocEntryAttributes & attr, mozApocEntryFlagValues flags) +{ attr |= flags; } + +inline void mozApocResetFlags(mozApocEntryAttributes & attr, mozApocEntryFlagValues flags) +{ attr &= ~mozApocEntryAttributes(flags); } + +inline PRBool mozApocExistsInPolicy(mozApocEntryAttributes attr) +{ return mozApocAreAllFlagsSet(attr,MOZAPOC_ENTRY_EXISTS_IN_POLICY); } + +inline PRBool mozApocIsNode(mozApocEntryAttributes attr) +{ return (attr & MOZAPOC_ENTRY_IS_PROPERTY) == MOZAPOC_ENTRY_EXISTS_IN_POLICY; } + +inline PRBool mozApocIsProperty(mozApocEntryAttributes attr) +{ return mozApocAreAllFlagsSet(attr,MOZAPOC_ENTRY_IS_PROPERTY); } + +inline PRBool mozApocHasValue(mozApocEntryAttributes attr) +{ return mozApocAreAllFlagsSet(attr,MOZAPOC_ENTRY_HASVALUE); } + + +#endif + diff --git a/src/mozApocPolicyNodeDOMData.cpp b/src/mozApocPolicyNodeDOMData.cpp new file mode 100644 index 0000000..6bb6930 --- /dev/null +++ b/src/mozApocPolicyNodeDOMData.cpp @@ -0,0 +1,349 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+/* vim:expandtab:shiftwidth=4:tabstop=4:
+ */
+/*
+ *******************************************************************************
+ * $RCSfile: mozApocPolicyNodeDOMData.cpp,v $
+ *
+ * Description:
+ *
+ * Last change: $Date: 2006/10/30 03:23:53 $ $Revision: 1.1.1.1 $
+ *
+ * Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use of this
+ * product is subject to license terms.
+ *
+ *******************************************************************************
+ * Source Code Control System - Header
+ *
+ * $Header: /export/src/cvs/firefox-apoc-adapter/mozApocPolicyNodeDOMData.cpp,v 1.1.1.1 2006/10/30 03:23:53 sunop Exp $
+ *******************************************************************************
+ */
+
+#include "mozApocPolicyNodeDOMData.h"
+#include "mozApocPolicyComponentDOMData.h"
+#include "mozApocStringList.h"
+//brian #include "nsString2.h"
+#include "nsLiteralString.h"
+
+#ifndef MOZAPOC_NAVIGATION_TRACE
+#ifdef DEBUG
+#define MOZAPOC_NAVIGATION_TRACE 0
+#else
+#define MOZAPOC_NAVIGATION_TRACE 0
+#endif
+#endif
+
+#define NAVTRACE if (!(MOZAPOC_NAVIGATION_TRACE)); else ::fprintf
+
+mozApocPolicyNodeLayerDOMData::mozApocPolicyNodeLayerDOMData()
+: mPolicyData()
+, mAttributes(0)
+{
+}
+
+mozApocPolicyNodeLayerDOMData::mozApocPolicyNodeLayerDOMData(const mozApocPolicyModelNodeRef & aDOMRoot, const nsACString & aComponent)
+: mPolicyData(aDOMRoot)
+, mAttributes(0)
+{
+ if (mPolicyData)
+ {
+ mozApocSetFlags(mAttributes,MOZAPOC_ENTRY_EXISTS_IN_POLICY);
+ NS_ASSERTION(mPolicyData->IsNamed(aComponent),
+ "apoc - Name of root element does not match component name");
+ AdjustAttributes();
+ NS_WARN_IF_FALSE(ExistsInPolicy(), "apoc - Could Not Initialize PolicyNodeLayerDOMData from existing DOM root");
+ }
+}
+
+nsresult mozApocPolicyNodeLayerDOMData::GetValue(nsAString & _retval) const
+{
+ if (!mPolicyData) return NS_ERROR_UNEXPECTED;
+ if (!IsProperty()) return NS_ERROR_UNEXPECTED;
+
+ // we must be within a <prop> node here
+ return mPolicyData->GetValue(_retval);
+}
+
+nsresult mozApocPolicyNodeLayerDOMData::GotoChild(const nsACString & aName)
+{
+ if (!this->ExistsInPolicy()) return NS_OK; // leave unchanged
+
+ NS_ENSURE_TRUE(mPolicyData, NS_ERROR_UNEXPECTED);
+
+ if (IsProperty())
+ {
+ NS_WARNING("apoc - unexpected: Attempting to GotoChild of a property node");
+ NAVTRACE(stderr,"apoc - No child %s in property !\n", PromiseFlatCString(aName).get());
+ mPolicyData.Release();
+ AdjustAttributes();
+ return NS_ERROR_UNEXPECTED;
+ }
+
+ nsresult rv = GetChildElement(aName, mPolicyData);
+
+ // In case of failure: clear this node (but ignore the error)
+ if (NS_FAILED(rv)) mPolicyData.Release();
+
+ rv = AdjustAttributes();
+ NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),"apoc - unexpected: Adjusting attributes for child node failed");
+ return rv;
+}
+
+nsresult mozApocPolicyNodeLayerDOMData::GetChildElement(const nsACString & aName, mozApocPolicyModelNodeRef & outElement)
+{
+ NS_PRECONDITION(mPolicyData,"apoc - trying to get child of non-existing element");
+
+ mozApocPolicyModelNodeRef aFoundElement = mPolicyData->GetChild(aName);
+
+ if (aFoundElement)
+ {
+ outElement = aFoundElement;
+ return NS_OK;
+ }
+ else
+ {
+ return NS_ERROR_FAILURE;
+ }
+}
+
+nsresult mozApocPolicyNodeLayerDOMData::ListChildren(mozApocUniqueCStringList & aList) const
+{
+ if (IsNode()) // else we have nothing to add
+ {
+ NS_ASSERTION(mPolicyData,"apoc - trying to list children of non-existing element");
+
+ for (const mozApocPolicyModelNode * Node = mPolicyData->GetFirstChild(); Node; Node = Node->GetNextSibling())
+ aList.Add( Node->GetName() );
+ }
+ return NS_OK;
+}
+
+nsresult mozApocPolicyNodeLayerDOMData::AdjustAttributes()
+{
+ // propagate access control
+ if (mozApocAreAnyFlagsSet(mAttributes,MOZAPOC_ENTRY_PROTECTED_FLAGS))
+ mozApocSetFlags(mAttributes,MOZAPOC_ENTRY_PROTECTED);
+ mozApocResetFlags(mAttributes, MOZAPOC_LOCAL_PROTECTION_FLAGS);
+
+ mozApocResetFlags(mAttributes,MOZAPOC_ENTRY_TYPE_MASK);
+ mozApocResetFlags(mAttributes,MOZAPOC_ENTRY_IS_NOT_EMPTY);
+
+ if (mPolicyData)
+ {
+ mozApocEntryFlagValues aDOMFlags = NS_STATIC_CAST(mozApocEntryFlagValues , mPolicyData->GetAttributes());
+ mozApocSetFlags( mAttributes, aDOMFlags );
+ }
+
+ return NS_OK;
+}
+
+mozApocPolicyNodeDOMData::mozApocPolicyNodeDOMData()
+: mLayers(nsnull)
+, mLayerCount(0)
+, mEffectiveAttributes(0)
+{
+
+}
+
+mozApocPolicyNodeDOMData::mozApocPolicyNodeDOMData(const mozApocPolicyComponentDOMData * aRawLayerData)
+: mLayers(nsnull)
+, mLayerCount(0)
+, mEffectiveAttributes(0)
+{
+ if (!aRawLayerData) return;
+
+ PRInt32 nCount = aRawLayerData->GetLayerCount();
+ if (nCount == 0) return;
+
+ mLayers = new mozApocPolicyNodeLayerDOMData[nCount];
+ // TODO: add error handling
+ if (!mLayers) return;
+
+ mLayerCount = nCount;
+
+ mozApocParsedLayerDataList aRawLayer = aRawLayerData->GetLayers();
+ const nsACString & aComponent = aRawLayerData->GetComponentName();
+
+ for (PRInt32 i=0; i<mLayerCount; ++i)
+ {
+ mLayers[i] = mozApocPolicyNodeLayerDOMData(aRawLayer,aComponent);
+ mozApocPolicyModelNode::NextInList(aRawLayer);
+ }
+ AccumulateAttributes();
+ NS_WARN_IF_FALSE(mozApocAreAnyFlagsSet(mEffectiveAttributes,MOZAPOC_ENTRY_EXISTS_IN_POLICY),
+ "apoc - Could Not Initialize PolicyNodeData from existing layer data");
+}
+
+mozApocPolicyNodeDOMData::mozApocPolicyNodeDOMData(const mozApocPolicyNodeDOMData & aOther)
+{
+ if (CopyLayers(aOther.mLayers,aOther.mLayerCount))
+ mEffectiveAttributes = aOther.mEffectiveAttributes;
+ else
+ mEffectiveAttributes = 0;
+}
+
+mozApocPolicyNodeDOMData & mozApocPolicyNodeDOMData::operator=(const mozApocPolicyNodeDOMData & aOther)
+{
+ if (this != &aOther)
+ {
+ delete [] mLayers;
+ if (CopyLayers(aOther.mLayers,aOther.mLayerCount))
+ mEffectiveAttributes = aOther.mEffectiveAttributes;
+ else
+ mEffectiveAttributes = 0;
+ }
+ return *this;
+}
+
+mozApocPolicyNodeDOMData::~mozApocPolicyNodeDOMData()
+{
+ delete [] mLayers;
+}
+
+PRBool mozApocPolicyNodeDOMData::CopyLayers(const mozApocPolicyNodeLayerDOMData * pData, PRInt32 nCount)
+{
+ mLayers = new mozApocPolicyNodeLayerDOMData[mLayerCount = nCount];
+ if (mLayers)
+ {
+ for (PRInt32 i=0; i<mLayerCount; ++i)
+ {
+ mLayers[i] = pData[i];
+ }
+ AccumulateAttributes();
+ }
+ else
+ mLayerCount = 0;
+
+ return mLayers != nsnull;
+}
+
+void mozApocPolicyNodeDOMData::AccumulateAttributes()
+{
+ if (!mLayers) return;
+
+ mozApocEntryAttributes attributes = 0;
+ mozApocEntryFlagValues valueType = MOZAPOC_ENTRY_TYPE_NONE;
+
+ for (PRInt32 i = 0; i<mLayerCount; ++i)
+ {
+ mozApocEntryAttributes layerAttributes = mLayers[i].GetAttributes();
+ // TODO: do consistency checks here
+ attributes |= layerAttributes & MOZAPOC_ENTRY_FLAGS_MASK;
+
+ // if this layer is protected, further layers can be ignored
+ if (mozApocAreAnyFlagsSet(attributes,MOZAPOC_ENTRY_PROTECTED_FLAGS))
+ SuppressDataFrom(i+1); // loop will terminate automatically
+
+ mozApocEntryFlagValues layerType = mozApocGetEntryType(layerAttributes);
+ if (layerType != MOZAPOC_ENTRY_TYPE_NONE)
+ {
+ if (valueType == MOZAPOC_ENTRY_TYPE_NONE)
+ valueType = layerType;
+ else if (valueType != layerType)
+ valueType = MOZAPOC_ENTRY_TYPE_ERROR;
+ }
+ }
+ // TODO: check for consistency with previous attributes
+ mEffectiveAttributes = attributes | mozApocEntryAttributes(valueType);
+}
+
+void mozApocPolicyNodeDOMData::SuppressDataFrom(PRInt32 nIndex)
+{
+ for (PRInt32 i=nIndex; i<mLayerCount; ++i)
+ mLayers[i] = mozApocPolicyNodeLayerDOMData();
+ mLayerCount = nIndex;
+}
+
+void mozApocPolicyNodeDOMData::Clear()
+{
+ delete [] mLayers, mLayers = 0;
+ mLayerCount = 0;
+}
+
+nsresult mozApocPolicyNodeDOMData::GotoChild(const nsACString & aName)
+{
+ nsresult rv = NS_OK;
+ for (PRInt32 i=0; i<mLayerCount; ++i)
+ {
+ rv = mLayers[i].GotoChild(aName);
+ if (NS_FAILED(rv))
+ break;
+ }
+ if (NS_SUCCEEDED(rv))
+ AccumulateAttributes();
+ else
+ mEffectiveAttributes = 0; // triggers subsequent Clear
+
+ if (!mozApocAreAnyFlagsSet(mEffectiveAttributes,MOZAPOC_ENTRY_EXISTS_IN_POLICY))
+ Clear();
+
+ else
+ NAVTRACE(stderr,"apoc - Got child data for %s [attributes=%#.4x]\n",
+ PromiseFlatCString(aName).get(), unsigned(mEffectiveAttributes));
+
+ return rv;
+}
+
+nsresult mozApocPolicyNodeDOMData::ListChildren(mozApocUniqueCStringList & aList) const
+{
+ nsresult rv = NS_OK;
+ for (PRInt32 i=0; i<mLayerCount; ++i)
+ {
+ nsresult rv2 = mLayers[i].ListChildren(aList);
+ if (NS_SUCCEEDED(rv)) rv = rv2;
+ }
+ return rv;
+}
+
+nsresult mozApocPolicyNodeDOMData::GetValue(nsAString & _retval) const
+{
+ if (!IsProperty()) return NS_ERROR_UNEXPECTED;
+
+ PRInt32 nIndexOfValue = mLayerCount-1;
+ if (HasValue())
+ {
+ // we have a value somewhere - lets go find it
+ for ( ; nIndexOfValue >= 0; --nIndexOfValue)
+ if (mLayers[nIndexOfValue].HasValue())
+ break;
+ }
+ // else simply let the last layer provide an error.
+ NS_ASSERTION( nIndexOfValue >= 0, "apoc - Error: PolicyNodeData did not find a value although it used to be there");
+
+ return mLayers[nIndexOfValue].GetValue(_retval);
+}
+
diff --git a/src/mozApocPolicyNodeDOMData.h b/src/mozApocPolicyNodeDOMData.h new file mode 100644 index 0000000..7736a6f --- /dev/null +++ b/src/mozApocPolicyNodeDOMData.h @@ -0,0 +1,108 @@ + + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_POLICYNODEDOMDATA_H_INCLUDED +#define MOZAPOC_POLICYNODEDOMDATA_H_INCLUDED + +#include "mozApocPolicyNodeAttributes.h" + +#include "mozApocPolicyModel.h" + +class mozApocPolicyComponentDOMData; +class mozApocUniqueCStringList; + +class mozApocPolicyNodeLayerDOMData +{ + mozApocPolicyModelNodeRef mPolicyData; + mozApocEntryAttributes mAttributes; +public: + mozApocPolicyNodeLayerDOMData(); + explicit + mozApocPolicyNodeLayerDOMData(const mozApocPolicyModelNodeRef & aDOMRoot, const nsACString & aComponent); + + mozApocEntryAttributes GetAttributes() const { return mAttributes; } + PRBool ExistsInPolicy() const { return mPolicyData != nsnull; } + // PRBool ExistsInPolicy() const { return mozApocExistsInPolicy(mAttributes); } + PRBool IsNode() const { return mozApocIsNode(mAttributes); } + PRBool IsProperty() const { return mozApocIsProperty(mAttributes); } + PRBool HasValue() const { return mozApocHasValue(mAttributes); } + + nsresult GetValue(nsAString & _retval) const; + + nsresult ListChildren(mozApocUniqueCStringList & aList) const; + + nsresult GotoChild(const nsACString & aName); +private: + nsresult GetChildElement(const nsACString & aName, mozApocPolicyModelNodeRef & aElement); + nsresult AdjustAttributes(); +}; + +class mozApocPolicyNodeDOMData +{ + mozApocPolicyNodeLayerDOMData * mLayers; + PRInt32 mLayerCount; + mozApocEntryAttributes mEffectiveAttributes; +public: + mozApocPolicyNodeDOMData(); + explicit + mozApocPolicyNodeDOMData(const mozApocPolicyComponentDOMData * aRawLayerData); + mozApocPolicyNodeDOMData(const mozApocPolicyNodeDOMData & aOther); + mozApocPolicyNodeDOMData & operator=(const mozApocPolicyNodeDOMData & aOther); + ~mozApocPolicyNodeDOMData(); + + mozApocEntryAttributes GetAttributes() const { return mEffectiveAttributes; } + PRBool IsReal() const { return mozApocExistsInPolicy(mEffectiveAttributes); } + PRBool IsNode() const { return mozApocIsNode(mEffectiveAttributes); } + PRBool IsProperty() const { return mozApocIsProperty(mEffectiveAttributes); } + PRBool HasValue() const { return mozApocHasValue(mEffectiveAttributes); } + + nsresult GetValue(nsAString & _retval) const; + // TODO: Add support for localized values + + nsresult ListChildren(mozApocUniqueCStringList & aList) const; + + nsresult GotoChild(const nsACString & aName); +private: + PRBool CopyLayers(const mozApocPolicyNodeLayerDOMData * pData, PRInt32 nCount); + void AccumulateAttributes(); + void SuppressDataFrom(PRInt32 nIndex); + void Clear(); +}; + +#endif + diff --git a/src/mozApocPolicyNodeData.cpp b/src/mozApocPolicyNodeData.cpp new file mode 100644 index 0000000..259f4ec --- /dev/null +++ b/src/mozApocPolicyNodeData.cpp @@ -0,0 +1,141 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+/* vim:expandtab:shiftwidth=4:tabstop=4:
+ */
+/*
+ *******************************************************************************
+ * $RCSfile: mozApocPolicyNodeData.cpp,v $
+ *
+ * Description:
+ *
+ * Last change: $Date: 2006/10/30 03:23:53 $ $Revision: 1.1.1.1 $
+ *
+ * Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use of this
+ * product is subject to license terms.
+ *
+ *******************************************************************************
+ * Source Code Control System - Header
+ *
+ * $Header: /export/src/cvs/firefox-apoc-adapter/mozApocPolicyNodeData.cpp,v 1.1.1.1 2006/10/30 03:23:53 sunop Exp $
+ *******************************************************************************
+ */
+
+#include "mozApocPolicyNodeData.h"
+#include "mozApocPolicyComponentData.h"
+#include "mozApocPolicyModel.h"
+
+#ifndef MOZAPOC_VALTRACE
+#define MOZAPOC_VALTRACE 0
+#endif
+
+#define VALTRACE if (!(MOZAPOC_VALTRACE)) ; else ::fprintf
+
+mozApocPolicyNodeData::mozApocPolicyNodeData()
+: mRealData(nsnull)
+, mAttributes(0)
+{
+
+}
+
+mozApocPolicyNodeData::mozApocPolicyNodeData(const mozApocPolicyComponentData * aComponentData)
+: mRealData(nsnull)
+, mAttributes(0)
+{
+ if (aComponentData)
+ Assign(aComponentData->getRootNode());
+}
+
+mozApocPolicyNodeData::mozApocPolicyNodeData(const mozApocPolicyModelNode * aRawData)
+: mRealData(nsnull)
+, mAttributes(0)
+{
+ Assign(aRawData);
+}
+
+mozApocPolicyNodeData::mozApocPolicyNodeData(const mozApocPolicyNodeData & aOther)
+: mRealData(nsnull)
+, mAttributes(0)
+{
+ Assign(aOther.mRealData);
+}
+
+mozApocPolicyNodeData & mozApocPolicyNodeData::operator=(const mozApocPolicyNodeData & aOther)
+{
+ Assign(aOther.mRealData);
+ return *this;
+}
+
+mozApocPolicyNodeData::~mozApocPolicyNodeData()
+{
+ Assign(nsnull);
+}
+
+void mozApocPolicyNodeData::Assign(const mozApocPolicyModelNode * aNewData)
+{
+ if (aNewData) aNewData->AcquireReference();
+ if (mRealData) mRealData->ReleaseReference();
+ mRealData = aNewData;
+ mAttributes = mRealData ? mRealData->GetAttributes() : 0;
+}
+
+PRBool mozApocPolicyNodeData::HasRealChild(const nsACString & aName) const
+{
+ nsresult dummyrv = NS_OK;
+ return mRealData && mRealData->GetChild(aName,&dummyrv) != nsnull;
+}
+
+nsresult mozApocPolicyNodeData::GotoChild(const nsACString & aName)
+{
+ nsresult rv = NS_OK;
+ if (mRealData)
+ Assign( mRealData->GetChild(aName,&rv) );
+ return rv;
+}
+
+nsresult mozApocPolicyNodeData::GetValue(nsAString & _retval) const
+{
+ nsresult rv = NS_ERROR_UNEXPECTED;
+ if (mRealData)
+ rv = mRealData->GetValue(_retval);
+
+ if (NS_SUCCEEDED(rv))
+ VALTRACE(stderr,"apoc - Providing node value: '%s'\n", NS_ConvertUCS2toUTF8(_retval).get());
+ else
+ NS_WARNING("apoc - GetNodeValue failed");
+
+ return rv;
+}
+
diff --git a/src/mozApocPolicyNodeData.h b/src/mozApocPolicyNodeData.h new file mode 100644 index 0000000..ec8b28e --- /dev/null +++ b/src/mozApocPolicyNodeData.h @@ -0,0 +1,79 @@ + + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_POLICYNODEDATA_H_INCLUDED +#define MOZAPOC_POLICYNODEDATA_H_INCLUDED + +#include "mozApocPolicyNodeAttributes.h" +#include "nsAString.h" + +class mozApocPolicyModelNode; +class mozApocPolicyComponentData; + +class mozApocPolicyNodeData +{ + typedef const mozApocPolicyModelNode * rawData; + rawData mRealData; + mozApocEntryAttributes mAttributes; +public: + mozApocPolicyNodeData(); + explicit + mozApocPolicyNodeData(rawData aRawData); + explicit + mozApocPolicyNodeData(const mozApocPolicyComponentData * aComponentData); + mozApocPolicyNodeData(const mozApocPolicyNodeData & aOther); + mozApocPolicyNodeData & operator=(const mozApocPolicyNodeData & aOther); + ~mozApocPolicyNodeData(); + + mozApocEntryAttributes GetAttributes() const { return mAttributes; } + PRBool IsProperty() const { return mozApocIsProperty(mAttributes); } + PRBool IsNode() const { return mozApocIsNode(mAttributes); } + PRBool HasValue() const { return mozApocHasValue(mAttributes); } + + // TODO: Add support for localized values + nsresult GetValue(nsAString & _retval) const; + + PRBool IsReal() const { return mRealData != nsnull; } + PRBool HasRealChild(const nsACString & aName) const; + nsresult GotoChild(const nsACString & aName); +private: + void Assign(rawData aNewData); +}; + +#endif + diff --git a/src/mozApocPrefBranch.cpp b/src/mozApocPrefBranch.cpp new file mode 100644 index 0000000..1c13ad4 --- /dev/null +++ b/src/mozApocPrefBranch.cpp @@ -0,0 +1,445 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ +/* + ******************************************************************************* + * $RCSfile: mozApocPrefBranch.cpp,v $ + * + * Description: + * + * Last change: $Date: 2006/10/30 03:23:53 $ $Revision: 1.1.1.1 $ + * + * Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use of this + * product is subject to license terms. + * + ******************************************************************************* + * Source Code Control System - Header + * + * $Header: /export/src/cvs/firefox-apoc-adapter/mozApocPrefBranch.cpp,v 1.1.1.1 2006/10/30 03:23:53 sunop Exp $ + ******************************************************************************* + */ + +#include "mozApocPrefBranch.h" +#include "mozApocPrefService.h" +#include "mozApocPolicyData.h" +#include <stdio.h> + +#ifndef MOZAPOC_ACCESS_TRACE +#ifdef DEBUG +#define MOZAPOC_ACCESS_TRACE 1 +#else +#define MOZAPOC_ACCESS_TRACE 0 +#endif +#endif + +#define ACCTRACE(lvl) if ((lvl) >= (MOZAPOC_ACCESS_TRACE)); else ::fprintf +#define ACCESSTRACE0 ACCTRACE(0) +#define ACCESSTRACE1 ACCTRACE(1) +#define ACCESSTRACE2 ACCTRACE(2) + +#if 0 +NS_IMPL_THREADSAFE_ISUPPORTS5(mozApocPrefBranchWrapper, + nsIPrefBranch,nsIPrefBranchInternal,nsISecurityPref, + nsIObserver,nsISupportsWeakReference); +#else +NS_IMPL_THREADSAFE_ADDREF(mozApocPrefBranchWrapper) +NS_IMPL_THREADSAFE_RELEASE(mozApocPrefBranchWrapper) + +NS_INTERFACE_MAP_BEGIN(mozApocPrefBranchWrapper) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrefBranch) + NS_INTERFACE_MAP_ENTRY(nsIPrefBranch) + NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIPrefBranch2, !mIsDefaultBranch) + NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIPrefBranchInternal, !mIsDefaultBranch) + NS_INTERFACE_MAP_ENTRY(nsISecurityPref) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) +NS_INTERFACE_MAP_END +#endif + +#define MA_PBW_ENSURE_INITIALIZED() NS_ENSURE_TRUE(mWrappedBranch, NS_ERROR_NOT_INITIALIZED) +#define MA_PBW_ENSURE_BRANCH() MA_PBW_ENSURE_INITIALIZED() + +// class mozApocPrefBranchWrapper +// +mozApocPrefBranchWrapper::mozApocPrefBranchWrapper() +: mPolicyBranch() +, mWrappedBranch() +, mIsDefaultBranch() +{ +} + +mozApocPrefBranchWrapper::~mozApocPrefBranchWrapper() +{ +} + +nsresult mozApocPrefBranchWrapper::Init(const mozApocPolicyData& aPolicyBranch, + const nsCOMPtr<nsIPrefBranch> & aOriginalBranch, + PRBool bDefault) +{ + if (mWrappedBranch) + return NS_ERROR_ALREADY_INITIALIZED; + + NS_ENSURE_ARG_POINTER(aOriginalBranch); + + NS_ENSURE_FALSE( aPolicyBranch.HasError(), aPolicyBranch.GetError() ); + + mPolicyBranch = aPolicyBranch; + mWrappedBranch = aOriginalBranch; + mIsDefaultBranch = bDefault; + + return NS_OK; +} + +// Policy Data Accessors +// + + +mozApocPolicyEntry mozApocPrefBranchWrapper::GetPolicyEntry(const char *aPrefName) +{ + return mPolicyBranch.GetEntry(aPrefName,PR_TRUE); +} + +PRBool mozApocPrefBranchWrapper::UsePolicyValue(const char * aPrefName, nsresult & rv) +{ + NS_PRECONDITION(mWrappedBranch, "apoc - ERROR: UsePolicyvalue called on non-initialized branch."); + + mozApocPolicyEntry aEntry = mPolicyBranch.GetEntry(aPrefName,PR_TRUE); + + if (aEntry.HasError()) + { + // NS_WARNING("apoc - Error in PolicyEntry - ignoring for path:"); + ACCESSTRACE0(stderr,"apoc - Error in PolicyEntry - ignoring possible entry for path: '%s'\n",aPrefName); + return PR_FALSE; + } + + if (!aEntry.HasValue()) + { + NS_WARN_IF_FALSE(!aEntry.IsProperty(),"apoc - Found property node that has no value"); + if (aEntry.IsInnerNode()) + { + NS_WARNING("apoc - Attempting to access value of inner node "); + rv = NS_ERROR_UNEXPECTED; + } + else if (aEntry.IsProtected() && !mIsDefaultBranch) + { + // TODO: Review this implementation choice, that manipulates the native value + ACCESSTRACE2(stderr,"apoc - Value for '%s' is locked to native default in policy\n", aPrefName); + rv = mWrappedBranch->LockPref(aPrefName); + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),"apoc - Cannot force native default: LockPref failed"); + } + return PR_FALSE; + } + + if (this->mIsDefaultBranch || aEntry.IsProtected()) + { + ACCESSTRACE2(stderr,"apoc - Providing %s value for '%s' from policy\n",mIsDefaultBranch ? "default" : "protected", aPrefName); + return PR_TRUE; + } + + PRBool bHasUserValue = PR_TRUE; // assume true, if not accessible + rv = mWrappedBranch->PrefHasUserValue(aPrefName, &bHasUserValue); + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),"apoc - Cannot determine whether there is an overriding user value"); + if (bHasUserValue) + ACCESSTRACE2(stderr,"apoc - Policy value for '%s' is overridden\n",aPrefName); + else + ACCESSTRACE2(stderr,"apoc - Providing not-overridden value for '%s' from policy\n",aPrefName); + return !bHasUserValue; +} + +nsresult mozApocPrefBranchWrapper::ValidateWrite(const char *aPrefName) +{ + mozApocPolicyEntry aEntry = mPolicyBranch.GetEntry(aPrefName,PR_TRUE); + NS_WARN_IF_FALSE(!aEntry.HasError(), "apoc - Error in PolicyEntry - ignoring"); + + if ( aEntry.HasError() ) return NS_OK; // aEntry.GetError(); + + if (aEntry.IsProtected()) + { + ACCESSTRACE0(stderr,"apoc - Blocking write to protected entry '%s' !\n", aPrefName); + return NS_ERROR_UNEXPECTED; + } + + if (this->mIsDefaultBranch && aEntry.HasValue()) + { + ACCESSTRACE0(stderr,"apoc - Blocking write to hidden default entry '%s' !\n", aPrefName); + return NS_ERROR_UNEXPECTED; + } + + return NS_OK; +} + +/* readonly attribute string root; */ +NS_IMETHODIMP mozApocPrefBranchWrapper::GetRoot(char * *aRoot) +{ + MA_PBW_ENSURE_BRANCH(); + return mWrappedBranch->GetRoot(aRoot); +} + +/* long getPrefType (in string aPrefName); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::GetPrefType(const char *aPrefName, PRInt32 *_retval) +{ + MA_PBW_ENSURE_BRANCH(); + return mWrappedBranch->GetPrefType(aPrefName,_retval); +} + +/* boolean getBoolPref (in string aPrefName); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::GetBoolPref(const char *aPrefName, PRBool *_retval) +{ + // TODO: Handle policy lock-to-default + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aPrefName); + + nsresult rv = NS_OK; + if (UsePolicyValue(aPrefName,rv)) + { + ACCESSTRACE1(stderr,"apoc - Using Policy Value for Bool '%s'\n",aPrefName); + + NS_ENSURE_ARG_POINTER(_retval); + + mozApocPolicyEntry aEntry = GetPolicyEntry(aPrefName); + rv = aEntry.GetBoolValue(_retval); + } + else + { + // NS_ENSURE_SUCCESS(rv,rv); + rv = mWrappedBranch->GetBoolPref(aPrefName,_retval); + } + return rv; +} + +/* void setBoolPref (in string aPrefName, in long aValue); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::SetBoolPref(const char *aPrefName, PRInt32 aValue) +{ + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aPrefName); + + nsresult rv = ValidateWrite(aPrefName); + NS_ENSURE_SUCCESS(rv,rv); + rv = mWrappedBranch->SetBoolPref(aPrefName,aValue); + return rv; +} + +/* string getCharPref (in string aPrefName); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::GetCharPref(const char *aPrefName, char **_retval) +{ + // TODO: Handle policy lock-to-default + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aPrefName); + + nsresult rv = NS_ERROR_FAILURE; + if (UsePolicyValue(aPrefName,rv)) + { + ACCESSTRACE1(stderr,"apoc - Using Policy Value for String '%s'\n",aPrefName); + + NS_ENSURE_ARG_POINTER(_retval); + + mozApocPolicyEntry aEntry = GetPolicyEntry(aPrefName); + rv = aEntry.GetCharValue(_retval); + } + else + { + rv = mWrappedBranch->GetCharPref(aPrefName,_retval); + } + return rv; +} + +/* void setCharPref (in string aPrefName, in string aValue); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::SetCharPref(const char *aPrefName, const char *aValue) +{ + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aPrefName); + + nsresult rv = ValidateWrite(aPrefName); + NS_ENSURE_SUCCESS(rv,rv); + rv = mWrappedBranch->SetCharPref(aPrefName,aValue); + return rv; +} + +/* long getIntPref (in string aPrefName); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::GetIntPref(const char *aPrefName, PRInt32 *_retval) +{ + // TODO: Handle policy lock-to-default + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aPrefName); + + nsresult rv = NS_ERROR_FAILURE; + if (UsePolicyValue(aPrefName,rv)) + { + ACCESSTRACE1(stderr,"apoc - Using Policy Value for Integer '%s'\n",aPrefName); + + NS_ENSURE_ARG_POINTER(_retval); + + mozApocPolicyEntry aEntry = GetPolicyEntry(aPrefName); + rv = aEntry.GetIntValue(_retval); + } + else + { + rv = mWrappedBranch->GetIntPref(aPrefName,_retval); + } + return rv; +} + +/* void setIntPref (in string aPrefName, in long aValue); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::SetIntPref(const char *aPrefName, PRInt32 aValue) +{ + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aPrefName); + + nsresult rv = ValidateWrite(aPrefName); + NS_ENSURE_SUCCESS(rv,rv); + rv = mWrappedBranch->SetIntPref(aPrefName,aValue); + return rv; +} + +/* void getComplexValue (in string aPrefName, in nsIIDRef aType, [iid_is (aType), retval] out nsQIResult aValue); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::GetComplexValue(const char *aPrefName, const nsIID & aType, void * *aValue) +{ + // TODO: Handle policy lock-to-default + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aPrefName); + + nsresult rv = NS_ERROR_FAILURE; + if (UsePolicyValue(aPrefName,rv)) + { + ACCESSTRACE1(stderr,"apoc - Using Policy Value for Complex '%s'\n",aPrefName); + + NS_ENSURE_ARG_POINTER(aValue); + + mozApocPolicyEntry aEntry = GetPolicyEntry(aPrefName); + rv = aEntry.GetComplexValue(aType,aValue); + } + else + { + rv = mWrappedBranch->GetComplexValue(aPrefName,aType,aValue); + } + return rv; +} + +/* void setComplexValue (in string aPrefName, in nsIIDRef aType, in nsISupports aValue); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::SetComplexValue(const char *aPrefName, const nsIID & aType, nsISupports *aValue) +{ + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aPrefName); + + nsresult rv = ValidateWrite(aPrefName); + NS_ENSURE_SUCCESS(rv,rv); + rv = mWrappedBranch->SetComplexValue(aPrefName,aType,aValue); + return rv; +} + +/* void clearUserPref (in string aPrefName); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::ClearUserPref(const char *aPrefName) +{ + MA_PBW_ENSURE_BRANCH(); + return mWrappedBranch->ClearUserPref(aPrefName); +} + +/* void lockPref (in string aPrefName); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::LockPref(const char *aPrefName) +{ + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aPrefName); + + if (GetPolicyEntry(aPrefName).IsProtected()) + return NS_ERROR_UNEXPECTED; + + return mWrappedBranch->LockPref(aPrefName); +} + +/* boolean prefHasUserValue (in string aPrefName); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::PrefHasUserValue(const char *aPrefName, PRBool *_retval) +{ + MA_PBW_ENSURE_BRANCH(); + return mWrappedBranch->PrefHasUserValue(aPrefName,_retval); +} + +/* boolean prefIsLocked (in string aPrefName); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::PrefIsLocked(const char *aPrefName, PRBool *_retval) +{ + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aPrefName); + + if (GetPolicyEntry(aPrefName).IsProtected()) + { + NS_ENSURE_ARG_POINTER(_retval); + + *_retval = PR_TRUE; + return NS_OK; + } + return mWrappedBranch->PrefIsLocked(aPrefName,_retval); +} + +/* void unlockPref (in string aPrefName); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::UnlockPref(const char *aPrefName) +{ + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aPrefName); + + if (GetPolicyEntry(aPrefName).IsProtected()) + return NS_ERROR_UNEXPECTED; + + return mWrappedBranch->UnlockPref(aPrefName); +} + +/* void deleteBranch (in string aStartingAt); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::DeleteBranch(const char *aStartingAt) +{ + MA_PBW_ENSURE_BRANCH(); + NS_ENSURE_ARG_POINTER(aStartingAt); + + mozApocPolicyEntry aEntry = mPolicyBranch.GetEntry(aStartingAt,PR_FALSE); + if (aEntry.IsMandatory()) + return NS_ERROR_UNEXPECTED; + + return mWrappedBranch->DeleteBranch(aStartingAt); +} + + +/* void getChildList (in string aStartingAt, out unsigned long aCount, [array, size_is (aCount), retval] out string aChildArray); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::GetChildList(const char *aStartingAt, PRUint32 *aCount, char ***aChildArray) +{ + MA_PBW_ENSURE_BRANCH(); + return mWrappedBranch->GetChildList(aStartingAt,aCount,aChildArray); +} + +/* void resetBranch (in string aStartingAt); */ +NS_IMETHODIMP mozApocPrefBranchWrapper::ResetBranch(const char *aStartingAt) +{ + MA_PBW_ENSURE_BRANCH(); + return mWrappedBranch->ResetBranch(aStartingAt); +} + diff --git a/src/mozApocPrefBranch.h b/src/mozApocPrefBranch.h new file mode 100644 index 0000000..1b08bed --- /dev/null +++ b/src/mozApocPrefBranch.h @@ -0,0 +1,90 @@ + + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_PREFBRANCH_H_INCLUDED +#define MOZAPOC_PREFBRANCH_H_INCLUDED + +//Brian #include "nsIPrefBranch.h" +#include "pref/nsIPrefBranchInternal.h" +#include "nsIObserver.h" +#include "pref/nsISecurityPref.h" +#include "nsCOMPtr.h" +#include "nsWeakReference.h" + +#include "mozApocPolicyData.h" + +//brian class mozApocPrefBranchWrapper : public nsIPrefBranch +class mozApocPrefBranchWrapper : public nsIPrefBranchInternal + , public nsISecurityPref + , public nsIObserver + , public nsSupportsWeakReference +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIPREFBRANCH + +#if 0 //Brian++ + NS_FORWARD_SAFE_NSIPREFBRANCHINTERNAL( +#else + NS_FORWARD_SAFE_NSIPREFBRANCH2( +#endif + nsCOMPtr<nsIPrefBranchInternal>(do_QueryInterface(mWrappedBranch)) + ) // NS_DECL_NSIPREFBRANCHINTERNAL + NS_FORWARD_SAFE_NSISECURITYPREF ( + nsCOMPtr<nsISecurityPref>(do_QueryInterface(mWrappedBranch)) + ) // NS_DECL_NSISECURITYPREF + NS_FORWARD_SAFE_NSIOBSERVER ( + nsCOMPtr<nsIObserver>(do_QueryInterface(mWrappedBranch)) + ) // NS_DECL_NSIOBSERVER + + mozApocPrefBranchWrapper(); + virtual ~mozApocPrefBranchWrapper(); + + nsresult Init(const mozApocPolicyData & aPolicyBranch, const nsCOMPtr<nsIPrefBranch> & aOriginalBranch, PRBool bDefault); +private: + mozApocPolicyEntry GetPolicyEntry(const char *aPrefName); + PRBool UsePolicyValue(const char *aPrefName, nsresult & rv); + nsresult ValidateWrite(const char *aPrefName); +private: + mozApocPolicyData mPolicyBranch; + nsCOMPtr<nsIPrefBranch> mWrappedBranch; + PRBool mIsDefaultBranch; +}; + +#endif + diff --git a/src/mozApocPrefService.cpp b/src/mozApocPrefService.cpp new file mode 100644 index 0000000..04c7e31 --- /dev/null +++ b/src/mozApocPrefService.cpp @@ -0,0 +1,292 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ +/* + ******************************************************************************* + * $RCSfile: mozApocPrefService.cpp,v $ + * + * Description: + * + * Last change: $Date: 2006/10/30 03:23:53 $ $Revision: 1.1.1.1 $ + * + * Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use of this + * product is subject to license terms. + * + ******************************************************************************* + * Source Code Control System - Header + * + * $Header: /export/src/cvs/firefox-apoc-adapter/mozApocPrefService.cpp,v 1.1.1.1 2006/10/30 03:23:53 sunop Exp $ + ******************************************************************************* + */ + +#include "mozApocPrefService.h" +#include "mozApocPrefBranch.h" +#include "mozApocNotificationImpl.h" + +//Brian++ #include "nsIServiceManagerUtils.h" +#include "nsServiceManagerUtils.h" +#include "nsIProxyObjectManager.h" +#include "nsDebug.h" + +#include <stdio.h> + +#ifndef MOZAPOC_INIT_TRACE +#ifdef DEBUG +#define MOZAPOC_INIT_TRACE 1 +#else +#define MOZAPOC_INIT_TRACE 0 +#endif +#endif +#ifndef MOZAPOC_BRANCH_TRACE +#ifdef DEBUG +#define MOZAPOC_BRANCH_TRACE 1 +#else +#define MOZAPOC_BRANCH_TRACE 0 +#endif +#endif + +#define INITTRACE if (!(MOZAPOC_INIT_TRACE)) ; else ::fprintf +#define BRANCHTRACE if (!(MOZAPOC_BRANCH_TRACE)) ; else ::fprintf +static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); + +#if 0 +NS_IMPL_THREADSAFE_ISUPPORTS5(mozApocPrefServiceWrapper, + nsIPrefService,nsIPrefBranch,nsIPrefBranchInternal, + nsIObserver,nsISupportsWeakReference); +#else +NS_IMPL_THREADSAFE_ADDREF(mozApocPrefServiceWrapper) +NS_IMPL_THREADSAFE_RELEASE(mozApocPrefServiceWrapper) + +NS_INTERFACE_MAP_BEGIN(mozApocPrefServiceWrapper) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrefService) + NS_INTERFACE_MAP_ENTRY(nsIPrefService) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsIPrefBranch) + NS_INTERFACE_MAP_ENTRY(nsIPrefBranch2) + NS_INTERFACE_MAP_ENTRY(nsIPrefBranchInternal) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) +NS_INTERFACE_MAP_END + +#endif + + +#define MA_PSW_ENSURE_INITIALIZED() NS_ENSURE_TRUE(mWrappedService, NS_ERROR_NOT_INITIALIZED) + +mozApocPrefServiceWrapper::mozApocPrefServiceWrapper() +: mWrappedService() , mUserBranch() +, mNotifier(nsnull) +{ + NS_INIT_ISUPPORTS(); +} + +mozApocPrefServiceWrapper::~mozApocPrefServiceWrapper() +{ + delete mNotifier; +} + +nsresult mozApocPrefServiceWrapper::Init() +{ + static NS_DEFINE_CID( kWrappedClsid, NS_PREFSERVICE_CID ); + + INITTRACE(stderr,"apoc: Initializing PrefServiceWrapper.\n"); + + if (mUserBranch) + return NS_ERROR_ALREADY_INITIALIZED; + + nsresult rv = NS_OK; + mWrappedService = do_GetService(kWrappedClsid,&rv); + + if (NS_SUCCEEDED(rv)) + { + InitNotifier(); // failure considered non-fatal + rv = CreateWrappedBranch(NULL,false,getter_AddRefs(mUserBranch)); + } + + if (NS_FAILED(rv)) + INITTRACE(stderr,"apoc: Initializing PrefServiceWrapper failed [rv = 0x%#.8x]\n", unsigned(rv)); + + return rv; +} + +nsresult mozApocPrefServiceWrapper::InitNotifier() +{ + NS_ENSURE_TRUE(!mNotifier, NS_ERROR_ALREADY_INITIALIZED); + NS_ENSURE_TRUE(mWrappedService, NS_ERROR_NOT_INITIALIZED); + + nsresult rv = NS_OK; + nsCOMPtr<nsIPrefBranch> aDefaultBranch; + nsCOMPtr<nsIPrefBranch> aDefaultBranchProxy; + nsCOMPtr<nsIProxyObjectManager> proxyObjectManager(do_GetService(kProxyObjectManagerCID, &rv)); + if (NS_FAILED(rv)) + return rv; + rv = mWrappedService->GetDefaultBranch(nsnull,getter_AddRefs(aDefaultBranch)); + if (NS_FAILED(rv)) + return rv; + rv = proxyObjectManager->GetProxyForObject(NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIPrefBranch), + aDefaultBranch, PROXY_SYNC | PROXY_ALWAYS, + getter_AddRefs(aDefaultBranchProxy)); + if (NS_SUCCEEDED(rv)) + { + mNotifier = new mozApocBranchNotifier(aDefaultBranchProxy); + + if (!mNotifier) rv = NS_ERROR_OUT_OF_MEMORY; + } + + if (NS_FAILED(rv)) + INITTRACE(stderr,"apoc: Initializing Notifier failed - notification will not work" + " [rv = 0x%#.8x]\n", unsigned(rv)); + + mBackend.SetNotifier(mNotifier); + + return rv; +} + +mozApocPolicyData mozApocPrefServiceWrapper::GetPolicyData(const char * aPrefRoot) +{ + if (aPrefRoot && *aPrefRoot) + { + return mozApocPolicyData(mozApocPolicyEntry(mBackend,aPrefRoot)); + } + else + { + return mozApocPolicyData(mBackend); + } +} + +nsresult mozApocPrefServiceWrapper::CreateWrappedBranch(const char *aPrefRoot, PRBool bDefault, nsIPrefBranch **_retval) +{ + NS_PRECONDITION(mWrappedService, "Wrapped service must be initialized before calling CreateWrappedBranch"); + + BRANCHTRACE(stderr,"apoc: Creating wrapped %s PrefBranch at %s.\n", + bDefault ? "default" : "user", + aPrefRoot ? *aPrefRoot ? aPrefRoot : "<ROOT> [empty]" : "<ROOT> [NULL]" ); + + NS_ENSURE_ARG_POINTER(_retval); + *_retval = nsnull; + + nsCOMPtr<nsIPrefBranch> aOriginalBranch; + nsresult rv = NS_OK; + if (aPrefRoot || bDefault) + rv = GetOriginalBranch(aPrefRoot,bDefault,getter_AddRefs(aOriginalBranch)); + else + rv = mWrappedService->GetBranch(aPrefRoot,getter_AddRefs(aOriginalBranch)); + NS_ENSURE_SUCCESS(rv,rv); + + mozApocPrefBranchWrapper * wrapper; + NS_NEWXPCOM( wrapper, mozApocPrefBranchWrapper ); + if (!wrapper) + return NS_ERROR_OUT_OF_MEMORY; + + nsCOMPtr< nsIPrefBranch > aResultBranch(wrapper); + rv = wrapper->Init(GetPolicyData(aPrefRoot),aOriginalBranch,bDefault); + if (NS_SUCCEEDED(rv)) + { + *_retval = aResultBranch; + NS_ADDREF(*_retval); + } + else if (rv == NS_ERROR_NOT_AVAILABLE) + { + //handle connection failures gracefully + *_retval = aOriginalBranch; + NS_ADDREF(*_retval); + rv = NS_OK; + } + + return rv; +} + +nsresult mozApocPrefServiceWrapper::GetOriginalBranch(const char *aPrefRoot, PRBool bDefault, nsIPrefBranch **_retval) +{ + NS_PRECONDITION(mWrappedService, "Wrapped service must be initialized before calling GetOriginalBranch"); + + return bDefault ? mWrappedService->GetDefaultBranch(aPrefRoot,_retval) + : mWrappedService->GetBranch (aPrefRoot,_retval); +} + +// nsIPrefService +/* void readUserPrefs (in nsIFile aFile); */ +NS_IMETHODIMP mozApocPrefServiceWrapper::ReadUserPrefs(nsIFile *aFile) +{ + MA_PSW_ENSURE_INITIALIZED(); + return mWrappedService->ReadUserPrefs(aFile); +} + +/* void resetPrefs (); */ +NS_IMETHODIMP mozApocPrefServiceWrapper::ResetPrefs() +{ + MA_PSW_ENSURE_INITIALIZED(); + return mWrappedService->ResetPrefs(); +} + +/* void resetUserPrefs (); */ +NS_IMETHODIMP mozApocPrefServiceWrapper::ResetUserPrefs() +{ + MA_PSW_ENSURE_INITIALIZED(); + return mWrappedService->ResetUserPrefs(); +} + +/* void savePrefFile (in nsIFile aFile); */ +NS_IMETHODIMP mozApocPrefServiceWrapper::SavePrefFile(nsIFile *aFile) +{ + MA_PSW_ENSURE_INITIALIZED(); + return mWrappedService->SavePrefFile(aFile); +} + +/* nsIPrefBranch getBranch (in string aPrefRoot); */ +NS_IMETHODIMP mozApocPrefServiceWrapper::GetBranch(const char *aPrefRoot, nsIPrefBranch **_retval) +{ + MA_PSW_ENSURE_INITIALIZED(); + + if (!aPrefRoot && mUserBranch) + { + NS_ENSURE_ARG_POINTER(_retval); + *_retval = mUserBranch.get(); + NS_ADDREF(*_retval); + return NS_OK; + } + else + return CreateWrappedBranch(aPrefRoot,PR_FALSE,_retval); +} + +/* nsIPrefBranch getDefaultBranch (in string aPrefRoot); */ +NS_IMETHODIMP mozApocPrefServiceWrapper::GetDefaultBranch(const char *aPrefRoot, nsIPrefBranch **_retval) +{ + MA_PSW_ENSURE_INITIALIZED(); + + return CreateWrappedBranch(aPrefRoot,PR_TRUE,_retval); +} + diff --git a/src/mozApocPrefService.h b/src/mozApocPrefService.h new file mode 100644 index 0000000..4e15841 --- /dev/null +++ b/src/mozApocPrefService.h @@ -0,0 +1,99 @@ + + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_PREFSERVICE_H_INCLUDED +#define MOZAPOC_PREFSERVICE_H_INCLUDED + +#include "mozApocPolicyBackend.h" + +#include "nsIPrefService.h" +//Brian #include "nsIPrefBranch.h" +#include "pref/nsIPrefBranchInternal.h" +#include "nsIObserver.h" +#include "nsCOMPtr.h" +#include "nsWeakReference.h" + +class mozApocPolicyData; +class mozApocBranchNotifier; + +// { 833fbe65-5a14-4634-8387-fcf47e24c9ca } +#define MOZAPOC_PREFSERVICEWRAPPER_CID \ +{ 0x833fbe65, 0x5a14, 0x4634, { 0x83, 0x87, 0xfc, 0xf4, 0x7e, 0x24, 0xc9, 0xca } } + +class mozApocPrefServiceWrapper : public nsIPrefService + , public nsIObserver +//Brian , public nsIPrefBranch + , public nsIPrefBranchInternal + , public nsSupportsWeakReference +{ +public: + NS_DECL_ISUPPORTS + + NS_DECL_NSIPREFSERVICE + NS_FORWARD_SAFE_NSIPREFBRANCH(mUserBranch) +#if 0 //Brian++ + NS_FORWARD_SAFE_NSIPREFBRANCHINTERNAL( +#else + NS_FORWARD_SAFE_NSIPREFBRANCH2( +#endif + nsCOMPtr<nsIPrefBranchInternal>(do_QueryInterface(mWrappedService)) + ) // NS_DECL_NSIPREFBRANCHINTERNAL + NS_FORWARD_SAFE_NSIOBSERVER( + nsCOMPtr<nsIObserver>(do_QueryInterface(mWrappedService)) + ) // NS_DECL_NSIOBSERVER + + mozApocPrefServiceWrapper(); + virtual ~mozApocPrefServiceWrapper(); + + nsresult Init(); + +private: + nsresult CreateWrappedBranch(const char *aPrefRoot, PRBool bDefault, nsIPrefBranch **_retval); + nsresult GetOriginalBranch(const char *aPrefRoot, PRBool bDefault, nsIPrefBranch **_retval); + mozApocPolicyData GetPolicyData(const char * aPrefRoot); + + nsresult InitNotifier(); +private: + mozApocPolicyBackend mBackend; + nsCOMPtr<nsIPrefService> mWrappedService; + nsCOMPtr<nsIPrefBranch> mUserBranch; + mozApocBranchNotifier * mNotifier; +}; + +#endif + diff --git a/src/mozApocSaxHandler.h b/src/mozApocSaxHandler.h new file mode 100644 index 0000000..7a6f8e2 --- /dev/null +++ b/src/mozApocSaxHandler.h @@ -0,0 +1,81 @@ + + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_SAXHANDLER_H_INCLUDED +#define MOZAPOC_SAXHANDLER_H_INCLUDED + +//brian #include "nsAFlatString.h" +#include "nsAString.h" + +typedef PRUnichar XML_Char; +typedef nsAFlatString XML_String; + +class mozApocSaxAttributeIterator +{ + XML_Char const * const * m_data; +public: + explicit + mozApocSaxAttributeIterator(XML_Char const * const * data) + : m_data(data) + {} + + PRBool Is() const { return m_data && *m_data; } + + void Next(); + + PRBool IsNamed( XML_String const & LocalName, + XML_String const * NamespaceURI = 0, + PRBool IsNamespaceRequired = PR_FALSE) const; + + XML_Char const * GetLocalName() const; + XML_Char const * GetAttributeValue() const; + + XML_Char const * FindAttributeValue(XML_String const & LocalName, + XML_String const * NamespaceURI = 0, + PRBool IsNamespaceRequired = PR_FALSE) const; +}; + +struct mozApocSaxHandler +{ + virtual void StartElement(XML_String const & Name, XML_String const * NamespaceURI, mozApocSaxAttributeIterator Attributes) = 0; + virtual void EndElement(XML_String const & Name, XML_String const * NamespaceURI) = 0; + virtual void CharacterData(XML_String const & Characters) = 0; +}; + +#endif + diff --git a/src/mozApocSaxWrapper.cpp b/src/mozApocSaxWrapper.cpp new file mode 100644 index 0000000..d11f3f7 --- /dev/null +++ b/src/mozApocSaxWrapper.cpp @@ -0,0 +1,282 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+/* vim:expandtab:shiftwidth=4:tabstop=4:
+ */
+/*
+ *******************************************************************************
+ * $RCSfile: mozApocSaxWrapper.cpp,v $
+ *
+ * Description:
+ *
+ * Last change: $Date: 2006/10/30 05:26:18 $ $Revision: 1.2 $
+ *
+ * Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use of this
+ * product is subject to license terms.
+ *
+ *******************************************************************************
+ * Source Code Control System - Header
+ *
+ * $Header: /export/src/cvs/firefox-apoc-adapter/mozApocSaxWrapper.cpp,v 1.2 2006/10/30 05:26:18 brian Exp $
+ *******************************************************************************
+ */
+
+#include "mozApocSaxWrapper.h"
+
+#include "nsString.h"
+#include "nsDependentString.h"
+#include <stdio.h>
+
+#define MOZAPOC_INDIRECT_HANDLER 0
+
+const XML_Char k_NSSep = XML_Char('|');
+
+static inline
+PRInt32 SplitQName(nsDependentString & Name)
+{
+ PRInt32 SplitIndex = Name.FindChar(k_NSSep);
+
+ Name.Rebind(Name.get() + SplitIndex + 1, Name.get() + Name.Length());
+
+ return SplitIndex;
+}
+
+void mozApocSaxAttributeIterator::Next()
+{
+ NS_PRECONDITION( this->Is(), "apoc - Error: advancing an invalid Sax Attribute Iterator");
+ m_data += 2;
+}
+
+PRBool mozApocSaxAttributeIterator::IsNamed(XML_String const & LocalName,
+ XML_String const * NamespaceURI,
+ PRBool IsNamespaceRequired) const
+{
+ NS_PRECONDITION( this->Is(), "apoc - Error: dereferencing an invalid Sax Attribute Iterator");
+
+ nsDependentString ActualName( *m_data );
+ PRInt32 SplitIndex = SplitQName(ActualName);
+
+ if (!ActualName.Equals(LocalName)) return PR_FALSE;
+
+ if (SplitIndex >= 0) // found namespace
+ {
+ if (NamespaceURI)
+ {
+ nsAutoString FoundURI(*m_data, PRUint32(SplitIndex));
+ return NamespaceURI->Equals(FoundURI);
+ }
+ }
+ else
+ {
+ if (!NamespaceURI)
+ return !PR_TRUE;
+ }
+
+ // one URI is there, the other isn't
+ return !IsNamespaceRequired;
+}
+
+XML_Char const * mozApocSaxAttributeIterator::GetLocalName() const
+{
+ NS_PRECONDITION( this->Is(), "apoc - Error: dereferencing an invalid Sax Attribute Iterator");
+
+ nsDependentString LocalName( *m_data );
+ SplitQName(LocalName);
+ return LocalName.get();
+}
+
+XML_Char const * mozApocSaxAttributeIterator::GetAttributeValue() const
+{
+ NS_PRECONDITION( this->Is(), "apoc - Error: dereferencing an invalid Sax Attribute Iterator");
+
+ return m_data[1];
+}
+
+XML_Char const * mozApocSaxAttributeIterator::FindAttributeValue(XML_String const & LocalName,
+ XML_String const * NamespaceURI,
+ PRBool IsNamespaceRequired) const
+{
+ for (mozApocSaxAttributeIterator it(m_data); it.Is(); it.Next())
+ {
+ if (it.IsNamed(LocalName,NamespaceURI,IsNamespaceRequired))
+ return it.GetAttributeValue();
+ }
+ return nsnull;
+}
+
+
+static
+inline
+mozApocSaxHandler * GetCallbackHandler(void * callbackdata)
+{
+#if MOZAPOC_INDIRECT_HANDLER
+ XML_Parser parser = NS_STATIC_CAST(XML_Parser, callbackdata);
+ NS_ASSERTION(parser,"apoc - Expat passing NULL parser in callback");
+ void * handler = XML_GetUserData(parser);
+#else
+ void * handler = callbackdata;
+#endif
+
+ NS_WARN_IF_FALSE(handler, "apoc - SAX callback invoked without a handler");
+
+ return NS_STATIC_CAST(mozApocSaxHandler *, handler);
+}
+
+nsresult TranslateSaxError(XML_Parser parser)
+{
+ XML_Error errcode = XML_GetErrorCode(parser);
+
+ if (errcode != XML_ERROR_NONE)
+ ::fprintf(stderr, "apoc - SAX Error (Code=%d)\n", int(errcode));
+
+ switch (errcode)
+ {
+ case XML_ERROR_NONE:
+ return NS_OK;
+
+ case XML_ERROR_NO_MEMORY:
+ return NS_ERROR_OUT_OF_MEMORY;
+
+ default:
+ return NS_ERROR_FAILURE;
+ }
+}
+
+static
+//brian int StartElementDispatch(void * callbackdata, const XML_Char * name, const XML_Char ** atts)
+void StartElementDispatch(void * callbackdata, const XML_Char * name, const XML_Char ** atts)
+{
+ mozApocSaxHandler * Handler = GetCallbackHandler(callbackdata);
+ if (Handler)
+ {
+ nsDependentString LocalName(name);
+ PRInt32 LengthNS = SplitQName(LocalName);
+ if (LengthNS >= 0)
+ {
+ nsAutoString NamespaceURI(name,PRUint32(LengthNS));
+ Handler->StartElement( LocalName, &NamespaceURI, mozApocSaxAttributeIterator(atts) );
+ }
+ else
+ Handler->StartElement( LocalName, nsnull, mozApocSaxAttributeIterator(atts) );
+
+ //brian return XML_ERROR_NONE;
+ return ;
+ }
+ else
+ //brian return XML_ERROR_NO_MEMORY;
+ return ;
+}
+
+static
+//brian int EndElementDispatch(void * callbackdata, const XML_Char * name)
+void EndElementDispatch(void * callbackdata, const XML_Char * name)
+{
+ mozApocSaxHandler * Handler = GetCallbackHandler(callbackdata);
+ if (Handler)
+ {
+ nsDependentString LocalName(name);
+ PRInt32 LengthNS = SplitQName(LocalName);
+ if (LengthNS >= 0)
+ {
+ nsAutoString NamespaceURI(name,PRUint32(LengthNS));
+ Handler->EndElement( LocalName, &NamespaceURI );
+ }
+ else
+ Handler->EndElement( LocalName, nsnull );
+
+ //brian return XML_ERROR_NONE;
+ return;
+ }
+ else
+ //brian return XML_ERROR_NO_MEMORY;
+ return;
+}
+
+static
+void CharacterDataDispatch(void * callbackdata, const XML_Char * characters, int len)
+{
+ mozApocSaxHandler * Handler = GetCallbackHandler(callbackdata);
+ if (Handler)
+ {
+ NS_ASSERTION(len >= 0, "apoc - Expat passing negative character count");
+
+ nsAutoString Data(characters, PRUint32(len));
+ Handler->CharacterData( Data );
+ }
+}
+
+mozApocSaxParser::mozApocSaxParser(PRBool bUseNamespaces, const XML_Char * encoding)
+{
+ XML_Char tmp[2];
+ *tmp = k_NSSep;
+
+ if (bUseNamespaces)
+ m_parser = XML_ParserCreate_MM(encoding, NULL,tmp);
+ else
+ m_parser = XML_ParserCreate_MM(encoding,NULL,NULL);
+
+ if (m_parser)
+ {
+#if MOZAPOC_INDIRECT_HANDLER
+ XML_UseParserAsHandlerArg(m_parser);
+#endif
+ XML_SetElementHandler(m_parser, StartElementDispatch, EndElementDispatch);
+ XML_SetCharacterDataHandler(m_parser, CharacterDataDispatch);
+ }
+ else
+ NS_WARNING("apoc - Creating Expat parser failed");
+}
+
+mozApocSaxParser::~mozApocSaxParser()
+{
+ if (m_parser) XML_ParserFree(m_parser);
+}
+
+nsresult mozApocSaxParser::Parse(mozApocSaxHandler & handler, const char * data, PRInt32 len) const
+{
+ if (!m_parser) return NS_ERROR_OUT_OF_MEMORY;
+
+ XML_SetUserData(m_parser, &handler);
+
+ nsresult rv = NS_OK;
+ if (! XML_Parse(m_parser, data, len, PR_TRUE) )
+ rv = TranslateSaxError( m_parser );
+
+ XML_SetUserData(m_parser,0);
+
+ return rv;
+}
+
+
diff --git a/src/mozApocSaxWrapper.h b/src/mozApocSaxWrapper.h new file mode 100644 index 0000000..1affb74 --- /dev/null +++ b/src/mozApocSaxWrapper.h @@ -0,0 +1,65 @@ + + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_SAXWRAPPER_H_INCLUDED +#define MOZAPOC_SAXWRAPPER_H_INCLUDED + +#include "mozApocSaxHandler.h" + +//Brian++ #include "xmlparse.h" +#include "expat/expat_config.h" +#include "expat/expat.h" + +class mozApocSaxParser +{ + XML_Parser m_parser; +public: + explicit + mozApocSaxParser(PRBool bUseNamespaces, const XML_Char * encoding = 0); + ~mozApocSaxParser(); + + nsresult Parse(mozApocSaxHandler & handler, const char * data, PRInt32 len) const; + +private: + // not implemented + mozApocSaxParser(mozApocSaxParser const &); + void operator=(mozApocSaxParser const &); +}; + +#endif + diff --git a/src/mozApocStringList.cpp b/src/mozApocStringList.cpp new file mode 100644 index 0000000..7a4dab8 --- /dev/null +++ b/src/mozApocStringList.cpp @@ -0,0 +1,91 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+/* vim:expandtab:shiftwidth=4:tabstop=4:
+ */
+/*
+ *******************************************************************************
+ * $RCSfile: mozApocStringList.cpp,v $
+ *
+ * Description:
+ *
+ * Last change: $Date: 2006/10/30 03:23:53 $ $Revision: 1.1.1.1 $
+ *
+ * Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use of this
+ * product is subject to license terms.
+ *
+ *******************************************************************************
+ * Source Code Control System - Header
+ *
+ * $Header: /export/src/cvs/firefox-apoc-adapter/mozApocStringList.cpp,v 1.1.1.1 2006/10/30 03:23:53 sunop Exp $
+ *******************************************************************************
+ */
+
+#include "mozApocStringList.h"
+
+mozApocUniqueCStringList::~mozApocUniqueCStringList()
+{
+ nodeType * aNode = mHead;
+ while (aNode)
+ {
+ nodeType * aNext = aNode->mNext;
+ delete aNode;
+ aNode = aNext;
+ }
+}
+
+nsresult mozApocUniqueCStringList::Add(stringType const & aString)
+{
+ nodeType ** pInsertPosition = &mHead;
+ while (*pInsertPosition)
+ {
+ int comp = Compare(aString, (**pInsertPosition).Value());
+
+ if (comp > 0) // continue search
+ pInsertPosition = &(**pInsertPosition).mNext;
+
+ else if (comp == 0) // already in the list
+ return NS_OK;
+
+ else // (comp < 0): insert here
+ break;
+ }
+ nodeType * pNewNode = new nodeType(aString, *pInsertPosition);
+ NS_ENSURE_TRUE(pNewNode, NS_ERROR_OUT_OF_MEMORY);
+
+ *pInsertPosition = pNewNode;
+ return NS_OK;
+}
+
diff --git a/src/mozApocStringList.h b/src/mozApocStringList.h new file mode 100644 index 0000000..85d21cb --- /dev/null +++ b/src/mozApocStringList.h @@ -0,0 +1,88 @@ + + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + + +#ifndef MOZAPOC_STRINGLIST_H_INCLUDED +#define MOZAPOC_STRINGLIST_H_INCLUDED + +#include "nsString.h" + +class mozApocCStringListNode +{ + friend class mozApocUniqueCStringList; + nsCString mValue; + mozApocCStringListNode * mNext; +public: + typedef nsACString stringType; + + explicit + mozApocCStringListNode(stringType const & aValue, mozApocCStringListNode * aNext = nsnull) + : mValue(aValue) + , mNext(aNext) + {} + + mozApocCStringListNode const * Next() const { return mNext; } + stringType const & Value() const { return mValue; } +}; + +class mozApocUniqueCStringList +{ + typedef mozApocCStringListNode nodeType; + nodeType * mHead; +public: + typedef nodeType const * iterator; + typedef nodeType::stringType stringType; + +public: + explicit + mozApocUniqueCStringList() + : mHead(nsnull) + { + } + + ~mozApocUniqueCStringList(); + + nsresult Add(stringType const & aString); + + iterator Iterate() const { return mHead; } +private: + mozApocUniqueCStringList(const mozApocUniqueCStringList&); + void operator=(const mozApocUniqueCStringList&); +}; + +#endif + diff --git a/src/mozApocXML.h b/src/mozApocXML.h new file mode 100644 index 0000000..7fd1bf4 --- /dev/null +++ b/src/mozApocXML.h @@ -0,0 +1,60 @@ +
+
+/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ +
+
+#ifndef MOZAPOC_XML_H_INCLUDED
+#define MOZAPOC_XML_H_INCLUDED
+
+#define k_mozApocXMLNamespaceOOR "http://openoffice.org/2001/registry"
+#define k_mozApocXMLTagRoot "component-data"
+#define k_mozApocXMLTagNode "node"
+#define k_mozApocXMLTagProp "prop"
+#define k_mozApocXMLTagValue "value"
+#define k_mozApocXMLAttributeName "name"
+#define k_mozApocXMLAttributeType "type"
+#define k_mozApocXMLAttributeFinalized "finalized"
+#define k_mozApocXMLAttributeMandatory "mandatory"
+#define k_mozApocXMLAttributeLanguage "xml:lang"
+
+#define k_mozApocXMLTypeValueString "xs:string"
+#define k_mozApocXMLTypeValueShort "xs:short"
+#define k_mozApocXMLTypeValueInt "xs:int"
+#define k_mozApocXMLTypeValueBool "xs:bool"
+#define k_mozApocXMLTypeValueBinary "oor:binary"
+
+#endif
+
diff --git a/src/papi/papi.h b/src/papi/papi.h new file mode 100644 index 0000000..1bdc157 --- /dev/null +++ b/src/papi/papi.h @@ -0,0 +1,137 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + +/* papi.h - Policy Access API */ + +#ifndef PAPI_H_ +#define PAPI_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "papiTypes.h" + +#ifdef WIN32 +#ifdef PAPI_EXPORTS +#define PAPI_API __declspec(dllexport) +#else +#define PAPI_API __declspec(dllimport) +#endif +#else +#define PAPI_API +#endif + +/* Main PAPI functions */ + +/* + * Obtain a new PAPI handle for the specified entity + * Specifying inEntityId=NULL will result in the entity id being calculated + * from the current user id. + */ +PAPI_API PAPI * papiInitialise( const char * inEntityId, + PAPIStatus * outStatus ); + +/* + * Invalidate and free all resoures associated with a PAPI handle + * previously returned by papiInitialise() + */ +PAPI_API void papiDeinitialise( PAPI * inPAPI, PAPIStatus * outStatus ); + +/* + * Retrieve all layers for a specified component + * Returns a PAPILayerList ( See papiTypes.h ) ordered according to mergepath + * + * The caller must "free" the returned PAPILayerList using papiFreeLayerList() + */ +PAPI_API PAPILayerList * papiReadComponentLayers( const PAPI * inPAPI, + const char * inComponentName, + PAPIStatus * outStatus ); + +/* + * List all available components which comply with the specified filter + * Returns a PAPIStringList ( See papiTypes.h ) + * + * The caller must "free" the returned PAPIStringList using papiFreeStringList() + * + * TBD: specify the supported filter syntax + */ +PAPI_API PAPIStringList * papiListComponentNames( const PAPI * inPAPI, + const char * inFilter, + PAPIStatus * outStatus ); + +/* + * Mark the specified component as offline or online + */ +PAPI_API void papiSetOffline( const PAPI * inPAPI, + const char * inComponentName, + int inOffline, + PAPIStatus * outStatus ); + +/* + * Query the online/offline status of a specified component + */ +PAPI_API int papiIsOffline( const PAPI * inPAPI, + const char * inComponentName, + int * outIsOffline, + PAPIStatus * outStatus ); + +/* + * Add a listener for changes to the specified component + */ +PAPI_API PAPIListenerId papiAddListener( const PAPI * inPAPI, + const char * inComponentName, + PAPIListener inListener, + void * inUserData, + PAPIStatus * outStatus ); + +/* + * Remove a listener previously added by papiAddListener() + */ +PAPI_API void papiRemoveListener( const PAPI * inPAPI, + PAPIListenerId inListenerId, + PAPIStatus * outStatus ); + +/* + * Free all resources associated with the specified list + */ +PAPI_API void papiFreeLayerList( PAPILayerList * inList ); +PAPI_API void papiFreeStringList( PAPIStringList * inList ); + +#ifdef __cplusplus +} +#endif + +#endif /* PAPI_H_ */ diff --git a/src/papi/papiTypes.h b/src/papi/papiTypes.h new file mode 100644 index 0000000..31990fb --- /dev/null +++ b/src/papi/papiTypes.h @@ -0,0 +1,91 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + +/* papiTypes.h - Policy Access API types */ + +#ifndef PAPITYPES_H_ +#define PAPITYPES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* opaque PAPI session handle */ +typedef struct PAPI PAPI; + +/* Status returned by PAPI functions */ +typedef enum { PAPISuccess = 0, + PAPIConnectionFailure, + PAPIAuthenticationFailure, + PAPINoSuchComponentFailure, + PAPILDBFailure, + PAPIInvalidArg, + PAPIOutOfMemoryFailure, + PAPIUnknownFailure } PAPIStatus; + +/* Notification stuff */ +typedef enum { PAPIComponentAdd, + PAPIComponentModify, + PAPIComponentRemove } PAPIEventType; + +typedef struct { + PAPIEventType eventType; + const char * componentName; +} PAPIEvent; + +typedef void ( *PAPIListener )( const PAPIEvent * inEvent, void * inUserData ); + +typedef void * PAPIListenerId; + +/* Layer stuff */ +typedef struct PAPILayerList +{ + const unsigned char * data; + int size; + const char * timestamp; + struct PAPILayerList * next; +} PAPILayerList; + +typedef struct PAPIStringList +{ + const char * data; + struct PAPIStringList * next; +} PAPIStringList; + +#ifdef __cplusplus +} +#endif + +#endif /* PAPITYPES_H_ */ diff --git a/src/papi/papidecl.h b/src/papi/papidecl.h new file mode 100644 index 0000000..52a930e --- /dev/null +++ b/src/papi/papidecl.h @@ -0,0 +1,115 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + +/* papidecl.h - Policy Access API library function declaration helper */ + +#ifndef PAPI_DECLARATION +#error Must #define PAPI_DECLARATION( resulttype, functionname, parameterlist ) before including papidecl.h +#endif + +/* PAPI functions */ + +/* don't include offline interface, unless requested */ +#ifndef PAPI_OFFLINE_CONTROL +#define PAPI_OFFLINE_CONTROL 0 +#endif + +/* Main PAPI functions */ + +/* + * Obtain a new PAPI handle for the specified entity + * Specifying inEntityId=NULL will result in the entity id being calculated + * from the current user id. + */ +PAPI_DECLARATION( PAPI *, papiInitialise, (const char * inEntityId, PAPIStatus * outStatus) ) + +/* + * Invalidate and free all resoures associated with a PAPI handle + * previously returned by papiInitialise() + */ +PAPI_DECLARATION( void, papiDeinitialise, (PAPI * inPAPI, PAPIStatus * outStatus) ) + +/* + * Retrieve all layers for a specified component + * Returns a PAPILayerList ( See papiTypes.h ) ordered according to mergepath + * + * The caller must "free" the returned PAPILayerList using papiFreeLayerList() + */ +PAPI_DECLARATION( PAPILayerList *, papiReadComponentLayers, + (const PAPI * inPAPI, const char * inComponentName, PAPIStatus * outStatus) ) + +/* + * List all available components which comply with the specified filter + * Returns a PAPIStringList ( See papiTypes.h ) + * + * The caller must "free" the returned PAPIStringList using papiFreeStringList() + * + * TBD: specify the supported filter syntax + */ +PAPI_DECLARATION( PAPIStringList *, papiListComponentNames, + (const PAPI * inPAPI, const char * inFilter, PAPIStatus * outStatus) ) + +#if PAPI_OFFLINE_CONTROL +/* + * Mark the specified component as offline or online + */ +PAPI_DECLARATION( void, papiSetOffline, + (const PAPI * inPAPI, const char * inComponentName, int inOffline, PAPIStatus * outStatus) ) + +/* + * Query the online/offline status of a specified component + */ +PAPI_DECLARATION( int, papiIsOffline, + (const PAPI * inPAPI, const char * inComponentName, int * outOffline, PAPIStatus * outStatus) ) +#endif + +/* + * Add a listener for changes to the specified component + */ +PAPI_DECLARATION( PAPIListenerId, papiAddListener, + ( const PAPI * inPAPI, const char * inComponentName, + PAPIListener inListener, void * inUserData, PAPIStatus * outStatus) ) + +/* + * Remove a listener previously added by papiAddListener() + */ +PAPI_DECLARATION( void, papiRemoveListener, ( const PAPI * inPAPI, PAPIListenerId inListenerId, PAPIStatus * outStatus) ) + +/* + * Free all resources associated with the specified list + */ +PAPI_DECLARATION( void, papiFreeLayerList, ( PAPILayerList * inList ) ) +PAPI_DECLARATION( void, papiFreeStringList, ( PAPIStringList * inList ) ) + diff --git a/src/papi/papilib.c b/src/papi/papilib.c new file mode 100644 index 0000000..1b0888b --- /dev/null +++ b/src/papi/papilib.c @@ -0,0 +1,133 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + +/* papilib.c - Policy Access API library stub implementations */ + +#include "papilib.h" + +/* declare stub functions for all interfaces */ +#define PAPI_DECLARATION( resulttype, functionname, parameterlist ) \ + static resulttype functionname ## Stub parameterlist; + +#include "papidecl.h" +#undef PAPI_DECLARATION + +/* define the global PAPILib instance */ +struct PAPILib gPAPILib = +{ +/* initialize function pointers for all interfaces to the stub functions */ +#define PAPI_DECLARATION( resulttype, functionname, parameterlist ) \ + functionname ## Stub, + +#include "papidecl.h" +#undef PAPI_DECLARATION + + 0 /* no module */ +}; + + +/* Initialize/deinitialize PAPI functions */ + +/* Provided by the context: */ +int PAPILib_loadLibrary(struct PAPILib * libdata); + +/* + * Load the PAPI functions if not yet done + */ +static PAPI * papiInitialiseStub(const char * inEntityId, PAPIStatus * outStatus) +{ + if (!PAPILib_loadLibrary(&gPAPILib)) + { + if (outStatus) *outStatus = PAPIConnectionFailure; + return 0; + } + + return gPAPILib.papiInitialise(inEntityId,outStatus); +} + +/* + * Invalidate and free all resoures associated with a PAPI handle + * previously returned by papiInitialise() + */ +static void papiDeinitialiseStub(PAPI * , PAPIStatus * outStatus) +{ + if (outStatus) *outStatus = PAPIConnectionFailure; +} + +/* other PAPI functions - empty stubs */ +static PAPILayerList * papiReadComponentLayersStub(const PAPI * , const char * , PAPIStatus * outStatus) +{ + if (outStatus) *outStatus = PAPIConnectionFailure; + return 0; +} + +static PAPIStringList * papiListComponentNamesStub(const PAPI * , const char * , PAPIStatus * outStatus) +{ + if (outStatus) *outStatus = PAPIConnectionFailure; + return 0; +} + +#if PAPI_OFFLINE_CONTROL +static void papiSetOfflineStub(const PAPI * , const char * , int , PAPIStatus * outStatus) +{ + if (outStatus) *outStatus = PAPIConnectionFailure; +} + +static int papiIsOfflineStub(const PAPI * , const char * , int * , PAPIStatus * outStatus) +{ + if (outStatus) *outStatus = PAPIConnectionFailure; + return 0; +} +#endif + +static PAPIListenerId papiAddListenerStub( const PAPI * , const char * , PAPIListener , void * , PAPIStatus * outStatus) +{ + if (outStatus) *outStatus = PAPIConnectionFailure; + + return 0; +} + +static void papiRemoveListenerStub( const PAPI * , PAPIListenerId , PAPIStatus * outStatus) +{ + if (outStatus) *outStatus = PAPIConnectionFailure; +} + +static void papiFreeLayerListStub( PAPILayerList * ) +{} + +static void papiFreeStringListStub( PAPIStringList * ) +{} + + diff --git a/src/papi/papilib.h b/src/papi/papilib.h new file mode 100644 index 0000000..038be26 --- /dev/null +++ b/src/papi/papilib.h @@ -0,0 +1,81 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + +/* papilib.h - Policy Access API library stub declarations */ + +#ifndef PAPILIB_H_ +#define PAPILIB_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "papiTypes.h" + +/* define function pointer types for all interfaces */ +#define PAPI_DECLARATION( resulttype, functionname, parameterlist ) \ + typedef resulttype (* functionname ## Ptr) parameterlist; + +#include "papidecl.h" +#undef PAPI_DECLARATION + +/* structure uniting all entry points */ +struct PAPILib +{ +/* declare function pointers for all interfaces */ +#define PAPI_DECLARATION( resulttype, functionname, parameterlist ) \ + functionname ## Ptr functionname; + +#include "papidecl.h" +#undef PAPI_DECLARATION + + void * module_; +}; + +extern struct PAPILib gPAPILib; + +/* + * The following needs to be provided by the context + + int PAPILib_loadLibrary(struct PAPILib * libdata); + + */ + +#ifdef __cplusplus +} +#endif + +#endif /* PAPILIB_H_ */ + |