pax_global_header00006660000000000000000000000064121562260410014511gustar00rootroot0000000000000052 comment=1ce26d949835c3aa284f8d34d4bcba812632fc5b scscp-imcce-1.0.0+ds/000077500000000000000000000000001215622604100143025ustar00rootroot00000000000000scscp-imcce-1.0.0+ds/AUTHORS000066400000000000000000000000471215622604100153530ustar00rootroot00000000000000Mickael Gastineau scscp-imcce-1.0.0+ds/COPYING_CECILL_C.LIB000066400000000000000000000525471215622604100172340ustar00rootroot00000000000000 CeCILL-C FREE SOFTWARE LICENSE AGREEMENT Notice This Agreement is a Free Software license agreement that is the result of discussions between its authors in order to ensure compliance with the two main principles guiding its drafting: * firstly, compliance with the principles governing the distribution of Free Software: access to source code, broad rights granted to users, * secondly, the election of a governing law, French law, with which it is conformant, both as regards the law of torts and intellectual property law, and the protection that it offers to both authors and holders of the economic rights over software. The authors of the CeCILL-C (for Ce[a] C[nrs] I[nria] L[ogiciel] L[ibre]) license are: Commissariat à l'Energie Atomique - CEA, a public scientific, technical and industrial research establishment, having its principal place of business at 25 rue Leblanc, immeuble Le Ponant D, 75015 Paris, France. Centre National de la Recherche Scientifique - CNRS, a public scientific and technological establishment, having its principal place of business at 3 rue Michel-Ange, 75794 Paris cedex 16, France. Institut National de Recherche en Informatique et en Automatique - INRIA, a public scientific and technological establishment, having its principal place of business at Domaine de Voluceau, Rocquencourt, BP 105, 78153 Le Chesnay cedex, France. Preamble The purpose of this Free Software license agreement is to grant users the right to modify and re-use the software governed by this license. The exercising of this right is conditional upon the obligation to make available to the community the modifications made to the source code of the software so as to contribute to its evolution. In consideration of access to the source code and the rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors only have limited liability. In this respect, the risks associated with loading, using, modifying and/or developing or reproducing the software by the user are brought to the user's attention, given its Free Software status, which may make it complicated to use, with the result that its use is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the suitability of the software as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions of security. This Agreement may be freely reproduced and published, provided it is not altered, and that no provisions are either added or removed herefrom. This Agreement may apply to any or all software for which the holder of the economic rights decides to submit the use thereof to its provisions. Article 1 - DEFINITIONS For the purpose of this Agreement, when the following expressions commence with a capital letter, they shall have the following meaning: Agreement: means this license agreement, and its possible subsequent versions and annexes. Software: means the software in its Object Code and/or Source Code form and, where applicable, its documentation, "as is" when the Licensee accepts the Agreement. Initial Software: means the Software in its Source Code and possibly its Object Code form and, where applicable, its documentation, "as is" when it is first distributed under the terms and conditions of the Agreement. Modified Software: means the Software modified by at least one Integrated Contribution. Source Code: means all the Software's instructions and program lines to which access is required so as to modify the Software. Object Code: means the binary files originating from the compilation of the Source Code. Holder: means the holder(s) of the economic rights over the Initial Software. Licensee: means the Software user(s) having accepted the Agreement. Contributor: means a Licensee having made at least one Integrated Contribution. Licensor: means the Holder, or any other individual or legal entity, who distributes the Software under the Agreement. Integrated Contribution: means any or all modifications, corrections, translations, adaptations and/or new functions integrated into the Source Code by any or all Contributors. Related Module: means a set of sources files including their documentation that, without modification to the Source Code, enables supplementary functions or services in addition to those offered by the Software. Derivative Software: means any combination of the Software, modified or not, and of a Related Module. Parties: mean both the Licensee and the Licensor. These expressions may be used both in singular and plural form. Article 2 - PURPOSE The purpose of the Agreement is the grant by the Licensor to the Licensee of a non-exclusive, transferable and worldwide license for the Software as set forth in Article 5 hereinafter for the whole term of the protection granted by the rights over said Software. Article 3 - ACCEPTANCE 3.1 The Licensee shall be deemed as having accepted the terms and conditions of this Agreement upon the occurrence of the first of the following events: * (i) loading the Software by any or all means, notably, by downloading from a remote server, or by loading from a physical medium; * (ii) the first time the Licensee exercises any of the rights granted hereunder. 3.2 One copy of the Agreement, containing a notice relating to the characteristics of the Software, to the limited warranty, and to the fact that its use is restricted to experienced users has been provided to the Licensee prior to its acceptance as set forth in Article 3.1 hereinabove, and the Licensee hereby acknowledges that it has read and understood it. Article 4 - EFFECTIVE DATE AND TERM 4.1 EFFECTIVE DATE The Agreement shall become effective on the date when it is accepted by the Licensee as set forth in Article 3.1. 4.2 TERM The Agreement shall remain in force for the entire legal term of protection of the economic rights over the Software. Article 5 - SCOPE OF RIGHTS GRANTED The Licensor hereby grants to the Licensee, who accepts, the following rights over the Software for any or all use, and for the term of the Agreement, on the basis of the terms and conditions set forth hereinafter. Besides, if the Licensor owns or comes to own one or more patents protecting all or part of the functions of the Software or of its components, the Licensor undertakes not to enforce the rights granted by these patents against successive Licensees using, exploiting or modifying the Software. If these patents are transferred, the Licensor undertakes to have the transferees subscribe to the obligations set forth in this paragraph. 5.1 RIGHT OF USE The Licensee is authorized to use the Software, without any limitation as to its fields of application, with it being hereinafter specified that this comprises: 1. permanent or temporary reproduction of all or part of the Software by any or all means and in any or all form. 2. loading, displaying, running, or storing the Software on any or all medium. 3. entitlement to observe, study or test its operation so as to determine the ideas and principles behind any or all constituent elements of said Software. This shall apply when the Licensee carries out any or all loading, displaying, running, transmission or storage operation as regards the Software, that it is entitled to carry out hereunder. 5.2 RIGHT OF MODIFICATION The right of modification includes the right to translate, adapt, arrange, or make any or all modifications to the Software, and the right to reproduce the resulting software. It includes, in particular, the right to create a Derivative Software. The Licensee is authorized to make any or all modification to the Software provided that it includes an explicit notice that it is the author of said modification and indicates the date of the creation thereof. 5.3 RIGHT OF DISTRIBUTION In particular, the right of distribution includes the right to publish, transmit and communicate the Software to the general public on any or all medium, and by any or all means, and the right to market, either in consideration of a fee, or free of charge, one or more copies of the Software by any means. The Licensee is further authorized to distribute copies of the modified or unmodified Software to third parties according to the terms and conditions set forth hereinafter. 5.3.1 DISTRIBUTION OF SOFTWARE WITHOUT MODIFICATION The Licensee is authorized to distribute true copies of the Software in Source Code or Object Code form, provided that said distribution complies with all the provisions of the Agreement and is accompanied by: 1. a copy of the Agreement, 2. a notice relating to the limitation of both the Licensor's warranty and liability as set forth in Articles 8 and 9, and that, in the event that only the Object Code of the Software is redistributed, the Licensee allows effective access to the full Source Code of the Software at a minimum during the entire period of its distribution of the Software, it being understood that the additional cost of acquiring the Source Code shall not exceed the cost of transferring the data. 5.3.2 DISTRIBUTION OF MODIFIED SOFTWARE When the Licensee makes an Integrated Contribution to the Software, the terms and conditions for the distribution of the resulting Modified Software become subject to all the provisions of this Agreement. The Licensee is authorized to distribute the Modified Software, in source code or object code form, provided that said distribution complies with all the provisions of the Agreement and is accompanied by: 1. a copy of the Agreement, 2. a notice relating to the limitation of both the Licensor's warranty and liability as set forth in Articles 8 and 9, and that, in the event that only the object code of the Modified Software is redistributed, the Licensee allows effective access to the full source code of the Modified Software at a minimum during the entire period of its distribution of the Modified Software, it being understood that the additional cost of acquiring the source code shall not exceed the cost of transferring the data. 5.3.3 DISTRIBUTION OF DERIVATIVE SOFTWARE When the Licensee creates Derivative Software, this Derivative Software may be distributed under a license agreement other than this Agreement, subject to compliance with the requirement to include a notice concerning the rights over the Software as defined in Article 6.4. In the event the creation of the Derivative Software required modification of the Source Code, the Licensee undertakes that: 1. the resulting Modified Software will be governed by this Agreement, 2. the Integrated Contributions in the resulting Modified Software will be clearly identified and documented, 3. the Licensee will allow effective access to the source code of the Modified Software, at a minimum during the entire period of distribution of the Derivative Software, such that such modifications may be carried over in a subsequent version of the Software; it being understood that the additional cost of purchasing the source code of the Modified Software shall not exceed the cost of transferring the data. 5.3.4 COMPATIBILITY WITH THE CeCILL LICENSE When a Modified Software contains an Integrated Contribution subject to the CeCILL license agreement, or when a Derivative Software contains a Related Module subject to the CeCILL license agreement, the provisions set forth in the third item of Article 6.4 are optional. Article 6 - INTELLECTUAL PROPERTY 6.1 OVER THE INITIAL SOFTWARE The Holder owns the economic rights over the Initial Software. Any or all use of the Initial Software is subject to compliance with the terms and conditions under which the Holder has elected to distribute its work and no one shall be entitled to modify the terms and conditions for the distribution of said Initial Software. The Holder undertakes that the Initial Software will remain ruled at least by this Agreement, for the duration set forth in Article 4.2. 6.2 OVER THE INTEGRATED CONTRIBUTIONS The Licensee who develops an Integrated Contribution is the owner of the intellectual property rights over this Contribution as defined by applicable law. 6.3 OVER THE RELATED MODULES The Licensee who develops a Related Module is the owner of the intellectual property rights over this Related Module as defined by applicable law and is free to choose the type of agreement that shall govern its distribution under the conditions defined in Article 5.3.3. 6.4 NOTICE OF RIGHTS The Licensee expressly undertakes: 1. not to remove, or modify, in any manner, the intellectual property notices attached to the Software; 2. to reproduce said notices, in an identical manner, in the copies of the Software modified or not; 3. to ensure that use of the Software, its intellectual property notices and the fact that it is governed by the Agreement is indicated in a text that is easily accessible, specifically from the interface of any Derivative Software. The Licensee undertakes not to directly or indirectly infringe the intellectual property rights of the Holder and/or Contributors on the Software and to take, where applicable, vis-à-vis its staff, any and all measures required to ensure respect of said intellectual property rights of the Holder and/or Contributors. Article 7 - RELATED SERVICES 7.1 Under no circumstances shall the Agreement oblige the Licensor to provide technical assistance or maintenance services for the Software. However, the Licensor is entitled to offer this type of services. The terms and conditions of such technical assistance, and/or such maintenance, shall be set forth in a separate instrument. Only the Licensor offering said maintenance and/or technical assistance services shall incur liability therefor. 7.2 Similarly, any Licensor is entitled to offer to its licensees, under its sole responsibility, a warranty, that shall only be binding upon itself, for the redistribution of the Software and/or the Modified Software, under terms and conditions that it is free to decide. Said warranty, and the financial terms and conditions of its application, shall be subject of a separate instrument executed between the Licensor and the Licensee. Article 8 - LIABILITY 8.1 Subject to the provisions of Article 8.2, the Licensee shall be entitled to claim compensation for any direct loss it may have suffered from the Software as a result of a fault on the part of the relevant Licensor, subject to providing evidence thereof. 8.2 The Licensor's liability is limited to the commitments made under this Agreement and shall not be incurred as a result of in particular: (i) loss due the Licensee's total or partial failure to fulfill its obligations, (ii) direct or consequential loss that is suffered by the Licensee due to the use or performance of the Software, and (iii) more generally, any consequential loss. In particular the Parties expressly agree that any or all pecuniary or business loss (i.e. loss of data, loss of profits, operating loss, loss of customers or orders, opportunity cost, any disturbance to business activities) or any or all legal proceedings instituted against the Licensee by a third party, shall constitute consequential loss and shall not provide entitlement to any or all compensation from the Licensor. Article 9 - WARRANTY 9.1 The Licensee acknowledges that the scientific and technical state-of-the-art when the Software was distributed did not enable all possible uses to be tested and verified, nor for the presence of possible defects to be detected. In this respect, the Licensee's attention has been drawn to the risks associated with loading, using, modifying and/or developing and reproducing the Software which are reserved for experienced users. The Licensee shall be responsible for verifying, by any or all means, the suitability of the product for its requirements, its good working order, and for ensuring that it shall not cause damage to either persons or properties. 9.2 The Licensor hereby represents, in good faith, that it is entitled to grant all the rights over the Software (including in particular the rights set forth in Article 5). 9.3 The Licensee acknowledges that the Software is supplied "as is" by the Licensor without any other express or tacit warranty, other than that provided for in Article 9.2 and, in particular, without any warranty as to its commercial value, its secured, safe, innovative or relevant nature. Specifically, the Licensor does not warrant that the Software is free from any error, that it will operate without interruption, that it will be compatible with the Licensee's own equipment and software configuration, nor that it will meet the Licensee's requirements. 9.4 The Licensor does not either expressly or tacitly warrant that the Software does not infringe any third party intellectual property right relating to a patent, software or any other property right. Therefore, the Licensor disclaims any and all liability towards the Licensee arising out of any or all proceedings for infringement that may be instituted in respect of the use, modification and redistribution of the Software. Nevertheless, should such proceedings be instituted against the Licensee, the Licensor shall provide it with technical and legal assistance for its defense. Such technical and legal assistance shall be decided on a case-by-case basis between the relevant Licensor and the Licensee pursuant to a memorandum of understanding. The Licensor disclaims any and all liability as regards the Licensee's use of the name of the Software. No warranty is given as regards the existence of prior rights over the name of the Software or as regards the existence of a trademark. Article 10 - TERMINATION 10.1 In the event of a breach by the Licensee of its obligations hereunder, the Licensor may automatically terminate this Agreement thirty (30) days after notice has been sent to the Licensee and has remained ineffective. 10.2 A Licensee whose Agreement is terminated shall no longer be authorized to use, modify or distribute the Software. However, any licenses that it may have granted prior to termination of the Agreement shall remain valid subject to their having been granted in compliance with the terms and conditions hereof. Article 11 - MISCELLANEOUS 11.1 EXCUSABLE EVENTS Neither Party shall be liable for any or all delay, or failure to perform the Agreement, that may be attributable to an event of force majeure, an act of God or an outside cause, such as defective functioning or interruptions of the electricity or telecommunications networks, network paralysis following a virus attack, intervention by government authorities, natural disasters, water damage, earthquakes, fire, explosions, strikes and labor unrest, war, etc. 11.2 Any failure by either Party, on one or more occasions, to invoke one or more of the provisions hereof, shall under no circumstances be interpreted as being a waiver by the interested Party of its right to invoke said provision(s) subsequently. 11.3 The Agreement cancels and replaces any or all previous agreements, whether written or oral, between the Parties and having the same purpose, and constitutes the entirety of the agreement between said Parties concerning said purpose. No supplement or modification to the terms and conditions hereof shall be effective as between the Parties unless it is made in writing and signed by their duly authorized representatives. 11.4 In the event that one or more of the provisions hereof were to conflict with a current or future applicable act or legislative text, said act or legislative text shall prevail, and the Parties shall make the necessary amendments so as to comply with said act or legislative text. All other provisions shall remain effective. Similarly, invalidity of a provision of the Agreement, for any reason whatsoever, shall not cause the Agreement as a whole to be invalid. 11.5 LANGUAGE The Agreement is drafted in both French and English and both versions are deemed authentic. Article 12 - NEW VERSIONS OF THE AGREEMENT 12.1 Any person is authorized to duplicate and distribute copies of this Agreement. 12.2 So as to ensure coherence, the wording of this Agreement is protected and may only be modified by the authors of the License, who reserve the right to periodically publish updates or new versions of the Agreement, each with a separate number. These subsequent versions may address new issues encountered by Free Software. 12.3 Any Software distributed under a given version of the Agreement may only be subsequently distributed under the same version of the Agreement or a subsequent version. Article 13 - GOVERNING LAW AND JURISDICTION 13.1 The Agreement is governed by French law. The Parties agree to endeavor to seek an amicable solution to any disagreements or disputes that may arise during the performance of the Agreement. 13.2 Failing an amicable solution within two (2) months as from their occurrence, and unless emergency proceedings are necessary, the disagreements or disputes shall be referred to the Paris Courts having jurisdiction, by the more diligent Party. Version 1.0 dated 2006-09-05. scscp-imcce-1.0.0+ds/COPYING_CECILL_V2.LIB000066400000000000000000000511551215622604100173330ustar00rootroot00000000000000 CeCILL FREE SOFTWARE LICENSE AGREEMENT Notice This Agreement is a Free Software license agreement that is the result of discussions between its authors in order to ensure compliance with the two main principles guiding its drafting: * firstly, compliance with the principles governing the distribution of Free Software: access to source code, broad rights granted to users, * secondly, the election of a governing law, French law, with which it is conformant, both as regards the law of torts and intellectual property law, and the protection that it offers to both authors and holders of the economic rights over software. The authors of the CeCILL (for Ce[a] C[nrs] I[nria] L[ogiciel] L[ibre]) license are: Commissariat à l'Energie Atomique - CEA, a public scientific, technical and industrial research establishment, having its principal place of business at 25 rue Leblanc, immeuble Le Ponant D, 75015 Paris, France. Centre National de la Recherche Scientifique - CNRS, a public scientific and technological establishment, having its principal place of business at 3 rue Michel-Ange, 75794 Paris cedex 16, France. Institut National de Recherche en Informatique et en Automatique - INRIA, a public scientific and technological establishment, having its principal place of business at Domaine de Voluceau, Rocquencourt, BP 105, 78153 Le Chesnay cedex, France. Preamble The purpose of this Free Software license agreement is to grant users the right to modify and redistribute the software governed by this license within the framework of an open source distribution model. The exercising of these rights is conditional upon certain obligations for users so as to preserve this status for all subsequent redistributions. In consideration of access to the source code and the rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors only have limited liability. In this respect, the risks associated with loading, using, modifying and/or developing or reproducing the software by the user are brought to the user's attention, given its Free Software status, which may make it complicated to use, with the result that its use is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the suitability of the software as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions of security. This Agreement may be freely reproduced and published, provided it is not altered, and that no provisions are either added or removed herefrom. This Agreement may apply to any or all software for which the holder of the economic rights decides to submit the use thereof to its provisions. Article 1 - DEFINITIONS For the purpose of this Agreement, when the following expressions commence with a capital letter, they shall have the following meaning: Agreement: means this license agreement, and its possible subsequent versions and annexes. Software: means the software in its Object Code and/or Source Code form and, where applicable, its documentation, "as is" when the Licensee accepts the Agreement. Initial Software: means the Software in its Source Code and possibly its Object Code form and, where applicable, its documentation, "as is" when it is first distributed under the terms and conditions of the Agreement. Modified Software: means the Software modified by at least one Contribution. Source Code: means all the Software's instructions and program lines to which access is required so as to modify the Software. Object Code: means the binary files originating from the compilation of the Source Code. Holder: means the holder(s) of the economic rights over the Initial Software. Licensee: means the Software user(s) having accepted the Agreement. Contributor: means a Licensee having made at least one Contribution. Licensor: means the Holder, or any other individual or legal entity, who distributes the Software under the Agreement. Contribution: means any or all modifications, corrections, translations, adaptations and/or new functions integrated into the Software by any or all Contributors, as well as any or all Internal Modules. Module: means a set of sources files including their documentation that enables supplementary functions or services in addition to those offered by the Software. External Module: means any or all Modules, not derived from the Software, so that this Module and the Software run in separate address spaces, with one calling the other when they are run. Internal Module: means any or all Module, connected to the Software so that they both execute in the same address space. GNU GPL: means the GNU General Public License version 2 or any subsequent version, as published by the Free Software Foundation Inc. Parties: mean both the Licensee and the Licensor. These expressions may be used both in singular and plural form. Article 2 - PURPOSE The purpose of the Agreement is the grant by the Licensor to the Licensee of a non-exclusive, transferable and worldwide license for the Software as set forth in Article 5 hereinafter for the whole term of the protection granted by the rights over said Software. Article 3 - ACCEPTANCE 3.1 The Licensee shall be deemed as having accepted the terms and conditions of this Agreement upon the occurrence of the first of the following events: * (i) loading the Software by any or all means, notably, by downloading from a remote server, or by loading from a physical medium; * (ii) the first time the Licensee exercises any of the rights granted hereunder. 3.2 One copy of the Agreement, containing a notice relating to the characteristics of the Software, to the limited warranty, and to the fact that its use is restricted to experienced users has been provided to the Licensee prior to its acceptance as set forth in Article 3.1 hereinabove, and the Licensee hereby acknowledges that it has read and understood it. Article 4 - EFFECTIVE DATE AND TERM 4.1 EFFECTIVE DATE The Agreement shall become effective on the date when it is accepted by the Licensee as set forth in Article 3.1. 4.2 TERM The Agreement shall remain in force for the entire legal term of protection of the economic rights over the Software. Article 5 - SCOPE OF RIGHTS GRANTED The Licensor hereby grants to the Licensee, who accepts, the following rights over the Software for any or all use, and for the term of the Agreement, on the basis of the terms and conditions set forth hereinafter. Besides, if the Licensor owns or comes to own one or more patents protecting all or part of the functions of the Software or of its components, the Licensor undertakes not to enforce the rights granted by these patents against successive Licensees using, exploiting or modifying the Software. If these patents are transferred, the Licensor undertakes to have the transferees subscribe to the obligations set forth in this paragraph. 5.1 RIGHT OF USE The Licensee is authorized to use the Software, without any limitation as to its fields of application, with it being hereinafter specified that this comprises: 1. permanent or temporary reproduction of all or part of the Software by any or all means and in any or all form. 2. loading, displaying, running, or storing the Software on any or all medium. 3. entitlement to observe, study or test its operation so as to determine the ideas and principles behind any or all constituent elements of said Software. This shall apply when the Licensee carries out any or all loading, displaying, running, transmission or storage operation as regards the Software, that it is entitled to carry out hereunder. 5.2 ENTITLEMENT TO MAKE CONTRIBUTIONS The right to make Contributions includes the right to translate, adapt, arrange, or make any or all modifications to the Software, and the right to reproduce the resulting software. The Licensee is authorized to make any or all Contributions to the Software provided that it includes an explicit notice that it is the author of said Contribution and indicates the date of the creation thereof. 5.3 RIGHT OF DISTRIBUTION In particular, the right of distribution includes the right to publish, transmit and communicate the Software to the general public on any or all medium, and by any or all means, and the right to market, either in consideration of a fee, or free of charge, one or more copies of the Software by any means. The Licensee is further authorized to distribute copies of the modified or unmodified Software to third parties according to the terms and conditions set forth hereinafter. 5.3.1 DISTRIBUTION OF SOFTWARE WITHOUT MODIFICATION The Licensee is authorized to distribute true copies of the Software in Source Code or Object Code form, provided that said distribution complies with all the provisions of the Agreement and is accompanied by: 1. a copy of the Agreement, 2. a notice relating to the limitation of both the Licensor's warranty and liability as set forth in Articles 8 and 9, and that, in the event that only the Object Code of the Software is redistributed, the Licensee allows future Licensees unhindered access to the full Source Code of the Software by indicating how to access it, it being understood that the additional cost of acquiring the Source Code shall not exceed the cost of transferring the data. 5.3.2 DISTRIBUTION OF MODIFIED SOFTWARE When the Licensee makes a Contribution to the Software, the terms and conditions for the distribution of the resulting Modified Software become subject to all the provisions of this Agreement. The Licensee is authorized to distribute the Modified Software, in source code or object code form, provided that said distribution complies with all the provisions of the Agreement and is accompanied by: 1. a copy of the Agreement, 2. a notice relating to the limitation of both the Licensor's warranty and liability as set forth in Articles 8 and 9, and that, in the event that only the object code of the Modified Software is redistributed, the Licensee allows future Licensees unhindered access to the full source code of the Modified Software by indicating how to access it, it being understood that the additional cost of acquiring the source code shall not exceed the cost of transferring the data. 5.3.3 DISTRIBUTION OF EXTERNAL MODULES When the Licensee has developed an External Module, the terms and conditions of this Agreement do not apply to said External Module, that may be distributed under a separate license agreement. 5.3.4 COMPATIBILITY WITH THE GNU GPL The Licensee can include a code that is subject to the provisions of one of the versions of the GNU GPL in the Modified or unmodified Software, and distribute that entire code under the terms of the same version of the GNU GPL. The Licensee can include the Modified or unmodified Software in a code that is subject to the provisions of one of the versions of the GNU GPL, and distribute that entire code under the terms of the same version of the GNU GPL. Article 6 - INTELLECTUAL PROPERTY 6.1 OVER THE INITIAL SOFTWARE The Holder owns the economic rights over the Initial Software. Any or all use of the Initial Software is subject to compliance with the terms and conditions under which the Holder has elected to distribute its work and no one shall be entitled to modify the terms and conditions for the distribution of said Initial Software. The Holder undertakes that the Initial Software will remain ruled at least by this Agreement, for the duration set forth in Article 4.2. 6.2 OVER THE CONTRIBUTIONS The Licensee who develops a Contribution is the owner of the intellectual property rights over this Contribution as defined by applicable law. 6.3 OVER THE EXTERNAL MODULES The Licensee who develops an External Module is the owner of the intellectual property rights over this External Module as defined by applicable law and is free to choose the type of agreement that shall govern its distribution. 6.4 JOINT PROVISIONS The Licensee expressly undertakes: 1. not to remove, or modify, in any manner, the intellectual property notices attached to the Software; 2. to reproduce said notices, in an identical manner, in the copies of the Software modified or not. The Licensee undertakes not to directly or indirectly infringe the intellectual property rights of the Holder and/or Contributors on the Software and to take, where applicable, vis-à-vis its staff, any and all measures required to ensure respect of said intellectual property rights of the Holder and/or Contributors. Article 7 - RELATED SERVICES 7.1 Under no circumstances shall the Agreement oblige the Licensor to provide technical assistance or maintenance services for the Software. However, the Licensor is entitled to offer this type of services. The terms and conditions of such technical assistance, and/or such maintenance, shall be set forth in a separate instrument. Only the Licensor offering said maintenance and/or technical assistance services shall incur liability therefor. 7.2 Similarly, any Licensor is entitled to offer to its licensees, under its sole responsibility, a warranty, that shall only be binding upon itself, for the redistribution of the Software and/or the Modified Software, under terms and conditions that it is free to decide. Said warranty, and the financial terms and conditions of its application, shall be subject of a separate instrument executed between the Licensor and the Licensee. Article 8 - LIABILITY 8.1 Subject to the provisions of Article 8.2, the Licensee shall be entitled to claim compensation for any direct loss it may have suffered from the Software as a result of a fault on the part of the relevant Licensor, subject to providing evidence thereof. 8.2 The Licensor's liability is limited to the commitments made under this Agreement and shall not be incurred as a result of in particular: (i) loss due the Licensee's total or partial failure to fulfill its obligations, (ii) direct or consequential loss that is suffered by the Licensee due to the use or performance of the Software, and (iii) more generally, any consequential loss. In particular the Parties expressly agree that any or all pecuniary or business loss (i.e. loss of data, loss of profits, operating loss, loss of customers or orders, opportunity cost, any disturbance to business activities) or any or all legal proceedings instituted against the Licensee by a third party, shall constitute consequential loss and shall not provide entitlement to any or all compensation from the Licensor. Article 9 - WARRANTY 9.1 The Licensee acknowledges that the scientific and technical state-of-the-art when the Software was distributed did not enable all possible uses to be tested and verified, nor for the presence of possible defects to be detected. In this respect, the Licensee's attention has been drawn to the risks associated with loading, using, modifying and/or developing and reproducing the Software which are reserved for experienced users. The Licensee shall be responsible for verifying, by any or all means, the suitability of the product for its requirements, its good working order, and for ensuring that it shall not cause damage to either persons or properties. 9.2 The Licensor hereby represents, in good faith, that it is entitled to grant all the rights over the Software (including in particular the rights set forth in Article 5). 9.3 The Licensee acknowledges that the Software is supplied "as is" by the Licensor without any other express or tacit warranty, other than that provided for in Article 9.2 and, in particular, without any warranty as to its commercial value, its secured, safe, innovative or relevant nature. Specifically, the Licensor does not warrant that the Software is free from any error, that it will operate without interruption, that it will be compatible with the Licensee's own equipment and software configuration, nor that it will meet the Licensee's requirements. 9.4 The Licensor does not either expressly or tacitly warrant that the Software does not infringe any third party intellectual property right relating to a patent, software or any other property right. Therefore, the Licensor disclaims any and all liability towards the Licensee arising out of any or all proceedings for infringement that may be instituted in respect of the use, modification and redistribution of the Software. Nevertheless, should such proceedings be instituted against the Licensee, the Licensor shall provide it with technical and legal assistance for its defense. Such technical and legal assistance shall be decided on a case-by-case basis between the relevant Licensor and the Licensee pursuant to a memorandum of understanding. The Licensor disclaims any and all liability as regards the Licensee's use of the name of the Software. No warranty is given as regards the existence of prior rights over the name of the Software or as regards the existence of a trademark. Article 10 - TERMINATION 10.1 In the event of a breach by the Licensee of its obligations hereunder, the Licensor may automatically terminate this Agreement thirty (30) days after notice has been sent to the Licensee and has remained ineffective. 10.2 A Licensee whose Agreement is terminated shall no longer be authorized to use, modify or distribute the Software. However, any licenses that it may have granted prior to termination of the Agreement shall remain valid subject to their having been granted in compliance with the terms and conditions hereof. Article 11 - MISCELLANEOUS 11.1 EXCUSABLE EVENTS Neither Party shall be liable for any or all delay, or failure to perform the Agreement, that may be attributable to an event of force majeure, an act of God or an outside cause, such as defective functioning or interruptions of the electricity or telecommunications networks, network paralysis following a virus attack, intervention by government authorities, natural disasters, water damage, earthquakes, fire, explosions, strikes and labor unrest, war, etc. 11.2 Any failure by either Party, on one or more occasions, to invoke one or more of the provisions hereof, shall under no circumstances be interpreted as being a waiver by the interested Party of its right to invoke said provision(s) subsequently. 11.3 The Agreement cancels and replaces any or all previous agreements, whether written or oral, between the Parties and having the same purpose, and constitutes the entirety of the agreement between said Parties concerning said purpose. No supplement or modification to the terms and conditions hereof shall be effective as between the Parties unless it is made in writing and signed by their duly authorized representatives. 11.4 In the event that one or more of the provisions hereof were to conflict with a current or future applicable act or legislative text, said act or legislative text shall prevail, and the Parties shall make the necessary amendments so as to comply with said act or legislative text. All other provisions shall remain effective. Similarly, invalidity of a provision of the Agreement, for any reason whatsoever, shall not cause the Agreement as a whole to be invalid. 11.5 LANGUAGE The Agreement is drafted in both French and English and both versions are deemed authentic. Article 12 - NEW VERSIONS OF THE AGREEMENT 12.1 Any person is authorized to duplicate and distribute copies of this Agreement. 12.2 So as to ensure coherence, the wording of this Agreement is protected and may only be modified by the authors of the License, who reserve the right to periodically publish updates or new versions of the Agreement, each with a separate number. These subsequent versions may address new issues encountered by Free Software. 12.3 Any Software distributed under a given version of the Agreement may only be subsequently distributed under the same version of the Agreement or a subsequent version, subject to the provisions of Article 5.3.4. Article 13 - GOVERNING LAW AND JURISDICTION 13.1 The Agreement is governed by French law. The Parties agree to endeavor to seek an amicable solution to any disagreements or disputes that may arise during the performance of the Agreement. 13.2 Failing an amicable solution within two (2) months as from their occurrence, and unless emergency proceedings are necessary, the disagreements or disputes shall be referred to the Paris Courts having jurisdiction, by the more diligent Party. Version 2.0 dated 2006-09-05. scscp-imcce-1.0.0+ds/Makefile.am000066400000000000000000000055261215622604100163460ustar00rootroot00000000000000#/*-----------------------------------------------------------------*/ #/*! # \file Makefile.am # \brief Makefile for automake # \author M. Gastineau # Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. # # Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS # email of the author : gastineau@imcce.fr # #*/ #/*-----------------------------------------------------------------*/ # #/*-----------------------------------------------------------------*/ #/* License of this file : # This file is "dual-licensed", you have to choose one of the two licenses # below to apply on this file. # # CeCILL-C # The CeCILL-C license is close to the GNU LGPL. # ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) # # or CeCILL v2.0 # The CeCILL license is compatible with the GNU GPL. # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) # # # This library is governed by the CeCILL-C or the CeCILL license under # French law and abiding by the rules of distribution of free software. # You can use, modify and/ or redistribute the software under the terms # of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA # at the following URL "http://www.cecill.info". # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # In this respect, the user's attention is drawn to the risks associated # with loading, using, modifying and/or developing or reproducing the # software by the user in light of its specific status of free software, # that may mean that it is complicated to manipulate, and that also # therefore means that it is reserved for developers and experienced # professionals having in-depth computer knowledge. Users are therefore # encouraged to load and test the software's suitability as regards their # requirements in conditions enabling the security of their systems and/or # data to be ensured and, more generally, to use and operate it in the # same conditions as regards security. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-C or CeCILL license and that you accept its terms. # */ # /*-----------------------------------------------------------------*/ ## Makefile.am -- Process this file with automake to produce Makefile.in SUBDIRS = src srcxx doc tests testsxx examples DIST_SUBDIRS = $(SUBDIRS) m4 AUTOMAKE_OPTIONS = foreign ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = Makefile.vc readme.txt COPYING_CECILL_C.LIB COPYING_CECILL_V2.LIB changelog pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libscscp-c.pc libscscp-cxx.pc scscp-imcce-1.0.0+ds/THANKS000066400000000000000000000000451215622604100152140ustar00rootroot00000000000000Jerome Benoit scscp-imcce-1.0.0+ds/changelog000066400000000000000000000067441215622604100161670ustar00rootroot00000000000000Version 1.0.0 (June 2013) Add the linker option version-script for the operating systems which require that flag. Add the functions SCSCP_ss_getport and Server::getport. Version 0.7.1 (October 2012) Bug fixes scscpomfbin fails on big-endian architecture [#8520] tests are too long or hang in some cases [#8521] C++ client and server negociate the version 1.3 and after the version 1.2 (instead of only 1.3). Version 0.7.0 (August 2012) Add the functions SCSCP_get_libversionstr and SCSCP_get_libversionnum. Add the macro SCSCP_CHECK_LIBVERSION. Add the support of pkg-config. Add the files AUTHORS and THANKS. Bug fixes The example decodeclient.c returns a status error [#8448] Version 0.6.4 (March 2012) Bug fixes missing type of action in a procedure call for SCSCP 1.2 and 1.3 [#8275] can't compile c++ tests on fedora 15 [#8277] can't compile c++ source files on windows [#8278] Version 0.6.3 (December 2011) Bug fixes some valid openmath expressions are reported invalid on server side [#8083] Version 0.6.2 (August 2011) Bug fixes does not report invalid OpenMath expression [#7939] Version 0.6.1 (May 2010) Bug fixes can't link on windows 64-bits [#6613] can't compile scscpsscommonxx.cpp on fedora 9 - i386 [#6622] Version 0.6.0 (December 2009) Add C++ interface. Add new function : SCSCP_xmlnode_getid. Support reference id for I/O into the C API Bug fixes can't compile scscpxmlnode.c on freebsd 7 [#6501] exit values in the documentation of SCSCP_init is duplicated [#6500] Version 0.5.0 (September 2009) Support the OpenMath binary encoding. Improve the parser for the xml encoding. Add new functions : SCSCP_xmlnode_readOMFdouble, SCSCP_xx_set_encodingtype, SCSCP_xx_get_encodingtype. Bug fixes slow sending data [#6388] bad encoding of the object OMV [#6391] openmath expressions encoded with namespaces are rejected [#6399] Version 0.4.3 (August 2009) Bug fixes The references objects (OMR) are written with href instead of xref [#6376] The library doesn't compile with a C++ compiler [#6358] Version 0.4.2 (May 2009) Change the licensing term : two distinct licenses CeCILL-C or CeCILL version 2. This allows a direct compatibility with GPL license. Bug fixes SCSCP_io_write doesn't update status on error [#6020] Tests fail on windows if xml dll arenot in standard path [#6032] Version 0.4.1 (May 2009) Remove the requirement of the C++ compiler to compile the library. Bug fixes crash when decoding the OpenMath error using the content dictionnary error [#5983] Add new functions : SCSCP_io_writexxx Add new constants : SCSCP_STATUS_OPENMATHNOTVALID Version 0.4.0 (Apr 2009) Update the library to be compliant with the specification version 1.3 Add new functions : SCSCP_status_strerror, SCSCP_status_clear, SCSCP_ro_set_message, SCSCP_ro_get_message, SCSCP_xmlnode_readOMxxx, SCSCP_io_writeOMxxx, SCSCP_sc_callsendinterrupt, SCSCP_sc_getxmlnoderawstring, SCSCP_sc_infomessagesend, SCSCP_sc_executehookxmlnode, SCSCP_sc_executehookstr, SCSCP_sc_remoteobjectxxx Add new constants : SCSCP_STATUS_INITIALIZER, SCSCP_STATUS_CALLIDISNOTSET , SCSCP_STATUS_RETURNTYPEISNOTSET, SCSCP_STATUS_USAGEUNKNOWNMESSAGE Remove constants : SCSCP_RETURNOPTIONS_DEFAULT, SCSCP_CALLOPTIONS_IGNORE Version 0.3.2 (Jan 2009) Fix the termination of the test server on windows. Remove syntax errors in the documentation. Version 0.3.1 (Jan 2009) Bug fixes The function SCSCP_ss_callrecvheader correctly updates the status information when the quit message is received. scscp-imcce-1.0.0+ds/configure.ac000066400000000000000000000104061215622604100165710ustar00rootroot00000000000000dnl /*-----------------------------------------------------------------*/ dnl /*! dnl \file configure.ac dnl \brief script for autoconf dnl \author M. Gastineau dnl Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. dnl dnl Copyright, 2008, 2009, 2010, 2011, 2012, 2013, M. Gastineau, IMCCE-CNRS dnl email of the author : gastineau@imcce.fr dnl dnl */ dnl /*-----------------------------------------------------------------*/ dnl dnl /*-----------------------------------------------------------------*/ dnl /* License of this file : dnl This file is "dual-licensed", you have to choose one of the two licenses dnl below to apply on this file. dnl dnl CeCILL-C dnl The CeCILL-C license is close to the GNU LGPL. dnl ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) dnl dnl or CeCILL v2.0 dnl The CeCILL license is compatible with the GNU GPL. dnl ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) dnl dnl dnl This library is governed by the CeCILL-C or the CeCILL license under dnl French law and abiding by the rules of distribution of free software. dnl You can use, modify and/ or redistribute the software under the terms dnl of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA dnl at the following URL "http://www.cecill.info". dnl dnl As a counterpart to the access to the source code and rights to copy, dnl modify and redistribute granted by the license, users are provided only dnl with a limited warranty and the software's author, the holder of the dnl economic rights, and the successive licensors have only limited dnl liability. dnl dnl In this respect, the user's attention is drawn to the risks associated dnl with loading, using, modifying and/or developing or reproducing the dnl software by the user in light of its specific status of free software, dnl that may mean that it is complicated to manipulate, and that also dnl therefore means that it is reserved for developers and experienced dnl professionals having in-depth computer knowledge. Users are therefore dnl encouraged to load and test the software's suitability as regards their dnl requirements in conditions enabling the security of their systems and/or dnl data to be ensured and, more generally, to use and operate it in the dnl same conditions as regards security. dnl dnl The fact that you are presently reading this means that you have had dnl knowledge of the CeCILL-C or CeCILL license and that you accept its terms. dnl */ dnl /*-----------------------------------------------------------------*/ AC_INIT([SCSCP],[1.0.0],[gastineau@imcce.fr],[scscp],[http://www.imcce.fr/trip/scscp/]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_AUX_DIR([config]) AC_CONFIG_SRCDIR([src/scscp.h]) AC_CONFIG_HEADER([src/scscpconfig.h]) AM_INIT_AUTOMAKE([gnu]) AM_MAINTAINER_MODE # check for which system. AC_CANONICAL_HOST dnl setup for the package AC_SCSCP_PACKAGE_SETUP dnl check for programs AC_PROG_CC AC_PROG_CPP AC_PROG_CXX AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_LIBTOOL dnl check windows 32bit API AH_TEMPLATE([HAVE_WIN32API],[Windows 32bit API]) AC_CHECK_HEADERS(windows.h) AC_CHECK_LIB([kernel32], main, [AC_TRY_LINK([ #if HAVE_WINDOWS_H #include #endif ], [ long x = WINVER; ] , AC_DEFINE(HAVE_WIN32API) AC_CHECK_LIB(Ws2_32, main) )] ) AC_CHECK_HEADERS(stdio.h) AC_CHECK_HEADERS(string.h) AC_CHECK_HEADERS(strings.h) AC_CHECK_HEADERS(time.h) AC_CHECK_HEADERS(unistd.h) AC_CHECK_HEADERS(sys/uio.h) AC_CHECK_HEADERS(sys/socket.h) AC_CHECK_HEADERS(netdb.h) AC_CHECK_HEADERS(netinet/in.h) AC_CHECK_HEADERS(arpa/inet.h) AC_CHECK_HEADERS(stdint.h) AC_CHECK_FUNCS(strtok_r) AC_CHECK_FUNCS(snprintf) AC_CHECK_FUNCS(strtoull) AC_CHECK_FUNCS(ntohl) AC_CHECK_FUNCS(htonl) AC_CHECK_FUNCS(ntohs) AC_CHECK_FUNCS(strncasecmp) AC_TYPE_UINT32_T AC_TYPE_INT32_T AC_TYPE_SIZE_T AC_C_INLINE AM_PATH_XML2(2.6.0,[],[AC_MSG_ERROR(could not find required version of libxml2)]) dnl checking for tests AC_CHECK_FUNCS(fork) AC_CHECK_HEADERS(sys/wait.h) dnl checking for linker script support gl_LD_VERSION_SCRIPT AC_CONFIG_FILES([ libscscp-c.pc libscscp-cxx.pc Makefile src/Makefile tests/Makefile doc/Makefile examples/Makefile srcxx/Makefile testsxx/Makefile m4/Makefile ]) AC_OUTPUT scscp-imcce-1.0.0+ds/doc/000077500000000000000000000000001215622604100150475ustar00rootroot00000000000000scscp-imcce-1.0.0+ds/doc/Makefile.am000066400000000000000000000054021215622604100171040ustar00rootroot00000000000000#/*-----------------------------------------------------------------*/ #/*! # \file Makefile.am # \brief Makefile for automake # \author M. Gastineau # Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. # # Copyright, 2008, 2009, 2012, M. Gastineau, IMCCE-CNRS # email of the author : gastineau@imcce.fr # #*/ #/*-----------------------------------------------------------------*/ # #/*-----------------------------------------------------------------*/ #/* License of this file : # This file is "dual-licensed", you have to choose one of the two licenses # below to apply on this file. # # CeCILL-C # The CeCILL-C license is close to the GNU LGPL. # ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) # # or CeCILL v2.0 # The CeCILL license is compatible with the GNU GPL. # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) # # # This library is governed by the CeCILL-C or the CeCILL license under # French law and abiding by the rules of distribution of free software. # You can use, modify and/ or redistribute the software under the terms # of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA # at the following URL "http://www.cecill.info". # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # In this respect, the user's attention is drawn to the risks associated # with loading, using, modifying and/or developing or reproducing the # software by the user in light of its specific status of free software, # that may mean that it is complicated to manipulate, and that also # therefore means that it is reserved for developers and experienced # professionals having in-depth computer knowledge. Users are therefore # encouraged to load and test the software's suitability as regards their # requirements in conditions enabling the security of their systems and/or # data to be ensured and, more generally, to use and operate it in the # same conditions as regards security. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-C or CeCILL license and that you accept its terms. # */ # /*-----------------------------------------------------------------*/ ## Makefile.am -- Process this file with automake to produce Makefile.in AUTOMAKE_OPTIONS = no-texinfo.tex AM_MAKEINFOFLAGS= --no-split info_TEXINFOS = scscp.texi scscp_TEXINFOS = scscp.texi #all: scscp.pdf scscp.html scscp.info #CLEANFILES = scscp.pdf scscp.html scscp.info EXTRA_DIST = scscp.pdf scscp-imcce-1.0.0+ds/doc/scscp.texi000066400000000000000000004553501215622604100170710ustar00rootroot00000000000000\input texinfo @c -*-texinfo-*- @setfilename scscp.info @set LIBRARYNAME SCSCP C Library @set LIBRARYCNAME C @set LIBRARYCXXNAME C++ @set LIBRARYSHORTNAME SCSCP @documentlanguage en @settitle SCSCP C Library @include version.texi @c %------------------------------------------------------------- @c macros for this file @set emailreportbugs @email{gastineau@@imcce.fr} @set scscpurl @url{http://www.imcce.fr/trip/scscp/} @set statusignoremessage @code{SCSCP_STATUS_IGNORE} could be used for @var{status} in order to ignore the returned value. @set funcfails On exit, it returns 0 if an error occurs, otherwise the return value is a non-zero value. @macro paramid @var{id} is the id of this object for the future reference (see OMR). @var{id} could be NULL if unset. @end macro @macro funcfailssetstatus{param1} On exit, it returns 0 if an error occurs, otherwise the return value is a non-zero value. If @code{\param1\ } fails, the value of @var{status} is set to the corresponding error value. @end macro @macro funcfailsptrsetstatus{param1} On exit, it returns @code{NULL} if an error occurs, otherwise the return value is a valid address. If @code{\param1\ } fails, the value of @var{status} is set to the corresponding error value. @end macro @macro funcfailsxmlreadOM{param1} On exit, it returns 0 if @var{node} doesn't contain \param1\ , otherwise the return value is a non-zero value. @end macro @macro funcxxfailssetstatus{param1} On exit, if an error occurs, then it returns 0 and an exception is raised if the exception mechanism is enabled. Otherwise the return value is a non-zero value. @end macro @macro funcxxfailsnoexcept{param1} On exit, it returns 0 if an error occurs, otherwise the return value is a non-zero value. @end macro @macro funcstreamxxfailssetstatus{param1} On exit, if an error occurs, then an exception is raised if the exception mechanism is enabled. @end macro @c %------------------------------------------------------------- @c The following two commands @c start the copyright page. @copying Copyright @copyright{} 2008, 2009, 2010, 2011, 2012, 2013, M. Gastineau, Astronomie et Syst@`emes Dynamiques, IMCCE, CNRS, Observatoire de Paris gastineau@@imcce.fr This library is governed by the CeCILL-C or CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. @end copying @titlepage @title @value{LIBRARYNAME} @subtitle Reference manual @subtitle version @value{VERSION} @subtitle @value{UPDATED} @author M. Gastineau @email{gastineau@@imcce.fr} @iftex @page @vskip 0pt plus 1filll @end iftex This manual documents how to install and use the @value{LIBRARYNAME}, version @value{VERSION}. Copyright @copyright{} 2008, 2009, 2010, 2011, 2012, 2013, M. Gastineau, Astronomie et Syst@`emes Dynamiques, IMCCE, CNRS, Observatoire de Paris @email{gastineau@@imcce.fr} @end titlepage @documentdescription How to install and use the @value{LIBRARYNAME}, version @value{VERSION}. @end documentdescription @contents @node Top, @value{LIBRARYNAME} Copying conditions, , (dir) @top @value{LIBRARYNAME} @menu * @value{LIBRARYNAME} Copying conditions :: * Introduction to @value{LIBRARYNAME} :: * Installing @value{LIBRARYNAME} :: * Reporting bugs :: * @value{LIBRARYNAME} Basics :: * @value{LIBRARYCNAME} Interface :: * Design a SCSCP C server :: * Design a SCSCP C client :: * @value{LIBRARYCXXNAME} Interface :: * Design a SCSCP C++ server :: * Design a SCSCP C++ client :: * References :: @end menu @node @value{LIBRARYNAME} Copying conditions, Introduction to @value{LIBRARYNAME}, Top, Top @chapter @value{LIBRARYNAME} Copying conditions @insertcopying @c %---------------------------------------------------------------------------- @c %---------------------------------------------------------------------------- @node Introduction to @value{LIBRARYNAME}, Installing @value{LIBRARYNAME},@value{LIBRARYNAME} Copying conditions, Top @chapter Introduction to @value{LIBRARYNAME} This library is an implementation of the Symbolic Computation Software Composibility Protocol (SCSCP). The current implementation is based on the specification version 1.3 (@pxref{References}). This library provides API to develop client applications to access Computer Algebra Systems which support that protocol. So these client applications will be refered as @samp{SCSCP client} in this documentation. Computer Algebra Systems could use the API to provide services to other applications using this protocol. So these Computer Algebra Systems will be refered as @samp{SCSCP server} in this documentation. This library provides a C and C++ API to allow to be used in C or C++ programs. @c %---------------------------------------------------------------------------- @c %---------------------------------------------------------------------------- @node Installing @value{LIBRARYNAME},Reporting bugs,Introduction to @value{LIBRARYNAME}, Top @chapter Installing @value{LIBRARYNAME} @section Installation on a Unix-like system (Linux, Mac OS X, BSD, cygwin, ...) To build @value{LIBRARYNAME}, you first have to install Libxml2 version 2.6 or later (see @url{http://xmlsoft.org/}) on your computer. You need C and C++ compilers, such as gcc and g++. And you need a standard Unix @samp{make} program, plus some other standard Unix utility programs. Here are the steps needed to install the library on Unix systems: @enumerate @item @samp{tar xzf scscp-@value{VERSION}.tar.gz} @item @samp{cd scscp-@value{VERSION}} @item @samp{./configure} Running @command{configure} might take a while. While running, it prints some messages telling which features it is checking for. @command{configure} recognizes the following options to control how it operates. @table @option @item --help @itemx -h Print a summary of all of the options to @command{configure}, and exit. @item --prefix=@var{dir} Use @var{dir} as the installation prefix. See the command @command{make install} for the installation names. @end table @item @samp{make} This compiles @value{LIBRARYNAME} in the working directory. @item @samp{make check} This will make sure @value{LIBRARYNAME} was built correctly. If you get error messages, please report them to @value{emailreportbugs} (@xref{Reporting bugs}, for information on what to include in useful bug reports). @item @samp{make install} This will copy the files @file{scscp.h}, @file{scscpxx.h} and @file{scscptypes.h} to the directory @file{/usr/local/include}, the files @file{libscscp.a} and @file{libscscpxx.a} to the directory @file{/usr/local/lib}, and the file @file{scscp.info} to the directory @file{/usr/local/share/info} (or if you passed the @samp{--prefix} option to @file{configure}, using the prefix directory given as argument to @samp{--prefix} instead of @file{/usr/local}). Note: you need write permissions on these directories. @end enumerate @subsection Other `make' Targets There are some other useful make targets: @itemize @bullet @item @samp{scscp.info} or @samp{info} Create an info version of the manual, in @file{scscp.info}. @item @samp{scscp.pdf} or @samp{pdf} Create a PDF version of the manual, in @file{scscp.pdf}. @item @samp{scscp.dvi} or @samp{dvi} Create a DVI version of the manual, in @file{scscp.dvi}. @item @samp{scscp.ps} or @samp{ps} Create a Postscript version of the manual, in @file{scscp.ps}. @item @samp{scscp.html} or @samp{html} Create an HTML version of the manual, in several pages in the directory @file{scscp.html}; if you want only one output HTML file, then type @samp{makeinfo --html --no-split scscp.texi} instead. @item @samp{clean} Delete all object files and archive files, but not the configuration files. @item @samp{distclean} Delete all files not included in the distribution. @item @samp{uninstall} Delete all files copied by @samp{make install}. @end itemize @section Installation on Windows system To build @value{LIBRARYNAME}, you first have to install Libxml2 version 2.6 or later (see @url{http://xmlsoft.org/}) on your computer. You need C and C++ compilers and a Windows SDK. It has been successfully compiled with the Windows Server 2003 R2 Platform SDK, the Windows SDK of Vista, and the Windows Server 2008 Platform SDK. Here are the steps needed to install the library on Windows systems: @enumerate @item Expand the file @samp{scscp-@value{VERSION}.tar.gz} @item Execute the command @samp{cmd.exe} from the menu @samp{Start} / @samp{Execute...} This will open a console window @item @samp{cd }@var{dir}@samp{\scscp-@value{VERSION}} Go to the directory @var{dir} where @value{LIBRARYNAME} has been expanded. @item @samp{nmake /f makefile.vc XMLDIR=@var{dir}} This compiles @value{LIBRARYNAME} in the working directory. Use @var{dir} as the installation directory of the libxml2 library. @item @samp{nmake /f makefile.vc XMLDIR=@var{dir} check} This will make sure @value{LIBRARYNAME} was built correctly. If you get error messages, please report them to @value{emailreportbugs} (@xref{Reporting bugs}, for information on what to include in useful bug reports). @item @samp{nmake /f makefile.vc install DESTDIR=@var{dir}} This will copy the files @file{scscp.h}, @file{scscpxx.h} and @file{scscptypes.h} to the directory @var{dir}@file{\include}, the files @file{scscp.lib} and @file{scscpxx.lib} to the directory @var{dir}@file{\lib}, the file @file{scscp.info} and @file{scscp.pdf} to the directory @var{dir}@file{\doc}. Note: you need write permissions on these directories. @end enumerate @c %---------------------------------------------------------------------------- @c %---------------------------------------------------------------------------- @node Reporting bugs, @value{LIBRARYNAME} Basics, Installing @value{LIBRARYNAME}, Top @chapter Reporting bugs @sp 1 If you think you have found a bug in the @value{LIBRARYNAME}, first have a look on the @value{LIBRARYNAME} web page @value{scscpurl} , in which case you may find there a workaround for it. Otherwise, please investigate and report it. We have made this library available to you, and it is not to ask too much from you, to ask you to report the bugs that you find. @sp 1 There are a few things you should think about when you put your bug report together. You have to send us a test case that makes it possible for us to reproduce the bug. Include instructions on how to run the test case. @sp 1 You also have to explain what is wrong; if you get a crash, or if the results printed are incorrect and in that case, in what way. @sp 1 Please include compiler version information in your bug report. This can be extracted using @samp{cc -V} on some machines, or, if you're using gcc, @samp{gcc -v}. Also, include the output from @samp{uname -a} and the @value{LIBRARYSHORTNAME} version. @sp 1 Send your bug report to: @value{emailreportbugs}. If you think something in this manual is unclear, or downright incorrect, or if the language needs to be improved, please send a note to the same address. @c %---------------------------------------------------------------------------- @c %---------------------------------------------------------------------------- @node @value{LIBRARYNAME} Basics, @value{LIBRARYCNAME} Interface, Reporting bugs, Top @chapter @value{LIBRARYNAME} Basics @c %---------------------------------------------------------------------------- @section Headers and Libraries All C declarations needed to use C interface are collected in the include file @file{scscp.h}. It is designed to work with both C and C++ compilers. All C++ declarations needed to use C++ interface are collected in the include file @file{scscpxx.h}. You should include that file in any C program using the @value{LIBRARYNAME} : @example #include @end example You should include that file in any C++ program using the @value{LIBRARYNAME} : @example #include @end example Note however that the @value{LIBRARYSHORTNAME} constants use @code{NULL}, the header file @file{stdio.h} must be included before. @example #include #include @end example @subsection Compilation on a Unix-like system All C programs using @value{LIBRARYSHORTNAME} must link against the @file{libscscp} library and the Libxml2 library. On Unix-like system this can be done with @option{-lscscp `xml2-config --libs`}, for example @example gcc myprogram.c -o myprogram -lscscp `xml2-config --libs` @end example @sp 1 All C++ programs using @value{LIBRARYSHORTNAME} must link against the @file{libscscpxx} and @file{libscscp} libraries and the Libxml2 library. On Unix-like system this can be done with @option{-lscscpxx -lscscp `xml2-config --libs`}, for example @example g++ myprogram.cpp -o myprogram -lscscpxx -lscscp `xml2-config --libs` @end example @sp 1 If @value{LIBRARYNAME} has been installed to a non-standard location then it may be necessary to use @option{-I} and @option{-L} compiler options to point to the right directories, and some sort of run-time path for a shared library. @subsection Compilation on a Windows system All C programs using @value{LIBRARYSHORTNAME} must link against the @file{scscp.lib} library and the Libxml2 library. On Windows system this can be done with @option{scscp.lib libxml2_a.lib iconv.lib wsock32.lib ws2_32.lib}, for example @example cl.exe /out:myprogram myprogram.c scscp.lib libxml2_a.lib iconv.lib \ wsock32.lib ws2_32.lib @end example @sp 1 All C++ programs using @value{LIBRARYSHORTNAME} must link against the @file{scscpxx.lib} and @file{scscp.lib} libraries and the Libxml2 library. On Windows system this can be done with @option{scscpxx.lib scscp.lib libxml2_a.lib iconv.lib wsock32.lib ws2_32.lib}, for example @example cl.exe /out:myprogram myprogram.cpp scscpxx.lib scscp.lib \ libxml2_a.lib iconv.lib wsock32.lib ws2_32.lib @end example @sp 1 If @value{LIBRARYNAME} has been installed to a non-standard location then it may be necessary to use @option{/I} and @option{/LIBPATH:} compiler options to point to the right directories. @c %---------------------------------------------------------------------------- @section Thread safe @value{LIBRARYNAME} is reentrant and thread-safe wit some exceptions: @enumerate @item It's safe for two threads to read from the same @value{LIBRARYSHORTNAME} variable simultaneously, but it's not safe for one to read while the another might be writing, nor for two threads to write simultaneously. @item If the standard I/O functions such as @code{send} are not reentrant then the @value{LIBRARYSHORTNAME} I/O functions using them will not be reentrant either. @end enumerate @c %---------------------------------------------------------------------------- @c %---------------------------------------------------------------------------- @node @value{LIBRARYCNAME} Interface, Design a SCSCP C server, @value{LIBRARYNAME} Basics, Top @chapter @value{LIBRARYCNAME} Interface @menu * Constants :: * Types :: * Server functions :: * Client functions :: * I/O functions :: * Status functions :: * Procedure call options functions :: * Procedure return options functions :: * XML parsing functions :: * Remote objects functions :: * Miscellaneous functions :: @end menu @c %---------------------------------------------------------------------------- @node Constants, Types,, @value{LIBRARYCNAME} Interface @section Constants SCSCP_VERSION_MAJOR This integer constant defines the major revision of this library. It can be used to distinguish different releases of this library. SCSCP_VERSION_MINOR This integer constant defines the minor revision of this library. It can be used to distinguish different releases of this library. SCSCP_VERSION_PATCH This integer constant defines the patch level revision of this library. It can be used to distinguish different releases of this library. @cartouche @example #if (SCSCP_VERSION_MAJOR>=2) || (SCSCP_VERSION_MAJOR>=1 && SCSCP_VERSION_MINOR>=3) ... #endif @end example @end cartouche SCSCP_PROTOCOL_VERSION_1_3 This string defines the version string for the SCSCP specification version 1.3 . SCSCP_PROTOCOL_VERSION_1_2 This string defines the version string for the SCSCP specification version 1.2 . SCSCP_PROTOCOL_DEFAULTPORT This integer is the default value on which port should listen the SCSCP server. The value 26133 for this port has been assigned to SCSCP by the Internet Assigned Numbers Authority (IANA) in November 2007, see http://www.iana.org/assignments/port-numbers. @c %---------------------------------------------------------------------------- @node Types, Server functions ,Constants, @value{LIBRARYCNAME} Interface @section Types @menu * SCSCP_socketserver :: * SCSCP_socketclient :: * SCSCP_incomingclient :: * SCSCP_status :: * SCSCP_calloptions :: * SCSCP_returnoptions :: * SCSCP_msgtype :: * SCSCP_encodingtype :: * SCSCP_xmlnodeptr :: * SCSCP_xmlattrptr :: * SCSCP_io :: @end menu @node SCSCP_socketserver, SCSCP_socketclient, , Types @subsection SCSCP_socketserver @deftp {Data type} SCSCP_socketserver This type contains all information of the SCSCP server. Before using any object of this type, the function @code{SCSCP_ss_init} must be called. @c % (@pxref{SCSCP_ss_init}). @end deftp @node SCSCP_socketclient, SCSCP_incomingclient, SCSCP_socketserver, Types @subsection SCSCP_socketclient @deftp {Data type} SCSCP_socketclient This type contains all information of the SCSCP client about the connection through a socket to a SCSCP server. Before using any object of this type, the function @code{SCSCP_sc_init} must be called. @c % (@pxref{SCSCP_sc_init}). @end deftp @node SCSCP_incomingclient, SCSCP_status, SCSCP_socketclient, Types @subsection SCSCP_incomingclient @deftp {Data type} SCSCP_incomingclient This type contains all information of an incoming connection accepted by a server. @end deftp @node SCSCP_status, SCSCP_calloptions, SCSCP_incomingclient, Types @subsection SCSCP_status @deftp {Data type} SCSCP_status This type contains all information about errors. Before using any object of this type, the @code{SCSCP_STATUS_INITIALIZER} must be used to initialize the status object. @cartouche @example SCSCP_status status = SCSCP_STATUS_INITIALIZER; ... @end example @end cartouche Each function of the library updates an object of this type if an error occurs during the processing. The value @code{SCSCP_STATUS_IGNORE} could be used in order to ignore the returned value by these functions. The possible values are @table @samp @item SCSCP_STATUS_OK No error occurs. @item SCSCP_STATUS_ERRNO The variable errno is set to a system error. The value of errno specifies the error. @item SCSCP_STATUS_EXECFAILED The remote execution fails. @item SCSCP_STATUS_NOMEM Not enough memory @item SCSCP_STATUS_OPENMATHNOTVALID The OpenMath expression isn't valid. @item SCSCP_STATUS_RECVCANCEL The interrupt message "" was received. @item SCSCP_STATUS_RECVQUIT The quit message "" was received or the socket is closed before receiving this message. @item SCSCP_STATUS_USAGEUNKNOWNDEBUGLEVEL The debug level isn't available in the procedure call message. @item SCSCP_STATUS_USAGEUNKNOWNMEM The memory usage isn't available in the procedure return message. @item SCSCP_STATUS_USAGEUNKNOWNMESSAGE The information message isn't available in the procedure return message. @item SCSCP_STATUS_USAGEUNKNOWNMINMEMORY The minimal memory isn't available in the procedure call message. @item SCSCP_STATUS_USAGEUNKNOWNMAXMEMORY The maximal memory isn't available in the procedure call message. @item SCSCP_STATUS_USAGEUNKNOWNRETURNTYPE The return type isn't available in the procedure call message @item SCSCP_STATUS_USAGEUNKNOWNRUNTIME The runtime usage isn't available in the procedure return message. @item SCSCP_STATUS_USAGEUNKNOWNRUNTIMELIMIT The runtime limit usage isn't available in the procedure call message. @item SCSCP_STATUS_VERSIONNEGOTIATIONFAILED The version negotiation fails. @end table The following values indicate an invalid usage of the library @table @samp @item SCSCP_STATUS_CALLIDISNOTSET The call identifier isn't defined in the options. @item SCSCP_STATUS_CALLOPTIONSOBJECTNULL The object call options passed to the function is NULL. @item SCSCP_STATUS_CLIENTOBJECTNULL The object client passed to the function is NULL. @item SCSCP_STATUS_RETURNOPTIONSOBJECTNULL The object return options passed to the function is NULL. @item SCSCP_STATUS_RETURNTYPEISNOTSET The return type isn't defined in the options. @item SCSCP_STATUS_SERVEROBJECTNULL The object server passed to the function is NULL. @item SCSCP_STATUS_STREAMOBJECTNULL The object stream passed to the function is NULL. @end table @end deftp @node SCSCP_calloptions, SCSCP_returnoptions, SCSCP_status, Types @subsection SCSCP_calloptions @deftp {Data type} SCSCP_calloptions This type contains all information about the options for a procedure call. The attribute of the procedure call could be set using the functions @code{SCSCP_co_set_xxx}. The attribute of the procedure call could be get using the functions @code{SCSCP_co_get_xxx}. The value @code{SCSCP_CALLOPTIONS_DEFAULT} could be used in order to use the default procedure call options. In this case, a unique call identifier will be generated using the prefix @code{libSCSCP:} and the procedure call will return no value (@code{SCSCP_option_return_nothing} will be used). Before using any object of this type, the function @code{SCSCP_co_init} must be called. @c % @pxref{SCSCP_co_init}. @end deftp @node SCSCP_returnoptions, SCSCP_msgtype, SCSCP_calloptions, Types @subsection SCSCP_returnoptions @deftp {Data type} SCSCP_returnoptions This type contains all information about the options for a procedure return. The attribute of the procedure return could be set using the functions @code{SCSCP_ro_set_xxx}. The attribute of the procedure return could be get using the functions @code{SCSCP_ro_get_xxx}. The value @code{SCSCP_RETURNOPTIONS_IGNORE} could be used in order to ignore the returned value by the function @code{SCSCP_sc_callrecvheader}, @code{SCSCP_sc_callrecvstr}. Before using any object of this type, the function @code{SCSCP_ro_init} must be called. @c % @pxref{SCSCP_ro_init}. @end deftp @node SCSCP_msgtype, SCSCP_encodingtype, SCSCP_returnoptions, Types @subsection SCSCP_msgtype @deftp {Data type} SCSCP_msgtype This type defines the type of sent messages between the client and the server. The available values are @table @samp @item SCSCP_msgtype_ProcedureTerminated The message is a "Procedure terminated". It is defined by the symbol @code{procedure_terminated} of the OpenMath Content Dictionary @code{scscp1}. @item SCSCP_msgtype_ProcedureCompleted The message is a "Procedure completed". It is defined by the symbol @code{procedure_completed} of the OpenMath Content Dictionary @code{scscp1}. @item SCSCP_msgtype_ProcedureCall The message is a "Procedure call". It is defined by the symbol @code{procedure_call} of the OpenMath Content Dictionary @code{scscp1}. @item SCSCP_msgtype_Interrupt The message is a "Interrupt" signal. It is defined by the processing instruction "". @end table @end deftp @node SCSCP_encodingtype, SCSCP_xmlnodeptr, SCSCP_msgtype, Types @subsection SCSCP_encodingtype @deftp {Data type} SCSCP_encodingtype This type defines the encoding type of the sent OpenMath Objects between the client and the server. The available values are @table @samp @item SCSCP_encodingtype_XML The OpenMath objects are encoded using the XML encoding. It is the default encoding for all connections. @item SCSCP_encodingtype_Binary The OpenMath objects are encoded using the Binary encoding. @end table @end deftp @node SCSCP_xmlnodeptr, SCSCP_xmlattrptr, SCSCP_encodingtype, Types @subsection SCSCP_xmlnodeptr @deftp {Data type} SCSCP_xmlnodeptr This type defines a pointer to a node of a XML tree. @end deftp @node SCSCP_xmlattrptr,SCSCP_io, SCSCP_xmlnodeptr, Types @subsection SCSCP_xmlattrptr @deftp {Data type} SCSCP_xmlattrptr This type defines a pointer to an attribute of a node of type SCSCP_xmlnodeptr (noode of a XML tree). @end deftp @node SCSCP_io,,SCSCP_xmlattrptr, Types @subsection SCSCP_io @deftp {Data type} SCSCP_io This type defines a pointer to a low-level Input/output stream. @end deftp @c %---------------------------------------------------------------------------- @node Server functions , Client functions, Types, @value{LIBRARYCNAME} Interface @section Server functions The following functions manage all operations on the @code{SCSCP_socketserver} and @code{SCSCP_incomingclient} objects. @subsection SCSCP_ss_init @deftypefn {Library Function} int SCSCP_ss_init ( SCSCP_socketserver* @var{server}, SCSCP_status* @var{status} , const char* @var{servicename}, const char* @var{serviceversion}, const char* @var{serviceid}, ...) @end deftypefn It initializes the internal structure of the object @var{server}. The variadic arguments should be of the type @code{const char*} and the last argument must be @code{NULL}. The variadic parameters define the allowed version of SCSCP protocol that could be negotiated with the SCSCP server. The arguments @var{servicename}, @var{serviceversion} and @var{serviceid} are used as the value of the attribute @code{service_name}, @code{service_version} and @code{service_id} of the @i{Connection Initiation Message}. The constants @code{SCSCP_PROTOCOL_VERSION_x_x} could be used for the variadic parameters. @funcfailssetstatus{SCSCP_ss_init} @value{statusignoremessage} The following example shows how to initialize the server supporting the scscp versions "1.3" and "1.001" . @cartouche @example SCSCP_status status; SCSCP_server server; int res; res = SCSCP_ss_init(&server, &status, "MYCAS","1","myid", SCSCP_PROTOCOL_VERSION_1_3, "1.001", NULL); @end example @end cartouche @c %----------------------- @subsection SCSCP_ss_clear @deftypefn {Library Function} int SCSCP_ss_clear ( SCSCP_socketserver* @var{server}, SCSCP_status* @var{status} ) @end deftypefn It clears the internal structure of the object @var{server} and frees allocated memory for this object by the function @code{SCSCP_ss_init}. @funcfailssetstatus{SCSCP_ss_clear} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_ss_listen @deftypefn {Library Function} int SCSCP_ss_listen ( SCSCP_socketserver* @var{server}, int @var{port}, int @var{firstavailable}, SCSCP_status* @var{status} ) @end deftypefn @var{server} creates an internal queue for the incoming connections and starts to listen on the @var{port} of "localhost". If the @var{port} isn't available and @var{firstavailable} = 0, it fails. If the @var{port} isn't available and @var{firstavailable} = 1, it retries with the next port until it finds an available port. If @var{port} is 0, an available random port is chosen. @funcfailssetstatus{SCSCP_ss_listen} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_ss_getport @deftypefn {Library Function} int SCSCP_ss_getport (SCSCP_socketserver* @var{server}) @end deftypefn It returns the port from the @var{server} is listening. If the function listen failed or is not called before, then this function returns -1. @c %----------------------- @subsection SCSCP_ss_close @deftypefn {Library Function} int SCSCP_ss_close ( SCSCP_socketserver* @var{server}, SCSCP_status* @var{status} ) @end deftypefn @var{server} terminates to listen for the incoming connections. @funcfailssetstatus{SCSCP_ss_close} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_ss_acceptclient @deftypefn {Library Function} int SCSCP_ss_acceptclient ( SCSCP_socketserver* @var{server}, SCSCP_incomingclient* @var{incomingclient}, SCSCP_status* @var{status} ) @end deftypefn @var{server} extracts the first connection request on the queue of pending connections. If no pending connections are present on the queue, it blocks the caller until a connection is present. After the @i{Connection Initiation}, the server returns, in the argument @var{incomingclient}, an object to manage future exchanged messages. After the transactions, @var{incomingclient} must be closed and cleared with the function @code{SCSCP_ss_closeincoming}. @funcfailssetstatus{SCSCP_ss_acceptclient} @value{statusignoremessage} The following example shows how to implement the main loop of the SCSCP server. @cartouche @example SCSCP_status status; SCSCP_incomingclient incomingclient; SCSCP_server server; /*initialization of the server */ SCSCP_ss_init(&server, &status, "MYCAS","1","myid", SCSCP_PROTOCOL_VERSION_1_3, "1.001", NULL); SCSCP_ss_listen(&server, SCSCP_PROTOCOL_DEFAULTPORT, &status); while (SCSCP_ss_acceptclient(&server, &incomingclient, &status)) @{ ... process incoming message ... SCSCP_ss_closeincoming(&incomingclient, &status); @} /* destroy the server */ SCSCP_ss_close(& server, &status); SCSCP_ss_clear(&server, &status); @end example @end cartouche @c %----------------------- @subsection SCSCP_ss_closeincoming @deftypefn {Library Function} int SCSCP_ss_closeincoming ( SCSCP_incomingclient* @var{incomingclient}, SCSCP_status* @var{status}) @end deftypefn It closes the connection with the client and clears the object @var{incomingclient}. @funcfailssetstatus{SCSCP_ss_closeincoming} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_ss_callrecvstr @deftypefn {Library Function} int SCSCP_ss_callrecvstr ( SCSCP_incomingclient* @var{incomingclient}, SCSCP_calloptions* @var{options}, SCSCP_msgtype* @var{msgtype}, char** @var{openmathbuffer}, SCSCP_status* @var{status}) @end deftypefn It waits for an incoming message. When a new message is available, then it reads the attribute, the type and the content of the message sent by the client @var{incomingclient}. The call options @var{options} could be get using the functions @code{SCSCP_co_get_xxx}. @var{options} must be initialized before with the function @code{SCSCP_co_init}. On exit, the argument @var{msgtype} must be @code{SCSCP_msgtype_ProcedureCall} or @code{SCSCP_msgtype_Interrupt}. The client sends only "Procedure Call" or "Interrupt" message. On exit, if the argument @var{msgtype} is @code{SCSCP_msgtype_Interrupt}, @var{options} contains the call identifier of the interrupted procedure call. On exit, the argument @var{openmathbuffer} contains the content of the message sent by the client. This string must be freed by the system call @code{free}. @funcfailssetstatus{SCSCP_ss_callrecvstr} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_ss_callrecvheader @deftypefn {Library Function} int SCSCP_ss_callrecvheader ( SCSCP_incomingclient* @var{incomingclient}, SCSCP_calloptions* @var{options}, SCSCP_msgtype* @var{msgtype}, SCSCP_status* @var{status}) @end deftypefn It reads the attribute and type of the message sent by the client @var{incomingclient}. The call options @var{options} could be get using the functions @code{SCSCP_co_get_xxx}. @var{options} must be initialized before with the function @code{SCSCP_co_init}. On exit, the argument @var{msgtype} must be @code{SCSCP_msgtype_ProcedureCall} or @code{SCSCP_msgtype_Interrupt}. The client sends only "Procedure Call" or "Interrupt" message. On exit, if the argument @var{msgtype} is @code{SCSCP_msgtype_Interrupt}, @var{options} contains the call identifier of the interrupted procedure call. @funcfailssetstatus{SCSCP_ss_callrecvheader} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_ss_getxmlnode @deftypefn {Library Function} SCSCP_xmlnodeptr SCSCP_ss_getxmlnode ( SCSCP_incomingclient* @var{incomingclient}, SCSCP_status* @var{status}) @end deftypefn This function returns a pointer to the current XML tree received from the client. This function could be used to start parsing the message sent by the client. This pointer is valid until the next call to the functions @code{SCSCP_ss_callrecv...}. @funcfailsptrsetstatus{SCSCP_ss_getxmlnode} @value{statusignoremessage} @subsection SCSCP_ss_getxmlnoderawstring @deftypefn {Library Function} char * SCSCP_ss_getxmlnoderawstring ( SCSCP_incomingclient* @var{incomingclient}, SCSCP_xmlnodeptr @var{curnode}, SCSCP_status* @var{status}) @end deftypefn This function returns the content of the current node @var{curnode} and its children as a string. This string must be freed by the system call @code{free}. @funcfailsptrsetstatus{SCSCP_ss_getxmlnoderawstring} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_ss_sendterminatedstr @deftypefn {Library Function} int SCSCP_ss_sendterminatedstr ( SCSCP_incomingclient* @var{incomingclient}, SCSCP_returnoptions* @var{options}, const char * @var{cdname}, const char * @var{symbolname}, const char * @var{message}, SCSCP_status* @var{status} ) @end deftypefn It sends a "procedure terminated" message to the SCSCP client with the @var{options}. The symbol of the OpenMath Error is defined by its name @var{symbolname} and its CD @var{cdname}. @var{message} is the message that will be inserted in a OMSTR OpenMath object. @funcfailssetstatus{SCSCP_ss_sendterminatedstr} @value{statusignoremessage} @cartouche @example SCSCP_ss_sendterminatedstr(&incomingclient, &options, "scscp1","error_system_specific", "can't store a remote object", &status); @end example @end cartouche @c %----------------------- @subsection SCSCP_ss_sendcompletedstr @deftypefn {Library Function} int SCSCP_ss_sendcompletedstr ( SCSCP_incomingclient* @var{incomingclient}, SCSCP_returnoptions* @var{options}, const char * @var{openmathbuffer}, SCSCP_status* @var{status} ) @end deftypefn It sends a "procedure completed" message to the SCSCP client with the @var{options}. The string @var{openmathbuffer} is the argument of the "procedure completed". The string @var{openmathbuffer} must be a valid OpenMath command or @code{NULL}. @funcfailssetstatus{SCSCP_ss_sendcompletedstr} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_ss_sendcompletedhook @deftypefn {Library Function} int SCSCP_ss_sendcompletedhook ( SCSCP_incomingclient* @var{incomingclient}, SCSCP_returnoptions* @var{options}, int (*@var{callbackwriteargs})(SCSCP_io* stream, void *param, SCSCP_status* status), void* @var{param}, SCSCP_status* @var{status}) @end deftypefn It sends a "procedure completed" message to the client with the @var{options}. The arguments of the "procedure completed" message must be written by the callback function @var{callbackwriteargs}. The function @var{callbackwriteargs} must use the I/O functions @code{SCSCP_io_writexxx}, such as @code{SCSCP_io_writeOMSTR}, to write data which are sent to the SCSCP client. The argument @var{param} is a pointer which is provided to the @var{callbackwriteargs} to exchange information. This pointer and its content isn't modified by @code{SCSCP_ss_sendcompletedhook}. @funcfailssetstatus{SCSCP_ss_sendcompletedhook} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_ss_infomessagesend @deftypefn {Library Function} int SCSCP_ss_infomessagesend ( SCSCP_incomingclient* @var{incomingclient}, const char* @var{messagebuffer}, SCSCP_status* @var{status} ) @end deftypefn It sends an information message to the SCSCP client for a debugging purpose. The string @var{messagebuffer} must be a valid string. @funcfailssetstatus{SCSCP_ss_infomessagesend} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_ss_set_encodingtype @deftypefn {Library Function} int SCSCP_ss_set_encodingtype ( SCSCP_incomingclient* @var{incomingclient}, SCSCP_encodingtype @var{encodingtype}, SCSCP_status* @var{status} ) @end deftypefn This function sets the current encoding of the OpenMath objects used by the SCSCP server to send an answer. The provided Openmath buffers, such as for the call @code{SCSCP_ss_sendcompletedstr}, must use the same encoding. The default encoding for the SCSCP server is the @code{SCSCP_encodingtype_XML}. @funcfailssetstatus{SCSCP_ss_set_encodingtype} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_ss_get_encodingtype @deftypefn {Library Function} int SCSCP_ss_set_encodingtype ( SCSCP_incomingclient* @var{incomingclient}, SCSCP_encodingtype* @var{encodingtype}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{encodingtype}, the current encoding for the OpenMath objects when the SCSCP server sends an answer. @funcfailssetstatus{SCSCP_ss_get_encodingtype} @value{statusignoremessage} @c %---------------------------------------------------------------------------- @node Client functions, I/O functions, Server functions, @value{LIBRARYCNAME} Interface @section Client functions The following functions manage all operations on the @code{SCSCP_socketclient} object. @subsection SCSCP_sc_init @deftypefn {Library Function} int SCSCP_sc_init ( SCSCP_socketclient* @var{client}, SCSCP_status* @var{status}, ... ) @end deftypefn It initializes the internal structure of the object @var{client}. The variadic arguments should be of the type @code{const char*} and the last argument must be @code{NULL}. The variadic parameters define the allowed version of SCSCP protocol that could be negotiated with the SCSCP server. During the negotiation with the server, the client will choose the first version in the variadic parameters that the server supports too. So the variadic parameters should start by from the highest level of the SCSCP version to the lowest version. The constants @code{SCSCP_PROTOCOL_VERSION_x_x} could be used for the variadic parameters. @funcfailssetstatus{SCSCP_sc_init} @value{statusignoremessage} @cartouche @example res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, "1.0beta", NULL); @end example @end cartouche @c %----------------------- @subsection SCSCP_sc_clear @deftypefn {Library Function} int SCSCP_sc_clear ( SCSCP_socketclient* @var{client}, SCSCP_status* @var{status} ) @end deftypefn It clears the internal structure of the object @var{client} and frees allocated memory for this object by the function @code{SCSCP_sc_init}. If a connection was already opened, the function @code{SCSCP_sc_close} is called before clearing the object. @funcfailssetstatus{SCSCP_sc_clear} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_connect @deftypefn {Library Function} int SCSCP_sc_connect ( SCSCP_socketclient* @var{client}, const char *@var{machine}, int @var{port}, SCSCP_status* @var{status} ) @end deftypefn It tries to connect to the SCSCP server which is running on the computer @var{machine} and is listening on the port @var{port}. @var{client} must be initialized with the function @code{SCSCP_sc_init} before calling this function. If the connection achieves, @var{client} is updated on exit. @var{machine} could be any string but it must resolved as an IP address. Its value could be "localhost" if the SCSCP server runs on the same computer. In most of the case, the default value @var{SCSCP_PROTOCOL_DEFAULTPORT} should be used for the port number. @funcfailssetstatus{SCSCP_sc_connect} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_close @deftypefn {Library Function} int SCSCP_sc_close ( SCSCP_socketclient* @var{client}, SCSCP_status* @var{status} ) @end deftypefn It closes a connection previously opened by a SCSCP client with the function @code{SCSCP_sc_connect}. @funcfailssetstatus{SCSCP_sc_close} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_set_encodingtype @deftypefn {Library Function} int SCSCP_sc_set_encodingtype ( SCSCP_socketclient* @var{client}, SCSCP_encodingtype @var{encodingtype}, SCSCP_status* @var{status} ) @end deftypefn This function sets the current encoding of the OpenMath objects used by the SCSCP client to send a "procedure call" message. The provided Openmath buffers, such as for the call @code{SCSCP_sc_callsendstr}, must use the same encoding. The default encoding for the SCSCP client is the @code{SCSCP_encodingtype_XML}. @funcfailssetstatus{SCSCP_sc_set_encodingtype} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_get_encodingtype @deftypefn {Library Function} int SCSCP_sc_set_encodingtype ( SCSCP_socketclient* @var{client}, SCSCP_encodingtype* @var{encodingtype}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{encodingtype}, the current encoding for the OpenMath objects when the SCSCP client sends a "procedure call" message. @funcfailssetstatus{SCSCP_sc_get_encodingtype} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_callsendstr @deftypefn {Library Function} int SCSCP_sc_callsendstr ( SCSCP_socketclient* @var{client}, SCSCP_calloptions* @var{options}, const char * @var{openmathbuffer}, SCSCP_status* @var{status} ) @end deftypefn The @var{client} sends a "procedure call" message to the SCSCP server with the @var{options}. The string @var{openmathbuffer} is the argument of the procedure call. A connection must be previously opened with @code{SCSCP_sc_connect} before preforming this procedure call. The string @var{openmathbuffer} must be an OpenMath Application object. The value @code{SCSCP_CALLOPTIONS_DEFAULT} could be used for the parameter @var{options} in order to use the default procedure call options. The procedure call options could be set using the functions @code{SCSCP_co_set_xxx}. @funcfailssetstatus{SCSCP_sc_callsendstr} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_callrecvstr @deftypefn {Library Function} int SCSCP_sc_callrecvstr ( SCSCP_socketclient* @var{client}, SCSCP_returnoptions* @var{options}, SCSCP_msgtype* @var{msgtype}, char** @var{openmathbuffer}, SCSCP_status* @var{status}) @end deftypefn The @var{client} reads the attribute, the type and the content of the message returned by the server in response of a procedure call. On exit, the argument @var{msgtype} contains the message type returned by the server. On exit, the argument @var{openmathbuffer} contains the content of the message returned by the server. This string must be freed by the system call @code{free}. The value @code{SCSCP_RETURNOPTIONS_IGNORE} could be used for the parameter @var{options} in order to ignore the returned value. The return options could be get using the functions @code{SCSCP_ro_get_xxx}. If @var{options} isn't @code{SCSCP_RETURNOPTIONS_IGNORE}, it must be initialized before with the function @code{SCSCP_ro_init}. @funcfailssetstatus{SCSCP_sc_callrecvstr} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_callsendhook @deftypefn {Library Function} int SCSCP_sc_callsendhook ( SCSCP_socketclient* @var{client}, SCSCP_calloptions* @var{options}, int (*@var{callbackwriteappli})(SCSCP_io* stream, void *param, SCSCP_status* status), void* @var{param}, SCSCP_status* @var{status}) @end deftypefn The @var{client} sends a "procedure call" message to the server with the @var{options}. The arguments of the procedure call must be written by the callback function @var{callbackwriteappli}. The function @var{callbackwriteappli} must use the functions @code{SCSCP_io_writexxx}, such as @code{SCSCP_io_writeOMSTR}, to write data which are sent to the SCSCP server. The function @var{callbackwriteappli} must write an OpenMath Application object. A connection must be previously opened with @code{SCSCP_sc_connect} before preforming this procedure call. The argument @var{param} is a pointer which is provided to the @var{callbackwriteargs} to exchange information. This pointer and its content isn't modified by @code{SCSCP_sc_callsendhook}. The value @code{SCSCP_CALLOPTIONS_DEFAULT} could be used for the parameter @var{options} in order to use the default procedure call options. The procedure call options could be set using the functions @code{SCSCP_co_set_xxx}. @funcfailssetstatus{SCSCP_sc_callsendhook} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_callrecvheader @deftypefn {Library Function} int SCSCP_sc_callrecvheader ( SCSCP_socketclient* @var{client}, SCSCP_returnoptions* @var{options}, SCSCP_msgtype* @var{msgtype}, SCSCP_status* @var{status}) @end deftypefn The @var{client} reads the attribute and type of the message returned by the server in response of a procedure call. The value @code{SCSCP_RETURNOPTIONS_IGNORE} could be used for the parameter @var{options} in order to ignore the returned value. The return options could be get using the functions @code{SCSCP_ro_get_xxx}. If @var{options} isn't @code{SCSCP_RETURNOPTIONS_IGNORE}, it must be initialized before with the function @code{SCSCP_ro_init}. On exit, the argument @var{msgtype} contains the message type returned by the server. @funcfailssetstatus{SCSCP_sc_callrecvheader} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_callrecvterminated @deftypefn {Library Function} int SCSCP_sc_callrecvterminated ( SCSCP_socketclient* @var{client}, char ** @var{cdname}, char ** @var{symbolname}, char** @var{messagebuffer}, SCSCP_status* @var{status}) @end deftypefn The @var{client} reads the content of the OpenMath error if the server replies with a "procedure terminated" message. This function must be called only if @code{SCSCP_sc_callrecvheader} returns @var{msgtype}=@code{SCSCP_msgtype_ProcedureTerminated}. On exit, the argument @var{symbolname} contains the name of the OpenMath symbol from the OpenMath content dictionnary @var{cdname}. These strings must be freed by the system call @code{free}. On exit, the argument @var{messagebuffer} contains the full content of the error (including the head symbol of the OpenMath error) returned by the server. This string must be freed by the system call @code{free}. @funcfailssetstatus{SCSCP_sc_callrecvterminated} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_callrecvcompleted @deftypefn {Library Function} int SCSCP_sc_callrecvcompleted ( SCSCP_socketclient* @var{client}, char** @var{openmathbuffer}, SCSCP_status* @var{status}) @end deftypefn The @var{client} reads the content of the messages if the server replies with a "procedure completed" message. This function must be called only if @code{SCSCP_sc_callrecvheader} returns @var{msgtype}=@code{SCSCP_msgtype_ProcedureCompleted}. On exit, the argument @var{openmathbuffer} contains the content of the message returned by the server. This string must be freed by the system call @code{free}. @funcfailssetstatus{SCSCP_sc_callrecvcompleted} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_callsendinterrupt @deftypefn {Library Function} int SCSCP_sc_callsendinterrupt ( SCSCP_socketclient* @var{client}, const char* @var{call_id}, SCSCP_status* @var{status} ) @end deftypefn It sends an interrupt signal to the SCSCP server with the call ID @var{call_id}. The server need not to complete the computation but the server will always reply to the procedure call. The argument @var{call_id} can't be NULL. @funcfailssetstatus{SCSCP_sc_callsendinterrupt} @value{statusignoremessage} @c %-------------------------- @subsection SCSCP_sc_executehookxmlnode @deftypefn {Library Function} int SCSCP_sc_executehookxmlnode ( SCSCP_socketclient* @var{client}, SCSCP_option_return @var{returntype}, const char * @var{cdname}, const char* @var{symbolname}, int (*@var{callbackwriteargs})(SCSCP_io* stream, void *param, SCSCP_status* status), void* @var{param}, SCSCP_xmlnodeptr* @var{node}, SCSCP_status* @var{status}) @end deftypefn The @var{client} sends a "procedure call" message to the server with an OpenMath symbol @var{symbolname} from the content dictionary @var{cdname} as first argument. The other arguments of the procedure call must be written by the callback function @var{callbackwriteargs}. The function @var{callbackwriteargs} must use the functions @code{SCSCP_io_writexxx}, such as @code{SCSCP_io_writeOMSTR}, to write data which are sent to the SCSCP server. A connection must be previously opened with @code{SCSCP_sc_connect} before preforming this procedure call. The argument @var{param} is a pointer which is provided to the @var{callbackwriteargs} to exchange information. This pointer and its content isn't modified by @code{SCSCP_sc_executehookxmlnode}. The server returns a result (object, cookie, nothing) depending on the value @var{returntype}. On exit, the argument @var{node} contains a pointer to the OpenMath object by the server. @funcfailssetstatus{SCSCP_sc_executehookxmlnode} @value{statusignoremessage} @c %-------------------------- @subsection SCSCP_sc_executehookstr @deftypefn {Library Function} int SCSCP_sc_executehookstr ( SCSCP_socketclient* @var{client}, SCSCP_option_return @var{returntype}, const char * @var{cdname}, const char* @var{symbolname}, int (*@var{callbackwriteargs})(SCSCP_io* stream, void *param, SCSCP_status* status), void* @var{param}, char ** @var{openmathbuffer}, SCSCP_status* @var{status}) @end deftypefn The @var{client} sends a "procedure call" message to the server with an OpenMath symbol @var{symbolname} from the content dictionary @var{cdname} as first argument. The other arguments of the procedure call must be written by the callback function @var{callbackwriteargs}. The function @var{callbackwriteargs} must use the functions @code{SCSCP_io_writexxx}, such as @code{SCSCP_io_writeOMSTR}, to write data which are sent to the SCSCP server. A connection must be previously opened with @code{SCSCP_sc_connect} before preforming this procedure call. The argument @var{param} is a pointer which is provided to the @var{callbackwriteargs} to exchange information. This pointer and its content isn't modified by @code{SCSCP_sc_callsendhookstr}. The server returns a result (object, cookie, nothing) depending on the value @var{returntype}. On exit, the argument @var{openmathbuffer} contains a string representing the OpenMath object by the server. @funcfailssetstatus{SCSCP_sc_callsendhookstr} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_infomessagesend @deftypefn {Library Function} int SCSCP_sc_infomessagesend ( SCSCP_socketclient* @var{client}, const char* @var{messagebuffer}, SCSCP_status* @var{status} ) @end deftypefn It sends an information message to the SCSCP server for a debugging purpose. The string @var{messagebuffer} must be a valid string. @funcfailssetstatus{SCSCP_sc_infomessagesend} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_getxmlnode @deftypefn {Library Function} SCSCP_xmlnodeptr SCSCP_sc_getxmlnode ( SCSCP_socketclient* @var{client}, SCSCP_status* @var{status}) @end deftypefn The @var{client} returns a pointer to the current XML tree. This function could be used to start parsing the message sent by the server. This pointer is valid until the next call to the functions @code{SCSCP_sc_callrecv...}. @funcfailsptrsetstatus{SCSCP_sc_getxmlnode} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_sc_getxmlnoderawstring @deftypefn {Library Function} char * SCSCP_sc_getxmlnoderawstring ( SCSCP_socketclient* @var{client}, SCSCP_xmlnodeptr @var{curnode}, SCSCP_status* @var{status}) @end deftypefn This function returns the content of the current node @var{curnode} and its children as a string. This string must be freed by the system call @code{free}. @funcfailsptrsetstatus{SCSCP_sc_getxmlnoderawstring} @value{statusignoremessage} @c %----------------------- @node I/O functions,Status functions, Client functions, @value{LIBRARYCNAME} Interface @section I/O functions @c %----------------------- @subsection SCSCP_io_write @deftypefn {Library Function} int SCSCP_io_write ( SCSCP_io* @var{stream}, const char *@var{buffer}, SCSCP_status* @var{status} ) @end deftypefn It writes the data @var{buffer} directly to the @var{stream}. The argument @var{buffer} can't be NULL. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_write} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeOMSTR @deftypefn {Library Function} int SCSCP_io_writeOMSTR ( SCSCP_io* @var{stream}, const char *@var{buffer}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the data @var{buffer} as an OpenMath string @code{...} to the @var{stream}. If the argument @var{buffer} is NULL, the OpenMath string is encoding with only one space. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeOMSTR} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeOMFdouble @deftypefn {Library Function} int SCSCP_io_writeOMFdouble ( SCSCP_io* @var{stream}, double @var{x}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the floating-point number @var{x} as an OpenMath float @code{} to the @var{stream}. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeOMFdouble} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeOMFstr @deftypefn {Library Function} int SCSCP_io_writeOMFstr ( SCSCP_io* @var{stream}, const char* @var{buffer}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the floating-point number @var{buffer} as an OpenMath float @code{} to the @var{stream}. The argument @var{buffer} can't be NULL. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeOMFstr} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeOMIint @deftypefn {Library Function} int SCSCP_io_writeOMIint ( SCSCP_io* @var{stream}, int @var{x}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the integer @var{x} as an OpenMath integer @code{...} to the @var{stream}. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeOMIint} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeOMIlonglong @deftypefn {Library Function} int SCSCP_io_writeOMIlonglong ( SCSCP_io* @var{stream}, long long @var{x}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the integer @var{x} as an OpenMath integer @code{...} to the @var{stream}. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeOMIlonglong} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeOMIstr @deftypefn {Library Function} int SCSCP_io_writeOMIstr ( SCSCP_io* @var{stream}, const char* @var{buffer}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the integer @var{buffer} as an OpenMath integer @code{...} to the @var{stream}. The argument @var{buffer} can't be NULL. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeOMIstr} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeOMS @deftypefn {Library Function} int SCSCP_io_writeOMS ( SCSCP_io* @var{stream}, const char* @var{cdname}, const char* @var{symbolname}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the symbol @var{symbolname} of the Content Dictionary @var{cdname} as an OpenMath symbol @code{} to the @var{stream}. The argument @var{cdname} and @var{symbolname} can't be NULL. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeOMS} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeOMV @deftypefn {Library Function} int SCSCP_io_writeOMV ( SCSCP_io* @var{stream}, const char* @var{buffer}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the variable @var{buffer} as an OpenMath variable @code{} to the @var{stream}. The argument @var{buffer} can't be NULL. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeOMV} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeOMR @deftypefn {Library Function} int SCSCP_io_writeOMR ( SCSCP_io* @var{stream}, const char* @var{buffer}, SCSCP_status* @var{status} ) @end deftypefn It writes the reference @var{buffer} as an OpenMath reference @code{} to the @var{stream}. The argument @var{buffer} can't be NULL. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeOMR} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeOMB @deftypefn {Library Function} int SCSCP_io_writeOMB ( SCSCP_io* @var{stream}, const void* @var{buffer}, size_t lenbuffer SCSCP_status* @var{status} ) @end deftypefn It writes the array @var{buffer} of @var{lenbuffer} bytes as an OpenMath byte array @code{...} to the @var{stream}. The argument @var{buffer} can't be NULL. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeOMB} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writebeginOMA @deftypefn {Library Function} int SCSCP_io_writebeginOMA ( SCSCP_io* @var{stream}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the beginning of the structured Open Math object @code{} to the stream @var{stream}. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writebeginOMA} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeendOMA @deftypefn {Library Function} int SCSCP_io_writeendOMA ( SCSCP_io* @var{stream}, SCSCP_status* @var{status} ) @end deftypefn It writes the end of the structured Open Math object @code{} to the @var{stream}. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeendOMA} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writebeginOMATP @deftypefn {Library Function} int SCSCP_io_writebeginOMATP ( SCSCP_io* @var{stream}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the beginning of the structured Open Math attribute pair @code{} to the stream @var{stream}. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writebeginOMATP} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeendOMATP @deftypefn {Library Function} int SCSCP_io_writeendOMATP ( SCSCP_io* @var{stream}, SCSCP_status* @var{status} ) @end deftypefn It writes the end of the structured Open Math attribute pair @code{} to the @var{stream}. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeendOMATP} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writebeginOMATTR @deftypefn {Library Function} int SCSCP_io_writebeginOMATTR ( SCSCP_io* @var{stream}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the beginning of the structured Open Math attribution @code{} to the stream @var{stream}. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writebeginOMATTR} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeendOMATTR @deftypefn {Library Function} int SCSCP_io_writeendOMATTR ( SCSCP_io* @var{stream}, SCSCP_status* @var{status} ) @end deftypefn It writes the end of the structured Open Math attribution @code{} to the @var{stream}. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeendOMATTR} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writebeginOMBIND @deftypefn {Library Function} int SCSCP_io_writebeginOMBIND ( SCSCP_io* @var{stream}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the beginning of the structured Open Math binding object @code{} to the stream @var{stream}. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writebeginOMBIND} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeendOMBIND @deftypefn {Library Function} int SCSCP_io_writeendOMBIND ( SCSCP_io* @var{stream}, SCSCP_status* @var{status} ) @end deftypefn It writes the end of the structured Open Math binding object @code{} to the @var{stream}. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeendOMBIND} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writebeginOME @deftypefn {Library Function} int SCSCP_io_writebeginOME ( SCSCP_io* @var{stream}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the beginning of the structured Open Math error @code{} to the stream @var{stream}. @paramid This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writebeginOME} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeendOME @deftypefn {Library Function} int SCSCP_io_writeendOME ( SCSCP_io* @var{stream}, SCSCP_status* @var{status} ) @end deftypefn It writes the end of the structured Open Math error @code{} to the @var{stream}. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeendOME} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writebeginOMFOREIGN @deftypefn {Library Function} int SCSCP_io_writebeginOMFOREIGN ( SCSCP_io* @var{stream}, const char *@var{id}, SCSCP_status* @var{status} ) @end deftypefn It writes the beginning of the structured Open Math foreign object @code{} to the stream @var{stream}. @paramid Currently, the binary encoding isn't supported, the function always fails. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writebeginOMFOREIGN} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeendOMFOREIGN @deftypefn {Library Function} int SCSCP_io_writeendOMFOREIGN ( SCSCP_io* @var{stream}, SCSCP_status* @var{status} ) @end deftypefn It writes the end of the structured Open Math foreign object @code{} to the @var{stream} Currently, the binary encoding isn't supported, the function always fails. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeendOMFOREIGN} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writebeginOMOBJ @deftypefn {Library Function} int SCSCP_io_writebeginOMOBJ ( SCSCP_io* @var{stream}, SCSCP_status* @var{status} ) @end deftypefn It writes the beginning of the structured Open Math object @code{} to the stream @var{stream}. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writebeginOMOBJ} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_io_writeendOMOBJ @deftypefn {Library Function} int SCSCP_io_writeendOMOBJ ( SCSCP_io* @var{stream}, SCSCP_status* @var{status} ) @end deftypefn It writes the end of the structured Open Math object @code{} to the @var{stream}. This function must only be called by the callback function @var{callbackwritearg} provided to the hook functions @code{SCSCP_ss_sendcompletedhook}, @code{SCSCP_sc_callsendhook}, .... @funcfailssetstatus{SCSCP_io_writeendOMOBJ} @value{statusignoremessage} @c %----------------------- @node Status functions, Procedure call options functions, I/O functions, @value{LIBRARYCNAME} Interface @section Status functions @c %----------------------- @subsection SCSCP_status_clear @deftypefn {Library Function} void SCSCP_status_clear (SCSCP_status* @var{status} ) @end deftypefn It clears the internal structure of the object @var{status} and frees allocated memory for this object by any error of the library. @c %----------------------- @subsection SCSCP_status_is @deftypefn {Library Function} int SCSCP_status_is ( SCSCP_status* @var{status} ) @end deftypefn This function returns the integer value of the status object. The returned value are defined in @xref{SCSCP_status}. @var{status} mustn't be @code{SCSCP_STATUS_IGNORE}. This function could be defined as a macro in the header file @file{scscp.h}. @cartouche @example int res = SCSCP_co_get_maxmemory(&options, &memsize, status); if (res) @{ printf("maximum memory = %lld\n", (long long)memsize); @} else if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNMAXMEMORY) @{ printf("maximum memory not available\n"); @} @end example @end cartouche @c %----------------------- @subsection SCSCP_status_strerror @deftypefn {Library Function} {const char*} SCSCP_status_strerror (const SCSCP_status* @var{status} ) @end deftypefn This function accepts an argument @var{status} and returns a pointer to the corresponding message string. @cartouche @example int res = SCSCP_co_get_maxmemory(&options, &memsize, status); if (res) @{ printf("maximum memory = %lld\n", (long long)memsize); @} else @{ printf("error message ='%s'\n", SCSCP_status_strerror(status)); @} @end example @end cartouche @c %----------------------- @node Procedure call options functions, Procedure return options functions , Status functions, @value{LIBRARYCNAME} Interface @section Procedure call options functions @subsection SCSCP_co_init @deftypefn {Library Function} int SCSCP_co_init ( SCSCP_calloptions* @var{options}, SCSCP_status* @var{status} ) @end deftypefn It initializes the internal structure of the object @var{options}. It generates and sets the call identifier of the options of the procedure call. This call identifier is defined as the symbol @code{call_id} of the OpenMath Content Dictionary @code{scscp1}. The call identifier is prefixed by @code{libSCSCP:}. It sets the return type to the value @code{SCSCP_option_return_object}. @funcfailssetstatus{SCSCP_co_init} @value{statusignoremessage} @subsection SCSCP_co_clear @deftypefn {Library Function} int SCSCP_co_clear ( SCSCP_calloptions* @var{options}, SCSCP_status* @var{status} ) @end deftypefn It clears the internal structure of the object @var{options} and frees allocated memory for this object by the function @code{SCSCP_co_init}. @funcfailssetstatus{SCSCP_co_clear} @value{statusignoremessage} @subsection SCSCP_co_set_callid @deftypefn {Library Function} int SCSCP_co_set_callid ( SCSCP_calloptions* @var{options}, const char *@var{buffer}, SCSCP_status* @var{status} ) @end deftypefn This function sets the call identifier of the options of the procedure call. It overwrites the default call identifier, generated by @code{SCSCP_co_init}. This call identifier is defined as the symbol @code{call_id} of the OpenMath Content Dictionary @code{scscp1}. The argument @var{buffer} can't be NULL and won't be duplicated by these functions. So @var{buffer} mustn't be destroyed until the function @code{SCSCP_co_clear} is called on the object @var{options}. The argument @var{buffer} shouldn't be use any string beginning with @code{libSCSCP:} because @code{SCSCP_co_init} generates unique call identifier with this prefix. The caller of this function is resposible of the unicity of the content of @var{buffer} during th connection. @funcfailssetstatus{SCSCP_co_set_callid} @value{statusignoremessage} @subsection SCSCP_co_get_callid @deftypefn {Library Function} int SCSCP_co_get_callid ( SCSCP_calloptions* @var{options}, const char **@var{buffer}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{buffer}, the call id of the options of the procedure call. This call id is defined as the symbol @code{call_id} of the OpenMath Content Dictionary @code{scscp1}. The argument @var{buffer} can't be NULL. The returned string mustn't be modified. @funcfailssetstatus{SCSCP_co_get_callid} @value{statusignoremessage} @subsection SCSCP_co_set_runtimelimit @deftypefn {Library Function} int SCSCP_co_set_runtimelimit ( SCSCP_calloptions* @var{options}, size_t @var{time}, SCSCP_status* @var{status} ) @end deftypefn This function sets the amount of time in milliseconds, with the value @var{time}, that the SCSCP server should spend on this call. This runtime limit is defined by the symbol @code{option_runtime} of the OpenMath Content Dictionary @code{scscp1}. @funcfailssetstatus{SCSCP_co_set_runtimelimit} @value{statusignoremessage} @subsection SCSCP_co_get_runtimelimit @deftypefn {Library Function} int SCSCP_co_get_runtimelimit ( SCSCP_calloptions* @var{options}, size_t* @var{time}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{time}, the amount of time in milliseconds that the server should spend on this call. This amount of time is defined as the symbol @code{option_runtime} of the OpenMath Content Dictionary @code{scscp1}. If the amount of time isn't available (not supplied by the server), the function fails and @var{status} is set to @code{SCSCP_STATUS_USAGEUNKNOWNRUNTIMELIMIT}. The argument @var{time} can't be NULL. @funcfailssetstatus{SCSCP_co_get_runtimelimit} @value{statusignoremessage} @subsection SCSCP_co_set_minmemory @deftypefn {Library Function} int SCSCP_co_set_minmemory ( SCSCP_calloptions* @var{options}, size_t @var{memsize}, SCSCP_status* @var{status} ) @end deftypefn This function sets the minimum amount of memory in bytes, with the value @var{memsize}, that the server should use on this call. This memory limit is defined by the symbol @code{option_min_memory} of the OpenMath Content Dictionary @code{scscp1}. @funcfailssetstatus{SCSCP_co_set_minmemory} @value{statusignoremessage} @subsection SCSCP_co_get_minmemory @deftypefn {Library Function} int SCSCP_co_get_minmemory ( SCSCP_calloptions* @var{options}, size_t* @var{memsize}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{memsize}, the minimum amount of memory in bytes that the server should use on this call. This amount of memory is defined as the symbol @code{option_min_memory} of the OpenMath Content Dictionary @code{scscp1}. If the amount of memory isn't available (not supplied by the server), the function fails and @var{status} is set to @code{SCSCP_STATUS_USAGEUNKNOWNMINMEMORY}. The argument @var{memsize} can't be NULL. @funcfailssetstatus{SCSCP_co_get_minmemory} @value{statusignoremessage} @subsection SCSCP_co_set_maxmemory @deftypefn {Library Function} int SCSCP_co_set_maxmemory ( SCSCP_calloptions* @var{options}, size_t @var{memsize}, SCSCP_status* @var{status} ) @end deftypefn This function sets the maximum amount of memory in bytes, with the value @var{memsize}, that the SCSCP server should use on this call. This memory limit is defined by the symbol @code{option_max_memory} of the OpenMath Content Dictionary @code{scscp1}. @funcfailssetstatus{SCSCP_co_set_maxmemory} @value{statusignoremessage} @subsection SCSCP_co_get_maxmemory @deftypefn {Library Function} int SCSCP_co_get_maxmemory ( SCSCP_calloptions* @var{options}, size_t* @var{memsize}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{memsize}, the maximum amount of memory in bytes that the server should use on this call. This amount of memory is defined as the symbol @code{option_max_memory} of the OpenMath Content Dictionary @code{scscp1}. If the amount of memory isn't available (not supplied by the server), the function fails and @var{status} is set to @code{SCSCP_STATUS_USAGEUNKNOWNMAXMEMORY}. The argument @var{memsize} can't be NULL. @funcfailssetstatus{SCSCP_co_get_maxmemory} @value{statusignoremessage} @subsection SCSCP_co_set_debuglevel @deftypefn {Library Function} int SCSCP_co_set_debuglevel ( SCSCP_calloptions* @var{options}, int @var{debuglevel}, SCSCP_status* @var{status} ) @end deftypefn This function sets the debug level, with the value @var{debuglevel}, that the client is interested. This debug level is defined by the symbol @code{option_debuglevel} of the OpenMath Content Dictionary @code{scscp1}. @funcfailssetstatus{SCSCP_co_set_debuglevel} @value{statusignoremessage} @subsection SCSCP_co_get_debuglevel @deftypefn {Library Function} int SCSCP_co_get_debuglevel ( SCSCP_calloptions* @var{options}, int* @var{debuglevel}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{debuglevel}, the debug level that the client is interested. This debug level is defined as the symbol @code{option_max_memory} of the OpenMath Content Dictionary @code{scscp1}. If the debug level isn't available (not supplied by the server), the function fails and @var{status} is set to @code{SCSCP_STATUS_USAGEUNKNOWNDEBUGLEVEL}. The argument @var{debuglevel} can't be NULL. @funcfailssetstatus{SCSCP_co_get_debuglevel} @value{statusignoremessage} @subsection SCSCP_co_set_returntype @deftypefn {Library Function} int SCSCP_co_set_returntype ( SCSCP_calloptions* @var{options}, SCSCP_option_return @var{returntype}, SCSCP_status* @var{status} ) @end deftypefn This function sets the return type, with the value @var{returntype}, of the procedure call that the server should send. The available value for @var{returntype} are @itemize @item @code{SCSCP_option_return_object}. The return value is an OpenMath object. It's defined by the symbol @code{option_return_object} of the OpenMath Content Dictionary @code{scscp1}. @item @code{SCSCP_option_return_cookie}. The return value is a cookie (a reference to an OpenMath object). It's defined by the symbol @code{option_return_cookie} of the OpenMath Content Dictionary @code{scscp1}. @item @code{SCSCP_option_return_nothing}. The procedure call returns no value. It's defined by the symbol @code{option_return_nothing} of the OpenMath Content Dictionary @code{scscp1}. @end itemize @funcfailssetstatus{SCSCP_co_set_returntype} @value{statusignoremessage} @subsection SCSCP_co_get_returntype @deftypefn {Library Function} int SCSCP_co_get_returntype ( SCSCP_calloptions* @var{options}, SCSCP_option_return* @var{returntype}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{returntype}, the return type of the "procedure call" message that the server should send. The possible value of @var{returntype} are described in the function @code{SCSCP_co_set_returntype}. If the return type isn't available (not supplied by the server), the function fails and @var{status} is set to @code{SCSCP_STATUS_USAGEUNKNOWNRETURNTYPE}. The argument @var{returntype} can't be NULL. @funcfailssetstatus{SCSCP_co_get_returntype} @value{statusignoremessage} @c %----------------------- @subsection SCSCP_co_get_encodingtype @deftypefn {Library Function} int SCSCP_co_get_encodingtype ( SCSCP_calloptions* @var{options}, SCSCP_encodingtype* @var{encodingtype}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{encodingtype}, the current encoding for the OpenMath objects associated with this "procedure call" message. @funcfailssetstatus{SCSCP_co_get_encodingtype} @value{statusignoremessage} @c %----------------------- @node Procedure return options functions , XML parsing functions, Procedure call options functions, @value{LIBRARYCNAME} Interface @section Procedure return options functions @subsection SCSCP_ro_init @deftypefn {Library Function} int SCSCP_ro_init ( SCSCP_returnoptions* @var{options}, SCSCP_status* @var{status} ) @end deftypefn It initializes the internal structure of the object @var{options}. @funcfailssetstatus{SCSCP_ro_init} @value{statusignoremessage} @subsection SCSCP_ro_clear @deftypefn {Library Function} int SCSCP_ro_clear ( SCSCP_returnoptions* @var{options}, SCSCP_status* @var{status} ) @end deftypefn It clears the internal structure of the object @var{options} and frees allocated memory for this object by the function @code{SCSCP_ro_init}. @funcfailssetstatus{SCSCP_ro_clear} @value{statusignoremessage} @subsection SCSCP_ro_set_callid @deftypefn {Library Function} int SCSCP_ro_set_callid ( SCSCP_returnoptions* @var{options}, const char *@var{buffer}, SCSCP_status* @var{status} ) @end deftypefn This function sets the call id, with the value @var{buffer}, of the options of the procedure return. This call id is defined as the symbol @code{call_id} of the OpenMath Content Dictionary @code{scscp1}. The argument @var{buffer} can't be NULL and won't be duplicated by this function. So @var{buffer} can't be destroyed until the function @code{SCSCP_ro_clear} is called on the object @var{options}. @funcfailssetstatus{SCSCP_ro_set_callid} @value{statusignoremessage} @subsection SCSCP_ro_get_callid @deftypefn {Library Function} int SCSCP_ro_get_callid ( SCSCP_returnoptions* @var{options}, const char **@var{buffer}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{buffer}, the call id of the options of the procedure return. This call id is defined as the symbol @code{call_id} of the OpenMath Content Dictionary @code{scscp1}. The argument @var{buffer} mustn't be NULL. The returned string mustn't be modified. @funcfailssetstatus{SCSCP_ro_get_callid} @value{statusignoremessage} @subsection SCSCP_ro_set_runtime @deftypefn {Library Function} int SCSCP_ro_set_runtime ( SCSCP_returnoptions* @var{options}, size_t @var{time}, SCSCP_status* @var{status} ) @end deftypefn This function sets the amount of time in milliseconds, with the value @var{time}, that the server spent on this call. This amount of time is defined as the symbol @code{info_runtime} of the OpenMath Content Dictionary @code{scscp1}. @funcfailssetstatus{SCSCP_ro_set_runtime} @value{statusignoremessage} @subsection SCSCP_ro_get_runtime @deftypefn {Library Function} int SCSCP_ro_get_runtime ( SCSCP_returnoptions* @var{options}, size_t* @var{time}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{time}, the amount of time in milliseconds that the server spent on this call. This amount of time is defined as the symbol @code{info_runtime} of the OpenMath Content Dictionary @code{scscp1}. If the amount of time isn't available (not supplied by the server), the function fails and @var{status} is set to @code{SCSCP_STATUS_USAGEUNKNOWNRUNTIME}. The argument @var{time} can't be NULL. @funcfailssetstatus{SCSCP_ro_get_runtime} @value{statusignoremessage} @subsection SCSCP_ro_set_memory @deftypefn {Library Function} int SCSCP_ro_set_memory ( SCSCP_returnoptions* @var{options}, size_t @var{memsize}, SCSCP_status* @var{status} ) @end deftypefn This function sets the amount of memory in bytes, with the value @var{memsize}, that the server used on this call. This amount of memory is defined as the symbol @code{info_memory} of the OpenMath Content Dictionary @code{scscp1}. @funcfailssetstatus{SCSCP_ro_set_memory} @value{statusignoremessage} @subsection SCSCP_ro_get_memory @deftypefn {Library Function} int SCSCP_ro_get_memory ( SCSCP_returnoptions* @var{options}, size_t* @var{memsize}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{memsize}, the amount of memory in bytes that the server used for this call. This amount of memory is defined as the symbol @code{info_memory} of the OpenMath Content Dictionary @code{scscp1}. If the amount of memory isn't available (not supplied by the server), the function fails and @var{status} is set to @code{SCSCP_STATUS_USAGEUNKNOWNMEM}. The argument @var{memsize} can't be NULL. @funcfailssetstatus{SCSCP_ro_get_runtime} @value{statusignoremessage} @subsection SCSCP_ro_set_message @deftypefn {Library Function} int SCSCP_ro_set_message ( SCSCP_returnoptions* @var{options}, const char *@var{buffer}, SCSCP_status* @var{status} ) @end deftypefn This function sets the information message, with the value @var{buffer}, of the options of the procedure return. This information message is defined as the symbol @code{info_message} of the OpenMath Content Dictionary @code{scscp1}. The argument @var{buffer} can't be NULL and won't be duplicated by this function. So @var{buffer} can't be destroyed until the function @code{SCSCP_ro_clear} is called on the object @var{options}. @funcfailssetstatus{SCSCP_ro_set_message} @value{statusignoremessage} @subsection SCSCP_ro_get_message @deftypefn {Library Function} int SCSCP_ro_get_message ( SCSCP_returnoptions* @var{options}, const char **@var{buffer}, SCSCP_status* @var{status} ) @end deftypefn This function returns, in the argument @var{buffer}, the information message of the options of the procedure return. This information message is defined as the symbol @code{info_message} of the OpenMath Content Dictionary @code{scscp1}. The argument @var{buffer} mustn't be NULL. The returned string mustn't be modified. @funcfailssetstatus{SCSCP_ro_get_message} @value{statusignoremessage} @c %----------------------- @node XML parsing functions, Remote objects functions, Procedure return options functions , @value{LIBRARYCNAME} Interface @section XML parsing functions The following functions are useful to parse incoming messages after reading the header of the message with the functions @code{SCSCP_sc_callrecvheader} or @code{SCSCP_ss_callrecvheader}. The following example prints each node and attribute of a XML tree. @cartouche @example void printelements(SCSCP_xmlnodeptr node, int tab) @{ SCSCP_xmlattrptr attr; const char *name; const char *value; int j; while (node!=NULL) @{ for(j=0; j) of the node @var{curnode}. The function returns NULL if the reference id isn't available. @subsection SCSCP_xmlnode_getchild @deftypefn {Library Function} SCSCP_xmlnodeptr SCSCP_xmlnode_getchild ( SCSCP_xmlnodeptr @var{curnode} ) @end deftypefn This function returns the first child of the node @var{curnode}. The function returns NULL if it has no child. @subsection SCSCP_xmlnode_getcontent @deftypefn {Library Function} {const char *} SCSCP_xmlnode_getcontent ( SCSCP_xmlnodeptr @var{curnode} ) @end deftypefn This function returns as a string the content of the node @var{curnode}. @subsection SCSCP_xmlnode_getattr @deftypefn {Library Function} SCSCP_xmlattrptr SCSCP_xmlnode_getattr ( SCSCP_xmlnodeptr @var{curnode} ) @end deftypefn This function returns the first attribute of the node @var{curnode}. @subsection SCSCP_xmlattr_getnext @deftypefn {Library Function} SCSCP_xmlattrptr SCSCP_xmlattr_getnext ( SCSCP_xmlattrptr @var{attr} ) @end deftypefn This function returns a pointer to the next attribute. If @var{attr} is the last attribute, this function returns @code{NULL}. @subsection SCSCP_xmlattr_getvalue @deftypefn {Library Function} int SCSCP_xmlattr_getvalue ( SCSCP_xmlattrptr @var{attr}, const char ** @var{name}, const char ** @var{value} ) @end deftypefn This function returns, in the argument @var{name}, a pointer to the name of the attribute @var{attr} and returns, in the argument @var{value}, a pointer to the value of the attribute @var{attr}. @value{funcfails} @c %----------- @subsection SCSCP_xmlnode_readOMS @deftypefn {Library Function} int SCSCP_xmlnode_readOMS ( SCSCP_xmlnodeptr* @var{node}, const char ** @var{cdname}, const char ** @var{symbolname} ) @end deftypefn This function reads an OpenMath symbol and the cd name to @var{cdname} and the name to @var{symbolname}. @var{symbolname} and @var{cdname} mustn't be NULL. @funcfailsxmlreadOM{an OpenMath symbol} @c %----------- @subsection SCSCP_xmlnode_readOMIstr @deftypefn {Library Function} int SCSCP_xmlnode_readOMIstr ( SCSCP_xmlnodeptr* @var{node}, const char ** @var{value}) @end deftypefn This function reads an OpenMath integer and stores it to @var{value}. @var{value} mustn't be NULL. @funcfailsxmlreadOM{an OpenMath integer} @c %----------- @subsection SCSCP_xmlnode_readOMIint @deftypefn {Library Function} int SCSCP_xmlnode_readOMIint ( SCSCP_xmlnodeptr* @var{node}, int* @var{value}) @end deftypefn This function reads an OpenMath integer and store it to @var{value}. @funcfailsxmlreadOM{an OpenMath integer} @c %----------- @subsection SCSCP_xmlnode_readOMFstr @deftypefn {Library Function} int SCSCP_xmlnode_readOMFstr ( SCSCP_xmlnodeptr* @var{node}, const char ** @var{value}, int * @var{base}) @end deftypefn This function reads an OpenMath floating-point number and stores it to @var{value}. It stores to @var{base} the base used to represent the floating-point number (16 for "hex", 10 for "dec"). @var{value} and @var{base} mustn't be NULL. @funcfailsxmlreadOM{an OpenMath floating-point} @c %----------- @subsection SCSCP_xmlnode_readOMFdouble @deftypefn {Library Function} int SCSCP_xmlnode_readOMFdouble ( SCSCP_xmlnodeptr* @var{node}, double* @var{value}) @end deftypefn This function reads an OpenMath floating-point number and stores it to @var{value}. @var{value} mustn't be NULL. @funcfailsxmlreadOM{an OpenMath floating-point} @c %----------- @subsection SCSCP_xmlnode_readOMSTR @deftypefn {Library Function} int SCSCP_xmlnode_readOMSTR ( SCSCP_xmlnodeptr* @var{node}, const char ** @var{value}) @end deftypefn This function reads an OpenMath string and store it to @var{value}. @var{value} mustn't be NULL. @funcfailsxmlreadOM{an OpenMath string} @c %----------- @subsection SCSCP_xmlnode_readOMR @deftypefn {Library Function} int SCSCP_xmlnode_readOMR ( SCSCP_xmlnodeptr* @var{node}, const char ** @var{value}) @end deftypefn This function reads an OpenMath reference and stores it to @var{value}. @var{value} mustn't be NULL. @funcfailsxmlreadOM{an OpenMath reference} @c %----------- @subsection SCSCP_xmlnode_readOMV @deftypefn {Library Function} int SCSCP_xmlnode_readOMV ( SCSCP_xmlnodeptr* @var{node}, const char ** @var{value}) @end deftypefn This function reads an OpenMath variable and stores it to @var{value}. @var{value} mustn't be NULL. @funcfailsxmlreadOM{an OpenMath variable} @c %----------- @subsection SCSCP_xmlnode_readpairOMSOMSTR @deftypefn {Library Function} int SCSCP_xmlnode_readpairOMSOMSTR ( SCSCP_xmlnodeptr* @var{node}, const char *@var{cdname}, const char *@var{symbolname}, const char **@var{buffer}) @end deftypefn This function reads an OpenMath symbol and an OpenMath string. It checks that the symbol has the same symbol name and cd name as the arguments @var{symbolname} and @var{cdname}. It stores the OpenMath string to @var{value}. @var{cdname}, @var{symbolname} and @var{value} mustn't be NULL. @funcfailsxmlreadOM{OpenMath symbol and an OpenMath string} @c %----------------------- @node Remote objects functions, Miscellaneous functions, XML parsing functions, @value{LIBRARYCNAME} Interface @section Remote objects functions @subsection SCSCP_sc_remoteobjectstoresessionhook @deftypefn {Library Function} int SCSCP_sc_remoteobjectstoresessionhook ( SCSCP_socketclient* @var{client}, int (*@var{callbackwriteargs})(SCSCP_io* stream, void *param, SCSCP_status* status), void* @var{param}, char ** @var{cookiename}, SCSCP_status* @var{status}) @end deftypefn The @var{client} sends a "procedure call" message to store an object on the server. This object will be usable in the remainder of the current SCSCP session. The object is written by the callback function @var{callbackwriteargs}. The function @var{callbackwriteargs} must use the functions @code{SCSCP_io_writexxx}, such as @code{SCSCP_io_writeOMSTR}, to write data which are sent to the SCSCP server. A connection must be previously opened with @code{SCSCP_sc_connect} before preforming this call. The argument @var{param} is a pointer which is provided to the @var{callbackwriteargs} to exchange information. This pointer and its content isn't modified by @code{SCSCP_sc_remoteobjectstoresessionhook}. On exit, the argument @var{cookiename} contains the name of the Openmath reference returned by the server. This string must be freed by the system call @code{free}. @funcfailssetstatus{SCSCP_sc_remoteobjectstoresessionhook} @value{statusignoremessage} @c %----------------------------- @subsection SCSCP_sc_remoteobjectstorepersistenthook @deftypefn {Library Function} int SCSCP_sc_remoteobjectstorepersistenthook ( SCSCP_socketclient* @var{client}, int (*@var{callbackwriteargs})(SCSCP_io* stream, void *param, SCSCP_status* status), void* @var{param}, char ** @var{cookiename}, SCSCP_status* @var{status}) @end deftypefn The @var{client} sends a "procedure call" message to store an object on the server. This object will be usable from different SCSCP session. The object is written by the callback function @var{callbackwriteargs}. The function @var{callbackwriteargs} must use the functions @code{SCSCP_io_writexxx}, such as @code{SCSCP_io_writeOMSTR}, to write data which are sent to the SCSCP server. A connection must be previously opened with @code{SCSCP_sc_connect} before preforming this call. The argument @var{param} is a pointer which is provided to the @var{callbackwriteargs} to exchange information. This pointer and its content isn't modified by @code{SCSCP_sc_remoteobjectstorepersistenthook}. On exit, the argument @var{cookiename} contains the name of the Openmath reference returned by the server. This string must be freed by the system call @code{free}. @funcfailssetstatus{SCSCP_sc_remoteobjectstorepersistenthook} @value{statusignoremessage} @c %----------------------------- @subsection SCSCP_sc_remoteobjectretrievexmlnode @deftypefn {Library Function} int SCSCP_sc_remoteobjectretrievexmlnode ( SCSCP_socketclient* @var{client}, const char *@var{cookiename}, SCSCP_xmlnodeptr* @var{node}, SCSCP_status* @var{status}) @end deftypefn The @var{client} sends a "procedure call" message to retrieve the value of an remote object @var{cookiename} from the server. A connection must be previously opened with @code{SCSCP_sc_connect} before preforming this call. This function returns, in the argument @var{node}, a pointer to this OpenMath object. @funcfailssetstatus{SCSCP_sc_remoteobjectretrievexmlnode} @value{statusignoremessage} @c %----------------------------- @subsection SCSCP_sc_remoteobjectretrievestr @deftypefn {Library Function} int SCSCP_sc_remoteobjectretrievestr ( SCSCP_socketclient* @var{client}, const char *@var{cookiename}, char** @var{openmathbuffer}, SCSCP_status* @var{status}) @end deftypefn The @var{client} sends a "procedure call" message to retrieve the value of an remote object @var{cookiename} from the server. A connection must be previously opened with @code{SCSCP_sc_connect} before preforming this call. This function returns, in the argument @var{openmathbuffer}, a string of this OpenMath object. This string must be freed by the system call @code{free}. @funcfailssetstatus{SCSCP_sc_remoteobjectretrievestr} @value{statusignoremessage} @c %----------------------------- @subsection SCSCP_sc_remoteobjectunbind @deftypefn {Library Function} int SCSCP_sc_remoteobjectunbind ( SCSCP_socketclient* @var{client}, const char *@var{cookiename}, SCSCP_status* @var{status}) @end deftypefn The @var{client} sends a "procedure call" message to remove the remote object @var{cookiename} from the server. A connection must be previously opened with @code{SCSCP_sc_connect} before preforming this call. @funcfailssetstatus{SCSCP_sc_remoteobjectunbind} @value{statusignoremessage} @c %----------------------- @node Miscellaneous functions, , Remote objects functions, @value{LIBRARYCNAME} Interface @section Miscellaneous functions @subsection SCSCP_get_libversionstr @deftypefn {Library Function} const char* SCSCP_get_libversionstr (void) @end deftypefn Return the @value{LIBRARYNAME} version, as a null-terminated string. @subsection SCSCP_get_libversionnum @deftypefn {Library Function} void SCSCP_get_libversionnum (unsigned int *@var{major}, unsigned int *@var{minor}, unsigned int *@var{patch}) @end deftypefn Return the @value{LIBRARYNAME} version as unsigned values. On exit, @var{major} contains the major revision, @var{minor} contains the minor revision and @var{patch} the patch level revision. @subsection SCSCP_CHECK_LIBVERSION @deftypefn {Library Function} int SCSCP_CHECK_LIBVERSION () @end deftypefn Verify that the @value{LIBRARYNAME} versions are consistent. It verifies that the version of the @value{LIBRARYNAME} with which an application was compiled matches the version of the @value{LIBRARYNAME} against which the application is currently linked. This function is defined as a macro and returns an integer of type int. On exit, it returns @itemize @item 0 if the version of the library are not compatible, @item 1 if the version of the library are compatible and are exactly the same. @item 2 if the version of the library are compatible and are not exactly the same. @end itemize @c %---------------------------------------------------------------------------- @node Design a SCSCP C server, Design a SCSCP C client, @value{LIBRARYCNAME} Interface, Top @chapter Design a SCSCP C server The file @file{examples/decodeserver.c} shows the server which decodes each node of the OpenMath expression received from the client. It sends an answer to the client depending on the call options. @sp 1 A simple SCSCP server could be done with the following operations. This server supports the scscp versions "1.3" and "1.5beta". @itemize @item Initialize the server @example SCSCP_socketserver server; SCSCP_status status = SCSCP_STATUS_INITIALIZER; SCSCP_ss_init(&server, &status, "MYCAS", "1.0", "myid", SCSCP_PROTOCOL_VERSION_1_3, "1.5beta", NULL); @end example @item Listen for incoming client @example SCSCP_ss_listen(&client, SCSCP_PROTOCOL_DEFAULTPORT, 0, &status); @end example @item Loop over new clients @example SCSCP_incomingclient incomingclient; while (SCSCP_ss_acceptclient(&server, &incomingclient, &status)) @{ @end example @itemize @item Receive the "procedure call" message : 2 solutions @example SCSCP_calloptions calloptions; SCSCP_returnoptions returnoptions; SCSCP_msgtype msgtype; SCSCP_co_init(&calloptions, status); SCSCP_ro_init(&returnopt, status); @end example @itemize @item solution 1 : read the header and decode each node of the openmath stream @example SCSCP_ss_callrecvheader(&incomingclient, &calloptions, &msgtype, &status); SCSCP_xmlnodeptr ptrnode; ptrnode = SCSCP_ss_getxmlnode(&incomingclient, &status); @end example @item solution 2 : read the header and store the content in a string buffer @example char *openmathbuffer; SCSCP_ss_callrecvstr(&incomingclient, &calloptions, &msgtype, &openmathbuffer, &status); @end example @end itemize @item Send the answer : procedure completed or terminated ? @itemize @item Send a "procedure completed" message @example const char *openmathanswer=""; SCSCP_ss_sendcompletedstr(&incomingclient, &returnopt, openmathanswer, &status); @end example @item Send a "procedure terminated" message @example const char *messageerror="can't store an object"; SCSCP_ss_sendterminatedstr(&incomingclient, &returnopt, "sccsp1", "error_system_specific", messageerror, &status); @end example @end itemize @item clear the options object @example SCSCP_co_clear(&options, status); SCSCP_ro_clear(&returnopt, status); @end example @end itemize @item Close the connection @example SCSCP_ss_closeincoming(&incomingclient, &status); @} @end example @item Stop to listen for incoming clients @example SCSCP_ss_close(&server, &status); @end example @item Clear the server @example SCSCP_ss_clear(&server, &status); @end example @end itemize @c %---------------------------------------------------------------------------- @node Design a SCSCP C client, @value{LIBRARYCXXNAME} Interface, Design a SCSCP C server, Top @chapter Design a SCSCP C client The file @file{examples/simplestclient.c} shows the simplest client which stores the value 6177887 on the server and prints the answer of the server. The file @file{examples/decodeclient.c} shows the client which decodes each node of the OpenMath expression received from the server. @sp 1 A simple SCSCP client could be done with the following operations. This simple client will connect with the SCSCP server located on "localhost" and listening on port 26133. @itemize @item Initialize the client @example SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); @end example @item Open the Connection @example SCSCP_sc_connect(&client, "localhost", SCSCP_PROTOCOL_DEFAULTPORT, &status); @end example @item Send a procedure call @example SCSCP_calloptions calloptions; SCSCP_co_init(&calloptions, status); SCSCP_sc_callsendstr(&client, &calloptions, "", &status); @end example @item Receive the answer of the procedure call : 2 solutions @itemize @item solution 1 : read the header and decode each node of the openmath stream @example SCSCP_msgtype msgtype; SCSCP_returnoptions options; SCSCP_ro_init(&options, status); SCSCP_sc_callrecvheader(client, &options, &msgtype, &status); if (msgtype==SCSCP_msgtype_ProcedureTerminated) @{ char *messagebuffer; char *cdname; char *symbolname; SCSCP_sc_callrecvterminated(client, &cdname, &symbolname, &messagebuffer, status); @} @end example @item solution 2 : read the header and store the content in a string buffer @example SCSCP_msgtype msgtype; SCSCP_returnoptions options; char *buffer; SCSCP_ro_init(&options, status); SCSCP_sc_callrecvstr(client, &options, &msgtype, &buffer, &status); @end example @end itemize @item Close the connection @example SCSCP_sc_close(&client,&status); @end example @item Clear the client @example SCSCP_sc_clear(&client,&status); @end example @end itemize @c %---------------------------------------------------------------------------- @c %---------------------------------------------------------------------------- @node @value{LIBRARYCXXNAME} Interface , Design a SCSCP C++ server, Design a SCSCP C client, Top @chapter @value{LIBRARYCXXNAME} Interface @menu * Server :: * IncomingClient :: * Client :: * Procedure call :: * Stream :: * Exception :: * OpenMath objects :: @end menu All C++ functions and class are grouped in the namespace @code{SCSCP}. @c %---------------------------------------------------------------------------- @node Server, IncomingClient, , @value{LIBRARYCXXNAME} Interface @section Server @c %----------------------- @subsection Constructor @deftypefn Constructor {} Server (const char* @var{servicename}, const char* @var{serviceversion}, const char* @var{serviceid}) throw(Exception) It initializes the SCSCP server with the default versions (@code{SCSCP_PROTOCOL_VERSION_1_3} and @code{SCSCP_PROTOCOL_VERSION_1_2}) of SCSCP protocol that could be negotiated. The arguments @var{servicename}, @var{serviceversion} and @var{serviceid} are used as the value of the attribute @code{service_name}, @code{service_version} and @code{service_id} of the @i{Connection Initiation Message}. @end deftypefn @deftypefn Destructor {} ~Server (void) If the server was listening on a port, the method @code{Server::close} is called before clearing the object. It destroys the SCSCP server. @end deftypefn @c %----------------------- @subsection listen @deftypemethod Server int listen (int @var{port}=SCSCP_PROTOCOL_DEFAULTPORT) throw(Exception) It creates an internal queue for the incoming connections and starts to listen on the @var{port} of "localhost". If the @var{port} isn't available, it retries with the next port until it finds an available port. If @var{port} is 0, an available random port is chosen. @funcxxfailssetstatus{listen} @end deftypemethod @c %----------------------- @subsection getport @deftypemethod Server int getport () const It returns the port from the server is listening. If the function listen failed or is not called before, then this function returns -1. @end deftypemethod @c %----------------------- @subsection close @deftypemethod Server int close () throw(Exception) It terminates to listen for the incoming connections. @funcxxfailssetstatus{close} @end deftypemethod @c %----------------------- @subsection eof @deftypemethod Server bool eof () const It returns true if the connection is closed. @end deftypemethod @c %----------------------- @subsection acceptclient @deftypemethod Server IncomingClient* acceptclient () throw () It extracts the first connection request on the queue of pending connections. If no pending connections are present on the queue, it blocks the caller until a connection is present. After the @i{Connection Initiation}, the server returns an object to manage future exchanged messages. After the transactions, the returned pointer must be deleted to close the connection and release the memory. @funcxxfailssetstatus{acceptclient} @end deftypemethod The following example shows how to implement the main loop of the SCSCP C++ server. @cartouche @example SCSCP::Server server("MYCAS","1","myid"); SCSCP::IncomingClient *incomingclient; /*listen on the default port */ server.listen(); while ((incomingclient=server.acceptclient())!=NULL) @{ ... process incoming messages ... delete incomingclient; @} /* stop the server */ server.close(); @end example @end cartouche @c %---------------------------------------------------------------------------- @node IncomingClient, Client, Server, @value{LIBRARYCXXNAME} Interface @section IncomingClient The class @code{IncomingClient} handles a connection on the SCSCP server side. So on the server side, several instances of that class could exist at the same time to handle connection from different clients. That class is only instanciated by the function @code{Server::acceptclient()}. On the server side, the "Procedure Call" request are handled by an instance of @code{Server::Computation}. @c %----------------------- @subsection Destructor @deftypefn Destructor {} ~IncomingClient (void) If a connection with a client was already opened, the connection is closed with the client. @end deftypefn @c %----------------------- @subsection eof @deftypemethod Client bool eof () const It returns true if the connection is closed. @end deftypemethod @c %---------------------------------------------------------------------------- @node Client, Procedure call, IncomingClient, @value{LIBRARYCXXNAME} Interface @section Client The class @code{Client} handles the connection on the SCSCP client side. After a connection is initialized, the procedure call could be performed using an instance of the class @code{Client::Computation} (@pxref{Procedure call}). @c %----------------------- @subsection Constructor @deftypefn Constructor {} Client (void) throw(Exception) It initializes the SCSCP client with the default version (@code{SCSCP_PROTOCOL_VERSION_1_3} and @code{SCSCP_PROTOCOL_VERSION_1_2}) of SCSCP protocol that could be negotiated. During the negotiation with the server, the client will choose the first version, that the server supports too, in the following order : @code{SCSCP_PROTOCOL_VERSION_1_3}, and @code{SCSCP_PROTOCOL_VERSION_1_2}. @end deftypefn @deftypefn Destructor {} ~Client (void) If a connection was already opened, the method @code{Client::close} is called before clearing the object. It destroys the SCSCP client. @end deftypefn @c %----------------------- @subsection connect @deftypemethod Client int connect (const char *@var{machine}, int @var{port}=SCSCP_PROTOCOL_DEFAULTPORT) throw(Exception) It tries to connect to the SCSCP server which is running on the computer @var{machine} and is listening on the port @var{port}. @var{machine} could be any string but it must resolved as an IP address. Its value could be "localhost" if the SCSCP server runs on the same computer. In most of the case, the default value @var{SCSCP_PROTOCOL_DEFAULTPORT} should be used for the port number. @funcxxfailssetstatus{connect} @end deftypemethod @c %----------------------- @subsection close @deftypemethod Client int close () throw(Exception) It closes a connection previously opened by the client with the method @code{Client::connect}. @funcxxfailssetstatus{close} @end deftypemethod @c %----------------------- @subsection eof @deftypemethod Client bool eof () const It returns true if the connection is closed. @end deftypemethod @c %---------------------------------------------------------------------------- @node Procedure call, Stream, Client, @value{LIBRARYCXXNAME} Interface @section Procedure call The procedure calls are managed on the client side by a instance of the class @code{Client::Computation}. The procedure calls are managed on the server side by a instance of the class @code{Server::Computation}. The class @code{Client::Computation} and @code{Server::Computation} derivate from @code{ProcedureCall} and inherit of all public methods of that class. @c %----------------------- @subsection ProcedureCall This class should not be instantiated by the application. Only the @code{Client::Computation} and @code{Server::Computation} should be instantiated. This class provides methods to access the call options or return options of a procedure call. @c %----------------------- @subsubsection ProcedureCall Constructor @deftypefn Constructor {} ProcedureCall (Client& @var{session}) It initializes the procedure call. It generates and sets the call identifier of the options of the procedure call. This call identifier is defined as the symbol @code{call_id} of the OpenMath Content Dictionary @code{scscp1}. The call identifier is prefixed by @code{libSCSCP:}. @end deftypefn @deftypefn Destructor {} ~ProcedureCall (void) It destroys the procedure call. @end deftypefn @c %----------------------- @subsubsection set_runtimelimit @deftypemethod ProcedureCall int set_runtimelimit (size_t @var{time}) This function sets the amount of time in milliseconds, with the value @var{time}, that the SCSCP server should spend on this call. This runtime limit is defined by the symbol @code{option_runtime} of the OpenMath Content Dictionary @code{scscp1}. @funcxxfailsnoexcept{set_runtimelimit} @end deftypemethod @c %----------------------- @subsubsection get_runtimelimit @deftypemethod ProcedureCall int get_runtimelimit (size_t& @var{time}) This function returns, in the argument @var{time}, the amount of time in milliseconds that the server should spend on this call. This amount of time is defined as the symbol @code{option_runtime} of the OpenMath Content Dictionary @code{scscp1}. If the amount of time isn't available (not supplied by the server), the function fails. @funcxxfailsnoexcept{get_runtimelimit} @end deftypemethod @c %----------------------- @subsubsection set_minmemory @deftypemethod ProcedureCall int set_minmemory (size_t @var{memsize}) This function sets the minimum amount of memory in bytes, with the value @var{memsize}, that the server should use on this call. This memory limit is defined by the symbol @code{option_min_memory} of the OpenMath Content Dictionary @code{scscp1}. @funcxxfailsnoexcept{set_minmemory} @end deftypemethod @c %----------------------- @subsubsection get_minmemory @deftypemethod ProcedureCall int get_minmemory (size_t& @var{memsize}) This function returns, in the argument @var{memsize}, the minimum amount of memory in bytes that the server should use on this call. This amount of memory is defined as the symbol @code{option_min_memory} of the OpenMath Content Dictionary @code{scscp1}. If the amount of memory isn't available (not supplied by the server), the function fails. @funcxxfailsnoexcept{get_minmemory} @end deftypemethod @c %----------------------- @subsubsection set_maxmemory @deftypemethod ProcedureCall int set_maxmemory (size_t @var{memsize}) This function sets the maximum amount of memory in bytes, with the value @var{memsize}, that the SCSCP server should use on this call. This memory limit is defined by the symbol @code{option_max_memory} of the OpenMath Content Dictionary @code{scscp1}. @funcxxfailsnoexcept{set_maxmemory} @end deftypemethod @c %----------------------- @subsubsection get_maxmemory @deftypemethod ProcedureCall int get_maxmemory (size_t& @var{memsize}) This function returns, in the argument @var{memsize}, the maximum amount of memory in bytes that the server should use on this call. This amount of memory is defined as the symbol @code{option_max_memory} of the OpenMath Content Dictionary @code{scscp1}. If the amount of memory isn't available (not supplied by the server), the function fails. @funcxxfailsnoexcept{get_maxmemory} @end deftypemethod @c %----------------------- @subsubsection set_debuglevel @deftypemethod ProcedureCall int set_debuglevel (int @var{debuglevel}) This function sets the debug level, with the value @var{debuglevel}, that the client is interested. This debug level is defined by the symbol @code{option_debuglevel} of the OpenMath Content Dictionary @code{scscp1}. @funcxxfailsnoexcept{set_debuglevel} @end deftypemethod @c %----------------------- @subsubsection get_debuglevel @deftypemethod ProcedureCall int get_debuglevel (int& @var{debuglevel}) This function returns, in the argument @var{debuglevel}, the debug level that the client is interested. This debug level is defined as the symbol @code{option_max_memory} of the OpenMath Content Dictionary @code{scscp1}. If the debug level isn't available (not supplied by the server), the function fails and returns 0. @funcxxfailsnoexcept{get_debuglevel} @end deftypemethod @c %----------------------- @subsubsection set_runtime @deftypemethod ProcedureCall int set_runtime (size_t @var{time}) This function sets the amount of time in milliseconds, with the value @var{time}, that the server spent on this call. This amount of time is defined as the symbol @code{info_runtime} of the OpenMath Content Dictionary @code{scscp1}. @funcxxfailsnoexcept{set_runtime} @end deftypemethod @c %----------------------- @subsubsection get_runtime @deftypemethod ProcedureCall int get_runtime (size_t& @var{time}) This function returns, in the argument @var{time}, the amount of time in milliseconds that the server spent on this call. This amount of time is defined as the symbol @code{info_runtime} of the OpenMath Content Dictionary @code{scscp1}. If the amount of time isn't available (not supplied by the server), the function fails. @funcxxfailsnoexcept{get_runtime} @end deftypemethod @c %----------------------- @subsubsection set_memory @deftypemethod ProcedureCall int set_memory (size_t @var{memsize}) This function sets the amount of memory in bytes, with the value @var{memsize}, that the server used on this call. This amount of memory is defined as the symbol @code{info_memory} of the OpenMath Content Dictionary @code{scscp1}. @funcxxfailsnoexcept{set_memory} @end deftypemethod @c %----------------------- @subsubsection get_memory @deftypemethod ProcedureCall int get_memory (size_t& @var{memsize}) This function returns, in the argument @var{memsize}, the amount of memory in bytes that the server used for this call. This amount of memory is defined as the symbol @code{info_memory} of the OpenMath Content Dictionary @code{scscp1}. If the amount of memory isn't available (not supplied by the server), the function fails. @funcxxfailsnoexcept{get_runtime} @end deftypemethod @c %----------------------- @subsubsection set_message @deftypemethod ProcedureCall int set_message ( const char *@var{buffer}) This function sets the information message, with the value @var{buffer}, of the options of the procedure return. This information message is defined as the symbol @code{info_message} of the OpenMath Content Dictionary @code{scscp1}. The argument @var{buffer} can't be NULL and won't be duplicated by this function. So @var{buffer} can't be destroyed until the instance of the object is destroyed. @funcxxfailsnoexcept{set_message} @end deftypemethod @c %----------------------- @subsubsection get_message @deftypemethod ProcedureCall int get_message (const char *&@var{buffer}) This function returns, in the argument @var{buffer}, the information message of the options of the procedure return. This information message is defined as the symbol @code{info_message} of the OpenMath Content Dictionary @code{scscp1}. The returned string mustn't be modified. @funcxxfailsnoexcept{get_message} @end deftypemethod @c %----------------------- @subsubsection set_encodingtype @deftypemethod ProcedureCall int set_encodingtype (SCSCP_encodingtype @var{encodingtype}) This function sets the current encoding of the OpenMath objects used by the SCSCP server or the client, to send the data. The provided Openmath buffers, such as for the call @code{sendstr}, and the streams operations must use the same encoding. The default encoding for the SCSCP client and server is the @code{SCSCP_encodingtype_XML}. @funcxxfailsnoexcept{set_encodingtype} @end deftypemethod @c %----------------------- @subsubsection get_encodingtype @deftypemethod ProcedureCall int get_encodingtype (SCSCP_encodingtype& @var{encodingtype}) This function returns, in the argument @var{encodingtype}, the current encoding of the OpenMath objects used by the SCSCP server or the client to send the data. @funcxxfailsnoexcept{get_encodingtype} @end deftypemethod @c %----------------------- @subsubsection get_returntype @deftypemethod ProcedureCall int get_returntype (SCSCP_option_return& @var{returntype}) This function returns, in the argument @var{returntype}, the return type of the "procedure call" message that the server should send. The possible value of @var{returntype} are described in the function @code{SCSCP_co_set_returntype}. If the return type isn't available (not supplied by the client), the function fails. @funcxxfailsnoexcept{get_returntype} @end deftypemethod @c %----------------------- @subsubsection get_callid @deftypemethod ProcedureCall int get_callid (const char*& @var{callid}) This function returns, in the argument @var{callid}, the call id of the procedure call. The returned string mustn't be modified. @funcxxfailsnoexcept{get_callid} @end deftypemethod @c %----------------------- @subsection Client::Computation @c %----------------------- @subsubsection Client::Computation Constructor @deftypefn Constructor {} Client::Computation (Client& @var{session}) : public ProcedureCall It initializes the procedure call on the client side. It generates and sets the call identifier of the options of the procedure call. This call identifier is defined as the symbol @code{call_id} of the OpenMath Content Dictionary @code{scscp1}. The call identifier is prefixed by @code{libSCSCP:}. @end deftypefn @deftypefn Destructor {} ~Client::Computation (void) It destroys the procedure call on the client side. @end deftypefn @c %----------------------- @subsubsection send @deftypemethod Client::Computation int send (const char *@var{openmathbuffer}, size_t @var{lenbuffer}, SCSCP_option_return @var{returntype}) The client sends a "procedure call" message to the SCSCP server with the options specified before. The server will return a result (object, cookie, nothing) depending on the value @var{returntype}. The array @var{openmathbuffer} is the argument of the procedure call and must be a valid OpenMath Application object with the same encoding as the instance. @var{lenbuffer} specifies the number of valid bytes in the array @var{openmathbuffer}. @funcxxfailssetstatus{send} @end deftypemethod @deftypemethod Client::Computation int send (SCSCP_option_return @var{returntype}, std::ostream *& @var{outstream}) throw (Exception) The client prepares a "procedure call" message to the SCSCP server with the options specified before. The server will return a result (object, cookie, nothing) depending on the value @var{returntype}. The OpenMath data must be written to the returned stream @var{outstream}. This stream only accepts data already encoded in the OpenMath format. The application is responsible to encode data in the same encoding as specified by @code{get_encodingtype}. The written data must be an OpenMath Application object. So it must start with @code{} and finish with @code{} if the XML encoding is used. The "procedure call" message must be completed with a call to @code{finish()} or discarded with a call to @code{discard()}. These functions will delete the pointer @var{outstream}. @funcxxfailssetstatus{send} The following example sends the "Procedure Call" message in order to compute 10! . @example Client::Computation mytask(client); std::ostream* mypstream; mytask.send(SCSCP_option_return_object, mystream); *mystream << ""; *mystream << ""; *mystream << "10"; *mystream << ""; mytask.finish(); @end example @end deftypemethod @deftypemethod Client::Computation int send (SCSCP_option_return @var{returntype}, Ounfstream*& @var{outstream}) throw (Exception) The client prepares a "procedure call" message to the SCSCP server with the options specified before. The server will return a result (object, cookie, nothing) depending on the value @var{returntype}. The data must be written to the returned stream @var{outstream}. The data will be converted to the OpenMath encoding using the encoding specified by @code{get_encodingtype}. The written data must be an OpenMath Application object. So it must start with @code{beginOMA()} and finish with @code{endOMA()}. The "procedure call" message must be completed with a call to @code{finish()} or discarded with a call to @code{discard()}. These functions will delete the pointer @var{outstream}. @funcxxfailssetstatus{send} The following example sends the "Procedure Call" message in order to compute 10! . @example Client::Computation mytask(client); Ounfstream *mystream; mytask.send(SCSCP_option_return_object, mystream); *mystream << beginOMA; *mystream << OMS("integer1", "factorial") << 10; *mystream << endOMA; mytask.finish(); @end example @end deftypemethod @c %----------------------- @subsubsection recv @deftypemethod Client::Computation int recv (SCSCP_msgtype& @var{msgtype}, char*& @var{openmathbuffer}, size_t& @var{lenbuffer}) The @var{client} waits for the answer of a "procedure call" message from the server. It reads the attribute, the type and the content of the message returned by the server in response of a procedure call. On exit, the argument @var{msgtype} contains the message type returned by the server. On exit, the argument @var{openmathbuffer} contains the content of the message returned by the server. This array must be freed by the system call @code{free}. @var{lenbuffer} contains the number of valid bytes in the array @var{openmathbuffer}. @funcxxfailssetstatus{recv} @end deftypemethod @deftypemethod Client::Computation int recv (SCSCP_msgtype& @var{msgtype}, Iunfstream* &@var{stream}) throw (Exception) The @var{client} waits for the answer of a "procedure call" message from the server. It reads the attribute, the type and the content of the message returned by the server in response of a procedure call. On exit, the argument @var{msgtype} contains the message type returned by the server. On exit, the argument @var{stream} contains a pointer to a stream. It allows to parse the input stream. This pointer is valid until to the next call to @code{recv} or @code{send}. @funcxxfailssetstatus{recv} @end deftypemethod @c %----------------------- @subsubsection discard @deftypemethod Client::Computation int discard (void) throw (Exception) It discards the "Procedure call" message previously created with @code{send}. The end of the message isn't sent to the server. So the server won't process this procedure call. The stream, returned by the function @code{send}, must not be longer used after that call. @funcxxfailssetstatus{discard} @end deftypemethod @c %----------------------- @subsubsection finish @deftypemethod Client::Computation int finish (void) throw (Exception) It completes the "Procedure call" message previously created with @code{send}. The end of the message is sent to the server. So the server will process it. The stream, returned by the function @code{send}, must not be longer used after that call. @funcxxfailssetstatus{finish} @end deftypemethod @c %----------------------- @subsection Server::Computation @c %----------------------- @subsubsection Server::Computation Constructor @deftypefn Constructor {} Server::Computation (IncomingClient& @var{session}) : public ProcedureCall It initializes the instance to handle the procedure call on the server side. @end deftypefn @deftypefn Destructor {} ~Server::Computation (void) It destroys the instance to handle the procedure call on the server side. @end deftypefn @c %----------------------- @subsubsection recv @deftypemethod Client::Computation int recv (SCSCP_msgtype& @var{msgtype}, char*& @var{openmathbuffer}, size_t& @var{lenbuffer}) throw (Exception) It waits for an incoming message. When a new message is available, then it reads the attribute, the type and the content of the message sent by the client @var{incomingclient}. On exit, the argument @var{msgtype} must be @code{SCSCP_msgtype_ProcedureCall} or @code{SCSCP_msgtype_Interrupt}. The client sends only "Procedure Call" or "Interrupt" message. On exit, if the argument @var{msgtype} is @code{SCSCP_msgtype_Interrupt}, the call identifier of the interrupted procedure call could be retrieved with a call to @code{get_callid()}. On exit, the argument @var{openmathbuffer} contains the content of the message sent by the client. This string must be freed by the system call @code{free}. @funcxxfailssetstatus{recv} @end deftypemethod @deftypemethod Client::Computation int recv (SCSCP_msgtype& @var{msgtype}, Iunfstream*& @var{stream}) throw (Exception) It waits for an incoming message. When a new message is available, then it reads the attribute, the type and the content of the message sent by the client @var{incomingclient}. On exit, the argument @var{msgtype} must be @code{SCSCP_msgtype_ProcedureCall} or @code{SCSCP_msgtype_Interrupt}. The client sends only "Procedure Call" or "Interrupt" message. On exit, if the argument @var{msgtype} is @code{SCSCP_msgtype_Interrupt}, the call identifier of the interrupted procedure call could be retrieved with a call to @code{get_callid()}. On exit, the argument @var{stream} contains a pointer to a stream. It allows to parse the input stream. This pointer is valid until to the next call to @code{recv} or @code{send}. @funcxxfailssetstatus{recv} @end deftypemethod @c %----------------------- @subsubsection sendcompleted These methods allow to send a "procedure completed" message to the client. @deftypemethod Client::Computation int sendcompleted (const char* @var{openmathbuffer}=NULL, size_t @var{lenbuffer}=0) throw (Exception) It sends a "procedure completed" message using an openmath buffer to the client with the options specified before. The array @var{openmathbuffer} is the argument of the procedure call and must be a valid OpenMath object with the same encoding as the instance. If the anwser is empty, @var{openmathbuffer} could be NULL. @var{lenbuffer} specifies the number of valid bytes in the array @var{openmathbuffer}. @funcxxfailssetstatus{sendcompleted} @end deftypemethod @deftypemethod Client::Computation int sendcompleted (std::ostream *& @var{outstream}) throw (Exception) The server prepares to send a "procedure completed" message using an openmath buffer to the client with the options specified before. The OpenMath data must be written to the returned stream @var{outstream}. This stream only accepts data already encoded in the OpenMath format. The application is responsible to encode data in the same encoding as specified by @code{get_encodingtype}. The written data must be an OpenMath object. The answer must be completed with a call to @code{finish()}. That function will delete the pointer @var{outstream}. @funcxxfailssetstatus{sendcompleted} @end deftypemethod @deftypemethod Server::Computation int sendcompleted (Ounfstream*& @var{outstream}) throw (Exception) The server prepares to send a "procedure completed" message using an openmath buffer to the client with the options specified before. The data must be written to the returned stream @var{outstream}. The data will be converted to the OpenMath encoding using the encoding specified by @code{get_encodingtype}. The written data must be an OpenMath object. The answer must be completed with a call to @code{finish()}. That function will delete the pointer @var{outstream}. @funcxxfailssetstatus{send} @end deftypemethod @c %----------------------- @subsubsection sendterminated That method allows to send a "procedure terminated" message to the client. @deftypemethod Client::Computation int sendterminated (const char * @var{cdname}, const char * @var{symbolname}, const char * @var{message}) throw (Exception) It sends a "procedure terminated" message to the SCSCP client with the options specified before. The symbol of the OpenMath Error is defined by its name @var{symbolname} and its CD @var{cdname}. @var{message} is the message that will be inserted in a OMSTR OpenMath object. @funcxxfailssetstatus{sendterminated} @end deftypemethod @c %----------------------- @subsubsection finish @deftypemethod Server::Computation int finish (void) throw (Exception) It completes the answer previously created with @code{sendcompleted}. The end of the message is sent to the client. So the client will process it. The stream, returned by the function @code{sendcompleted}, must not be longer used after that call. @funcxxfailssetstatus{finish} @end deftypemethod @c %---------------------------------------------------------------------------- @node Stream, Exception, Procedure call, @value{LIBRARYCXXNAME} Interface @section Stream @subsection Ounfstream This output stream handles the writing of the basic C data-types, such as int, double, .... It supports also the manipulators to build complex OpenMath objects. It encodes in binary or XML the OpenMath objects according to the current encoding of the stream. The following example buids the OpenMath Object, corresponding to 1+n^2 : @example Ounfstream& stream =... stream<< beginOMA << OMS("arith1","plus") stream<< 1 stream<< beginOMA <} to the stream @var{stream}. @funcstreamxxfailssetstatus{} @end deftypemethod @c %----------------------- @subsubsection endOMA @deftypemethod Ounfstream& beginOMA (Ounfstream&) throw (Exception) It writes the end of the structured Open Math object @code{} to the @var{stream}. @funcstreamxxfailssetstatus{} @end deftypemethod @c %----------------------- @subsubsection beginOMATP @deftypemethod Ounfstream& beginOMATP (Ounfstream&) throw (Exception) It writes the beginning of the structured Open Math object @code{} to the stream @var{stream}. @funcstreamxxfailssetstatus{} @end deftypemethod @c %----------------------- @subsubsection endOMATP @deftypemethod Ounfstream& endOMATP (Ounfstream&) throw (Exception) It writes the end of the structured Open Math object @code{} to the @var{stream}. @funcstreamxxfailssetstatus{} @end deftypemethod @c %----------------------- @subsubsection beginOMATTR @deftypemethod Ounfstream& beginOMATTR (Ounfstream&) throw (Exception) It writes the beginning of the structured Open Math object @code{} to the stream @var{stream}. @funcstreamxxfailssetstatus{} @end deftypemethod @c %----------------------- @subsubsection endOMATTR @deftypemethod Ounfstream& endOMATTR (Ounfstream&) throw (Exception) It writes the end of the structured Open Math object @code{} to the @var{stream}. @funcstreamxxfailssetstatus{} @end deftypemethod @c %----------------------- @subsubsection beginOME @deftypemethod Ounfstream& beginOME (Ounfstream&) throw (Exception) It writes the beginning of the structured Open Math object @code{} to the stream @var{stream}. @funcstreamxxfailssetstatus{} @end deftypemethod @c %----------------------- @subsubsection endOME @deftypemethod Ounfstream& endOME (Ounfstream&) throw (Exception) It writes the end of the structured Open Math object @code{} to the @var{stream}. @funcstreamxxfailssetstatus{} @end deftypemethod @c %----------------------- @subsubsection beginOMOBJ @deftypemethod Ounfstream& beginOMOBJ (Ounfstream&) throw (Exception) It writes the beginning of the structured Open Math object @code{} to the stream @var{stream}. @funcstreamxxfailssetstatus{} @end deftypemethod @c %----------------------- @subsubsection endOMOBJ @deftypemethod Ounfstream& endOMOBJ (Ounfstream&) throw (Exception) It writes the end of the structured Open Math object @code{} to the @var{stream}. @funcstreamxxfailssetstatus{} @end deftypemethod @c %----------------------- @subsubsection operator<< @deftypeop operator<< Ounfstream Ounfstream& operator << (Ounfstream& @var{out}, int @var{x}) throw (Exception) It writes @var{x} to the stream @code{out} as the basic OpenMath object @code{...} according to the current encoding. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator<< Ounfstream Ounfstream& operator << (Ounfstream& @var{out}, double @var{x}) throw (Exception) It writes @var{x} to the stream @code{out} as the basic OpenMath object @code{} according to the current encoding. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator<< Ounfstream Ounfstream& operator << (Ounfstream& @var{out}, const char * @var{str}) throw (Exception) It writes the C-style string @var{str} to the stream @code{out} as the basic OpenMath object @code{...} according to the current encoding. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator<< Ounfstream Ounfstream& operator << (Ounfstream& @var{out}, OMF @var{x}) throw (Exception) It writes the OpenMath float @var{x} to the stream @code{out} according to the current encoding. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator<< Ounfstream Ounfstream& operator << (Ounfstream& @var{out}, OMI @var{x}) throw (Exception) It writes the OpenMath integer @var{x} to the stream @code{out} according to the current encoding. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator<< Ounfstream Ounfstream& operator << (Ounfstream& @var{out}, OMR @var{x}) throw (Exception) It writes the OpenMath reference @var{x} to the stream @code{out} according to the current encoding. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator<< Ounfstream Ounfstream& operator << (Ounfstream& @var{out}, OMS @var{x}) throw (Exception) It writes the OpenMath symbol @var{x} to the stream @code{out} according to the current encoding. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator<< Ounfstream Ounfstream& operator << (Ounfstream& @var{out}, OMV @var{x}) throw (Exception) It writes the OpenMath variable @var{x} to the stream @code{out} according to the current encoding. @funcstreamxxfailssetstatus{} @end deftypeop @c %----------------------- @subsection Iunfstream @c %----------------------- @subsubsection omtype This type is an enumeration of the possible values of the node. The possible values are @table @samp @item SCSCP_omtype_OMI OpenMath integer. @item SCSCP_omtype_OMF OpenMath IEEE floating point number. @item SCSCP_omtype_OMV OpenMath variable. @item SCSCP_omtype_OMS OpenMath symbol. @item SCSCP_omtype_OMSTR OpenMath string. @item SCSCP_omtype_OMB OpenMath byte array. @item SCSCP_omtype_OMFOREIGN OpenMath foreign. @item SCSCP_omtype_OMA OpenMath application. @item SCSCP_omtype_OMBIND OpenMath binding. @item SCSCP_omtype_OMATTR OpenMath attribution. @item SCSCP_omtype_OME OpenMath error. @item SCSCP_omtype_OMATP OpenMath attribute pair. @item SCSCP_omtype_OMOBJ OpenMath object. @item SCSCP_omtype_OMBVAR OpenMath variables used in binding. @item SCSCP_omtype_OMR OpenMath reference. @item SCSCP_omtype_CONTENT content node. @end table @c %----------------------- @subsubsection iterator_attr This type in an iterator on the attributes of the Openmath elements. it could be used in a similar as iteraor of the STL. @cartouche @example Iunfstream& stream = .... ; for (Iunfstream::iterator_attr attr = stream.get_attr(); attr.end() ; ++attr) @{ PRINTAB(tab+1); cout <<"attribute : '" << attr.get_name() <<"' = '" << attr.get_value() <<"'"<> @deftypeop operator>> Iunfstream Iunfstream& operator >> (int& @var{x}) throw (Exception) It reads an OpenMath object from the stream and converts it to the integer @var{x}. If this OpenMath object can't be converted to a floating-point, an exception is raised. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator>> Iunfstream Iunfstream& operator >> (double& @var{x}) throw (Exception) It reads an OpenMath object from the stream and converts it to the floating-point @var{x}. If this OpenMath object can't be converted to a floating-point, an exception is raised. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator>> Iunfstream Iunfstream& operator >> (const char*& @var{x}) throw (Exception) It reads an OpenMath string from the stream and store it to @var{x}. If this OpenMath object can't be converted to a string, an exception is raised. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator>> Iunfstream Iunfstream& operator >> (OMF @var{x}) throw (Exception) It reads the OpenMath float @var{x} from the stream. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator>> Iunfstream Iunfstream& operator >> (OMI @var{x}) throw (Exception) It reads the OpenMath integer @var{x} from the stream. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator>> Iunfstream Iunfstream& operator >> (OMR @var{x}) throw (Exception) It reads the OpenMath reference @var{x} from the stream. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator>> Iunfstream Iunfstream& operator >> (OMS @var{x}) throw (Exception) It reads the OpenMath symbol @var{x} from the stream. @funcstreamxxfailssetstatus{} @end deftypeop @deftypeop operator>> Iunfstream Iunfstream& operator >> (OMV @var{x}) throw (Exception) It reads the OpenMath variable @var{x} from the stream. @funcstreamxxfailssetstatus{} @end deftypeop @c %---------------------------------------------------------------------------- @node Exception , OpenMath objects, Stream, @value{LIBRARYCXXNAME} Interface @section Exception On errors, the C++ functions raise an exception of type @code{Exception} which derivates from the STL @code{std::exception}. @c %----------------------- @subsection Constructor @deftypefn Constructor {} Exception (const SCSCP_status* status) : public std::exception It initializes the SCSCP exception wit the specified status information. @end deftypefn @deftypefn Destructor {} ~Exception (void) It destroys the exception. @end deftypefn @c %----------------------- @subsection what @deftypemethod Exception const char * what () const throw() It returns a C-style character string describing the general cause of the current error. @end deftypemethod @c %---------------------------------------------------------------------------- @node OpenMath objects, , Exception, @value{LIBRARYCXXNAME} Interface @section OpenMath objects These OpenMath objects are usefull to perform the input or output from/to the stream. All these OpenMath objects derivate from the base class @code{OMBase}. The C-style string accepted by their constructor aren't duplicated and must exist during the life of the instance of the object. The method @code{beginOM} is a common method for derived OpenMath object, such as OMA, OME, .... @c %----------------------- @subsection OMBase @deftypemethod OMBase const char * get_id () const It returns the reference id () of the Openmath object. It may return NULL if the reference id of the object is unset. @end deftypemethod @c %----------------------- @subsection OMA @deftypefn Constructor {} OMA (const char *@var{id}=NULL) It creates the OpenMath application with the reference @var{id}. paramid @end deftypefn @deftypemethod OMA Iunfstream beginOM () It returns a stream to parse the children nodes of the derived OpenMath objects. @end deftypemethod @c %----------------------- @subsection OMBIND @deftypefn Constructor {} OMBIND (const char *@var{id}=NULL) It creates the OpenMath binding with the reference @var{id}. paramid @end deftypefn @deftypemethod OMBIND Iunfstream beginOM () It returns a stream to parse the children nodes of the derived OpenMath objects. @end deftypemethod @c %----------------------- @subsection OME @deftypefn Constructor {} OME (const char *@var{id}=NULL) It creates the OpenMath error with the reference @var{id}. paramid @end deftypefn @deftypemethod OME Iunfstream beginOM () It returns a stream to parse the children nodes of the derived OpenMath objects. @end deftypemethod @c %----------------------- @subsection OMF @deftypefn Constructor {} OMF (const char* @var{value}, const char *@var{id}=NULL) It creates the OpenMath float with the @var{value} and the reference @var{id}. paramid The C-style string @var{href} isn't duplicated. @var{value} must be in base 10. @end deftypefn @deftypemethod OMF const char * get_value () const This function returns the value of the Openmath float. @end deftypemethod @deftypemethod OMF int get_base () const This function returns the base number of the Openmath float. @end deftypemethod @c %----------------------- @subsection OMI @deftypefn Constructor {} OMI (const char* @var{value}, const char *@var{id}=NULL) It creates the OpenMath integer with the @var{value} and the reference @var{id}. paramid The C-style string @var{href} isn't duplicated. @var{value} must be in base 10. @end deftypefn @deftypemethod OMI const char * get_value () const This function returns the value of the Openmath integer. @end deftypemethod @c %----------------------- @subsection OMR @deftypefn Constructor {} OMR (const char* @var{href}) It creates the OpenMath reference @var{href}. The C-style string @var{href} isn't duplicated. @end deftypefn @deftypemethod OMR const char * get_reference () const This function returns the value of the Openmath reference. @end deftypemethod @c %----------------------- @subsection OMS @deftypefn Constructor {} OMS (const char* @var{cdname}, const char* @var{symbolname}, const char *@var{id}=NULL) It creates the OpenMath symbol @var{symbolname} of the Content Dictionary @var{cdname}. The C-style strings @var{cdname} and @var{symbolname} aren't duplicated. @paramid @end deftypefn @deftypemethod OMS const char * get_cdname () const This function returns the cd name of the Openmath symbol. @end deftypemethod @deftypemethod OMS const char * get_symbolname () const This function returns the symbol name of the Openmath symbol. @end deftypemethod @c %----------------------- @subsection OMV @deftypefn Constructor {} OMV (const char* @var{name}, const char *@var{id}=NULL) It creates the OpenMath variable @var{name}. The C-style string @var{name} isn't duplicated. @paramid @end deftypefn @deftypemethod OMS const char * get_name () const This function returns the name of the Openmath variable. @end deftypemethod @c %---------------------------------------------------------------------------- @node Design a SCSCP C++ server, Design a SCSCP C++ client, @value{LIBRARYCXXNAME} Interface, Top @chapter Design a SCSCP C++ server The file @file{examples/decodeserverxx.cpp} shows the server which decodes each node of the OpenMath expression received from the client. It sends an answer to the client depending on the call options. @sp 1 A simple SCSCP C++ server could be done with the following operations. This server supports the scscp versions "1.3". @itemize using namespace SCSCP; @item Initialize the server @example Server server("MYCAS", "1.0", "myid"); @end example @item Listen for incoming client @example server.listen(); @end example @item Loop over new clients @example IncomingClient *incomingclient; while ((incomingclient=server.acceptclient())!=NULL) @{ @end example @itemize @item Receive the "procedure call" message : 2 solutions @example Server::Computation mytask(incomingclient); @end example @itemize @item solution 1 : read the header and parse the openmath stream @example Iunfstream *mystream; mytask.recv(msgtype, mystream); ... @end example @item solution 2 : read the header and store the content in a string buffer @example char *openmathbuffer; mytask.recv(msgtype, openmathbuffer, lenbuffer); .... free(openmathbuffer); @end example @end itemize @item Send the answer : procedure completed or terminated ? @itemize @item Send a "procedure completed" message : 3 solutions @itemize @item solution 1 : C-style byte array using the XML or binary encoding (C-string is XML) @example const char *answer="10"; mytask.sendcompleted(answer, ::strlen(answer)); @end example @item solution 2 : STL ostream using the XML encoding only @example std::ostream*& stream; mytask.sendcompleted(stream); *stream << "10"; mytask.finish(); @end example @item solution 3 : unformatted stream using the XML or binary encoding @example Ounfstream* stream; mytask.sendcompleted(stream); *stream << 10; mytask.finish(); @end example @end itemize @item Send a "procedure terminated" message @example const char *messageerror="can't store an object"; mytask.sendterminated("sccsp1", "error_system_specific", messageerror); @end example @end itemize @end itemize @item Close the connection @example delete incomingclient; @} @end example @item Stop to listen for incoming clients @example server.close(); @end example @end itemize @c %---------------------------------------------------------------------------- @node Design a SCSCP C++ client, References, Design a SCSCP C++ server, Top @chapter Design a SCSCP C++ client The file @file{examples/simplestclientxx.cpp} shows the simplest client which stores the value 6177887 on the server using the C-byte array and prints the answer of the server. The file @file{examples/simplestclientstreamfmtxx.cpp} shows the simplest client which stores the value 6177887 on the server using the STL ostream and prints the answer of the server. The file @file{examples/simplestclientstreamunfxx.cpp} shows the simplest client which stores the value 435 on the server using the unformatted stream and prints the answer of the server. @sp 1 A simple SCSCP client could be done with the following operations. This simple client will connect with the SCSCP server located on "localhost" and listening on port 26133. @itemize @item Initialize the client @example SCSCP::Client client; @end example @item Open the Connection @example client.connect("localhost"); @end example @item Send a procedure call : 3 solutions Client::Computation mytask(myclient); @itemize @item solution 1 : C-style byte array using the XML or binary encoding (C-string is XML) @example const char *cmd = ""; mytask.send(cmd, ::strlen(cmd), SCSCP_option_return_object); @end example @item solution 2 : STL ostream using the XML encoding only @example std::ostream*& stream; mytask.send(SCSCP_option_return_object, stream); *stream << ""; *stream << " *stream << "; mytask.finish(); @end example @item solution 3 : unformatted stream using the XML or binary encoding @example Ounfstream* stream; mytask.send(SCSCP_option_return_object, stream); *stream << beginOMA; *stream << OMS("scscp2","get_allowed_heads"); *stream << endOMA; mytask.finish(); @end example @end itemize @item Receive the answer of the procedure call : 2 solutions @itemize @item solution 1 : read the header and parse the openmath stream @example Iunfstream *mystream; mytask.recv(msgtype, mystream); ... @end example @item solution 2 : read the header and store the content in a string buffer @example char *buffer; size_t lenbuffer; SCSCP_msgtype msgtype; mytask.recv(msgtype, buffer,lenbuffer); @end example @end itemize @item Close the connection @example client.close(); @end example @end itemize @c %---------------------------------------------------------------------------- @node References, , Design a SCSCP C++ client, Top @chapter References @itemize @item Symbolic Computation Software Composability Protocol (SCSCP) specification Version 1.3, 2009 S.Freundt, P.Horn, A.Konovalov, S.Linton, D.Roozemond. @url{http://www.symcomp.org/scscp} @item OpenMath content dictionary scscp1 D. Roozemond @url{http://www.win.tue.nl/SCIEnce/cds/scscp1.html} @item OpenMath content dictionary scscp2 D. Roozemond @url{http://www.win.tue.nl/SCIEnce/cds/scscp2.html} @end itemize @bye scscp-imcce-1.0.0+ds/examples/000077500000000000000000000000001215622604100161205ustar00rootroot00000000000000scscp-imcce-1.0.0+ds/examples/Makefile.am000066400000000000000000000075621215622604100201660ustar00rootroot00000000000000#/*-----------------------------------------------------------------*/ #/*! # \file Makefile.am # \brief Makefile for automake # \author M. Gastineau # Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. # # Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS # email of the author : gastineau@imcce.fr # #*/ #/*-----------------------------------------------------------------*/ # #/*-----------------------------------------------------------------*/ #/* License of this file : # This file is "dual-licensed", you have to choose one of the two licenses # below to apply on this file. # # CeCILL-C # The CeCILL-C license is close to the GNU LGPL. # ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) # # or CeCILL v2.0 # The CeCILL license is compatible with the GNU GPL. # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) # # # This library is governed by the CeCILL-C or the CeCILL license under # French law and abiding by the rules of distribution of free software. # You can use, modify and/ or redistribute the software under the terms # of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA # at the following URL "http://www.cecill.info". # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # In this respect, the user's attention is drawn to the risks associated # with loading, using, modifying and/or developing or reproducing the # software by the user in light of its specific status of free software, # that may mean that it is complicated to manipulate, and that also # therefore means that it is reserved for developers and experienced # professionals having in-depth computer knowledge. Users are therefore # encouraged to load and test the software's suitability as regards their # requirements in conditions enabling the security of their systems and/or # data to be ensured and, more generally, to use and operate it in the # same conditions as regards security. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-C or CeCILL license and that you accept its terms. # */ # /*-----------------------------------------------------------------*/ ## Makefile.am -- Process this file with automake to produce Makefile.in AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/srcxx $(XML_CPPFLAGS) CXXEXAMPLES = simplestclientxx simplestclientstreamfmtxx simplestclientstreamunfxx decodeserverxx noinst_PROGRAMS = simplestclient decodeclient remoteclient execclient decodeserver $(CXXEXAMPLES) # /*-----------------------------------------------------------------*/ # C examples # /*-----------------------------------------------------------------*/ LDADD = $(top_builddir)/src/libscscp.la $(XML_LIBS) simplestclient_SOURCES = simplestclient.c decodeclient_SOURCES = decodeclient.c remoteclient_SOURCES = remoteclient.c decodeserver_SOURCES = decodeserver.c execclient_SOURCES = execclient.c # /*-----------------------------------------------------------------*/ # C++ examples # /*-----------------------------------------------------------------*/ CXXLDADD_FLAGS = $(top_builddir)/srcxx/libscscpxx.la $(LDADD) simplestclientxx_SOURCES = simplestclientxx.cpp simplestclientxx_LDADD = $(CXXLDADD_FLAGS) simplestclientstreamfmtxx_SOURCES = simplestclientstreamfmtxx.cpp simplestclientstreamfmtxx_LDADD = $(CXXLDADD_FLAGS) simplestclientstreamunfxx_SOURCES = simplestclientstreamunfxx.cpp simplestclientstreamunfxx_LDADD = $(CXXLDADD_FLAGS) decodeserverxx_SOURCES = decodeserverxx.cpp decodeserverxx_LDADD = $(CXXLDADD_FLAGS) EXTRA_DIST = Makefile.vc readme.txt scscp-imcce-1.0.0+ds/examples/decodeclient.c000066400000000000000000000163131215622604100207120ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file decodeclient.c \brief check that client could decode the completed message with complex parse \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include #include /*-----------------------------------------------------------------*/ /* print the xml tree */ /*-----------------------------------------------------------------*/ static void printelements(SCSCP_xmlnodeptr node, int tab) { #define PRINTAB(x) for(j=0; j", &status); printf ("-----------receive the first answer----------\n"); /* receive the answer */ if (res) res = decodeanswer(&client, &status); /* some server disconnects after an error.... So we reconnect */ if (res) res = SCSCP_sc_close(&client, &status); if (res) res = SCSCP_sc_connect(&client, host, port, &status); /* send a valid symbol */ printf ("----------- valid command----------\n"); if (res) res = SCSCP_co_init(&calloptions, &status); if (res) res = SCSCP_co_set_returntype(&calloptions, SCSCP_option_return_object, &status); if (res) res = SCSCP_sc_callsendstr(&client, &calloptions, "", &status); printf ("-----------receive the second answer----------\n"); /* receive the answer */ if (res) res = decodeanswer(&client, &status); /* send an invalid symbol */ printf ("-----------invalid command----------\n"); if (res) res = SCSCP_sc_callsendstr(&client, SCSCP_CALLOPTIONS_DEFAULT, "", &status); printf ("-----------receive the third answer----------\n"); /* receive the answer */ if (res) res = decodeanswer(&client, &status); /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); if (res) res = SCSCP_co_clear(&calloptions, &status); if (res==0) printf("status=%s\n", SCSCP_status_strerror(&status)); SCSCP_status_clear(&status); return (res!=1); } scscp-imcce-1.0.0+ds/examples/decodeserver.c000066400000000000000000000213631215622604100207430ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file decodeserver.c \brief This server which decodes each node of the OpenMath expression received from the client. It prints the received OpenMath expression and returns a "procedure completed" message. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include #include static int processcall(SCSCP_incomingclient *incomingclient, SCSCP_status *status); static void printelements(SCSCP_xmlnodeptr node, int tab); static int runserver(); /*-----------------------------------------------------------------*/ /*! start the server and listen on default port */ /*-----------------------------------------------------------------*/ static int runserver() { SCSCP_socketserver server; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res; SCSCP_incomingclient incomingclient; int port = SCSCP_PROTOCOL_DEFAULTPORT; /*initialization of the server */ res = SCSCP_ss_init(&server, &status, "MYCASEXAMPLE","1","myid", SCSCP_PROTOCOL_VERSION_1_3, SCSCP_PROTOCOL_VERSION_1_2, "1.001", NULL); /*listen to incoming clients */ if (res) res = SCSCP_ss_listen(&server, port, 1, &status); if (res) { /* wait for a new client */ while (SCSCP_ss_acceptclient(&server, &incomingclient, &status)) { printf("a new client is accepted !\n"); /* loop until an error occurs */ res=1; while (res) res = processcall(&incomingclient, &status); printf("close the connection with the client !\n"); SCSCP_ss_closeincoming(&incomingclient, &status); } } /* destroy the server */ SCSCP_ss_close(&server, &status); res = SCSCP_ss_clear(&server, &status); SCSCP_status_clear(&status); printf("the server exists\n"); return 0; } /*-----------------------------------------------------------------*/ /* print the xml tree */ /*-----------------------------------------------------------------*/ static void printelements(SCSCP_xmlnodeptr node, int tab) { #define PRINTAB(x) for(j=0; j0", status); break; case SCSCP_option_return_cookie: res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt,"", status); break; case SCSCP_option_return_nothing : default: res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt,"", status); break; } } SCSCP_co_clear(&options, status); SCSCP_ro_clear(&returnopt, status); return res; } /*-----------------------------------------------------------------*/ /*! main program */ /*-----------------------------------------------------------------*/ int main(int argc, char *argv[]) { return runserver(); } scscp-imcce-1.0.0+ds/examples/decodeserverxx.cpp000066400000000000000000000224301215622604100216570ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file decodeserverxx.cpp \brief This C++ server which decodes each node of the OpenMath expression received from the client. It prints the received OpenMath expression and returns a "procedure completed" message. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include #include #include using namespace SCSCP; using namespace std; static int processcall(IncomingClient &incomingclient); static void printelements(Iunfstream& stream, int tab); static int runserver(); /*-----------------------------------------------------------------*/ /*! start the server and listen on default port */ /*-----------------------------------------------------------------*/ static int runserver() { Server server( "MYCASEXAMPLE","1","myid"); int res; IncomingClient *incomingclient; /*listen to incoming clients */ try { server.listen(); printf("wait for a client\n"); /* wait for a new client */ while ((incomingclient = server.acceptclient())!=NULL) { printf("a new client is accepted !\n"); /* loop until an error occurs */ while (processcall(*incomingclient)); printf("close the connection with the client !\n"); delete incomingclient; printf("wait for a client\n"); } } catch (Exception e) { /* error */ printf("Exception : %s\n", e.what()); return 1; } /* destroy the server */ server.close(); printf("the server exists\n"); return 0; } /*-----------------------------------------------------------------*/ /* print the answer */ /*-----------------------------------------------------------------*/ static void printelements(Iunfstream& stream, int tab) { #define PRINTAB(x) for(j=0; j> v; cout << "integer = "<< v <> f; cout << "floating-point = "<< f <> var; cout << "variable = "<< var.get_name() <> symbol; cout << "symbol = name : "<< symbol.get_symbolname() << " cd : "<< symbol.get_cdname() <> s; cout << "string = '"<< s << "'" <> href; cout << "reference = '"<< href.get_reference() << "'" <0"); break; case SCSCP_option_return_cookie: mytask.sendcompleted(""); break; case SCSCP_option_return_nothing : default: mytask.sendcompleted(""); break; } res = 1; } catch (Exception e) { /* error */ printf("error in the procedure call !\nException : %s\n", e.what()); res= 0; } return res; } /*-----------------------------------------------------------------*/ /*! main program */ /*-----------------------------------------------------------------*/ int main(int argc, char *argv[]) { return runserver(); } scscp-imcce-1.0.0+ds/examples/execclient.c000066400000000000000000000124241215622604100204120ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file execclient.c \brief client computes the 1+sqrt(n). n is a remote object \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include #include /*-----------------------------------------------------------------*/ /* hook function */ /*-----------------------------------------------------------------*/ static int writeobject(SCSCP_io *stream, void *param, SCSCP_status *status) { return SCSCP_io_writeOMIint(stream, *(int *)param, NULL, status); } /*-----------------------------------------------------------------*/ /* hook function : write 1 n^2 */ /*-----------------------------------------------------------------*/ static int writeexec(SCSCP_io *stream, void *param, SCSCP_status *status) { int res = SCSCP_io_writeOMIint(stream, 1, NULL, status); res &= SCSCP_io_writebeginOMA(stream, NULL, status); res &= SCSCP_io_writeOMS(stream, "arith1","power", NULL, status); res &= SCSCP_io_writeOMR(stream, (const char *)param, status); res &= SCSCP_io_writeOMIint(stream,2, NULL, status); res &= SCSCP_io_writeendOMA(stream, status); return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main(int argc, char *argv[]) { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int n = 3; char *cookiename = NULL; char *openmathbuffer = NULL; const char *host = "localhost"; int port = SCSCP_PROTOCOL_DEFAULTPORT; int res; if (argc==3) { host = argv[1]; port = atoi(argv[2]); } printf("---------- connecting to %s:%d ---------\n", host, port); /* open connection with the server on port 26133 */ res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, host, port, &status); /* store the value 3 as a remote object */ printf ("----------store the value n ---------\n"); if (res) res = SCSCP_sc_remoteobjectstoresessionhook(&client, writeobject, &n, &cookiename, &status); if (res) printf("reference object name = %s\n", cookiename); /* execute the computation : 1+n^2 */ printf ("----------- 1+n^2 ---------\n"); if (res) res = SCSCP_sc_executehookstr(&client, SCSCP_option_return_object, "arith1", "plus", writeexec, cookiename, &openmathbuffer, &status); if (res) { printf("OpenMath object representation from the server :'%s'\n", openmathbuffer); free(openmathbuffer); } /* delete the remote object */ printf ("----------- delete remote object ----------\n"); if (res) res = SCSCP_sc_remoteobjectunbind(&client, cookiename, &status); if( cookiename) free(cookiename); /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); if (res==0) printf("error message=%s\n", SCSCP_status_strerror(&status)); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); return (res!=1); } scscp-imcce-1.0.0+ds/examples/readme.txt000066400000000000000000000037371215622604100201300ustar00rootroot00000000000000This directory contains some examples to build SCSCP client and server. C examples ---------- - simplestclient.c : The simplest client stores the value 6177887 on the SCSCP server which runs on "localhost" and listens on port 26133 . It prints the returned message. - decodeclient.c : This client decodes each node of the OpenMath expression received from the server. It requests the allowed procedure names. After decoding the first answer, it sends a symbol which doesn't exist in order to produce an error. - remoteclient.c : This client sends the value 3 to the server and store it as a remote object. It retrieves the value of the remote object. At end, it deletes the remote object from the server. - execclient.c : This client sends the value 3.0 to the server and store it as a remote object. It computes and gets the result of "1+n^2" where n is the previous remote object. At end, it deletes the remote object from the server. - decodeserver.c : This server which decodes each node of the OpenMath expression received from the client. It prints the received OpenMath expression and returns a "procedure completed" message. C++ examples ---------- - simplestclientxx.cpp : The simplest client stores the value 6177887 on the SCSCP server using the function sendstr/recvstr which runs on "localhost" and listens on port 26133 . It prints the returned message. - simplestclientstreamfmtxx.cpp : The simplest client stores the value 6177887 on the SCSCP server using the formatted stream which runs on "localhost" and listens on port 26133 . It prints the returned message. - simplestclientstreamunfxx.cpp : The simplest client stores the value 435 on the SCSCP server using the unformatted stream which runs on "localhost" and listens on port 26133 . It prints the returned message. - decodeserverxx.cpp : This server which decodes each node of the OpenMath expression received from the client. It prints the received OpenMath expression and returns a "procedure completed" message. scscp-imcce-1.0.0+ds/examples/remoteclient.c000066400000000000000000000112361215622604100207610ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file remoteclient.c \brief client send, retrieve and delete a remote object using string \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include #include /*-----------------------------------------------------------------*/ /* hook function */ /*-----------------------------------------------------------------*/ static int writeobject(SCSCP_io *stream, void *param, SCSCP_status *status) { return SCSCP_io_writeOMIint(stream, *(int *)param, NULL, status); } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main(int argc, char *argv[]) { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int n = 3; char *cookiename = NULL; char *openmathbuffer = NULL; const char *host = "localhost"; int port = SCSCP_PROTOCOL_DEFAULTPORT; int res; if (argc==3) { host = argv[1]; port = atoi(argv[2]); } printf("---------- connecting to %s:%d ---------\n", host, port); /* open connection with the server on port 26133 */ res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, SCSCP_PROTOCOL_VERSION_1_2, NULL); if (res) res = SCSCP_sc_connect(&client, host, port, &status); /* store the value 3 as a remote object */ printf ("---------- store the value n ---------\n"); if (res) res = SCSCP_sc_remoteobjectstoresessionhook(&client, writeobject, &n, &cookiename, &status); if (res) printf("reference object name = %s\n", cookiename); /* retrieve its value */ printf ("----------- retrieve its value ---------\n"); if (res) res = SCSCP_sc_remoteobjectretrievestr(&client, cookiename, &openmathbuffer, &status); if (res) { printf("OpenMath object representation from the server :'%s'\n", openmathbuffer); free(openmathbuffer); } /* delete the remote object */ printf ("----------- delete remote object ----------\n"); if (res) res = SCSCP_sc_remoteobjectunbind(&client, cookiename, &status); if( cookiename) free(cookiename); /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); if (res==0) printf("error message=%s\n", SCSCP_status_strerror(&status)); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); return (res!=1); } scscp-imcce-1.0.0+ds/examples/simplestclient.c000066400000000000000000000111201215622604100213160ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file simplestclient.c \brief example : the simplest client ! \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include #include /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main(int argc, char *argv[]) { SCSCP_status status = SCSCP_STATUS_INITIALIZER; SCSCP_socketclient client; const char *openmath = "6177887"; char *buffer; SCSCP_msgtype msgtype; SCSCP_calloptions calloptions; const char *host = "localhost"; int port = SCSCP_PROTOCOL_DEFAULTPORT; int res; if (argc==3) { host = argv[1]; port = atoi(argv[2]); } printf("---------- connecting to %s:%d ---------\n", host, port); /* open connection with the server on port 26133 */ res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, SCSCP_PROTOCOL_VERSION_1_2, NULL); if (res) res = SCSCP_sc_connect(&client, host, port, &status); /* send the command openmath */ SCSCP_co_init(&calloptions, &status); if (res) SCSCP_co_set_returntype(&calloptions,SCSCP_option_return_cookie, &status); if (res) res = SCSCP_sc_callsendstr(&client, &calloptions, openmath, &status); /* receive the answer */ if (res) res = SCSCP_sc_callrecvstr(&client, SCSCP_RETURNOPTIONS_IGNORE, &msgtype, &buffer, &status); /* print the answer */ if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated\n"); break; case SCSCP_msgtype_ProcedureCompleted : printf("Procedure Completed\n"); break; default : printf("unknown message type !!!\n"); break; } printf("returned message :\n"); printf("--------cut here--------\n"); puts(buffer); printf("--------cut here--------\n"); } /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_co_clear(&calloptions, &status); /* display the error if an error occurs */ if (res==0) { printf("error : %d\n", SCSCP_status_is(&status)); } SCSCP_status_clear(&status); return (res!=1); } scscp-imcce-1.0.0+ds/examples/simplestclientstreamfmtxx.cpp000066400000000000000000000102571215622604100241730ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file simplestclientstreamfmtxx.cpp \brief example : the simplest C++ client using formatted stream ! \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include #include #include using namespace SCSCP; /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main(int argc, char *argv[]) { Client myclient; const char *openmath = "6177887"; char *buffer; size_t lenbuffer; SCSCP_msgtype msgtype; const char *host = "localhost"; int port = SCSCP_PROTOCOL_DEFAULTPORT; int res; if (argc==3) { host = argv[1]; port = atoi(argv[2]); } printf("---------- connecting to %s:%d ---------\n", host, port); try { /* open connection with the server on port 26133 */ res = myclient.connect(host, port); printf("---------- procedure call with formatted stream ---------\n"); /* send the command openmath */ Client::Computation mytask2(myclient); std::ostream* stream; mytask2.send(SCSCP_option_return_object, stream); *stream << openmath; mytask2.finish(); /* receive the answer */ mytask2.recv(msgtype, buffer,lenbuffer); /* print the answer */ switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated\n"); break; case SCSCP_msgtype_ProcedureCompleted : printf("Procedure Completed\n"); break; default : printf("unknown message type !!!\n"); break; } printf("returned message (%d bytes):\n",(int)lenbuffer); printf("--------cut here--------\n"); puts(buffer); printf("--------cut here--------\n"); /* close the connection */ myclient.close(); } catch (Exception e) { /* error */ printf("Exception : %s\n", e.what()); return 1; } return (res!=1); } scscp-imcce-1.0.0+ds/examples/simplestclientstreamunfxx.cpp000066400000000000000000000152651215622604100242010ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file simplestclientstreamunfxx.cpp \brief example : the simplest C++ client using unformatted stream ! \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include #include #include #include using namespace SCSCP; using namespace std; /*-----------------------------------------------------------------*/ /* print the answer */ /*-----------------------------------------------------------------*/ static void printelements(Iunfstream& stream, int tab) { #define PRINTAB(x) for(j=0; j> v; cout << "integer = "<< v <> f; cout << "floating-point = "<< f <> var; cout << "variable = "<< var.get_name() <> symbol; cout << "symbol = name : "<< symbol.get_symbolname() << " cd : "<< symbol.get_cdname() <> s; cout << "string = '"<< s << "'" <> href; cout << "reference = '"<< href.get_reference() << "'" <6177887"; SCSCP_msgtype msgtype; const char *host = "localhost"; int port = SCSCP_PROTOCOL_DEFAULTPORT; if (argc==3) { host = argv[1]; port = atoi(argv[2]); } printf("---------- connecting to %s:%d ---------\n", host, port); try { /* open connection with the server on port 26133 */ myclient.connect(host, port); printf("---------- procedure call with unformatted stream ---------\n"); /* send the command openmath */ Client::Computation mytask(myclient); Ounfstream* stream; mytask.send(SCSCP_option_return_object, stream); *stream << beginOMA << OMS("scscp2","store_session") << 435 << endOMA; mytask.finish(); /* receive the answer */ Iunfstream* myrecvstream; mytask.recv(msgtype, myrecvstream); /* print the answer */ switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated\n"); break; case SCSCP_msgtype_ProcedureCompleted : printf("Procedure Completed\n"); break; default : printf("unknown message type !!!\n"); break; } printelements(*myrecvstream,0); /* close the connection */ myclient.close(); } catch (Exception e) { /* error */ printf("Exception : %s\n", e.what()); return 1; } return 0; } scscp-imcce-1.0.0+ds/examples/simplestclientxx.cpp000066400000000000000000000101051215622604100222400ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file simplestclientxx.cpp \brief example : the simplest C++ client ! \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include #include #include using namespace SCSCP; /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main(int argc, char *argv[]) { Client myclient; const char *openmath = "6177887"; char *buffer; size_t lenbuffer; SCSCP_msgtype msgtype; const char *host = "localhost"; int port = SCSCP_PROTOCOL_DEFAULTPORT; if (argc==3) { host = argv[1]; port = atoi(argv[2]); } printf("---------- connecting to %s:%d ---------\n", host, port); try { /* open connection with the server on port 26133 */ myclient.connect(host, port); printf("---------- procedure call with openmath buffer ---------\n"); /* send the command openmath */ Client::Computation mytask(myclient); mytask.send(openmath, ::strlen(openmath), SCSCP_option_return_object); /* receive the answer */ mytask.recv(msgtype, buffer,lenbuffer); /* print the answer */ switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated\n"); break; case SCSCP_msgtype_ProcedureCompleted : printf("Procedure Completed\n"); break; default : printf("unknown message type !!!\n"); break; } printf("returned message (%d bytes):\n",(int)lenbuffer); printf("--------cut here--------\n"); puts(buffer); printf("--------cut here--------\n"); /* close the connection */ myclient.close(); } catch (Exception e) { /* error */ printf("Exception : %s\n", e.what()); return 1; } return 0; } scscp-imcce-1.0.0+ds/libscscp-c.pc.in000066400000000000000000000004101215622604100172500ustar00rootroot00000000000000prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: libSCSCP Description: IMCCE SCSCP C Library Requires: libxml-2.0 >= 2.6 Version: @LIBSCSCP_DOTTED_VERSION@ URL: @LIBSCSCP_URL@ Libs: @LIBSCSCP_LIBS@ Cflags: @LIBSCSCP_CFLAGS@ scscp-imcce-1.0.0+ds/libscscp-cxx.pc.in000066400000000000000000000004141215622604100176340ustar00rootroot00000000000000prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: libSCSCP Description: IMCCE SCSCP C Library Requires: libxml-2.0 >= 2.6 Version: @LIBSCSCP_DOTTED_VERSION@ URL: @LIBSCSCP_URL@ Libs: @LIBSCSCPXX_LIBS@ Cflags: @LIBSCSCP_CXXFLAGS@ scscp-imcce-1.0.0+ds/m4/000077500000000000000000000000001215622604100146225ustar00rootroot00000000000000scscp-imcce-1.0.0+ds/m4/Makefile.am000066400000000000000000000051101215622604100166530ustar00rootroot00000000000000#/*-----------------------------------------------------------------*/ #/*! # \file Makefile.am # \brief Makefile for automake # \author M. Gastineau # Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. # # Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS # email of the author : gastineau@imcce.fr # #*/ #/*-----------------------------------------------------------------*/ # #/*-----------------------------------------------------------------*/ #/* License of this file : # This file is "dual-licensed", you have to choose one of the two licenses # below to apply on this file. # # CeCILL-C # The CeCILL-C license is close to the GNU LGPL. # ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) # # or CeCILL v2.0 # The CeCILL license is compatible with the GNU GPL. # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) # # # This library is governed by the CeCILL-C or the CeCILL license under # French law and abiding by the rules of distribution of free software. # You can use, modify and/ or redistribute the software under the terms # of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA # at the following URL "http://www.cecill.info". # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # In this respect, the user's attention is drawn to the risks associated # with loading, using, modifying and/or developing or reproducing the # software by the user in light of its specific status of free software, # that may mean that it is complicated to manipulate, and that also # therefore means that it is reserved for developers and experienced # professionals having in-depth computer knowledge. Users are therefore # encouraged to load and test the software's suitability as regards their # requirements in conditions enabling the security of their systems and/or # data to be ensured and, more generally, to use and operate it in the # same conditions as regards security. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-C or CeCILL license and that you accept its terms. # */ # /*-----------------------------------------------------------------*/ ## Makefile.am -- Process this file with automake to produce Makefile.in EXTRA_DIST = \ scscp_setup.m4 scscp-imcce-1.0.0+ds/m4/ld-version-script.m4000066400000000000000000000033571215622604100204600ustar00rootroot00000000000000# ld-version-script.m4 serial 3 dnl Copyright (C) 2008-2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Simon Josefsson # FIXME: The test below returns a false positive for mingw # cross-compiles, 'local:' statements does not reduce number of # exported symbols in a DLL. Use --disable-ld-version-script to work # around the problem. # gl_LD_VERSION_SCRIPT # -------------------- # Check if LD supports linker scripts, and define automake conditional # HAVE_LD_VERSION_SCRIPT if so. AC_DEFUN([gl_LD_VERSION_SCRIPT], [ AC_ARG_ENABLE([ld-version-script], AS_HELP_STRING([--enable-ld-version-script], [enable linker version script (default is enabled when possible)]), [have_ld_version_script=$enableval], []) if test -z "$have_ld_version_script"; then AC_MSG_CHECKING([if LD -Wl,--version-script works]) save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map" cat > conftest.map < conftest.map < was received */ #define SCSCP_STATUS_RECVCANCEL (-8) /*! SCSCP library error code : The interrupt message ' was received */ #define SCSCP_STATUS_RECVQUIT (-9) /*! SCSCP library error code : The return options passed to the function is NULL */ #define SCSCP_STATUS_RETURNOPTIONSOBJECTNULL (-5) /*! SCSCP library error code : The object server passed to the function is NULL */ #define SCSCP_STATUS_SERVEROBJECTNULL (-6) /*! SCSCP library error code : The object stream passed to the function is NULL */ #define SCSCP_STATUS_STREAMOBJECTNULL (-7) /*! SCSCP library error code : The call identifier isn't defined in the options */ #define SCSCP_STATUS_CALLIDISNOTSET (-10) /*! SCSCP library error code : The return type isn't defined in the options */ #define SCSCP_STATUS_RETURNTYPEISNOTSET (-11) /*! SCSCP library error code : The runtime usage isn't available in the procedure return message */ #define SCSCP_STATUS_USAGEUNKNOWNRUNTIME (-20) /*! SCSCP library error code : The memory usage isn't available in the procedure return message */ #define SCSCP_STATUS_USAGEUNKNOWNMEM (-21) /*! SCSCP library error code : The information message isn't available in the procedure return message */ #define SCSCP_STATUS_USAGEUNKNOWNMESSAGE (-27) /*! SCSCP library error code : The runtime limit usage isn't available in the procedure call message */ #define SCSCP_STATUS_USAGEUNKNOWNRUNTIMELIMIT (-22) /*! SCSCP library error code : The min memory isn't available in the procedure call message */ #define SCSCP_STATUS_USAGEUNKNOWNMINMEMORY (-23) /*! SCSCP library error code : The max memory isn't available in the procedure call message */ #define SCSCP_STATUS_USAGEUNKNOWNMAXMEMORY (-24) /*! SCSCP library error code : The debug level isn't available in the procedure call message */ #define SCSCP_STATUS_USAGEUNKNOWNDEBUGLEVEL (-25) /*! SCSCP library error code : The return type isn't available in the procedure call message */ #define SCSCP_STATUS_USAGEUNKNOWNRETURNTYPE (-26) /*! SCSCP library error code : The version negotiation fails */ #define SCSCP_STATUS_VERSIONNEGOTIATIONFAILED (-30) /*! SCSCP library error code : The remote execution fails */ #define SCSCP_STATUS_EXECFAILED (-31) /*! SCSCP library error code : The openmath expression isn't valid */ #define SCSCP_STATUS_OPENMATHNOTVALID (-32) /*! default status value to initialize the status to SCSCP_STATUS_OK */ #define SCSCP_STATUS_INITIALIZER SCSCP_status_getinitializer() /*! default status value to ignore returned value */ #define SCSCP_STATUS_IGNORE NULL /*! return the numerical value of the status (if NULL returns always OK) */ #define SCSCP_status_is(status) ((status)==NULL?SCSCP_STATUS_OK:(status)->m_code) /*! return a pointer to the corresponding message string */ __SCSCP_DECLSPEC const char* SCSCP_status_strerror(const SCSCP_status* status); /*! clear the status object */ __SCSCP_DECLSPEC void SCSCP_status_clear(SCSCP_status* src); /*! copy the content of src to dst */ __SCSCP_DECLSPEC void SCSCP_status_copy(SCSCP_status* dst, const SCSCP_status *src); /*! return 0 if status indicates an error */ __SCSCP_DECLSPEC int SCSCP_status_isok(const SCSCP_status* status); /*----------------------------------------------------------------------------------------------*/ /* defines and functions for procedure call options object */ /*----------------------------------------------------------------------------------------------*/ /*! default procedure call option to send to server */ #define SCSCP_CALLOPTIONS_DEFAULT NULL /*! initialize the call options and set status if an error occurs */ __SCSCP_DECLSPEC int SCSCP_co_init(SCSCP_calloptions* options, SCSCP_status* status); /*! clear the call options previously initialized by SCSCP_co_init */ __SCSCP_DECLSPEC int SCSCP_co_clear(SCSCP_calloptions* options, SCSCP_status* status); /*! set the procedure call ID (buffer can't be released before calling SCSCP_co_clear) */ __SCSCP_DECLSPEC int SCSCP_co_set_callid(SCSCP_calloptions* options, const char *buffer, SCSCP_status* status); /*! get the procedure call ID */ __SCSCP_DECLSPEC int SCSCP_co_get_callid(SCSCP_calloptions* options, const char **buffer, SCSCP_status* status); /*! set the runtime limit */ __SCSCP_DECLSPEC int SCSCP_co_set_runtimelimit(SCSCP_calloptions* options, size_t p_time, SCSCP_status* status); /*! get the runtime limit */ __SCSCP_DECLSPEC int SCSCP_co_get_runtimelimit(SCSCP_calloptions* options, size_t* p_time, SCSCP_status* status); /*! set the minimum memory */ __SCSCP_DECLSPEC int SCSCP_co_set_minmemory(SCSCP_calloptions* options, size_t memsize, SCSCP_status* status); /*! get the minimum memory */ __SCSCP_DECLSPEC int SCSCP_co_get_minmemory(SCSCP_calloptions* options, size_t* memsize, SCSCP_status* status); /*! set the maximum memory */ __SCSCP_DECLSPEC int SCSCP_co_set_maxmemory(SCSCP_calloptions* options, size_t memsize, SCSCP_status* status); /*! get the maximum memory */ __SCSCP_DECLSPEC int SCSCP_co_get_maxmemory(SCSCP_calloptions* options, size_t* memsize, SCSCP_status* status); /*! set the debug level */ __SCSCP_DECLSPEC int SCSCP_co_set_debuglevel(SCSCP_calloptions* options, int debuglevel, SCSCP_status* status); /*! get the debug level */ __SCSCP_DECLSPEC int SCSCP_co_get_debuglevel(SCSCP_calloptions* options, int* debuglevel, SCSCP_status* status); /*! set the return type */ __SCSCP_DECLSPEC int SCSCP_co_set_returntype(SCSCP_calloptions* options, SCSCP_option_return returntype, SCSCP_status* status); /*! get the return type */ __SCSCP_DECLSPEC int SCSCP_co_get_returntype(SCSCP_calloptions* options, SCSCP_option_return* returntype, SCSCP_status* status); /*! return the encoding type */ __SCSCP_DECLSPEC int SCSCP_co_get_encodingtype(SCSCP_calloptions* options, SCSCP_encodingtype* encodingtype, SCSCP_status* status); /*----------------------------------------------------------------------------------------------*/ /* defines and functions for procedure return options object */ /*----------------------------------------------------------------------------------------------*/ /*! default procedure return option to ignore returned value */ #define SCSCP_RETURNOPTIONS_IGNORE NULL /*! initialize the return options and set status if an error occurs */ __SCSCP_DECLSPEC int SCSCP_ro_init(SCSCP_returnoptions* options, SCSCP_status* status); /*! clear the return options previously initialized by SCSCP_ro_init */ __SCSCP_DECLSPEC int SCSCP_ro_clear(SCSCP_returnoptions* options, SCSCP_status* status); /*! set the procedure call ID */ __SCSCP_DECLSPEC int SCSCP_ro_set_callid(SCSCP_returnoptions* options, const char *buffer, SCSCP_status* status); /*! get the procedure call ID */ __SCSCP_DECLSPEC int SCSCP_ro_get_callid(SCSCP_returnoptions* options, const char **buffer, SCSCP_status* status); /*! set the runtime usage */ __SCSCP_DECLSPEC int SCSCP_ro_set_runtime(SCSCP_returnoptions* options, size_t p_time, SCSCP_status* status); /*! get the runtime usage */ __SCSCP_DECLSPEC int SCSCP_ro_get_runtime(SCSCP_returnoptions* options, size_t* p_time, SCSCP_status* status); /*! set the memory usage */ __SCSCP_DECLSPEC int SCSCP_ro_set_memory(SCSCP_returnoptions* options, size_t mem, SCSCP_status* status); /*! get the memory usage */ __SCSCP_DECLSPEC int SCSCP_ro_get_memory(SCSCP_returnoptions* options, size_t* mem, SCSCP_status* status); /*! set the information message */ __SCSCP_DECLSPEC int SCSCP_ro_set_message(SCSCP_returnoptions* options, const char *buffer, SCSCP_status* status); /*! get the information message */ __SCSCP_DECLSPEC int SCSCP_ro_get_message(SCSCP_returnoptions* options, const char **buffer, SCSCP_status* status); /*----------------------------------------------------------------------------------------------*/ /* functions for the SCSCP_xmlnodeptr/SCSCP_xmlattr only */ /*----------------------------------------------------------------------------------------------*/ /*! return the next node after the current xml node */ __SCSCP_DECLSPEC SCSCP_xmlnodeptr SCSCP_xmlnode_getnext(SCSCP_xmlnodeptr curnode); /*! return the name of the current xml node */ __SCSCP_DECLSPEC const char* SCSCP_xmlnode_getname(SCSCP_xmlnodeptr curnode); /*! return the first child node in the current xml node */ __SCSCP_DECLSPEC SCSCP_xmlnodeptr SCSCP_xmlnode_getchild(SCSCP_xmlnodeptr curnode); /*! read the content of the current node */ __SCSCP_DECLSPEC const char * SCSCP_xmlnode_getcontent(SCSCP_xmlnodeptr node); /*! read the id of the current node */ __SCSCP_DECLSPEC const char * SCSCP_xmlnode_getid(SCSCP_xmlnodeptr node); /*! read the first attribute of the current node */ __SCSCP_DECLSPEC SCSCP_xmlattrptr SCSCP_xmlnode_getattr(SCSCP_xmlnodeptr curnode); /*! return the next attribute after attr */ __SCSCP_DECLSPEC SCSCP_xmlattrptr SCSCP_xmlattr_getnext(SCSCP_xmlattrptr attr); /*! get the content of the attribute */ __SCSCP_DECLSPEC int SCSCP_xmlattr_getvalue(SCSCP_xmlattrptr attr, const char **name, const char **value); /*! read an OpenMath Symbol */ __SCSCP_DECLSPEC int SCSCP_xmlnode_readOMS(SCSCP_xmlnodeptr* curnode, const char **cdname, const char **symbolname); /*! read an OpenMath integer */ __SCSCP_DECLSPEC int SCSCP_xmlnode_readOMIstr(SCSCP_xmlnodeptr* curnode, const char **value); /*! read an OpenMath integer */ __SCSCP_DECLSPEC int SCSCP_xmlnode_readOMIint(SCSCP_xmlnodeptr* curnode, int *value); /*! read an OpenMath floating-point */ __SCSCP_DECLSPEC int SCSCP_xmlnode_readOMFstr(SCSCP_xmlnodeptr* curnode, const char **value, int *base); /*! read an OpenMath floating-point */ __SCSCP_DECLSPEC int SCSCP_xmlnode_readOMFdouble(SCSCP_xmlnodeptr* curnode, double *value); /*! read an OpenMath string */ __SCSCP_DECLSPEC int SCSCP_xmlnode_readOMSTR(SCSCP_xmlnodeptr* curnode, const char **value); /*! read an OpenMath reference */ __SCSCP_DECLSPEC int SCSCP_xmlnode_readOMR(SCSCP_xmlnodeptr* curnode, const char **value); /*! read an OpenMath variable */ __SCSCP_DECLSPEC int SCSCP_xmlnode_readOMV(SCSCP_xmlnodeptr* curnode, const char **value); /*! read an OpenMath byte arra */ __SCSCP_DECLSPEC int SCSCP_xmlnode_readOMB(SCSCP_xmlnodeptr* curnode, const void **buffer, size_t* lenbuffer); /*! read an OpenMath Symbol , check the symbol name with symbolname and the CD anme and return the next OpenMath string */ __SCSCP_DECLSPEC int SCSCP_xmlnode_readpairOMSOMSTR(SCSCP_xmlnodeptr* curnode, const char *cdname, const char *symbolname, const char **buffer); /*----------------------------------------------------------------------------------------------*/ /* functions for the SCSCP low I/O */ /*----------------------------------------------------------------------------------------------*/ /* These function must be called only from function SCSCP_xx_xxxcallback ! */ /*! write the openmath expression directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_write(SCSCP_io* stream, const char *buffer, SCSCP_status* status); /*! write buffer as an OpenMath string directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeOMSTR(SCSCP_io* stream, const char *buffer, const char *id, SCSCP_status* status); /*! write x as an OpenMath float-point directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeOMFdouble(SCSCP_io* stream, double x, const char *id, SCSCP_status* status); /*! write buffer as an OpenMath floating-point directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeOMFstr(SCSCP_io* stream, const char *buffer, const char *id, SCSCP_status* status); /*! write x as an OpenMath integer directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeOMIint(SCSCP_io* stream, int x, const char *id, SCSCP_status* status); /*! write x as an OpenMath integer directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeOMIlonglong(SCSCP_io* stream, long long x, const char *id, SCSCP_status* status); /*! write buffer as an OpenMath integer directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeOMIstr(SCSCP_io* stream, const char* buffer, const char *id, SCSCP_status* status); /*! write symbolname/cdname as an OpenMath symbol directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeOMS(SCSCP_io* stream, const char* cdname, const char* symbolname, const char *id, SCSCP_status* status); /*! write buffer as an OpenMath variable directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeOMV(SCSCP_io* stream, const char *buffer, const char *id, SCSCP_status* status); /*! write buffer as an OpenMath reference directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeOMR(SCSCP_io* stream, const char *buffer, SCSCP_status* status); /*! write buffer as an OpenMath byte array ... directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeOMB(SCSCP_io* stream, const void *buffer, size_t lenbuffer, const char *id, SCSCP_status* status); /* structured openmath object */ /*! write the beginning OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writebeginOMA(SCSCP_io* stream, const char *id, SCSCP_status* status); /*! write the end OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeendOMA(SCSCP_io* stream, SCSCP_status* status); /*! write the beginning OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writebeginOMATP(SCSCP_io* stream, const char *id, SCSCP_status* status); /*! write the end OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeendOMATP(SCSCP_io* stream, SCSCP_status* status); /*! write the beginning OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writebeginOMATTR(SCSCP_io* stream, const char *id, SCSCP_status* status); /*! write the end OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeendOMATTR(SCSCP_io* stream, SCSCP_status* status); /*! write the beginning OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writebeginOME(SCSCP_io* stream, const char *id, SCSCP_status* status); /*! write the end OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeendOME(SCSCP_io* stream, SCSCP_status* status); /*! write the beginning OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writebeginOMOBJ(SCSCP_io* stream, SCSCP_status* status); /*! write the end OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeendOMOBJ(SCSCP_io* stream, SCSCP_status* status); /*! write the beginning OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writebeginOMBIND(SCSCP_io* stream, const char *id, SCSCP_status* status); /*! write the end OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeendOMBIND(SCSCP_io* stream, SCSCP_status* status); /*! write the beginning OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writebeginOMFOREIGN(SCSCP_io* stream, const char *id, SCSCP_status* status); /*! write the end OpenMath tag directly to the SCSCP client or server */ __SCSCP_DECLSPEC int SCSCP_io_writeendOMFOREIGN(SCSCP_io* stream, SCSCP_status* status); /*----------------------------------------------------------------------------------------------*/ /* functions for the SCSCP client only */ /*----------------------------------------------------------------------------------------------*/ /*! initialize the object client and set status if an error occurs */ __SCSCP_DECLSPEC int SCSCP_sc_init(SCSCP_socketclient* client, SCSCP_status* status, ...); /*! clear the object client previously initialized by SCSCP_sc_init */ __SCSCP_DECLSPEC int SCSCP_sc_clear(SCSCP_socketclient* client, SCSCP_status* status); /*! connect the client to a server on the specified host and port */ __SCSCP_DECLSPEC int SCSCP_sc_connect(SCSCP_socketclient* client, const char *machine, int port, SCSCP_status* status); /*! close the connection of the client to a server previously opened by SCSCP_sc_connect */ __SCSCP_DECLSPEC int SCSCP_sc_close(SCSCP_socketclient* client, SCSCP_status* status); /*! set the current encoding for the OpenMath objects */ __SCSCP_DECLSPEC int SCSCP_sc_set_encodingtype(SCSCP_socketclient* client, SCSCP_encodingtype encodingtype, SCSCP_status* status); /*! get the current encoding for the OpenMath objects */ __SCSCP_DECLSPEC int SCSCP_sc_get_encodingtype(SCSCP_socketclient* client, SCSCP_encodingtype* encodingtype, SCSCP_status* status); /*! send a procedure call with a openmath expression as arguments to the SCSCP server */ __SCSCP_DECLSPEC int SCSCP_sc_callsendstr(SCSCP_socketclient* client, SCSCP_calloptions* options, const char *openmathbuffer, SCSCP_status* status); /*! send a procedure call to the SCSCP server. The arguments are written by callbackwriteargs */ __SCSCP_DECLSPEC int SCSCP_sc_callsendhook(SCSCP_socketclient* client, SCSCP_calloptions* options, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, SCSCP_status* status); /*! read the attribute of the answer for the procedure call and the type of the answer message */ __SCSCP_DECLSPEC int SCSCP_sc_callrecvheader(SCSCP_socketclient* client, SCSCP_returnoptions* options, SCSCP_msgtype *msgtype, SCSCP_status* status); /* for "interrupt" message */ /*! send the "interrupt" message to the server */ __SCSCP_DECLSPEC int SCSCP_sc_callsendinterrupt (SCSCP_socketclient* client, const char* call_id, SCSCP_status* status); /* for "procedure terminated" message */ /*! read the content of a "procedure terminated message" and the error message is stored in errortype and messagebuffer */ __SCSCP_DECLSPEC int SCSCP_sc_callrecvterminated(SCSCP_socketclient* client, char **cdname, char **symbolname, char **messagebuffer, SCSCP_status* status); /* for "procedure completed" message */ /*! read the content of a "procedure completed message" and store it in openmathbuffer */ __SCSCP_DECLSPEC int SCSCP_sc_callrecvcompleted(SCSCP_socketclient* client, char **openmathbuffer, SCSCP_status* status); /*! read the answer of the procedure call and store it in a string buffer */ __SCSCP_DECLSPEC int SCSCP_sc_callrecvstr(SCSCP_socketclient* client, SCSCP_returnoptions* options, SCSCP_msgtype *msgtype, char **openmathbuffer, SCSCP_status* status); /*! return the first node in the current location of the openmath message */ __SCSCP_DECLSPEC SCSCP_xmlnodeptr SCSCP_sc_getxmlnode(SCSCP_socketclient *client, SCSCP_status* status); /*! return node and its children as a raw string */ __SCSCP_DECLSPEC char* SCSCP_sc_getxmlnoderawstring(SCSCP_socketclient* client, SCSCP_xmlnodeptr node, SCSCP_status *status); /* for "information" message */ /*! send the "information" message to the server. */ __SCSCP_DECLSPEC int SCSCP_sc_infomessagesend (SCSCP_socketclient* client, const char * messagebuffer, SCSCP_status* status); /* high-level functions */ /* send a procedure call to the server with symbolname and cdname and wait for the answer */ __SCSCP_DECLSPEC int SCSCP_sc_executehookxmlnode(SCSCP_socketclient* client, SCSCP_option_return returntype, const char *cdname, const char*symbolname, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *paramwrite, SCSCP_xmlnodeptr* node, SCSCP_status* status); /* send a procedure call to the server with symbolname and cdname and wait for the answer */ __SCSCP_DECLSPEC int SCSCP_sc_executehookstr(SCSCP_socketclient* client, SCSCP_option_return returntype, const char *cdname, const char*symbolname, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *paramwrite, char** openmathbuffer, SCSCP_status* status); /*----------------------------------------------------------------------------------------------*/ /* functions for remote objects */ /*----------------------------------------------------------------------------------------------*/ /*! store during a session a remote object and returns its reference name */ __SCSCP_DECLSPEC int SCSCP_sc_remoteobjectstoresessionhook(SCSCP_socketclient* client, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, char ** cookiename, SCSCP_status* status); /*! store for multiple sessions a remote object and returns its reference name */ __SCSCP_DECLSPEC int SCSCP_sc_remoteobjectstorepersistenthook(SCSCP_socketclient* client, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, char ** cookiename, SCSCP_status* status); /*! retrieve the value of a remote object and returns a pointer to the XML tree of this object */ __SCSCP_DECLSPEC int SCSCP_sc_remoteobjectretrievexmlnode(SCSCP_socketclient* client, const char * cookiename, SCSCP_xmlnodeptr* node,SCSCP_status* status); /*! retrieve the value of a remote object and returns a string */ __SCSCP_DECLSPEC int SCSCP_sc_remoteobjectretrievestr(SCSCP_socketclient* client, const char * cookiename, char **openmathbuffer,SCSCP_status* status); /*! unbind a remote object */ __SCSCP_DECLSPEC int SCSCP_sc_remoteobjectunbind(SCSCP_socketclient* client, const char * cookiename, SCSCP_status* status); /*----------------------------------------------------------------------------------------------*/ /* functions for the SCSCP server only */ /*----------------------------------------------------------------------------------------------*/ /*! initialize the object server and set status if an error occurs */ __SCSCP_DECLSPEC int SCSCP_ss_init(SCSCP_socketserver* server, SCSCP_status* status, const char *servicename, const char *serviceversion, const char *serviceid, ...); /*! clear the object server previously initialized by SCSCP_ss_init */ __SCSCP_DECLSPEC int SCSCP_ss_clear(SCSCP_socketserver* server, SCSCP_status* status); /*! the object server listen on the specified port */ __SCSCP_DECLSPEC int SCSCP_ss_listen(SCSCP_socketserver* server, int port, int firstavailable, SCSCP_status* status); /*! return the port from the server is listening */ __SCSCP_DECLSPEC int SCSCP_ss_getport(SCSCP_socketserver* server); /*! the object server terminates to listen */ __SCSCP_DECLSPEC int SCSCP_ss_close(SCSCP_socketserver* server, SCSCP_status* status); /*! the object accepts an incoming connection and returns a incoming client connection */ __SCSCP_DECLSPEC int SCSCP_ss_acceptclient(SCSCP_socketserver* server, SCSCP_incomingclient* incomingclient, SCSCP_status* status); /*----------------------------------------------------------------------------------------------*/ /* functions for the SCSCP incoming connection only (server only) */ /*----------------------------------------------------------------------------------------------*/ /*! receive the "procedure call" message from the client : read the attribute of the incoming procedure call and the type of the incoming message store the arguments in the openmathbuffer */ __SCSCP_DECLSPEC int SCSCP_ss_callrecvstr(SCSCP_incomingclient* incomingclient, SCSCP_calloptions* options, SCSCP_msgtype *msgtype, char **openmathbuffer, SCSCP_status* status); /*! receive the "procedure call" message : read the attribute of the incoming procedure call and the type of the incoming message */ __SCSCP_DECLSPEC int SCSCP_ss_callrecvheader(SCSCP_incomingclient* incomingclient, SCSCP_calloptions* options, SCSCP_msgtype *msgtype, SCSCP_status* status); /*! the server sends the "procedure terminated" message with an error type and a text message to the client */ __SCSCP_DECLSPEC int SCSCP_ss_sendterminatedstr(SCSCP_incomingclient* incomingclient, SCSCP_returnoptions* options, const char *cdname, const char *symbolname, const char *messagebuffer, SCSCP_status* status); /*! the server sends the "procedure completed" message with a openmath expression as arguments to the client */ __SCSCP_DECLSPEC int SCSCP_ss_sendcompletedstr(SCSCP_incomingclient* incomingclient, SCSCP_returnoptions* options, const char *openmathbuffer, SCSCP_status* status); /*! the server sends the "procedure completed" message to the client. The arguments are written by callbackwriteargs */ __SCSCP_DECLSPEC int SCSCP_ss_sendcompletedhook(SCSCP_incomingclient* incomingclient, SCSCP_returnoptions* options, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, SCSCP_status* status); /*! the server sends the "information" message to the client. */ __SCSCP_DECLSPEC int SCSCP_ss_infomessagesend (SCSCP_incomingclient* client, const char * messagebuffer, SCSCP_status* status); /*! set the current encoding for the OpenMath objects */ __SCSCP_DECLSPEC int SCSCP_ss_set_encodingtype(SCSCP_incomingclient* client, SCSCP_encodingtype encodingtype, SCSCP_status* status); /*! get the current encoding for the OpenMath objects */ __SCSCP_DECLSPEC int SCSCP_ss_get_encodingtype(SCSCP_incomingclient* client, SCSCP_encodingtype* encodingtype, SCSCP_status* status); /*! terminate an incoming connection */ __SCSCP_DECLSPEC int SCSCP_ss_closeincoming(SCSCP_incomingclient* client, SCSCP_status* status); /*! return the first node in the current location of the openmath message */ __SCSCP_DECLSPEC SCSCP_xmlnodeptr SCSCP_ss_getxmlnode(SCSCP_incomingclient* client, SCSCP_status* status); /*! return node and its children as a raw string */ __SCSCP_DECLSPEC char* SCSCP_ss_getxmlnoderawstring(SCSCP_incomingclient* client, SCSCP_xmlnodeptr node, SCSCP_status *status); /*----------------------------------------------------------------------------------------------*/ /* private part of the library : required visible from outside */ /*----------------------------------------------------------------------------------------------*/ /*! return initializer variable : this function is for internal use only */ __SCSCP_DECLSPEC SCSCP_status SCSCP_status_getinitializer(void); /*! check the SCSCP library compatibility */ __SCSCP_DECLSPEC int SCSCP_check_libversion(unsigned int major, unsigned int minor, unsigned int patch); #if defined (__cplusplus) } #endif /*defined (__cplusplus)*/ #endif /*__SCSCP_H__*/ scscp-imcce-1.0.0+ds/src/scscp.sym000066400000000000000000000075271215622604100167510ustar00rootroot00000000000000#/*-----------------------------------------------------------------*/ #/*! # \file scscp.sym # \brief Exported C symbols for the gnu ld linkers # \author M. Gastineau # Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. # # Copyright, 2008, 2009, 2010, 2011, 2012, 2013, M. Gastineau, CNRS # email of the author : gastineau@imcce.fr # #*/ #/*-----------------------------------------------------------------*/ # # # initial version generated with the following command : #grep __SCSCP_DECLSPEC scscp.h | sed 's/__SCSCP_DECLSPEC//g' | sed 's/([^$]*$//g' | sed 's/ int //g' | sed 's/ SCSCP_xmlnodeptr //g' | sed 's/ const char *//g' || sed 's/ char\*//g' | sed 's/ SCSCP_status //g' | sed 's/ void //g' # LIBSCSCP_1.0.0 { global: SCSCP_get_libversionstr; SCSCP_get_libversionnum; SCSCP_status_strerror; SCSCP_status_clear; SCSCP_status_copy; SCSCP_status_isok; SCSCP_co_init; SCSCP_co_clear; SCSCP_co_set_callid; SCSCP_co_get_callid; SCSCP_co_set_runtimelimit; SCSCP_co_get_runtimelimit; SCSCP_co_set_minmemory; SCSCP_co_get_minmemory; SCSCP_co_set_maxmemory; SCSCP_co_get_maxmemory; SCSCP_co_set_debuglevel; SCSCP_co_get_debuglevel; SCSCP_co_set_returntype; SCSCP_co_get_returntype; SCSCP_co_get_encodingtype; SCSCP_ro_init; SCSCP_ro_clear; SCSCP_ro_set_callid; SCSCP_ro_get_callid; SCSCP_ro_set_runtime; SCSCP_ro_get_runtime; SCSCP_ro_set_memory; SCSCP_ro_get_memory; SCSCP_ro_set_message; SCSCP_ro_get_message; SCSCP_xmlnode_getnext; SCSCP_xmlnode_getname; SCSCP_xmlnode_getchild; SCSCP_xmlnode_getcontent; SCSCP_xmlnode_getid; SCSCP_xmlnode_getattr; SCSCP_xmlattr_getnext; SCSCP_xmlattr_getvalue; SCSCP_xmlnode_readOMS; SCSCP_xmlnode_readOMIstr; SCSCP_xmlnode_readOMIint; SCSCP_xmlnode_readOMFstr; SCSCP_xmlnode_readOMFdouble; SCSCP_xmlnode_readOMSTR; SCSCP_xmlnode_readOMR; SCSCP_xmlnode_readOMV; SCSCP_xmlnode_readOMB; SCSCP_xmlnode_readpairOMSOMSTR; SCSCP_io_write; SCSCP_io_writeOMSTR; SCSCP_io_writeOMFdouble; SCSCP_io_writeOMFstr; SCSCP_io_writeOMIint; SCSCP_io_writeOMIlonglong; SCSCP_io_writeOMIstr; SCSCP_io_writeOMS; SCSCP_io_writeOMV; SCSCP_io_writeOMR; SCSCP_io_writeOMB; SCSCP_io_writebeginOMA; SCSCP_io_writeendOMA; SCSCP_io_writebeginOMATP; SCSCP_io_writeendOMATP; SCSCP_io_writebeginOMATTR; SCSCP_io_writeendOMATTR; SCSCP_io_writebeginOME; SCSCP_io_writeendOME; SCSCP_io_writebeginOMOBJ; SCSCP_io_writeendOMOBJ; SCSCP_io_writebeginOMBIND; SCSCP_io_writeendOMBIND; SCSCP_io_writebeginOMFOREIGN; SCSCP_io_writeendOMFOREIGN; SCSCP_sc_init; SCSCP_sc_clear; SCSCP_sc_connect; SCSCP_sc_close; SCSCP_sc_set_encodingtype; SCSCP_sc_get_encodingtype; SCSCP_sc_callsendstr; SCSCP_sc_callsendhook; SCSCP_sc_callrecvheader; SCSCP_sc_callsendinterrupt ; SCSCP_sc_callrecvterminated; SCSCP_sc_callrecvcompleted; SCSCP_sc_callrecvstr; SCSCP_sc_getxmlnode; SCSCP_sc_getxmlnoderawstring; SCSCP_sc_infomessagesend ; SCSCP_sc_executehookxmlnode; SCSCP_sc_executehookstr; SCSCP_sc_remoteobjectstoresessionhook; SCSCP_sc_remoteobjectstorepersistenthook; SCSCP_sc_remoteobjectretrievexmlnode; SCSCP_sc_remoteobjectretrievestr; SCSCP_sc_remoteobjectunbind; SCSCP_ss_init; SCSCP_ss_clear; SCSCP_ss_listen; SCSCP_ss_getport; SCSCP_ss_close; SCSCP_ss_acceptclient; SCSCP_ss_callrecvstr; SCSCP_ss_callrecvheader; SCSCP_ss_sendterminatedstr; SCSCP_ss_sendcompletedstr; SCSCP_ss_sendcompletedhook; SCSCP_ss_infomessagesend ; SCSCP_ss_set_encodingtype; SCSCP_ss_get_encodingtype; SCSCP_ss_closeincoming; SCSCP_ss_getxmlnode; SCSCP_ss_getxmlnoderawstring; SCSCP_status_getinitializer; SCSCP_check_libversion; #following exported symbols are required only for scscpxx internals, it should not be used by standard users. SCSCP_procedurecompleted_write_finish; SCSCP_io_writelen; SCSCP_procedurecall_write_cancel; SCSCP_procedurecall_write_start; SCSCP_procedurecall_write_finish; SCSCP_status_setexecfailed; SCSCP_omnode_getexternaltype; SCSCP_procedurecompleted_write_start; local: *; }; scscp-imcce-1.0.0+ds/src/scscpbinary.c000066400000000000000000000657131215622604100175710ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpbinary.h \brief support of the binary encoding for OpenMath objects \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009,2010,2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 01/10/12 : ticket [#8520] omf wrong hexa encoding with big-endian order */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #if HAVE_STRING_H #include #endif #if HAVE_STDINT_H #include #endif #if HAVE_ARPA_INET_H #include #endif #include #include #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpdebug.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpbinary.h" #include "scscpomdoc.h" /*-----------------------------------------------------------------*/ /* private definitions */ /*-----------------------------------------------------------------*/ /*! return 1 if long flag is set */ #define SCSCP_binary_islongflagset(c) ((c)&128U) /*-----------------------------------------------------------------*/ /* private types */ /*-----------------------------------------------------------------*/ /*! buffer definition */ typedef struct { unsigned char *m_Buffer; /*!< data */ size_t m_Size; /*!< size of the buffer */ size_t m_Readpos; /*!< read position */ size_t m_Writepos; /*!< write position */ xmlInputReadCallback m_StreamRead; /*!< function to read the stream */ void *m_UserData; /*!< user data (provided to streamread) */ } t_buffer; /*-----------------------------------------------------------------*/ /* private functions */ /*-----------------------------------------------------------------*/ static int SCSCP_buffer_init(t_buffer *buffer, xmlInputReadCallback streamread, void *user_data, SCSCP_status* status); static void SCSCP_buffer_clear(t_buffer *buffer); static int SCSCP_buffer_getuchar(t_buffer *buffer, unsigned char *c); static int SCSCP_buffer_getchar(t_buffer *buffer, char *c); static int SCSCP_buffer_getucharn(t_buffer *buffer, unsigned char *c, int n); static int SCSCP_buffer_peekuchar(t_buffer *buffer, unsigned char *c); static unsigned char* SCSCP_buffer_loaducharn(t_buffer *buffer, int n); static int SCSCP_DOMbinaryReadIO_parsecheck(unsigned char token, t_buffer *buffer); static int SCSCP_DOMbinaryReadIO_parsetest(unsigned char token, t_buffer *buffer); static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMOBJ(SCSCP_xmldocptr doc, t_buffer *buffer); static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_parse(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer); static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMIchar(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer, unsigned char token); static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMIstr(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer, unsigned char token); static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMF(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer, unsigned char token); static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMS(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer, unsigned char token); static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMV(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer, unsigned char token); static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMSTR(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer, unsigned char token); static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMR(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer, unsigned char token); static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMsimple(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer, unsigned char token, unsigned char lasttoken); static int SCSCP_DOMbinaryReadIO_getustring(t_buffer *buffer, int nvalue, int *lenvalue, unsigned char **value, unsigned char token); /*-----------------------------------------------------------------*/ /*! initialize the buffer data structure return 0 on error @param buffer (out) object to initialize @param streamread (in) function to read to stream @param user_data (in) user data (provided to streamread) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_buffer_init(t_buffer *buffer, xmlInputReadCallback streamread, void *user_data, SCSCP_status* status) { buffer->m_Size = SCSCP_PI_MAXLENBUFFER; buffer->m_Buffer = (unsigned char *)SCSCP_malloc(buffer->m_Size, status); buffer->m_Readpos = 0; buffer->m_Writepos = 0; buffer->m_StreamRead = streamread; buffer->m_UserData = user_data; return (buffer->m_Buffer!=NULL); } /*-----------------------------------------------------------------*/ /*! clear the buffer data structure @param buffer (inout) object to destroy */ /*-----------------------------------------------------------------*/ void SCSCP_buffer_clear(t_buffer *buffer) { buffer->m_Size = 0; buffer->m_Readpos = 0; buffer->m_Writepos = 0; free(buffer->m_Buffer); } /*-----------------------------------------------------------------*/ /*! retrieve one character from the buffer data structure return 0 on error @param buffer (inout) object to read @param c (out) array of 1 characters */ /*-----------------------------------------------------------------*/ int SCSCP_buffer_getuchar(t_buffer *buffer, unsigned char *c) { int retval = SCSCP_buffer_peekuchar(buffer, c); if (retval) buffer->m_Readpos++; return retval; } /*-----------------------------------------------------------------*/ /*! retrieve one character from the buffer data structure return 0 on error @param buffer (inout) object to read @param c (out) array of 1 characters */ /*-----------------------------------------------------------------*/ int SCSCP_buffer_getchar(t_buffer *buffer, char *c) { return SCSCP_buffer_getuchar(buffer, (unsigned char*)c); } /*-----------------------------------------------------------------*/ /*! peek one character from the buffer data structure but don't remove from buffer return 0 on error @param buffer (inout) object to read @param c (out) array of 1 characters */ /*-----------------------------------------------------------------*/ int SCSCP_buffer_peekuchar(t_buffer *buffer, unsigned char *c) { int retval = 1; if (buffer->m_Writepos==buffer->m_Readpos) { int nread = buffer->m_StreamRead(buffer->m_UserData, (char *)buffer->m_Buffer, buffer->m_Size); if (nread>0) { *c = buffer->m_Buffer[0]; buffer->m_Readpos = 0; buffer->m_Writepos = nread; } else { retval = 0; } } else *c = buffer->m_Buffer[buffer->m_Readpos]; return retval; } /*-----------------------------------------------------------------*/ /*! retrieve n characters from the buffer data structure return 0 on error @param buffer (inout) object to read @param c (out) array of n characters @param n (in) n numbers of characters */ /*-----------------------------------------------------------------*/ int SCSCP_buffer_getucharn(t_buffer *buffer, unsigned char *c, int n) { unsigned char* buffloc; int retval; buffloc = SCSCP_buffer_loaducharn(buffer, n); retval = (buffloc!=NULL); if (retval) { memcpy(c,buffloc, n); } return retval; } /*-----------------------------------------------------------------*/ /*! retrieve n characters from the buffer data structure return the address of the data @param buffer (inout) object to read @param n (in) n numbers of characters */ /*-----------------------------------------------------------------*/ unsigned char * SCSCP_buffer_loaducharn(t_buffer *buffer, int n) { unsigned char *bufferload=NULL; if (buffer->m_Writepos<=buffer->m_Readpos+n-1) { int nread; size_t copylen = buffer->m_Writepos-buffer->m_Readpos; if (copylen>0) memmove(buffer->m_Buffer, buffer->m_Buffer+buffer->m_Readpos, copylen); buffer->m_Readpos = 0; buffer->m_Writepos = copylen; nread = buffer->m_StreamRead(buffer->m_UserData, (char *)buffer->m_Buffer+buffer->m_Writepos, buffer->m_Size-buffer->m_Writepos); if (nread>1) { buffer->m_Writepos+=nread; copylen = buffer->m_Writepos-buffer->m_Readpos; if (copylen>=n) { bufferload = buffer->m_Buffer+buffer->m_Readpos; buffer->m_Readpos += n; } } } else { bufferload = buffer->m_Buffer+buffer->m_Readpos; buffer->m_Readpos += n; } return bufferload; } /*-----------------------------------------------------------------*/ /*! read one token and check if the value is correct return 0 on error @param token (in) value to check @param buffer (inout) buffer */ /*-----------------------------------------------------------------*/ int SCSCP_DOMbinaryReadIO_parsecheck(unsigned char token, t_buffer *buffer) { int retval; unsigned char c; SCSCP_debugprint("SCSCP_DOMbinaryReadIO_parsecheck(%d) - enter\n",(int)token); retval = SCSCP_buffer_getuchar(buffer, &c); SCSCP_debugprint("SCSCP_DOMbinaryReadIO_parsecheck() - c=%d - return %d\n",c, retval && c==token ); return retval && c==token; } /*-----------------------------------------------------------------*/ /*! read one token and test if the value is correct return 1 if token is equal return 0 on error return -1 if token isn't equal @param token (in) value to check @param buffer (inout) buffer */ /*-----------------------------------------------------------------*/ int SCSCP_DOMbinaryReadIO_parsetest(unsigned char token, t_buffer *buffer) { int retval; unsigned char c; int res; SCSCP_debugprint("SCSCP_DOMbinaryReadIO_parsetest(%d) - enter\n",(int)token); retval = SCSCP_buffer_peekuchar(buffer, &c); res = (retval==0)?0:(c==token?1:-1); if (res==1) res = SCSCP_buffer_getuchar(buffer, &c); SCSCP_debugprint("SCSCP_DOMbinaryReadIO_parsetest() - c=%d - return %d\n",c, res); return res; } /*-----------------------------------------------------------------*/ /*! read nvalue integers accoding to the token flags put the location of the strings and their len in lenvalue and value @param buffer (inout) buffer */ /*-----------------------------------------------------------------*/ static int SCSCP_DOMbinaryReadIO_getustring(t_buffer *buffer, int nvalue, int *lenvalue, unsigned char **value, unsigned char token) { int retval = 1; int j; unsigned char *bufferloc; size_t lenstrings; if (SCSCP_binary_isidflagset(token)) nvalue++; if (!SCSCP_binary_islongflagset(token)) { char *nlen = (char *)alloca(nvalue*sizeof(char)); retval = SCSCP_buffer_getucharn(buffer,(unsigned char*)nlen, nvalue); if (retval) { for (j=0; j>4]; valuestrdbl[2*j+1] = hexArray[val&0xF]; } valuestrdbl[16]='\0'; lenname[0]=16; name[0] = valuestrdbl; } if (retval) { node = SCSCP_xmlnode_inittokenattr(doc,owner,token, 2, attrname, (char **) name, lenname); } SCSCP_debugprint("SCSCP_DOMbinaryReadIO_OMF() - return %p\n", node); return node; } /*-----------------------------------------------------------------*/ /*! read a token of type OMSTR @param doc (inout) XML document to build @param owner (inout) parent node of this object @param buffer (inout) buffer @param c (in) current token */ /*-----------------------------------------------------------------*/ static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMSTR(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer, unsigned char token) { SCSCP_xmlnodeptr node=NULL; int retval=1; int lenname[2]; /* name and id */ unsigned char * name[2]; /* address of the value */ const char *attrname[]={"id"}; SCSCP_debugprint("SCSCP_DOMbinaryReadIO_OMSTR() - enter\n"); retval = SCSCP_DOMbinaryReadIO_getustring(buffer,1, lenname, name, token); if (retval) { node = SCSCP_xmlnode_inittokenattrcontent(doc,owner,token, 1,attrname, (char **)(&(name[1])), lenname+1, (char*)name[0], lenname[0]); } SCSCP_debugprint("SCSCP_DOMbinaryReadIO_OMSTR() - return %p\n", node); return node; } /*-----------------------------------------------------------------*/ /*! read a token of type OMI @param doc (inout) XML document to build @param owner (inout) parent node of this object @param buffer (inout) buffer @param c (in) current token */ /*-----------------------------------------------------------------*/ static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMIchar(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer, unsigned char token) { SCSCP_xmlnodeptr node=NULL; int retval=1; int lenname[1]; /* id */ unsigned char * name[1]; /* address of the value */ char c; int32_t c32; unsigned char c4[4]; const char *attrname[1]={"id"}; SCSCP_debugprint("SCSCP_DOMbinaryReadIO_OMIchar(, %u) - enter\n",(unsigned int ) token); retval = SCSCP_DOMbinaryReadIO_getustring(buffer,0, lenname, name, token); if (retval) { if (SCSCP_binary_islongflagset(token)) { retval = SCSCP_buffer_getucharn(buffer,c4,4); c32 = ntohl(*(uint32_t *)c4); } else { retval = SCSCP_buffer_getchar(buffer,&c); c32 = (int32_t)c; } if (retval) { char cstr[128]; sprintf(cstr, "%ld", (long)c32); // const char *cstr=" "; node = SCSCP_xmlnode_inittokenattrcontent(doc, owner, token,1,attrname, (char **)name, lenname ,cstr, (int)strlen(cstr)); SCSCP_omnode_setbinary(doc, node, &c32,sizeof(c32)); } } SCSCP_debugprint("SCSCP_DOMbinaryReadIO_OMIchar( c32=%d) - return %p\n", (int)c32, node); return node; } /*-----------------------------------------------------------------*/ /*! read a token 2 of type OMI @param doc (inout) XML document to build @param owner (inout) parent node of this object @param buffer (inout) buffer @param c (in) current token */ /*-----------------------------------------------------------------*/ static SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMIstr(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, t_buffer *buffer, unsigned char token) { SCSCP_xmlnodeptr node=NULL; int retval=1; int lenname[1]; /* digits + id */ unsigned char * name[1]; /* address of the value */ const char *attrname[]={"id"}; SCSCP_debugprint("SCSCP_DOMbinaryReadIO_OMIstr(,%u) - enter\n",(unsigned int) token); retval = SCSCP_DOMbinaryReadIO_getustring(buffer,1, lenname, name, token); if (retval) { node = SCSCP_xmlnode_inittokenattrcontent(doc,owner, token,1,attrname, (char **)(&(name[1])), lenname+1 , (char *)name[0], lenname[0]); } SCSCP_debugprint("SCSCP_DOMbinaryReadIO_OMIstr() - return %p\n", node); return node; } /*-----------------------------------------------------------------*/ /*! read the start statement . provide the user_data to streamread. update the XML document @param doc (inout) XML document to update @param buffer (inout) buffer */ /*-----------------------------------------------------------------*/ SCSCP_xmlnodeptr SCSCP_DOMbinaryReadIO_OMOBJ(SCSCP_xmldocptr doc, t_buffer *buffer) { int retval; unsigned char c; unsigned char c2[2]; SCSCP_xmlnodeptr rootnode = NULL; SCSCP_xmlnodeptr node = NULL; SCSCP_debugprint("SCSCP_DOMbinaryReadIO_OMOBJ() - enter\n"); /* read the start statement */ retval = SCSCP_buffer_getuchar(buffer, &c); if (retval==0 || SCSCP_binary_gettoken(c)!=SCSCP_omnodetype_OMOBJ) { SCSCP_debugprint("token=%d retval=%d\n", (int)SCSCP_binary_gettoken(c), retval); retval = 0; } /* read version if long flag set */ else if (SCSCP_binary_islongflagset(c)) { /* read version number */ retval = SCSCP_buffer_getucharn(buffer, c2,2); } if (retval) { rootnode = SCSCP_xmlnode_initroottoken(doc, SCSCP_omnodetype_OMOBJ); if (rootnode) { node = SCSCP_DOMbinaryReadIO_parse(doc, rootnode, buffer); } if (node) { retval = SCSCP_DOMbinaryReadIO_parsecheck(25, buffer); } else retval = 0; if (retval==0) {SCSCP_debugprint("clear %p\n",rootnode); SCSCP_xmlnode_clear(rootnode); rootnode = NULL; } } SCSCP_debugprint("SCSCP_DOMbinaryReadIO_OMOBJ() - return %p\n", rootnode); return rootnode; } /*-----------------------------------------------------------------*/ /*! read the openmath stream encoded in binary. provide the user_data to streamread. return an XML document @param streamread (in) function to read to stream @param user_data (in) user data (provided to streamread) */ /*-----------------------------------------------------------------*/ SCSCP_xmldocptr SCSCP_DOMbinaryReadIO(xmlInputReadCallback streamread, void *user_data) { SCSCP_xmldocptr pdoc = NULL; SCSCP_xmlnodeptr rootnode = NULL; t_buffer buffer; SCSCP_debugprint("SCSCP_DOMbinaryReadIO() -enter\n"); if (SCSCP_buffer_init(&buffer, streamread, user_data, SCSCP_STATUS_IGNORE)) { /* start processing */ pdoc = SCSCP_xmldoc_init((xmlChar*)"1.0"); if (pdoc!=NULL) { rootnode = SCSCP_DOMbinaryReadIO_OMOBJ(pdoc, &buffer); SCSCP_buffer_clear(&buffer); /* set root document */ if (rootnode==NULL) { SCSCP_xmldoc_free(pdoc); pdoc =NULL; } else { #if !defined(SCSCP_DISABLE_DEBUG) SCSCP_xmldoc_dump(stdout, pdoc); #endif } } } SCSCP_debugprint("SCSCP_DOMbinaryReadIO() - return %p\n", pdoc); return pdoc; } scscp-imcce-1.0.0+ds/src/scscpbinary.h000066400000000000000000000056401215622604100175670ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpbinary.h \brief support of the binary encoding for OpenMath objects \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPBINARY_H__ #define __SCSCPBINARY_H__ #if defined (__cplusplus) extern "C" { #endif /* (__cplusplus) */ SCSCP_xmldocptr SCSCP_DOMbinaryReadIO(xmlInputReadCallback streamread, void *user_data); /*! get the token value */ #define SCSCP_binary_gettoken(c) ((c)&0x1FU) /*! return 1 if id flag is set */ #define SCSCP_binary_isidflagset(c) ((c)&64U) /*! get the token value without the long flag */ #define SCSCP_binary_removelongflag(c) ((c)&0x3FU) #if defined (__cplusplus) } #endif #endif /*__SCSCPBINARY_H__*/ scscp-imcce-1.0.0+ds/src/scscpcallid.c000066400000000000000000000116521215622604100175260ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpcallid.c \brief SCSCP call ID implementation \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is governed by the CeCILL-C license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute this file under the terms of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpcallid.h" #include "scscptags.h" /*-----------------------------------------------------------------*/ /*! constructor */ /*-----------------------------------------------------------------*/ int SCSCP_callid_init(SCSCP_call_id *callid) { callid->m_ID= callid->m_WritableID = NULL; return 1; } /*-----------------------------------------------------------------*/ /*! destructor */ /*-----------------------------------------------------------------*/ int SCSCP_callid_clear(SCSCP_call_id *callid) { if (callid->m_WritableID) free(callid->m_WritableID); return 1; } /*-----------------------------------------------------------------*/ /*! write the object to output stream @param stream (inout) output stream @param callid (in) call id @param status (inout) error code */ /*-----------------------------------------------------------------*/ int SCSCP_callid_write(SCSCP_io *stream, const SCSCP_call_id* callid, SCSCP_status* status) { return SCSCP_io_writePairOMSOMSTR(stream, SCSCP_TAGS_cdname, SCSCP_TAGS_call_id , callid->m_ID, status); } /*-----------------------------------------------------------------*/ /*! read the object from th input stream @param stream (inout) input stream @param iter (inout) iterator on the input stream */ /*-----------------------------------------------------------------*/ int SCSCP_callid_read(SCSCP_xmlnodeptr* node, SCSCP_call_id* callid, SCSCP_status* status) { return SCSCP_xmlnode_readpairOMSOMSTR(node, SCSCP_TAGS_cdname, SCSCP_TAGS_call_id , &callid->m_ID); } /*-----------------------------------------------------------------*/ /*! return the string buffer of the call id @param callid (in) call id */ /*-----------------------------------------------------------------*/ const_SCSCP_string SCSCP_callid_get(const SCSCP_call_id *callid) { return callid->m_ID; } /*-----------------------------------------------------------------*/ /*! return the string buffer of the call id @param callid (in) call id @param buffer (inout) new value (not duplicated and destroyed by callid) */ /*-----------------------------------------------------------------*/ void SCSCP_callid_setwritable(SCSCP_call_id *callid, char *buffer) { SCSCP_callid_set(callid, NULL); callid->m_ID = callid->m_WritableID = buffer; } /*-----------------------------------------------------------------*/ /*! return the string buffer of the call id @param callid (in) call id @param buffer (in) new value (not duplicated) */ /*-----------------------------------------------------------------*/ void SCSCP_callid_set(SCSCP_call_id *callid, const char *buffer) { if (callid->m_WritableID) free(callid->m_WritableID); callid->m_WritableID = NULL; callid->m_ID = buffer; } scscp-imcce-1.0.0+ds/src/scscpcallid.h000066400000000000000000000066761215622604100175450ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpcallid.h \brief SCSCP call ID definition \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPCALLID_H__ #define __SCSCPCALLID_H__ /*-----------------------------------------------------------------*/ /*! \brief handle the call id de SCSCP */ /*-----------------------------------------------------------------*/ typedef struct { /*-----------------------------------------------------------------*/ /* attributes */ /*-----------------------------------------------------------------*/ SCSCP_string m_WritableID; /*!< writable ID */ const_SCSCP_string m_ID; /*!< id value */ } SCSCP_call_id; int SCSCP_callid_init(SCSCP_call_id *callid); int SCSCP_callid_clear(SCSCP_call_id *callid); const_SCSCP_string SCSCP_callid_get(const SCSCP_call_id *callid); void SCSCP_callid_setwritable(SCSCP_call_id *callid, char *buffer); void SCSCP_callid_set(SCSCP_call_id *callid, const char *buffer); int SCSCP_callid_write(SCSCP_io *stream, const SCSCP_call_id* callid, SCSCP_status* status); int SCSCP_callid_read(SCSCP_xmlnodeptr* node, SCSCP_call_id* callid, SCSCP_status* status); #endif /*__SCSCPCALLID_H__*/ scscp-imcce-1.0.0+ds/src/scscpdebug.h000066400000000000000000000052571215622604100173750ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpdebug.h \brief SCSCP debug \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012 M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPDEBUG_H__ #define __SCSCPDEBUG_H__ #include /*! define it if debug is disabled */ #define SCSCP_DISABLE_DEBUG #if defined(SCSCP_DISABLE_DEBUG) static inline void SCSCP_debugprint(const char* format, ...) { } #else #define SCSCP_debugprint printf #endif #endif /*__SCSCPDEBUG_H__*/ scscp-imcce-1.0.0+ds/src/scscpfileclient.c000066400000000000000000001265771215622604100204310ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpfileclient.c \brief SCSCP client over file or socket \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011,2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 \bug M. GASTINEAU 06/12/11 : fix bug in SCSCP_sc_readline */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #include #if HAVE_SYS_SOCKET_H #include #endif #if HAVE_NETDB_H #include #endif #if HAVE_NETINET_IN_H #include #endif #if HAVE_ARPA_INET_H #include #endif #if HAVE_STRING_H #include #endif #include #if HAVE_UNISTD_H #include #endif #include #include #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpprocedurecall.h" #include "scscpdebug.h" #include "scscpomdoc.h" #include "scscpbinary.h" #include "scscpxmlparser.h" /*-----------------------------------------------------------------*/ /* private defines */ /*-----------------------------------------------------------------*/ /*! convert xmlchar to char */ #define xmlChar2char(x) ((char*)(x)) /*-----------------------------------------------------------------*/ /* private types */ /*-----------------------------------------------------------------*/ /*! parameter for hook excute functions */ typedef struct { const char *cdname; const char *symbolname; int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status); void *param; } t_paramexecutehook; /*! stream context */ typedef struct { SCSCP_fileio* file; /*!< socket stream */ char *buffer; /*!< last read buffer */ int lastbufvalid; /*!< lastbuf est valide */ SCSCP_status status; /*!< status of the connection */ int mathfind; /*!< processing instruction found */ char *pmathfind; /*! location of the processing instruction */ int firstcall; /*!< =1 if first call */ SCSCP_encodingtype m_recvencodingtype; /*!< type of encoding */ } t_controlpipe; /*-----------------------------------------------------------------*/ /* private functions */ /*-----------------------------------------------------------------*/ static int SCSCP_sc_callsendstr_callback(SCSCP_io* client, void *param, SCSCP_status* status); static int SCSCP_sc_clearallowedversions(SCSCP_Fileclient* client, SCSCP_status* localstatus); static int SCSCP_readstream_post(t_controlpipe* ctx, int retval); static int SCSCP_readstream_pre(t_controlpipe* ctx, char* buff, int len); static int SCSCP_readstream_XML(t_controlpipe* ctx, char* buff, int len); static int SCSCP_readstream_Binary(t_controlpipe* ctx, char* buff, int len); /*-----------------------------------------------------------------*/ /*! connect to a server at the specified port return 1 on success on error, geterror() will give the error message @param client (inout) SCSCP client @param servername (in) name of the server @param port (in) port on the server of the SCSCP server @param status (out) status */ /*-----------------------------------------------------------------*/ int SCSCP_sc_connectsocket(SCSCP_Fileclient* client, const char *servername, int port, SCSCP_status* status) { int bres = 1; static int binitsocket=1; const char *supportedversion; struct hostent * hp; int fd; SCSCP_debugprint("SCSCP_sc_connectsocket( %s, %d) - entree\n",servername,port); client->m_recvquit = 0; client->m_bufferInputValid = 0; if (binitsocket && !SCSCP_initsocket()) { SCSCP_debugprint("SCSCP_sc_connectsocket() - SCSCP_initsocket failed\n"); SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); bres = 0; } hp = gethostbyname(servername); if ( hp == NULL ) { SCSCP_debugprint("SCSCP_sc_connectsocket() - gethostbyname failed\n"); SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); bres = 0; } /* creer une socket pour se connecter au serveur */ else if ((fd = socket(AF_INET, SOCK_STREAM, 0))==INVALID_SOCKET) { SCSCP_debugprint("SCSCP_sc_connectsocket() - socket failed\n"); SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); bres = 0; } else { struct sockaddr_in adresseServeur; adresseServeur.sin_family = AF_INET; adresseServeur.sin_port = htons(port);/* host to network short */ memcpy(&adresseServeur.sin_addr.s_addr, hp->h_addr, hp->h_length); SCSCP_debugprint("SCSCP_sc_connectsocket() - socket sucess fd=%d\n", fd); SCSCP_debugprint("SCSCP_sc_connectsocket() - server address : %s\n", inet_ntoa(adresseServeur.sin_addr)); /* se connecter au serveur */ if (connect(fd, (struct sockaddr *)&adresseServeur, sizeof(adresseServeur))== SOCKET_ERROR ) { SCSCP_debugprint("SCSCP_sc_connectsocket() - connect failed\n"); SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); bres = 0; closesocket(fd); fd = -1; } else { SCSCP_sc_setsocket(client, fd); bres = SCSCP_sc_readCIM(client, &supportedversion, status); if (bres) bres = SCSCP_sc_writeCIMVersion(client, supportedversion); if (bres) bres = SCSCP_sc_readCIMVersion(client, status); if (!bres) SCSCP_sc_closesocket(client); } } binitsocket = 0; SCSCP_debugprint("SCSCP_sc_connectsocket(this=%p, fd = %d) - returns %d\n", client, fd, bres); return bres; } /*-----------------------------------------------------------------*/ /*! close the connection to the server @param client (inout) SCSCP client */ /*-----------------------------------------------------------------*/ void SCSCP_sc_closesocket(SCSCP_Fileclient* client) { SCSCP_debugprint("SCSCP_sc_closesocket() - enter\n"); if (SCSCP_sc_getsocket(client)!=-1) { if (client->m_recvquit==0) { const char *msg="\n"; SCSCP_fileio_write(&client->m_OutStream, msg, strlen(msg)*sizeof(char)); SCSCP_fileio_flush(&client->m_OutStream); } closesocket(SCSCP_sc_getsocket(client)); SCSCP_sc_setsocket(client, -1); } SCSCP_debugprint("SCSCP_sc_closesocket() - exit\n"); } /*-----------------------------------------------------------------*/ /*! read a line from the input stream and return 1 on success @param client (inout) SCSCP client @param buffer (out) buffer to fill @param lenbuffer (in) size of buffer @param status (inout) error code */ /*-----------------------------------------------------------------*/ int SCSCP_sc_readline(SCSCP_Fileclient* client, char *buffer, int lenbuffer, SCSCP_status *status) { int bres = 1; int j=-1; int found = 0; SCSCP_debugprint("SCSCP_sc_readline() - enter\n"); SCSCP_debugprint("valid buffer: %d '%s'\n", client->m_bufferInputValid, client->m_bufferInput); /*read from buffers */ if (client->m_bufferInputValid>0) { do { j++; buffer[j] = client->m_bufferInput[j]; } while (jm_bufferInputValid && buffer[j]!='\n' && jm_bufferInputValid) { client->m_bufferInputValid -=(j+1); memmove(client->m_bufferInput, client->m_bufferInput+j+1, client->m_bufferInputValid+1 /* +1 to keep '\0'*/); } else { client->m_bufferInputValid=0; client->m_bufferInput[0]='\0'; } found = 1; } } SCSCP_debugprint("after buffer: %d '%s'\n", client->m_bufferInputValid, client->m_bufferInput); /* read from socket */ if (jm_InStream, buffer+j, sizeof(char))!=SOCKET_ERROR); } while (bres && buffer[j]!='\n' && jm_allowedversionscount && *supportedversion==NULL; j++) { if (strcmp(vers,client->m_allowedversions[j])==0) *supportedversion = client->m_allowedversions[j]; } } /* aucune version supporter => on donne la + grande */ if (*supportedversion==NULL) *supportedversion=client->m_allowedversions[0]; } else { bres = 0; SCSCP_status_seterror(status, SCSCP_STATUS_VERSIONNEGOTIATIONFAILED); } } SCSCP_debugprint("SCSCP_Fileclient::ReadCIM - exit and return %d\n", bres); return bres; } /*-----------------------------------------------------------------*/ /*! read the Connection information Message Version from the server and return 1 on success @param client (inout) SCSCP client @param status (inout) status */ /*-----------------------------------------------------------------*/ int SCSCP_sc_readCIMVersion(SCSCP_Fileclient* client, SCSCP_status* status) { int bres; char c[SCSCP_PI_MAXLENBUFFER]; char *scscp_versions; SCSCP_debugprint("SCSCP_sc_readCIMVersion() - enter\n"); bres = SCSCP_sc_readline(client,c, SCSCP_PI_MAXLENBUFFER, status); if (bres) { scscp_versions = SCSCP_findPIstring(c,"version"); if (scscp_versions==NULL) { bres = 0; SCSCP_status_seterror(status, SCSCP_STATUS_VERSIONNEGOTIATIONFAILED); } } SCSCP_debugprint("SCSCP_sc_readCIMVersion - exit and return %d\n", bres); return bres; } /*-----------------------------------------------------------------*/ /*! write the SCSCP version of the client to the server and return 1 on success @param client (inout) SCSCP client @param supportedversion (in) supported version */ /*-----------------------------------------------------------------*/ int SCSCP_sc_writeCIMVersion(SCSCP_Fileclient* client, const char *supportedversion) { int bres; const char *msg1="\n"; SCSCP_debugprint("SCSCP_sc_writeCIMVersion() - enter\n"); bres = SCSCP_fileio_write(&client->m_OutStream,msg1, strlen(msg1)*sizeof(char)); if (bres) bres = SCSCP_fileio_write(&client->m_OutStream,supportedversion, strlen(supportedversion)*sizeof(char)); if (bres) bres = SCSCP_fileio_write(&client->m_OutStream,msg2, strlen(msg2)*sizeof(char)); if (bres) bres = SCSCP_fileio_flush(&client->m_OutStream); SCSCP_debugprint("SCSCP_sc_writeCIMVersion - exit and return %d\n", bres); return bres; } /*-----------------------------------------------------------------*/ /*! attach the specified socket to the client @param client (inout) SCSCP client @param socketid (in) socket to be attached */ /*-----------------------------------------------------------------*/ void SCSCP_sc_setsocket(SCSCP_Fileclient* client,int socketid) { SCSCP_fileio_setfile(&client->m_OutStream,socketid, 1); SCSCP_fileio_setfile(&client->m_InStream, socketid, 1); } /*-----------------------------------------------------------------*/ /*! return the socket associated to the client */ /*-----------------------------------------------------------------*/ int SCSCP_sc_getsocket(SCSCP_Fileclient* client) { return SCSCP_fileio_getfile(&client->m_OutStream); } /*-----------------------------------------------------------------*/ /*! checks if SCSCP client is null and returns 0 on error @param client (in) object to be checked @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_checkNULL(SCSCP_socketclient* client, SCSCP_status* status) { int res = 1; if (client==NULL || *client==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_CLIENTOBJECTNULL); res = 0; } return res; } /*-----------------------------------------------------------------*/ /*! initialize the object client and set status if an error occurs @param client (inout) object to be initialized @param status (inout) status error xparam ... (in) allowed version to be negotiated */ /*-----------------------------------------------------------------*/ int SCSCP_sc_init(SCSCP_socketclient* client, SCSCP_status* status, ...) { va_list versions; int res = 1; SCSCP_debugprint("SCSCP_sc_init(%p,%d) - enter\n", client,SCSCP_status_is(status)); if (client==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_CLIENTOBJECTNULL); res = 0; } else { SCSCP_Fileclient* pclient; *client = pclient = ( SCSCP_Fileclient*)SCSCP_malloc(sizeof(SCSCP_Fileclient), status); if (pclient==NULL) { res = 0; } else { /* count elements */ size_t counter = 0; va_list listcount; va_start(listcount, status); while (va_arg(listcount, const char*)!=NULL) counter++; va_end(listcount); pclient->m_sendencodingtype = SCSCP_encodingtype_XML; pclient->m_recvencodingtype = SCSCP_encodingtype_XML; pclient->m_doc =NULL; SCSCP_sc_setsocket(pclient, -1); pclient->m_bufferInput = (char*)SCSCP_malloc(sizeof(char)*(SCSCP_PI_MAXLENBUFFER+1), status ); pclient->m_bufferInputValid = 0; pclient->m_recvquit = 0; /* duplicate the elements of versions */ pclient->m_allowedversions = (SCSCP_string*)SCSCP_malloc(sizeof(SCSCP_string)*counter, status); res = (pclient->m_allowedversions!=NULL && pclient->m_bufferInput!=NULL); if (res) { size_t cpt; va_start(versions, status); for( cpt=0; cptm_allowedversions[cpt] = SCSCP_strdup(va_arg(versions, const char*), status); res = (pclient->m_allowedversions[cpt]!=NULL); } pclient->m_allowedversionscount = counter; va_end(versions); } } } SCSCP_debugprint("SCSCP_sc_init(%p, %d) - return %d\n", *client, SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! clear the allowed version to be negiotiated to the client @param client (inout) object to be cleared @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_sc_clearallowedversions(SCSCP_Fileclient* client, SCSCP_status* status) { int res = 1; SCSCP_debugprint("SCSCP_sc_clearallowedversions() - enter\n"); if (client==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_CLIENTOBJECTNULL); res = 0; } else { /* clear the elements of versions */ if (client->m_allowedversions!=NULL) { size_t cpt; for(cpt=0; cptm_allowedversionscount; cpt++) { free(client->m_allowedversions[cpt]); } free(client->m_allowedversions); client->m_allowedversions = NULL; client->m_allowedversionscount = 0; } } SCSCP_debugprint("SCSCP_sc_clearallowedversions() - returns %d\n", res); return res; } /*-----------------------------------------------------------------*/ /*! clear the object client previously initialized by SCSCP_sc_init @param client (inout) object to be deleted @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_clear(SCSCP_socketclient* client, SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_sc_clear(%p,%p) - enter\n", client, status); res = SCSCP_sc_checkNULL(client, status); if (!res) return res; res = SCSCP_sc_clearallowedversions(*client, status); SCSCP_sc_closesocket(*client); SCSCP_sc_freexmldoc(*client); free((*client)->m_bufferInput); free (*client); SCSCP_debugprint("SCSCP_sc_clear(%d) - return %d\n", SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! connect the client to a server on the specified host and port @param client (inout) scscp client @param machine (in) computer name or IP address @param port (in) port on the remote computer @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_connect(SCSCP_socketclient* client, const char *machine, int port, SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_sc_connect(%p, %s, %d, %p) - enter\n", client, machine, port, status); res = SCSCP_sc_checkNULL(client, status); if (!res) return res; res = SCSCP_sc_connectsocket(*client, machine, port,status); if (!res && SCSCP_status_is(status)==SCSCP_STATUS_OK) SCSCP_status_seterror(status,SCSCP_STATUS_ERRNO); SCSCP_debugprint("SCSCP_sc_connect(%d) - return %d\n", SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! close the connection of the client to a server previously opened by SCSCP_sc_connect @param client (inout) scscp client @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_close(SCSCP_socketclient* client, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); if (res) SCSCP_sc_closesocket(*client); return res; } /*-----------------------------------------------------------------*/ /*! set that we receive the quit message on the socket of the client @param client (inout) SCSCP client */ /*-----------------------------------------------------------------*/ void SCSCP_sc_setrecvquit(SCSCP_Fileclient* client) { client->m_recvquit = 1; } /*-----------------------------------------------------------------*/ /*! set the current encoding for the OpenMath objects @param client (inout) scscp client @param encodingtype (in) new encoding @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_set_encodingtype(SCSCP_socketclient* client, SCSCP_encodingtype encodingtype, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); if (res) (*client)->m_sendencodingtype = encodingtype; return res; } /*-----------------------------------------------------------------*/ /*! get the current encoding for the OpenMath objects @param client (inout) scscp client @param encodingtype (out) new encoding @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_get_encodingtype(SCSCP_socketclient* client, SCSCP_encodingtype* encodingtype, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); if (res) *encodingtype = (*client)->m_sendencodingtype; return res; } /*-----------------------------------------------------------------*/ /*! write the openmath buffer to the scscp server @param stream (inout) scscp stream @param param (in) openmath expression (must be a const char *) @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_sc_callsendstr_callback(SCSCP_io* stream, void *param, SCSCP_status* status) { const char *openmathbuffer = (const char*)param; return SCSCP_io_write(stream, openmathbuffer, status); } /*-----------------------------------------------------------------*/ /*! send an openmath string to the SCSCP server with some options for a procedure call @param client (inout) scscp client @param options (in) options of the call @param openmathbuffer (in) openmath expression @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_callsendstr(SCSCP_socketclient* client, SCSCP_calloptions* options, const char *openmathbuffer, SCSCP_status* status) { return SCSCP_sc_callsendhook(client, options, SCSCP_sc_callsendstr_callback, (void*)openmathbuffer, status); } /*-----------------------------------------------------------------*/ /*! send a procedure call to the SCSCP server with some options The parameter of the procedure call are written by the callback function "callbackwriteargs" @param client (inout) scscp client @param options (in) options of the call @param callbackwriteargs (in) callback function to write the parameters of the procedure call @param param (inout) opaque data given to callbackwriteargs @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_callsendhook(SCSCP_socketclient* client, SCSCP_calloptions* options, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); if (res) res = SCSCP_procedurecall_write(client, options==NULL?NULL:*options, callbackwriteargs, param, status); return res; } /*-----------------------------------------------------------------*/ /*! the client sends the "information" message to the server. @param client (inout) scscp client @param messagebuffer (in) information @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_infomessagesend (SCSCP_socketclient* client, const char * messagebuffer, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); if (res) { res = SCSCP_io_writef(client, status, "\n", NULL); if (res) res = SCSCP_io_flush(client, status); } return res; } /*-----------------------------------------------------------------*/ /*! the client sends the "interrupt" message to the server with the call id. @param client (inout) scscp client @param call_id (in) call ID of the canceled procedure @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_callsendinterrupt(SCSCP_socketclient* client, const char* call_id, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); if (res) { res = SCSCP_io_writef(client, status, "\n", NULL); if (res) res = SCSCP_io_flush(client, status); } return res; } /*-----------------------------------------------------------------*/ /*! write the expression : @param stream (inout) stream session @param status (inout) error type @param param (in) name of the remote object */ /*-----------------------------------------------------------------*/ static int SCSCP_sc_executehookwrite(SCSCP_io* stream, void *param, SCSCP_status *status) { int res; t_paramexecutehook *hookparam = (t_paramexecutehook*)param; res = SCSCP_io_writebeginOMA(stream, NULL, status); if (res) res = SCSCP_io_writeOMS(stream, hookparam->cdname, hookparam->symbolname, NULL, status); if (res && hookparam->callbackwriteargs!=NULL) res = hookparam->callbackwriteargs(stream, hookparam->param, status); if (res) res = SCSCP_io_writeendOMA(stream, status); return res; } /*-----------------------------------------------------------------*/ /*! send a procedure call to the server with symbolname and cdname and wait for the answer. @param client (inout) scscp client @param returntype (in) return type @param cdname (inout) name of the CD @param symbolname (inout) name of the symbol @param callbackwriteargs (in) function to write arguments @param paramwrite (inout) opaque object given to callbackwriteargs @param node (out) xml node of the result @param status (inout) error code */ /*-----------------------------------------------------------------*/ int SCSCP_sc_executehookxmlnode(SCSCP_socketclient* client, SCSCP_option_return returntype, const char *cdname, const char* symbolname, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, SCSCP_xmlnodeptr* node, SCSCP_status* status) { int res, res1; SCSCP_calloptions options; SCSCP_msgtype msgtype; char *cdnameerr; char *symbolnameerr; char *msg; t_paramexecutehook hookparam={cdname, symbolname, callbackwriteargs, param}; SCSCP_debugprint("SCSCP_sc_executehookxmlnode(%p, %d, %s, %s, %p, %p, %p, %p) - enter\n", client, (int)returntype, cdname, symbolname, callbackwriteargs , param, node, status); res1 = res = SCSCP_co_init(&options, status); if (res) res = SCSCP_co_set_returntype(&options, returntype,status); if (res) res = SCSCP_sc_callsendhook(client,&options, SCSCP_sc_executehookwrite, &hookparam, status); if (res) res = SCSCP_sc_callrecvheader(client, SCSCP_RETURNOPTIONS_IGNORE, &msgtype, status); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureCompleted : *node = SCSCP_sc_getxmlnode(client, status); break; case SCSCP_msgtype_ProcedureTerminated : *node = NULL; if (res) res = SCSCP_sc_callrecvterminated(client, &cdnameerr, &symbolnameerr, &msg, status); SCSCP_status_setexecfailed(status, cdnameerr, symbolnameerr, msg); res = 0; break; default : *node = NULL; break; } } if (res1) SCSCP_co_clear(&options, status); SCSCP_debugprint("SCSCP_sc_executehookxmlnode( %p, %d) - returns %d\n", *node, SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! send a procedure call to the server with symbolname and cdname and wait for the answer. @param client (inout) scscp client @param returntype (in) return type @param cdname (inout) name of the CD @param symbolname (inout) name of the symbol @param callbackwriteargs (in) function to write arguments @param paramwrite (inout) opaque object given to callbackwriteargs @param openmathbuffer (out) openmath result @param status (inout) error code */ /*-----------------------------------------------------------------*/ int SCSCP_sc_executehookstr(SCSCP_socketclient* client, SCSCP_option_return returntype, const char *cdname, const char* symbolname, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, char ** openmathbuffer, SCSCP_status* status) { int res, res1; SCSCP_calloptions options; SCSCP_msgtype msgtype; char *cdnameerr; char *symbolnameerr; char *msg; t_paramexecutehook hookparam={cdname, symbolname, callbackwriteargs, param}; SCSCP_debugprint("SCSCP_sc_executehookstr(%p, %d, %s, %s, %p, %p, %p, %p) - enter\n", client, (int)returntype, cdname, symbolname, callbackwriteargs , param, openmathbuffer, status); *openmathbuffer = NULL; res1 = res = SCSCP_co_init(&options, status); if (res) res = SCSCP_co_set_returntype(&options, returntype,status); if (res) res = SCSCP_sc_callsendhook(client,&options, SCSCP_sc_executehookwrite, &hookparam, status); if (res) res = SCSCP_sc_callrecvheader(client, SCSCP_RETURNOPTIONS_IGNORE, &msgtype, status); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureCompleted : res = SCSCP_sc_callrecvcompleted(client,openmathbuffer, status); break; case SCSCP_msgtype_ProcedureTerminated : if (res) res = SCSCP_sc_callrecvterminated(client, &cdnameerr, &symbolnameerr, &msg, status); SCSCP_status_setexecfailed(status, cdnameerr, symbolnameerr, msg); res = 0; break; default : *openmathbuffer = NULL; break; } } if (res1) SCSCP_co_clear(&options, status); SCSCP_debugprint("SCSCP_sc_executehook( %p, %d) - returns %d\n", *openmathbuffer, SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! return the first node in the current location of the openmath message @param client (inout) scscp client @param status (inout) status error */ /*-----------------------------------------------------------------*/ SCSCP_xmlnodeptr SCSCP_sc_getxmlnode(SCSCP_socketclient *client, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); return res?(*client)->m_iter:NULL; } /*-----------------------------------------------------------------*/ /*! \internal return the address of the first node in the current location of the openmath message @param client (inout) scscp client @param status (inout) status error */ /*-----------------------------------------------------------------*/ SCSCP_xmlnodeptr* SCSCP_sc_getxmlnodeptr(SCSCP_socketclient *client, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); return res?&((*client)->m_iter):NULL; } /*----------------------------------------------------------------------------------------------*/ /*! return node and its children as a raw string return NULL on error @param client (in) client. mustn't be NULL @param node (in) current valid node. mustn't be NULL @param status (in) error code */ /*----------------------------------------------------------------------------------------------*/ char* SCSCP_sc_getxmlnoderawstring(SCSCP_socketclient* client, SCSCP_xmlnodeptr node, SCSCP_status *status) { char* str = NULL; int res = SCSCP_sc_checkNULL(client, status); #if SCSCP_PARSERTYPE==SCSCP_PARSERDOM xmlBufferPtr buffer; #endif SCSCP_debugprint("SCSCP_sc_getxmlnoderawstring(%p,%p,%p) - enter\n",client, node, status); if (res==0) return str; #if SCSCP_PARSERTYPE==SCSCP_PARSERDOM buffer = xmlBufferCreate(); if (xmlNodeDump(buffer, (*client)->m_doc, node, 1,1)!=-1) { const xmlChar *strxml = xmlBufferContent(buffer); if (strxml!=NULL) { int len = xmlStrlen(strxml)+1; str = (char*)SCSCP_malloc(sizeof(char)*len, status); if (str!=NULL) { strcpy(str, xmlChar2char(strxml)); } } else { SCSCP_status_seterror(status, SCSCP_STATUS_NOMEM); } } else { SCSCP_status_seterror(status, SCSCP_STATUS_NOMEM); } #elif SCSCP_PARSERTYPE==SCSCP_PARSERSAX str = SCSCP_omnode_getrawstring(node, status); #endif SCSCP_debugprint(" SCSCP_sc_getxmlnoderawstring() - return '%s'\n", str); return str; } /*-----------------------------------------------------------------*/ /*! free the xml document */ /*-----------------------------------------------------------------*/ void SCSCP_sc_freexmldoc(SCSCP_Fileclient* client) { if (client->m_doc) SCSCP_xmldoc_free(client->m_doc); client->m_doc = NULL; } /*-----------------------------------------------------------------------*/ /*! read data from socket and put contents to buff of size len return -1 on error or if was foudn before @param ctx (inout) stream context @param buff (inout) buffer @param len (in) size of the buffer */ /*-----------------------------------------------------------------------*/ static int SCSCP_readstream_pre(t_controlpipe* ctx, char* buff, int len) { SCSCP_fileio* file=ctx->file; const char *symbol = "mathfind==1) return /*-1*/0; if (ctx->mathfind==0) { do { int copydata=0; int res = 0; if (copylen+ctx->lastbufvalidlastbufvalid); if (nbbytestoread>SCSCP_PI_MAXLENBUFFER-ctx->lastbufvalid) nbbytestoread = SCSCP_PI_MAXLENBUFFER-ctx->lastbufvalid; lenread = SCSCP_fileio_read(file, ctx->buffer+ctx->lastbufvalid, nbbytestoread); res = lenread; eof = (lenread<=0); if (!eof) { /* no error */ /* try to find PI instruction : lastbufvalid; int lookstart = (lastlen>lensymbol?lastlen-lensymbol:0); ctx->lastbufvalid+=lenread; ctx->buffer[ctx->lastbufvalid] = '\0'; pfind = SCSCP_findstr(ctx->buffer+lookstart, symbol, ctx->lastbufvalid-lookstart); if (pfind!=NULL) { ctx->mathfind=1; ctx->pmathfind = (char *)pfind; res = pfind-ctx->buffer; copydata=1; if (res==0) eof=1; } } } else { /* must copy the data */ copydata=1; res = len-copylen; } if (copydata==1 && res>0) { /* copy from last buffer to buff */ memcpy(buff+copylen, ctx->buffer, res); copylen += res; ctx->lastbufvalid -= res; if (pfind!=NULL) ctx->pmathfind -=res; if (ctx->lastbufvalid>0) memmove(ctx->buffer, ctx->buffer+res,ctx->lastbufvalid); } } while(eof==0 && copylenmathfind==0); } retval = (eof==1)?-1:copylen; return retval; } /*-----------------------------------------------------------------------*/ /*! read an XML stream. This function is called by xmlReadIO. must be compatible with xmlInputReadCallback return the size of the valid buffer return -1 on error or if was found before @param ctx (inout) stream context @param buff (inout) buffer @param len (in) size of the buffer */ /*-----------------------------------------------------------------------*/ static int SCSCP_readstream_XML(t_controlpipe* ctx, char* buff, int len) { int retval; SCSCP_debugprint("SCSCP_readstream_XML(%p,%p,%d) - enter\n", ctx, buff, len); /*read data from socket */ retval = SCSCP_readstream_pre(ctx, buff, len); if (retval>0) { /*! check that the encoding isn't Binary */ if (ctx->firstcall==1 && (buff[0]==24 || buff[0]==88)) { SCSCP_debugprint("find a binary encoding\n"); ctx->m_recvencodingtype = SCSCP_encodingtype_Binary; if (ctx->lastbufvalid>0) memmove(ctx->buffer+len, ctx->buffer,ctx->lastbufvalid); ctx->lastbufvalid += retval; ctx->pmathfind +=retval; memcpy(ctx->buffer, buff, retval); SCSCP_readstream_post(ctx, 0); retval=-1; } else { ctx->firstcall = 0; retval = SCSCP_readstream_post(ctx, retval); } } if (retval>0) { SCSCP_debugprint("read from socket : '%.*s", retval, buff); } SCSCP_debugprint("SCSCP_readstream_XML() - return %d\n", retval); return retval; } /*-----------------------------------------------------------------------*/ /*! function called by SCSCP_binaryReadIO. must be compatible with xmlInputReadCallback return the size of the valid buffer return -1 on error or if was found before @param ctx (inout) stream context @param buff (inout) buffer @param len (in) size of the buffer */ /*-----------------------------------------------------------------------*/ static int SCSCP_readstream_Binary(t_controlpipe* ctx, char* buff, int len) { int retval; SCSCP_debugprint("SCSCP_readstream_Binary() - enter(%p, %p, %d) - enter\n", ctx, buff, len); /*on first call, we already have valid data */ if (ctx->firstcall==1) { retval = (lenlastbufvalid)?len:ctx->lastbufvalid; memcpy(buff, ctx->buffer, retval); ctx->lastbufvalid -= retval; if (ctx->lastbufvalid>0) memmove(ctx->buffer, ctx->buffer+retval,ctx->lastbufvalid); ctx->firstcall = 0; } else { /*read data from socket */ retval = SCSCP_readstream_pre(ctx, buff, len); if (retval>0) retval = SCSCP_readstream_post(ctx, retval); } #if !defined(SCSCP_DISABLE_DEBUG) SCSCP_debugprint("buffer return :\n"); { int j; for (j=0; jfile; const char *symbol = " find which PI ? */ if (ctx->mathfind==1) { const char *lastPI; int posbuf; int eof; ctx->buffer[ctx->lastbufvalid] = '\0'; eof=0; SCSCP_debugprint("start PI processing :'%s'\n", ctx->pmathfind); /* find the character "?>" */ while (!eof && (lastPI=SCSCP_findstr(ctx->pmathfind,"?>", ctx->lastbufvalid-(ctx->pmathfind-ctx->buffer)))==NULL) { /*read more data */ int lenread; /*compute the number of bytes to read */ int nbbytestoread = SCSCP_PI_MAXLENBUFFER-ctx->lastbufvalid; if (nbbytestoread==0) { SCSCP_debugprint("too long PI \n"); return -1; } lenread = SCSCP_fileio_read(file, ctx->buffer+ctx->lastbufvalid, nbbytestoread); eof = (lenread<=-1); if (!eof) { ctx->lastbufvalid+=lenread; ctx->buffer[ctx->lastbufvalid] = '\0'; } else { SCSCP_status_seterror(&ctx->status, SCSCP_STATUS_RECVCANCEL); SCSCP_debugprint("I/O error...\n"); retval = -1; } } /* now : detect which PI */ posbuf = lensymbol; while (isspace(ctx->pmathfind[posbuf])) posbuf++; SCSCP_debugprint("PI processing :'%s'\n", ctx->pmathfind+posbuf); if (strncmp(ctx->pmathfind+posbuf,"cancel", strlen("cancel"))==0) { SCSCP_debugprint("cancel received\n"); SCSCP_status_seterror(&ctx->status, SCSCP_STATUS_RECVCANCEL); retval = -1; } if (strncmp(ctx->pmathfind+posbuf,"end", strlen("end"))==0) { SCSCP_debugprint("end received\n"); } /* now =>remove this PI */ copylen = ctx->lastbufvalid-((lastPI+2)-ctx->buffer); if (copylen>0) memmove(ctx->pmathfind, lastPI+2,copylen); SCSCP_debugprint("copylen=%d : %p %p %d\n",copylen, ctx->pmathfind, ctx->buffer, ctx->lastbufvalid); ctx->lastbufvalid=ctx->pmathfind-ctx->buffer+copylen; ctx->buffer[ctx->lastbufvalid] = '\0'; SCSCP_debugprint("keep this buffer for future : %d '%s'\n",ctx->lastbufvalid, ctx->buffer); } SCSCP_debugprint("SCSCP_readstream_post() - return %d\n", retval); return retval; } /*-----------------------------------------------------------------*/ /*! read the xml document. return 1 on success @param status (inout) error code */ /*-----------------------------------------------------------------*/ int SCSCP_sc_readxmldoc(SCSCP_Fileclient *client, SCSCP_status* status) { int res; t_controlpipe ctx; SCSCP_xmldocptr doc = NULL; SCSCP_debugprint("\nSCSCP_sc_readxmldoc() - enter\n"); LIBXML_TEST_VERSION ctx.file = &client->m_InStream; ctx.status = SCSCP_STATUS_INITIALIZER; ctx.buffer = client->m_bufferInput; ctx.lastbufvalid = client->m_bufferInputValid; ctx.mathfind = 0; ctx.firstcall = 1; ctx.m_recvencodingtype = SCSCP_encodingtype_XML; client->m_recvencodingtype = SCSCP_encodingtype_XML; #if SCSCP_PARSERTYPE==SCSCP_PARSERDOM doc = xmlReadIO((xmlInputReadCallback)SCSCP_readstream_XML,NULL, &ctx, NULL, NULL, XML_PARSE_NOERROR|XML_PARSE_NOWARNING| XML_PARSE_NOBLANKS); #elif SCSCP_PARSERTYPE==SCSCP_PARSERSAX doc = SCSCP_DOMxmlReadIO((xmlInputReadCallback)SCSCP_readstream_XML, status, &ctx); #else #pragma error "unknown SCSCP_PARSERTYPE" #endif /* revert to binary encoding */ if (doc==NULL && ctx.m_recvencodingtype==SCSCP_encodingtype_Binary) { client->m_recvencodingtype = SCSCP_encodingtype_Binary; doc = SCSCP_DOMbinaryReadIO((xmlInputReadCallback)SCSCP_readstream_Binary, &ctx); } client->m_bufferInputValid = ctx.lastbufvalid; if (SCSCP_status_is(status)==SCSCP_STATUS_OK) SCSCP_status_copy(status, &ctx.status); res = (doc!=NULL); if (res) { SCSCP_sc_freexmldoc(client); client->m_doc = doc; } else if (SCSCP_status_is(status)==SCSCP_STATUS_OK) { SCSCP_status_seterror(status, SCSCP_STATUS_OPENMATHNOTVALID); } SCSCP_debugprint("\nSCSCP_sc_readxmldoc(,%d) - returns %d\n", SCSCP_status_is(status), res); return res; } scscp-imcce-1.0.0+ds/src/scscpfileclient.h000066400000000000000000000155411215622604100204220ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpfileclient.h \brief SCSCP client with file descriptor \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPFILECLIENT_H__ #define __SCSCPFILECLIENT_H__ #include "scscputil.h" #include "scscpfileio.h" #include "scscpomdoc.h" #if defined (__cplusplus) extern "C" { #endif /* (__cplusplus) */ /*-----------------------------------------------------------------*/ /*! handle client connection SCSCP with file descriptor */ /*-----------------------------------------------------------------*/ typedef struct SCSCP_stFileclient { /*-----------------------------------------------------------------*/ /* attributes */ /*-----------------------------------------------------------------*/ SCSCP_fileio m_OutStream; /*!< flux sortant */ SCSCP_fileio m_InStream; /*!< flux entrant */ char * m_bufferInput; /*!< input buffer */ int m_bufferInputValid; /*!< number of valid characters in the input buffer */ SCSCP_string *m_allowedversions; /*!< allowed versions */ size_t m_allowedversionscount; /*!< number of elements of m_allowedversions */ int m_recvquit; /*!< = 1 if quit message was received */ SCSCP_encodingtype m_sendencodingtype; /*!< encoding used for the sent messages */ SCSCP_encodingtype m_recvencodingtype; /*!< encoding used for the received messages */ /* to migrate in a call manager */ SCSCP_xmldocptr m_doc; /*!< xml document */ SCSCP_xmlnodeptr m_iter; /*!< current iterator on DOM document */ } SCSCP_Fileclient; int SCSCP_sc_checkNULL(SCSCP_socketclient* client, SCSCP_status* status); SCSCP_xmlnodeptr* SCSCP_sc_getxmlnodeptr(SCSCP_socketclient *client, SCSCP_status* status); int SCSCP_sc_xmlnodereadOMEstr(SCSCP_socketclient* client, SCSCP_xmlnodeptr* curnode, const char **cdname, const char **symbolname, char **value, SCSCP_status *status); void SCSCP_sc_freexmldoc(SCSCP_Fileclient* client); int SCSCP_sc_readxmldoc(SCSCP_Fileclient* client, SCSCP_status *status); /*! connect to a server at the specified port*/ int SCSCP_sc_connectsocket(SCSCP_Fileclient* client, const char *servername, int port, SCSCP_status* status); /*! close the connexion to the server */ void SCSCP_sc_closesocket(SCSCP_Fileclient* client); /*! Attach a socket*/ void SCSCP_sc_setsocket(SCSCP_Fileclient* client, int socketid); /*! Get the socket number*/ int SCSCP_sc_getsocket(SCSCP_Fileclient* client); /*! read a line from the input stream and fill buffer.*/ int SCSCP_sc_readline(SCSCP_Fileclient* client, char *buffer, int lenbuffer, SCSCP_status *status); /*! read the CIM version from the server*/ int SCSCP_sc_readCIMVersion(SCSCP_Fileclient* client, SCSCP_status* status); /*! write the Connection information Message from the server*/ int SCSCP_sc_readCIM(SCSCP_Fileclient* client, const char **supportedversion,SCSCP_status* status); /*! write the CIM version to the server*/ int SCSCP_sc_writeCIMVersion(SCSCP_Fileclient* client, const char *supportedversion); /*! set that the client receive the quit message */ void SCSCP_sc_setrecvquit(SCSCP_Fileclient* client); int SCSCP_io_flush(SCSCP_io* stream, SCSCP_status* status); int SCSCP_io_readxmldoc(SCSCP_io *stream, SCSCP_xmlnodeptr* iter, SCSCP_status *status); int SCSCP_io_ReadPI(SCSCP_io* stream, SCSCP_msgtype* msgtype, char *bufferPI, SCSCP_status* status); int SCSCP_io_writelen(SCSCP_io* stream, const void *buffer, size_t len, SCSCP_status* status); int SCSCP_io_writef(SCSCP_io* stream, SCSCP_status* status, const char *buffer, ...); int SCSCP_io_writeOMIsizet(SCSCP_io* stream, size_t value, SCSCP_status* status); int SCSCP_io_writeOMEwithOMSOMSTR(SCSCP_io* stream, const char *cdname, const char*symbolname, const char *message, SCSCP_status* status); int SCSCP_io_writePairOMSOMIsizet(SCSCP_io* stream, const char *cdname, const char*symbolname, size_t value, SCSCP_status* status); int SCSCP_io_writePairOMSOMIint(SCSCP_io* stream, const char *cdname, const char*symbolname, int value, SCSCP_status* status); int SCSCP_io_writePairOMSOMSTR(SCSCP_io* stream, const char *cdname, const char*symbolname, const char* value, SCSCP_status* status); int SCSCP_io_writeSCSCPSTART(SCSCP_io* stream, SCSCP_status* status); int SCSCP_io_writeSCSCPEND(SCSCP_io* stream, SCSCP_status* status); int SCSCP_io_writeSCSCPCANCEL(SCSCP_io* stream, SCSCP_status* status); #if defined (__cplusplus) } #endif /* (__cplusplus) */ #endif /*__SCSCPFILECLIENT_H__*/ scscp-imcce-1.0.0+ds/src/scscpfileio.c000066400000000000000000000141741215622604100175470ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpfileio.c \internal \brief write/read to file descriptor (fd) or socket \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008,2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_SYS_SOCKET_H #include #endif #if HAVE_SYS_UIO_H #include #endif #if HAVE_UNISTD_H #include #endif #if HAVE_STRING_H #include #endif #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscputil.h" #include "scscpfileio.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* private functions */ /*-----------------------------------------------------------------*/ static int SCSCP_fileio_write_internal(SCSCP_fileio *io, const void *buf, size_t len); /*-----------------------------------------------------------------*/ /*! set the connector to file or socket @param io (inout) object to initialize @param fd (in) handle of the file or socket @param bsocket (in) = 1 => socket = 0 => file */ /*-----------------------------------------------------------------*/ void SCSCP_fileio_setfile(SCSCP_fileio *io, int fd, int bsocket) { io->m_fd = fd; io->m_issocket = bsocket; io->m_bufferOutputValid = 0; } /*-----------------------------------------------------------------*/ /*! get the file descriptor of the stream @param io (inout) stream */ /*-----------------------------------------------------------------*/ int SCSCP_fileio_getfile(SCSCP_fileio *io) { return io->m_fd; } /*-----------------------------------------------------------------*/ /*! write the buffer buf of length len (bytes) to a file or socket return 0 on error @param io (inout) stream @param buf (in) write buffer @param len (in) length of buf */ /*-----------------------------------------------------------------*/ int SCSCP_fileio_write_internal(SCSCP_fileio *io, const void *buf, size_t len) { if (io->m_issocket) { return (send(io->m_fd, buf, len, 0)!=SOCKET_ERROR); } else { return (write(io->m_fd, buf, len)!=-1); } } /*-----------------------------------------------------------------*/ /*! write the buffer buf of length len (bytes) to a file or socket return false on error @param io (inout) stream @param buf (in) write buffer @param len (in) length of buf */ /*-----------------------------------------------------------------*/ int SCSCP_fileio_write(SCSCP_fileio *io, const void *buf, size_t len) { int res = 1; /* flush pending data if new buffer becomes too large */ if (len+io->m_bufferOutputValid>=SCSCP_PI_MAXLENBUFFER) { res = SCSCP_fileio_flush(io); } if (res) { if (len>=SCSCP_PI_MAXLENBUFFER) { res = SCSCP_fileio_write_internal(io,buf, len); } else { memcpy(io->m_bufferOutput+io->m_bufferOutputValid, buf, len); io->m_bufferOutputValid+=len; } } return res; } /*-----------------------------------------------------------------*/ /*! read a buffer buf of length len (bytes) from a file or socket return the number of readen bytes return -1 on error @param io (inout) stream @param buf (out) read buffer @param len (in) length of buf */ /*-----------------------------------------------------------------*/ int SCSCP_fileio_read(SCSCP_fileio *io, char *buf, size_t len) { if (io->m_issocket) { return recv(io->m_fd, buf, len, 0); } else { return read(io->m_fd, buf, len); } } /*-----------------------------------------------------------------*/ /*! write pending data to a file or socket return 0 on error @param io (inout) stream */ /*-----------------------------------------------------------------*/ int SCSCP_fileio_flush(SCSCP_fileio *io) { int res = 1; if (io->m_bufferOutputValid>0) { res = SCSCP_fileio_write_internal(io, io->m_bufferOutput, io->m_bufferOutputValid); io->m_bufferOutputValid = 0; } return res; } scscp-imcce-1.0.0+ds/src/scscpfileio.h000066400000000000000000000067131215622604100175540ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpfileio.h \internal \brief Open Math Input Stream with file descriptor (int) definition. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __omlfileio_H__ #define __omlfileio_H__ /*-----------------------------------------------------------------*/ /*! handle IO to a file or a socket */ /*-----------------------------------------------------------------*/ typedef struct { /*-----------------------------------------------------------------*/ /* attributes */ /*-----------------------------------------------------------------*/ int m_fd; //!< file descriptor int m_issocket; //!< = true if socket char m_bufferOutput[SCSCP_PI_MAXLENBUFFER+1]; size_t m_bufferOutputValid; } SCSCP_fileio; //! attach the stream to an opened file descriptor void SCSCP_fileio_setfile(SCSCP_fileio *io,int fd, int bsocket); //! get the file descriptor of the stream int SCSCP_fileio_getfile(SCSCP_fileio *io); //! write a buffer int SCSCP_fileio_write(SCSCP_fileio *io,const void *buf, size_t len); //! read a buffer int SCSCP_fileio_read(SCSCP_fileio *io,char *buf, size_t len); //! flush all pending buffer int SCSCP_fileio_flush(SCSCP_fileio *io); #endif /*__omlfileio_H__*/ scscp-imcce-1.0.0+ds/src/scscpfileserver.c000066400000000000000000000734611215622604100204520ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpfileserver.c \brief SCSCP server \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012 M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 \bug M. GASTINEAU 29/03/12 : correct message if type of action is missing (SCSCP_option_return_???) and protocol is 1.2 or previous (ticket #8275) */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #include #if HAVE_SYS_SOCKET_H #include #endif #if HAVE_NETINET_IN_H #include #endif #include #if HAVE_UNISTD_H #include #endif #if HAVE_STRING_H #include #endif #include #include #if HAVE_STRING_H #include #endif #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpfileserver.h" #include "scscpfileclient.h" #include "scscpdebug.h" #include "scscpprocedurecall.h" #include "scscpprocedurecompleted.h" #include "scscpprocedureterminated.h" static void SCSCP_ss_closesocketclient(int socketid); /*! read the Connection information Message from the client */ static int SCSCP_ss_readCIM(SCSCP_Fileserver* server,int socketid, const char **supportedversion, SCSCP_status *status); /*! write the Connection information Message to the client */ static int SCSCP_ss_writeCIM(SCSCP_Fileserver* server,int socketid); /*! write the CIM version to the client */ static int SCSCP_ss_writeCIMVersion(int socketid, const char *supportedversion); /*-----------------------------------------------------------------*/ /*! listen for the clients on the specified port return 0 on failure on error, geterror() will give the error message @param port (in) port on the server of the SCSCP server @param status (inout) error code */ /*-----------------------------------------------------------------*/ static int SCSCP_ss_listen_an(SCSCP_Fileserver* server, int port, SCSCP_status *status) { int bres = 1; static int binitsocket=1; SCSCP_debugprint("SCSCP_ss_listen_an(%d) - entree\n", port); if (binitsocket && !SCSCP_initsocket()) { SCSCP_debugprint("SCSCP_ss_listen_an() - socket failed\n"); SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); bres = 0; } /* creer une socket pour se connecter au serveur */ else if ((server->m_fd = socket(AF_INET, SOCK_STREAM, 0))==INVALID_SOCKET) { SCSCP_debugprint("SCSCP_ss_listen_an() - socket failed\n"); SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); bres = 0; } else { int optval = 1; struct sockaddr_in adresseServeur; memset(&adresseServeur, 0, sizeof(adresseServeur)); adresseServeur.sin_family = AF_INET; adresseServeur.sin_addr.s_addr = htonl(INADDR_ANY); adresseServeur.sin_port = htons(port);/* host to network short */ SCSCP_debugprint("SCSCP_ss_listen_an() - socket sucess m_fd=%d\n",server->m_fd); /* avoid the error of type: "Address already in use" */ #if !HAVE_WINDOWS_H #if defined(SOL_SOCKET) && defined(SO_REUSEADDR) setsockopt(server->m_fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); #endif #endif /* se connecter au serveur */ if (bind(server->m_fd, (struct sockaddr *) &adresseServeur, sizeof(adresseServeur)) < 0) { SCSCP_debugprint("SCSCP_ss_listen_an() - bind failed\n"); SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); bres = 0; } else if (listen(server->m_fd, 5) < 0) { SCSCP_debugprint("SCSCP_ss_listen_an() - listen failed\n"); SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); bres = 0; } } binitsocket = 0; SCSCP_debugprint("SCSCP_ss_listen_an() - returns %d\n", bres); return bres; } /*-----------------------------------------------------------------*/ /*! accept an incoming connection @param newsocket (out) socket to perform the communication @param negotiatedversion (out) negotiated version of the protocol @param status (inout) error code */ /*-----------------------------------------------------------------*/ static int SCSCP_ss_accept(SCSCP_Fileserver* server, int* newsocket, const char** negotiatedversion, SCSCP_status *status) { int bres = 1; struct sockaddr that; const char *supportedversion = NULL; socklen_t lg = sizeof(that); int retry=1; SCSCP_debugprint("SCSCP_ss_accept() - enter\n"); do { retry = 0; *newsocket = accept(server->m_fd, &that, &lg); if (*newsocket==INVALID_SOCKET) { SCSCP_debugprint("SCSCP_Fileserver::Accept() - accept failed\n"); SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); bres = 0; } else { bres = SCSCP_ss_writeCIM(server,*newsocket); if (bres) bres = SCSCP_ss_readCIM(server, *newsocket,&supportedversion, status); if (bres) bres = SCSCP_ss_writeCIMVersion(*newsocket, supportedversion); if (!bres) { SCSCP_ss_closesocketclient(*newsocket); retry = 1; } } } while(retry); *negotiatedversion = supportedversion; SCSCP_debugprint("SCSCP_ss_accept(%d) - returns %d\n", *newsocket, bres); return bres; } /*-----------------------------------------------------------------*/ /*! close the connexion to the client @param socketid (in) socket descriptor */ /*-----------------------------------------------------------------*/ static void SCSCP_ss_closesocketclient(int socketid) { if (socketid!=-1) { const char *msg=""; send(socketid, msg, strlen(msg)*sizeof(char), 0); closesocket(socketid); }; } /*-----------------------------------------------------------------*/ /*! read the Connection information Message from the client choose the negotiated version and return 1 on success @param socketid (in) socket descriptor @param supportedversion (out) negotiated version. =NULL if no common version @param status (inout) error code @bug M. Gastineau 09/09/08 : add bres in the the while test in the case that recv is failed. */ /*-----------------------------------------------------------------*/ int SCSCP_ss_readCIM(SCSCP_Fileserver* server, int socketid, const char** supportedversion, SCSCP_status *status) { #define CIMLEN 4094 int bres = 1; char c[CIMLEN]; char *versionstr; int j=-1; SCSCP_debugprint("SCSCP_ss_readCIM(,%d,) - enter\n", socketid); do { j++; bres=(recv(socketid, c+j, sizeof(char), 0)!=SOCKET_ERROR); } while (bres && c[j]!='\n' && jm_services.m_allowedversionscount && *supportedversion==NULL; k++) { if (strcmp(versionstr,server->m_services.m_allowedversions[k])==0) *supportedversion = server->m_services.m_allowedversions[k]; } } } SCSCP_debugprint("SCSCP_ss_readCIM(,'%s') -returns %d\n", *supportedversion, bres); return bres; } /*-----------------------------------------------------------------*/ /*! write the Connection information Message to the client and return 1 on success @param server (inout) SCSCP server @param socketid (in) socket descriptor */ /*-----------------------------------------------------------------*/ int SCSCP_ss_writeCIM(SCSCP_Fileserver* server, int socketid) { int bres; size_t j; const char *msg1="\n"; SCSCP_debugprint("SCSCP_Fileserver::WriteCIM(%d) - entree\n", socketid); bres = (send(socketid, msg1, strlen(msg1)*sizeof(char), 0)!=SOCKET_ERROR); if (bres) bres = (send(socketid, server->m_services.m_servicename, strlen(server->m_services.m_servicename)*sizeof(char), 0)!=SOCKET_ERROR); if (bres) bres = (send(socketid, msg2, strlen(msg2)*sizeof(char), 0)!=SOCKET_ERROR); if (bres) bres = (send(socketid, server->m_services.m_serviceversion, strlen(server->m_services.m_serviceversion)*sizeof(char), 0)!=SOCKET_ERROR); if (bres) bres = (send(socketid, msg3, strlen(msg3)*sizeof(char), 0)!=SOCKET_ERROR); if (bres) bres = (send(socketid, server->m_services.m_serviceid, strlen(server->m_services.m_serviceid)*sizeof(char), 0)!=SOCKET_ERROR); if (bres) bres = (send(socketid, msg4, strlen(msg4)*sizeof(char), 0)!=SOCKET_ERROR); for (j=0; jm_services.m_allowedversionscount && bres; j++) { bres = (send(socketid, server->m_services.m_allowedversions[j], strlen(server->m_services.m_allowedversions[j])*sizeof(char), 0)!=SOCKET_ERROR); if (bres) bres = (send(socketid, " ", strlen(" ")*sizeof(char), 0)!=SOCKET_ERROR); } if (bres) bres = (send(socketid, msg5, strlen(msg5)*sizeof(char), 0)!=SOCKET_ERROR); SCSCP_debugprint("SCSCP_Fileserver::WriteCIM - returns %d\n", bres); return bres; } /*-----------------------------------------------------------------*/ /*! write the SCSCP version of the server the client and return 1 on success if (supportedversion==NULL) => close the session with "scscp quit" and return 0 @param socketid (in) socket descriptor @param supportedversion (in) negotiated version. =NULL if no common version => close connection */ /*-----------------------------------------------------------------*/ static int SCSCP_ss_writeCIMVersion(int socketid, const char *supportedversion) { int bres; const char *msg1="\n"; const char *msg3="\n"; SCSCP_debugprint("SCSCP_Fileserver::WriteCIMVersion(%d, %s) - enter\n", socketid, supportedversion); if (supportedversion!=NULL) { bres = (send(socketid, msg1, strlen(msg1)*sizeof(char), 0)!=SOCKET_ERROR); if (bres) bres = (send(socketid, supportedversion, strlen(supportedversion)*sizeof(char), 0)!=SOCKET_ERROR); if (bres) bres = (send(socketid, msg2, strlen(msg2)*sizeof(char), 0)!=SOCKET_ERROR); } else { bres = (send(socketid, msg3, strlen(msg3)*sizeof(char), 0)!=SOCKET_ERROR); bres = 0; /* => force close connection */ } SCSCP_debugprint("SCSCP_Fileserver::WriteCIMVersion - returns %d\n", bres); return bres; } /*-----------------------------------------------------------------*/ /*! checks if SCSCP server is null and returns 0 on error @param server (in) object to be checked @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_ss_checkNULL(SCSCP_socketserver* server, SCSCP_status* status) { int res = 1; if (server==NULL || *server==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_SERVEROBJECTNULL); res = 0; } return res; } /*-----------------------------------------------------------------*/ /*! initialize the object server and set status if an error occurs @param server (inout) object to be initialized @param servicename (in) name of service @param serviceversion (in) service version @param serviceid (in) service version @param status (inout) status error @param ... (in) allowed version to be negotiated */ /*-----------------------------------------------------------------*/ int SCSCP_ss_init(SCSCP_socketserver* server, SCSCP_status* status, const char *servicename, const char *serviceversion, const char *serviceid, ...) { va_list versions; int res = 1; if (server==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_SERVEROBJECTNULL); res = 0; } else { SCSCP_socketserver pserver; *server = pserver = (SCSCP_Fileserver*)SCSCP_malloc(sizeof(SCSCP_Fileserver),status); if (pserver==NULL) { res = 0; } else { /* count elements */ size_t counter = 0; va_list listcount; va_start(listcount, serviceid); while (va_arg(listcount, const char*)!=NULL) counter++; va_end(listcount); pserver->m_fd = -1; pserver->m_port = -1; SCSCP_ss_initcmn(&pserver->m_services, status); /* duplicate the elements of versions */ pserver->m_services.m_allowedversions = (SCSCP_string*)SCSCP_malloc(sizeof(SCSCP_string)*counter, status); res = (pserver->m_services.m_allowedversions!=NULL); if (res) { size_t cpt; va_start(versions, serviceid); for( cpt=0; cptm_services.m_allowedversions[cpt] = SCSCP_strdup(va_arg(versions, const char*), status); res = (pserver->m_services.m_allowedversions[cpt]!=NULL); } pserver->m_services.m_allowedversionscount = counter; va_end(versions); } /* duplicate information about the services */ if (res) { SCSCP_ss_setservice(&pserver->m_services,servicename, serviceversion, serviceid, status); } } } return res; } /*-----------------------------------------------------------------*/ /*! clear the object server previously initialized by SCSCP_ss_init @param server (inout) object to be deleted @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_clear(SCSCP_socketserver* server, SCSCP_status* status) { SCSCP_socketserver pserver; int res = SCSCP_ss_checkNULL(server, status); if (!res) return res; pserver = *server; res = SCSCP_ss_clearcmn(&pserver->m_services, status); free(pserver); return res; } /*-----------------------------------------------------------------*/ /*! the object server listen on the specified port @param server (inout) server @param port (in) port number. if port=0 then a random port is chosen @param firstavailable (in) = 0 => if the port isn't available, return an error = 1 => retry until a port is available (such that >port) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_listen(SCSCP_socketserver* server, int port, int firstavailable, SCSCP_status* status) { SCSCP_socketserver pserver; int res = SCSCP_ss_checkNULL(server, status); int curport = port; if (res) { pserver = *server; do { res = SCSCP_ss_listen_an(pserver,curport, status); if (res==0 && firstavailable==1) curport++; } while (res==0 && firstavailable==1 && curport>port); } if (res) { /* a random port was used */ if (port==0) { socklen_t lenadresseServeur=sizeof(struct sockaddr_in); struct sockaddr_in adresseServeur; memset(&adresseServeur, 0, sizeof(adresseServeur)); if (getsockname(pserver->m_fd, (struct sockaddr *)&adresseServeur, &lenadresseServeur)!=0) { SCSCP_ss_close(server, status); SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); res = 0; } else { pserver->m_port = ntohs(adresseServeur.sin_port); } } else { pserver->m_port = curport; } } return res; } /*-----------------------------------------------------------------*/ /*! return the port from the server is listening. it returns -1 if the server is not listening @param server (in) server */ /*-----------------------------------------------------------------*/ int SCSCP_ss_getport(SCSCP_socketserver* server) { SCSCP_socketserver pserver; int res = -1; if (server!=NULL) { pserver = *server; res = pserver->m_port; } return res; } /*-----------------------------------------------------------------*/ /*! the object server terminates to listen @param server (inout) server @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_close(SCSCP_socketserver* server, SCSCP_status* status) { SCSCP_socketserver pserver; int res = SCSCP_ss_checkNULL(server, status); if (res) { pserver = *server; if (pserver->m_fd!=-1) { closesocket(pserver->m_fd); pserver->m_fd = -1; pserver->m_port = -1; }; } return res; } /*-----------------------------------------------------------------*/ /*! the object waits for an incoming connection and accepts a incoming client connection @param server (inout) server @param incomingclient (out) new client @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_acceptclient(SCSCP_socketserver* server, SCSCP_incomingclient* incomingclient, SCSCP_status* status) { SCSCP_socketserver pserver; const char *supportedversion; int res = SCSCP_ss_checkNULL(server, status); if (res) { int newsocket; pserver = *server; res = SCSCP_ss_accept(pserver, &newsocket, &supportedversion, status); if (res) { SCSCP_sc_init(incomingclient, status, supportedversion, NULL); if (*incomingclient!=NULL) { SCSCP_sc_setsocket(*incomingclient, newsocket); } else { SCSCP_status_seterror(status, SCSCP_STATUS_NOMEM); res = 0; } } } return res; } /*-----------------------------------------------------------------*/ /*! receive the "procedure call" message from the client : read the attribute of the incoming procedure call and the type of the incoming message store the arguments in the openmathbuffer @param client (inout) scscp client @param options (inout) options of the procedure return @param msgtype (out) type of returned message @param openmathbuffer (out) openmath buffer. This buffer must be freed with 'free' @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_callrecvstr(SCSCP_incomingclient* client, SCSCP_calloptions* options, SCSCP_msgtype *msgtype, char **openmathbuffer, SCSCP_status* status) { int res = SCSCP_ss_callrecvheader(client, options, msgtype, status); if (res) { *openmathbuffer = SCSCP_ss_getxmlnoderawstring(client, SCSCP_ss_getxmlnode(client, status), status); } return res; } /*-----------------------------------------------------------------*/ /*! receive the "procedure call" message from the client : read the attribute of the incoming procedure call and the type of the incoming message @param client (inout) scscp client @param options (inout) options of the procedure return. can't be NULL. @param msgtype (out) type of returned message. could be SCSCP_msgtype_ProcedureCall, SCSCP_msgtype_Interrupt, in the current specification @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_callrecvheader(SCSCP_incomingclient* client, SCSCP_calloptions* options, SCSCP_msgtype *msgtype, SCSCP_status* status) { SCSCP_incomingclient pclient; int res; SCSCP_debugprint("SCSCP_ss_callrecvheader() - start\n"); res = SCSCP_sc_checkNULL(client, status); if (res) { pclient = *client; do { char bufferPI[SCSCP_PI_MAXLENBUFFER]; char *callid; SCSCP_status mystatus = SCSCP_status_getinitializer(); /* lecture du nouveau PI */ res = SCSCP_io_ReadPI(&pclient, msgtype, bufferPI, &mystatus); SCSCP_status_copy(status, &mystatus); if (SCSCP_status_is(&mystatus)== SCSCP_STATUS_RECVQUIT) { SCSCP_sc_setrecvquit(pclient); } /* read the header of the procedure call */ if (res) { switch (*msgtype) { case SCSCP_msgtype_ProcedureCall: res = SCSCP_procedurecall_read(client, *options, &pclient->m_iter, status); break; case SCSCP_msgtype_Interrupt: callid = SCSCP_findPIstring(bufferPI,"call_id"); if (callid==NULL) { SCSCP_debugprint("SCSCP_ss_callrecvheader() - unknown call_id : PI='%s'\n",bufferPI); res = 0; SCSCP_status_seterror(status,SCSCP_STATUS_RECVCANCEL); } else { /* set the call id to options */ char *calliddup = SCSCP_strdup(callid,status); if (calliddup) { SCSCP_co_set_writablecallid(options, calliddup, status); } else { res =0; } } break; default: break; } } } while (res==0 && SCSCP_status_is(status)==SCSCP_STATUS_RECVCANCEL); } SCSCP_debugprint("SCSCP_ss_callrecvheader(,%d,%d) - returns %d\n",(int)(*msgtype), SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! write the openmath buffer to the scscp client @param client (inout) scscp incoming client @param param (in) openmath expression (must be a const char *) @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_ss_callsendstr_callback(SCSCP_incomingclient* client, void *param, SCSCP_status* status) { const char *openmathbuffer = (const char*)param; return SCSCP_io_write(client, openmathbuffer, status); } /*-----------------------------------------------------------------*/ /*!the server send the "procedure terminated" message with an error type and a message to the client @param client (inout) scscp client @param options (in) options of the call @param cdname (in) name of the cd for the error @param symbolname (in) name of the symbole for the error @param openmathbuffer (in) openmath expression @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_sendterminatedstr(SCSCP_incomingclient* client, SCSCP_returnoptions* options, const char *cdname, const char *symbolname, const char *messagebuffer, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); SCSCP_debugprint("SCSCP_ss_sendterminatedstr(%p,%p,%s,%s,%s, %p) - enter\n", client, options, cdname, symbolname, messagebuffer, status); if (res) { SCSCP_procedureterminated aprocterm; res &= SCSCP_procedureterminated_init2(&aprocterm, *options, cdname, symbolname, messagebuffer, status ); res &= SCSCP_procedureterminated_write(client, &aprocterm, status); } SCSCP_debugprint("SCSCP_ss_sendterminatedstr(%d) - returns %d\n", SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! the server send the "procedure completed" message with a openmath expression as arguments to the client @param client (inout) scscp client @param options (in) options of the call @param openmathbuffer (in) openmath expression @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_sendcompletedstr(SCSCP_incomingclient* client, SCSCP_returnoptions* options, const char *openmathbuffer, SCSCP_status* status) { return SCSCP_ss_sendcompletedhook(client, options, SCSCP_ss_callsendstr_callback, (void*)openmathbuffer, status); } /*-----------------------------------------------------------------*/ /*! the server send the "procedure completed" message to the client. The arguments are written by callbackwriteargs @param client (inout) scscp client @param options (in) options of the call @param callbackwriteargs (in) callback function to write the parameters of the procedure call @param param (inout) opaque data given to callbackwriteargs @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_sendcompletedhook(SCSCP_incomingclient* client, SCSCP_returnoptions* options, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); if (!res) return res; res = SCSCP_procedurecompleted_write(client, *options, callbackwriteargs, param, status); return res; } /*-----------------------------------------------------------------*/ /*! the server sends the "information" message to the client. @param client (inout) scscp client @param messagebuffer (in) information @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_infomessagesend (SCSCP_incomingclient* client, const char * messagebuffer, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); SCSCP_debugprint("SCSCP_ss_infomessagesend(%p,'%s',%p) - enter\n",client, messagebuffer, status); if (res) { res = SCSCP_io_writef(client, status, "\n", NULL); } SCSCP_debugprint("SCSCP_ss_infomessagesend(,%d) - returns %d\n",SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! close an incoming connection @param client (inout) scscp client @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_closeincoming(SCSCP_incomingclient* client, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); if (res) { SCSCP_sc_close(client, status); res = SCSCP_sc_clear(client, status); } return res; } /*-----------------------------------------------------------------*/ /*! return the first node in the current location of the openmath message @param client (inout) incoming client @param status (inout) status error */ /*-----------------------------------------------------------------*/ SCSCP_xmlnodeptr SCSCP_ss_getxmlnode(SCSCP_incomingclient *client, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); return res?(*client)->m_iter:NULL; } /*----------------------------------------------------------------------------------------------*/ /*! return node and its children as a raw string return NULL on error @param client (in) client. mustn't be NULL @param node (in) current valid node. mustn't be NULL @param status (in) error code */ /*----------------------------------------------------------------------------------------------*/ char* SCSCP_ss_getxmlnoderawstring(SCSCP_incomingclient* client, SCSCP_xmlnodeptr node, SCSCP_status *status) { return SCSCP_sc_getxmlnoderawstring(client, node, status); } /*-----------------------------------------------------------------*/ /*! get the current encoding for the OpenMath objects @param client (inout) scscp client. mustn't be NULL @param encodingtype (out) current encoding. mustn't be NULL @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_get_encodingtype(SCSCP_incomingclient* client, SCSCP_encodingtype* encodingtype, SCSCP_status* status) { return SCSCP_sc_get_encodingtype(client, encodingtype, status); } /*-----------------------------------------------------------------*/ /*! set the current encoding for the OpenMath objects @param client (inout) scscp client. mustn't be NULL @param encodingtype (in) new encoding @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_set_encodingtype(SCSCP_socketclient* client, SCSCP_encodingtype encodingtype, SCSCP_status* status) { return SCSCP_sc_set_encodingtype(client, encodingtype, status); } scscp-imcce-1.0.0+ds/src/scscpfileserver.h000066400000000000000000000060551215622604100204520ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpfileserver.h \brief SCSCP server with file descriptor \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2012, 2013, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPFILESERVER_H__ #define __SCSCPFILESERVER_H__ #include "scscpserver.h" /*-----------------------------------------------------------------*/ /*! handle a SCSCP server using sockets */ /*-----------------------------------------------------------------*/ typedef struct SCSCP_stFileserver { //////////////////////////////////////////////////////////////////////////// // attribut //////////////////////////////////////////////////////////////////////////// int m_fd; //!< socket descriptor int m_port; //!< port from the server is listening SCSCP_server m_services; //!common services } SCSCP_Fileserver; #endif /*__SCSCPFILESERVER_H__*/ scscp-imcce-1.0.0+ds/src/scscpinternal.h000066400000000000000000000063751215622604100201250ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpinternal.h \brief SCSCP internal functions \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if !defined(__SCSCPINTERNAL_H__) #define __SCSCPINTERNAL_H__ #include #if defined (__cplusplus) extern "C" { #endif /* (__cplusplus) */ /*! set the error to value */ void SCSCP_status_seterror(SCSCP_status* status, int value); /*! set the error to value : EXECFAILED */ void SCSCP_status_setexecfailed(SCSCP_status* status, const char *cdname, const char *symbolname, const char *msg); /*-----------------------------------------------------------------*/ //! buffer for len for scscp Processing instruction /*-----------------------------------------------------------------*/ #define SCSCP_PI_MAXLENBUFFER 16000 #ifndef INT32_MAX #define INT32_MAX 2147483647 #endif #ifndef INT32_MIN #define INT32_MIN (-2147483647-1) #endif #if defined (__cplusplus) } #endif /* (__cplusplus) */ #endif /*__SCSCPINTERNAL_H__*/ scscp-imcce-1.0.0+ds/src/scscpio.c000066400000000000000000001245711215622604100167120ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpio.cxx \brief SCSCP I/O function \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #include #if HAVE_STRING_H #include #endif #if HAVE_UNISTD_H #include #endif #if HAVE_STDINT_H #include #endif #if HAVE_ARPA_INET_H #include #endif #include #include #include #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpdebug.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "float.h" /*-----------------------------------------------------------------*/ /* private functions */ /*-----------------------------------------------------------------*/ static int SCSCP_io_checkNULL(SCSCP_io* stream, SCSCP_status* status); static int SCSCP_io_write_binarytagscharid(SCSCP_io* stream, unsigned char tags, const char *buffer, const char *id, SCSCP_status* status); static int SCSCP_io_write_binarytagscharid2(SCSCP_io* stream, unsigned char tags, const char *buffer1, const char *buffer2, const char *id, SCSCP_status* status); static int SCSCP_io_writeOMIchar_binary(SCSCP_io* stream, char x, SCSCP_status* status); static int SCSCP_io_writeOMIint32_binary(SCSCP_io* stream, int32_t x, SCSCP_status* status); static int SCSCP_io_write_XMLbegin(SCSCP_io* stream, const char *tag, const char *id, SCSCP_status* status); static int SCSCP_io_write_binarybegin(SCSCP_io* stream, unsigned char tag, const char *id, SCSCP_status* status); /*-----------------------------------------------------------------*/ /* private defines */ /*-----------------------------------------------------------------*/ /*! long flag set for binary encoding */ #define SCSCP_BINARY_SETLONGFLAG 128 /*-----------------------------------------------------------------*/ /*! Set the long flag if buffer is >256. and write the tags and buffer for the binary encoding. return 0 on error @param stream (inout) scscp stream @param tags (in) token identifier @param buffer (in) some data @param id (in) sharing id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_io_write_binarytagscharid(SCSCP_io* stream, unsigned char tags, const char *buffer, const char *id, SCSCP_status* status) { size_t l0=strlen(buffer); uint32_t l=(uint32_t)l0; int res; size_t lenid=(id==NULL?0:strlen(id)); uint32_t lenid32=(uint32_t)lenid; if (id!=NULL) tags+=64; if (l>=256 || lenid>=256) { tags+=SCSCP_BINARY_SETLONGFLAG; res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); l = htonl(l); if (res) res = SCSCP_io_writelen(stream, &l, sizeof(l), status); if (id!=NULL) { lenid32 = htonl(lenid32); if (res) res = SCSCP_io_writelen(stream, &lenid32, sizeof(lenid32), status); } } else { unsigned char sl = (unsigned char)l; res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); if (res) res = SCSCP_io_writelen(stream, &sl, sizeof(sl), status); if (id!=NULL) { unsigned char slenid = (unsigned char)lenid; if (res) res = SCSCP_io_writelen(stream, &slenid, sizeof(slenid), status); } } if (res) res = SCSCP_io_writelen(stream, buffer, l0, status); if (res && id!=NULL) res = SCSCP_io_writelen(stream, id, lenid, status); return res; } /*-----------------------------------------------------------------*/ /*! Set the long flag if buffer1 or buffer2 is >256. and write the tags and buffer1, and buffer2 for the binary encoding. return 0 on error @param stream (inout) scscp stream @param tags (in) token identifier @param buffer1 (in) some data @param buffer2 (in) some data @param id (in) sharing id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_io_write_binarytagscharid2(SCSCP_io* stream, unsigned char tags, const char *buffer1, const char *buffer2, const char *id, SCSCP_status* status) { uint32_t l1=(uint32_t)strlen(buffer1); uint32_t l2=(uint32_t)strlen(buffer2); int res; size_t lenid=(id==NULL?0:strlen(id)); uint32_t lenid32=(uint32_t)lenid; if (id!=NULL) tags+=64; if (l1>=256 || l2>=256 || lenid>=256) { tags+=SCSCP_BINARY_SETLONGFLAG; res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); l1 = htonl(l1); if (res) res = SCSCP_io_writelen(stream, &l1, sizeof(l1), status); l2 = htonl(l2); if (res) res = SCSCP_io_writelen(stream, &l2, sizeof(l2), status); if (id!=NULL) { lenid32 = htonl(lenid32); if (res) res = SCSCP_io_writelen(stream, &lenid32, sizeof(lenid32), status); } } else { unsigned char sl1 = (unsigned char)l1; unsigned char sl2 = (unsigned char)l2; res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); if (res) res = SCSCP_io_writelen(stream, &sl1, sizeof(sl1), status); if (res) res = SCSCP_io_writelen(stream, &sl2, sizeof(sl2), status); if (id!=NULL) { unsigned char slenid = (unsigned char)lenid; if (res) res = SCSCP_io_writelen(stream, &slenid, sizeof(slenid), status); } } if (res) res = SCSCP_io_writelen(stream, buffer1, l1, status); if (res) res = SCSCP_io_writelen(stream, buffer2, l2, status); if (res && id!=NULL) res = SCSCP_io_writelen(stream, id, lenid, status); return res; } /*-----------------------------------------------------------------*/ /*! write the beginning OpenMath tag with the id directly to the SCSCP client or server usign the BINARY encoding. "id" follows the "tags". return 0 on error @param stream (inout) scscp stream @param tags (in) binary tag @param id (in) reference id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_io_write_binarybegin(SCSCP_io* stream, unsigned char tags, const char *id, SCSCP_status* status) { int res; if (id==NULL) { res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); } else { size_t lenid = strlen(id); tags += 64U; if (lenid>=256) { /* id is longer than a 256 bytes */ uint32_t lenid32 = (uint32_t)lenid; lenid32 = htonl(lenid32); tags += SCSCP_BINARY_SETLONGFLAG; res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); if (res) res = SCSCP_io_writelen(stream, &lenid32, sizeof(lenid32), status); } else { /* id is shorter or equal than a 256 bytes */ unsigned char sl1 = (unsigned char)lenid; res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); if (res) res = SCSCP_io_writelen(stream, &sl1, sizeof(sl1), status); } if (res) res = SCSCP_io_write(stream, id, status); } return res; } /*-----------------------------------------------------------------*/ /*! write x as an OpenMath integer in binary encoding using one byte directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param x (in) some data @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_io_writeOMIchar_binary(SCSCP_io* stream, char x, SCSCP_status* status) { int res; const unsigned char tags = 1; SCSCP_debugprint("SCSCP_io_writeOMIchar_binary(%p,%d,%d) - enter\n", stream, (int)x, SCSCP_status_is(status)); res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); if (res) res = SCSCP_io_writelen(stream, &x, sizeof(x), status); SCSCP_debugprint("SCSCP_io_writeOMIchar_binary() - return %d\n", res); return res; } /*-----------------------------------------------------------------*/ /*! write x as an OpenMath integer in binary encoding using 4 bytes directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param x (in) some data @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_io_writeOMIint32_binary(SCSCP_io* stream, int32_t x, SCSCP_status* status) { int res; uint32_t ux; const unsigned char tags = 1+SCSCP_BINARY_SETLONGFLAG; SCSCP_debugprint("SCSCP_io_writeOMIint32_binary(%p,%ld,%d) - enter\n", stream, (long)x, SCSCP_status_is(status)); res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); ux = htonl((uint32_t)x); if (res) res = SCSCP_io_writelen(stream, &ux, sizeof(ux), status); SCSCP_debugprint("SCSCP_io_writeOMIint32_binary() - return %d\n", res); return res; } /*-----------------------------------------------------------------*/ /*! write some data to the SCSCP server or client return 0 on error @param stream (inout) scscp stream @param buffer (in) some data @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writelen(SCSCP_io* stream, const void *buffer, size_t len, SCSCP_status* status) { int res; res = SCSCP_fileio_write(&(*stream)->m_OutStream, buffer, len); if (!res) SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); return res; } /*-----------------------------------------------------------------*/ /*! write some data to the SCSCP server or client return 0 on error @param stream (inout) scscp stream @param buffer (in) some data @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_write(SCSCP_io* stream, const char *buffer, SCSCP_status* status) { int res = SCSCP_io_checkNULL(stream, status); if (res) { res = SCSCP_fileio_write(&(*stream)->m_OutStream, buffer, strlen(buffer)*sizeof(char)); if (!res) SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); } return res; } /*-----------------------------------------------------------------*/ /*! flush the connection return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_flush(SCSCP_io* stream, SCSCP_status* status) { int res = SCSCP_io_write(stream,"\n", status); if (res) { res = SCSCP_fileio_flush(&(*stream)->m_OutStream); if (!res) SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); } return res; } /*-----------------------------------------------------------------*/ /*! write some data to the SCSCP server or client The list must finish a NULL pointer return 0 on error @param client (inout) scscp stream @param buffer (in) some data @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writef(SCSCP_io* stream, SCSCP_status* status, const char *buffer, ...) { va_list buflist; const char *data; int res = SCSCP_io_checkNULL(stream, status); if (res) { res = SCSCP_io_write(stream, buffer, status); va_start(buflist, buffer); while (res && ((data=va_arg(buflist, const char*))!=NULL)) { res = SCSCP_io_write(stream, data, status); } va_end(buflist); } return res; } /*-----------------------------------------------------------------*/ /*! write the beginning OpenMath tag with the id directly to the SCSCP client or server usign the XML encoding return 0 on error @param stream (inout) scscp stream @param tag (in) XML tag @param id (in) sharing id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_io_write_XMLbegin(SCSCP_io* stream, const char *tag, const char *id, SCSCP_status* status) { int res; if (id==NULL) { res = SCSCP_io_writef(stream, status, "<", tag, ">",NULL); } else { res = SCSCP_io_writef(stream, status, "<", tag, "id=\"", id ,"\" >",NULL); } return res; } /*-----------------------------------------------------------------*/ /*! write buffer as an OpenMath string directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param buffer (in) some data @param id (in) sharing id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeOMSTR(SCSCP_io* stream, const char *buffer, const char *id, SCSCP_status* status) { int res; if (buffer!=NULL) { if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { res = SCSCP_io_write_binarytagscharid(stream, 6, buffer, id, status); } else { res = SCSCP_io_write_XMLbegin(stream, "OMSTR", id, status); if (res) res = SCSCP_io_writef(stream, status, buffer, "", NULL); } } else { if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { /* send a string of length 1 instead of 0 to avoid Openmath INRIA C library assertion */ res = SCSCP_io_writeOMSTR(stream," ", id, status); } else { res = SCSCP_io_write(stream, "", status); } } return res; } /*-----------------------------------------------------------------*/ /*! write x as an OpenMath float-point directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param x (in) some data @param id (in) sharing id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeOMFdouble(SCSCP_io* stream, double x, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { double nx; const unsigned char tags = 3; res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); nx = SCSCP_htond(x); if (res) res = SCSCP_io_writelen(stream, &nx, sizeof(nx), status); } else { char valeur[400]; sprintf(valeur,"dec=\"%+-.*E\" />",(int)DBL_DIG+1,x); if (id==NULL) { res = SCSCP_io_writef(stream, status, "", NULL); } if (res) res = SCSCP_io_write(stream, valeur, status); } return res; } /*-----------------------------------------------------------------*/ /*! write buffer as an OpenMath floating-point directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param buffer (in) some data @param id (in) sharing id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeOMFstr(SCSCP_io* stream, const char *buffer, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { double x = strtod(buffer, (char **)NULL); res = SCSCP_io_writeOMFdouble(stream, x, id, status); } else { if (id==NULL) { res = SCSCP_io_writef(stream, status, "", NULL); } else { res = SCSCP_io_writef(stream, status, "", NULL); } } return res; } /*-----------------------------------------------------------------*/ /*! write x as an OpenMath integer directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param x (in) some data @param id (in) sharing id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeOMIint(SCSCP_io* stream, int x, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { if (-128<=x && x<=127) { res = SCSCP_io_writeOMIchar_binary(stream, (char)x, status); } else if (INT32_MIN<=x && x<=INT32_MAX) { res = SCSCP_io_writeOMIint32_binary(stream, (int32_t)x, status); } else { char valeur[400]; sprintf(valeur,"%d",x); res = SCSCP_io_writeOMIstr(stream, valeur, id, status); } } else { char valeur[400]; sprintf(valeur,"%d",x); res = SCSCP_io_write_XMLbegin(stream, "OMI", id, status); if (res) res = SCSCP_io_write(stream, valeur, status); } return res; } /*-----------------------------------------------------------------*/ /*! write x as an OpenMath integer directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param x (in) some data @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeOMIsizet(SCSCP_io* stream, size_t x, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { if (x<=127) { res = SCSCP_io_writeOMIchar_binary(stream, (char)x, status); } else if (x<=INT32_MAX) { res = SCSCP_io_writeOMIint32_binary(stream, (int32_t)x, status); } else { char valeur[400]; sprintf(valeur,"%llu",(unsigned long long)x); res = SCSCP_io_writeOMIstr(stream, valeur, NULL, status); } } else { char valeur[400]; sprintf(valeur,"%llu",(unsigned long long)x); res = SCSCP_io_write(stream, valeur, status); } return res; } /*-----------------------------------------------------------------*/ /*! write x as an OpenMath integer directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param x (in) some data @param id (in) sharing id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeOMIlonglong(SCSCP_io* stream, long long x, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { if (-128<=x && x<=127) { res = SCSCP_io_writeOMIchar_binary(stream, (char)x, status); } else if (INT32_MIN<=x && x<=INT32_MAX) { res = SCSCP_io_writeOMIint32_binary(stream, (int32_t)x, status); } else { char valeur[400]; sprintf(valeur,"%lld",x); res = SCSCP_io_writeOMIstr(stream, valeur, id, status); } } else { char valeur[400]; sprintf(valeur,"%lld",x); res = SCSCP_io_write_XMLbegin(stream, "OMI", id, status); if (res) res = SCSCP_io_write(stream, valeur, status); } return res; } /*-----------------------------------------------------------------*/ /*! write buffer as an OpenMath integer directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param buffer (in) some data @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeOMIstr(SCSCP_io* stream, const char *buffer, const char *id, SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_io_writeOMIstr(%p,%s,%d) -enter\n", stream, buffer, SCSCP_status_is(status)); if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { uint32_t l0=(uint32_t)strlen(buffer); unsigned char tags=2; uint32_t l = l0; if (*buffer=='-' || *buffer=='+') l--; if (l>=256) { tags+=SCSCP_BINARY_SETLONGFLAG; res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); l = htonl(l); if (res) res = SCSCP_io_writelen(stream, &l, sizeof(l), status); } else { unsigned char sl = (unsigned char)l; res = SCSCP_io_writelen(stream, &tags, sizeof(tags), status); if (res) res = SCSCP_io_writelen(stream, &sl, sizeof(sl), status); } if (res) { if (*buffer!='-' && *buffer!='+') res = SCSCP_io_writelen(stream, "+", 1, status); if (res) res = SCSCP_io_writelen(stream, buffer, l0, status); } } else { /* XML encoding */ res = SCSCP_io_write_XMLbegin(stream, "OMI", id, status); if (res) res = SCSCP_io_writef(stream, status, buffer, "", NULL); } SCSCP_debugprint("SCSCP_io_writeOMIstr() - return %d\n", res); return res; } /*-----------------------------------------------------------------*/ /*! write symbolname/cdname as an OpenMath symbol directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param cdname (in) cd name @param symbolname (in) symbol name @param id (in) sharing id (could be NULL) => id isn't written @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeOMS(SCSCP_io* stream, const char* cdname, const char* symbolname, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { res = SCSCP_io_write_binarytagscharid2(stream, 8, cdname, symbolname, id, status); } else { /* XML encoding */ if (id==NULL) { res = SCSCP_io_writef(stream, status, "", NULL); } else { res = SCSCP_io_writef(stream, status, "", NULL); } } return res; } /*-----------------------------------------------------------------*/ /*! write buffer as an OpenMath variable directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param buffer (in) some data @param id (in) sharing id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeOMV(SCSCP_io* stream, const char *buffer, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { res = SCSCP_io_write_binarytagscharid(stream, 5, buffer, id, status); } else { /* XML encoding */ if (id==NULL) { res = SCSCP_io_writef(stream, status, "", NULL); } else { res = SCSCP_io_writef(stream, status, "", NULL); } } return res; } /*-----------------------------------------------------------------*/ /*! write buffer as an OpenMath reference directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param buffer (in) some data @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeOMR(SCSCP_io* stream, const char *buffer, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { res = SCSCP_io_write_binarytagscharid(stream, 31, buffer, NULL, status); } else { /* XML encoding */ res = SCSCP_io_writef(stream, status, "", NULL); } return res; } /*-----------------------------------------------------------------*/ /*! write the beginning OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param id (in) sharing id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writebeginOMA(SCSCP_io* stream, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { res = SCSCP_io_write_binarybegin(stream, 16U, id, status); } else { res = SCSCP_io_write_XMLbegin(stream, "OMA", id, status); } return res; } /*-----------------------------------------------------------------*/ /*! write the end OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeendOMA(SCSCP_io* stream, SCSCP_status* status) { const char binaryencoding[] = { 17,'\0'}; const char* xmlencoding=""; const char *encoding = xmlencoding; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) encoding = binaryencoding; return SCSCP_io_write(stream, encoding, status); } /*-----------------------------------------------------------------*/ /*! write the beginning OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param id (in) reference id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writebeginOME(SCSCP_io* stream, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { res = SCSCP_io_write_binarybegin(stream, 22U, id, status); } else { res = SCSCP_io_write_XMLbegin(stream, "OME", id, status); } return res; } /*-----------------------------------------------------------------*/ /*! write the end OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeendOME(SCSCP_io* stream, SCSCP_status* status) { const char binaryencoding[] = { 23,'\0'}; const char* xmlencoding=""; const char *encoding = xmlencoding; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) encoding = binaryencoding; return SCSCP_io_write(stream, encoding, status); } /*-----------------------------------------------------------------*/ /*! write the beginning OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writebeginOMOBJ(SCSCP_io* stream, SCSCP_status* status) { const char binaryencoding[] = { 24,'\0'}; const char* xmlencoding=""; const char *encoding = xmlencoding; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) encoding = binaryencoding; return SCSCP_io_write(stream, encoding, status); } /*-----------------------------------------------------------------*/ /*! write the end OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeendOMOBJ(SCSCP_io* stream, SCSCP_status* status) { const char binaryencoding[] = { 25,'\0'}; const char* xmlencoding=""; const char *encoding = xmlencoding; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) encoding = binaryencoding; return SCSCP_io_write(stream, encoding, status); } /*-----------------------------------------------------------------*/ /*! write the beginning OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param id (in) reference id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writebeginOMBIND(SCSCP_io* stream, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { res = SCSCP_io_write_binarybegin(stream, 26U, id, status); } else { res = SCSCP_io_write_XMLbegin(stream, "OMBIND", id, status); } return res; } /*-----------------------------------------------------------------*/ /*! write the end OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeendOMBIND(SCSCP_io* stream, SCSCP_status* status) { const char binaryencoding[] = { 27,'\0'}; const char* xmlencoding=""; const char *encoding = xmlencoding; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) encoding = binaryencoding; return SCSCP_io_write(stream, encoding, status); } /*-----------------------------------------------------------------*/ /*! write the beginning OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param id (in) reference id (could be NULL) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writebeginOMFOREIGN(SCSCP_io* stream, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { res = 0; } else { res = SCSCP_io_write_XMLbegin(stream, "OMFOREIGN", id, status); } return res; } /*-----------------------------------------------------------------*/ /*! write the end OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeendOMFOREIGN(SCSCP_io* stream, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { res = 0; } else { res = SCSCP_io_write(stream, "", status); } return res; } /*-----------------------------------------------------------------*/ /*! write the beginning OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param id (in) sharing id (could be NULL) => id isn't written @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writebeginOMATTR(SCSCP_io* stream, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { res = SCSCP_io_write_binarybegin(stream, 18U, id, status); } else { res = SCSCP_io_write_XMLbegin(stream, "OMATTR", id, status); } return res; } /*-----------------------------------------------------------------*/ /*! write the end OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeendOMATTR(SCSCP_io* stream, SCSCP_status* status) { const char binaryencoding[] = { 19,'\0'}; const char* xmlencoding=""; const char *encoding = xmlencoding; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) encoding = binaryencoding; return SCSCP_io_write(stream, encoding, status); } /*-----------------------------------------------------------------*/ /*! write the beginning OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param id (in) sharing id (could be NULL) => id isn't written @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writebeginOMATP(SCSCP_io* stream, const char *id, SCSCP_status* status) { int res; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) { res = SCSCP_io_write_binarybegin(stream, 20U, id, status); } else { res = SCSCP_io_write_XMLbegin(stream, "OMATP", id, status); } return res; } /*-----------------------------------------------------------------*/ /*! write the end OpenMath tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeendOMATP(SCSCP_io* stream, SCSCP_status* status) { const char binaryencoding[] = { 21,'\0'}; const char* xmlencoding=""; const char *encoding = xmlencoding; if ((*stream)->m_sendencodingtype==SCSCP_encodingtype_Binary) encoding = binaryencoding; return SCSCP_io_write(stream, encoding, status); } /*-----------------------------------------------------------------*/ /*! write the expression directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeSCSCPSTART(SCSCP_io* stream, SCSCP_status* status) { int res= SCSCP_io_write(stream, "", status); return res && SCSCP_io_flush(stream,status); } /*-----------------------------------------------------------------*/ /*! write the SCSCP tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeSCSCPEND(SCSCP_io* stream, SCSCP_status* status) { int res = SCSCP_io_flush(stream,status); res &= SCSCP_io_write(stream, "", status); res &= SCSCP_io_flush(stream,status); return res; } /*-----------------------------------------------------------------*/ /*! write the SCSCP tag directly to the SCSCP client or server return 0 on error @param stream (inout) scscp stream @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_writeSCSCPCANCEL(SCSCP_io* stream, SCSCP_status* status) { int res = SCSCP_io_flush(stream,status); res &= SCSCP_io_write(stream, "", status); res &= SCSCP_io_flush(stream,status); return res; } /*-----------------------------------------------------------------*/ /*! checks if SCSCP stream is null and returns 0 on error @param stream (in) object to be checked @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_io_checkNULL(SCSCP_io* stream, SCSCP_status* status) { int res = 1; if (stream==NULL || *stream==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_STREAMOBJECTNULL); res = 0; } return res; } /*-----------------------------------------------------------------*/ /*! \internal read one processing instruction (PI) of the stream. get the content of the PI from the stream Store the type of PI Store the content of PI @param stream (in) object to be checked @param msgtype (out) type of returned message. could be SCSCP_msgtype_ProcedureCall, SCSCP_msgtype_Interrupt, in the current specification @param bufferPI (out) buffer will contain the PI. It must contain at least SCSCP_PI_MAXLENBUFFER characters @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_io_ReadPI(SCSCP_io* stream, SCSCP_msgtype* msgtype, char *bufferPI, SCSCP_status* status) { const char *PIinfo = ""; const char *PIquit = "m_doc); return res; } scscp-imcce-1.0.0+ds/src/scscpomdoc.c000066400000000000000000001035041215622604100173750ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpomdoc.c \brief OpenMath documents \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #if HAVE_STRING_H #include #endif #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpdebug.h" #include "scscputil.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpomdoc.h" #include "scscpbinary.h" /*-----------------------------------------------------------------*/ /* private variables */ /*-----------------------------------------------------------------*/ //! table of openmath type/name const struct { SCSCP_omnodetype type; /*internal type */ const char *name; SCSCP_omtype typeexternal; /*!< external type */ } s_tableindicename[]= { { SCSCP_omnodetype_OMIchar, "OMI" , SCSCP_omtype_OMI }, { SCSCP_omnodetype_OMIint32, "OMI" , SCSCP_omtype_OMI }, { SCSCP_omnodetype_OMIstr, "OMI" , SCSCP_omtype_OMI }, { SCSCP_omnodetype_OMF, "OMF" , SCSCP_omtype_OMF }, { SCSCP_omnodetype_OMV, "OMV" , SCSCP_omtype_OMV }, { SCSCP_omnodetype_OMSTRlatin1, "OMSTR" , SCSCP_omtype_OMSTR }, { SCSCP_omnodetype_OMSTRUTF16, "OMSTR" , SCSCP_omtype_OMSTR }, { SCSCP_omnodetype_OMS, "OMS" , SCSCP_omtype_OMS }, { SCSCP_omnodetype_OMB, "OMB" , SCSCP_omtype_OMB }, { SCSCP_omnodetype_OMFOREIGN, "OMFOREIGN" , SCSCP_omtype_OMFOREIGN }, { SCSCP_omnodetype_OMA, "OMA" , SCSCP_omtype_OMA }, { SCSCP_omnodetype_OMBIND,"OMBIND", SCSCP_omtype_OMBIND }, { SCSCP_omnodetype_OMATTR, "OMATTR" , SCSCP_omtype_OMATTR }, { SCSCP_omnodetype_OME, "OME" , SCSCP_omtype_OME }, { SCSCP_omnodetype_OMATP, "OMATP" , SCSCP_omtype_OMATP }, { SCSCP_omnodetype_OMBVAR, "OMATP" , SCSCP_omtype_OMBVAR }, { SCSCP_omnodetype_OMRinternal, "OMR" , SCSCP_omtype_OMR }, { SCSCP_omnodetype_OMR, "OMR" , SCSCP_omtype_OMR }, { SCSCP_omnodetype_OMOBJ , "OMOBJ" , SCSCP_omtype_OMOBJ }, { SCSCP_omnodetype_OMFdec , "OMF" ,SCSCP_omtype_OMF } }; /*-----------------------------------------------------------------*/ /* private functions */ /*-----------------------------------------------------------------*/ static SCSCP_omattrptr SCSCP_omdoc_allocateattr(SCSCP_omdocptr doc, size_t len); static SCSCP_omnodeptr SCSCP_omdoc_allocatenode(SCSCP_omdocptr doc); static void* SCSCP_omdoc_allocateinnode(SCSCP_omdocptr doc, size_t len); static void SCSCP_omdoc_setrootnode(SCSCP_omdocptr doc,SCSCP_omnodeptr node); static int SCSCP_omnode_movetotagtype(SCSCP_omnodeptr* curnode, SCSCP_omnodetype omtype, int children, int gotochildnode); static int SCSCP_omnode_setattrID(SCSCP_omdocptr doc, SCSCP_omnodeptr node, unsigned char token, const char *value, int lenvalue); static SCSCP_omnodeptr SCSCP_omnode_inittoken0(SCSCP_omdocptr doc, unsigned char token); static void SCSCP_omnode_attachchild(SCSCP_omnodeptr parent, SCSCP_omnodeptr child); static size_t SCSCP_omnode_getrawstring_computesize(SCSCP_omnodeptr node); static SCSCP_omtype SCSCP_omnode_externalfromtype(SCSCP_omnodetype omtype); static size_t SCSCP_omattr_getrawstring_computesize(SCSCP_omattrptr attr); static char* SCSCP_omattr_sdump(char* buffer, SCSCP_omattrptr attr); /*-----------------------------------------------------------------*/ /*! initialize the SCSCP OpenMath document @param doc (out) document to be initialized */ /*-----------------------------------------------------------------*/ SCSCP_omdocptr SCSCP_omdoc_init(void) { SCSCP_omdocptr doc; doc = (SCSCP_omdocptr)SCSCP_malloc(sizeof(SCSCP_omdoc), SCSCP_STATUS_IGNORE); if (doc) { doc->m_rawom = NULL; doc->m_nodes = NULL; doc->m_rootnode = NULL; doc->m_Writepos_nodes = 0; } return doc; } /*-----------------------------------------------------------------*/ /*! clear the SCSCP OpenMath document @param doc (inout) document to be destroyed */ /*-----------------------------------------------------------------*/ void SCSCP_omdoc_clear(SCSCP_omdocptr doc) { SCSCP_buffer_list_clear(doc->m_rawom); SCSCP_buffer_list_clear(doc->m_nodes); } /*-----------------------------------------------------------------*/ /*!return the root node of the OpenMath Document @param doc (inout) document to be destroyed */ /*-----------------------------------------------------------------*/ SCSCP_omnodeptr SCSCP_omdoc_getrootnode(SCSCP_omdocptr doc) { return doc->m_rootnode; } /*-----------------------------------------------------------------*/ /*! set the root node of the OpenMath Document @param doc (inout) document to be modified */ /*-----------------------------------------------------------------*/ static void SCSCP_omdoc_setrootnode(SCSCP_omdocptr doc,SCSCP_omnodeptr node) { doc->m_rootnode = node; } /*-----------------------------------------------------------------*/ /*! dump the content of the document @param file (inout) output stream @param doc (in) document */ /*-----------------------------------------------------------------*/ void SCSCP_omdoc_dump(FILE* file, SCSCP_omdocptr doc) { SCSCP_omnode_dump(file, doc->m_rootnode); } /*-----------------------------------------------------------------*/ /*! allocate memory for an attribute + len bytes in the field nodes of doc @param doc (inout) XML document to build */ /*-----------------------------------------------------------------*/ static SCSCP_omattrptr SCSCP_omdoc_allocateattr(SCSCP_omdocptr doc, size_t len) { size_t lenneed = 1 + (len+sizeof(SCSCP_omattr)-1)/sizeof(SCSCP_omattr); return (SCSCP_omattrptr)SCSCP_omdoc_allocateinnode(doc, lenneed*sizeof(SCSCP_omattr)); } /*-----------------------------------------------------------------*/ /*! allocate memory for a node in the field nodes of doc @param doc (inout) XML document to build */ /*-----------------------------------------------------------------*/ static SCSCP_omnodeptr SCSCP_omdoc_allocatenode(SCSCP_omdocptr doc) { return (SCSCP_omnodeptr)SCSCP_omdoc_allocateinnode(doc, sizeof(SCSCP_omnode)); } /*-----------------------------------------------------------------*/ /*! allocate memory in the field nodes of doc @param doc (inout) XML document to build */ /*-----------------------------------------------------------------*/ static void* SCSCP_omdoc_allocateinnode(SCSCP_omdocptr doc, size_t len) { void *data; SCSCP_debugprint("SCSCP_omdoc_allocateinnode(%p,%lu) - enter\n", doc, (unsigned long) len); len = (len+sizeof(void*)-1)&(~(sizeof(void*)-1)); if (doc->m_nodes==NULL || doc->m_Writepos_nodes+len>=doc->m_nodes->m_len) { SCSCP_debugprint("rellocate : doc->m_Writepos_nodes=%lu %lu %lu\n", (unsigned long) doc->m_Writepos_nodes, (unsigned long) len, (unsigned long) (doc->m_nodes==NULL)?0:doc->m_nodes->m_len); doc->m_nodes = SCSCP_buffer_list_init(doc->m_nodes,len); doc->m_Writepos_nodes = 0; } if (doc->m_nodes!=NULL) { data = ((char *)doc->m_nodes->m_data)+doc->m_Writepos_nodes; doc->m_Writepos_nodes+=len; } SCSCP_debugprint("SCSCP_omdoc_allocateinnode() -return %p (doc->m_Writepos_nodes=%lu)\n", data,(unsigned long)doc->m_Writepos_nodes); return data; } /*----------------------------------------------------------------------------------------------*/ /*! return the name of the current xml node. @param curnode (in) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ const char *SCSCP_omnode_getname(SCSCP_omnodeptr node) { const char *name; SCSCP_debugprint("SCSCP_omnode_getname(%p) - enter\n", node); name = SCSCP_omnode_namefromtype(node->omtype); SCSCP_debugprint("SCSCP_omnode_getname() - return %s\n", name); return name; } /*----------------------------------------------------------------------------------------------*/ /*! return the name from the type. @param omtype (in) valid OpenMath type */ /*----------------------------------------------------------------------------------------------*/ const char *SCSCP_omnode_namefromtype(SCSCP_omnodetype omtype) { const char *name=NULL; size_t cpt; /*SCSCP_debugprint("SCSCP_omnode_namefromtype(%d) - enter\n", omtype);*/ for(cpt=0; cptomtype); SCSCP_debugprint("SCSCP_omnode_getexternaltype() - return %d\n", (int)type); return type; } /*----------------------------------------------------------------------------------------------*/ /*! return the external type from the internal type. @param omtype (in) valid OpenMath type */ /*----------------------------------------------------------------------------------------------*/ static SCSCP_omtype SCSCP_omnode_externalfromtype(SCSCP_omnodetype omtype) { SCSCP_omtype type = SCSCP_omtype_CONTENT; size_t cpt; /*SCSCP_debugprint("SCSCP_omnode_externalfromtype(%d) - enter\n", omtype);*/ for(cpt=0; cpt look only in the children @param gotochildnode (in) = 0 => return the looking node = 1 => return the first child node */ /*-----------------------------------------------------------------*/ int SCSCP_omnode_movetotag(SCSCP_omnodeptr* curnode, const char *string, int children, int gotochildnode) { return SCSCP_omnode_movetotagtype(curnode, SCSCP_omnode_typefromname(string),children, gotochildnode); } /*-----------------------------------------------------------------*/ /*!move the current node pointer to the first specified item return true on success @param curnode (inout) iterator on the xml doc @param omtype (in) OpenMath type to find @param children (in) = true => look only in the children @param gotochildnode (in) = 0 => return the looking node = 1 => return the first child node */ /*-----------------------------------------------------------------*/ static int SCSCP_omnode_movetotagtype(SCSCP_omnodeptr* curnode, SCSCP_omnodetype omtype, int children, int gotochildnode) { int res = 0; #if SCSCP_PARSERTYPE==SCSCP_PARSERSAX SCSCP_omnodeptr itertmp = *curnode; SCSCP_omnodeptr iter = *curnode; SCSCP_debugprint("SCSCP_omnode_movetotagtype(%p,%d,%d) - enter\n", *curnode, omtype, children); if (children) { if (iter) { if (iter->xmltype==XML_TEXT_NODE) { // cas de texte entre les noeuds SCSCP_xmlnodeptr next = SCSCP_xmlnode_getnext(iter); res = SCSCP_omnode_movetotagtype(&next, omtype, children, gotochildnode); } else if (iter->xmltype == XML_ELEMENT_NODE) { SCSCP_debugprint("SCSCP_omnode_movetotagtype() - node %d type XML_ELEMENT_NODE \n", iter->omtype); res = (omtype==iter->omtype); } if (!res) { itertmp = iter->children; res = SCSCP_omnode_movetotagtype(&itertmp, omtype, children, gotochildnode); if (res) *curnode = itertmp; } } } else { while (iter!=NULL && !res) { if (iter->xmltype == XML_ELEMENT_NODE) { SCSCP_debugprint("SCSCP_omnode_movetotagtype() - node %d type XML_ELEMENT_NODE \n", iter->omtype); res = (omtype==iter->omtype); } if (!res) iter = SCSCP_xmlnode_getnext(iter); } *curnode = iter; } if (res && gotochildnode) *curnode = SCSCP_xmlnode_getchild(*curnode); #endif /*SCSCP_PARSERTYPE==SCSCP_PARSERSAX*/ SCSCP_debugprint("SCSCP_omnode_movetotagtype(%p,) - returns %d\n", *curnode, res); return res; } /*-----------------------------------------------------------------*/ /*! set the id of the node if the token contains an id using the followed value @param doc (inout) document @param node (inout) node @param token (in) token of the current @param value (in) value of id (only the lenvalue first characters are valid) @param lenvalue (in) valid character of value */ /*-----------------------------------------------------------------*/ static int SCSCP_omnode_setattrID(SCSCP_omdocptr doc, SCSCP_omnodeptr node, unsigned char token, const char *value, int lenvalue) { int retval = 1; if (SCSCP_binary_isidflagset(token)) { retval = SCSCP_omnode_setattr(doc, node, "id", value, lenvalue); } return retval; } /*-----------------------------------------------------------------*/ /*! set the attribute of the node using the value @param doc (inout) document @param node (inout) node @param token (in) token of the current @param name (in) name of the attribute @param value (in) value of id (only the lenvalue first characters are valid) @param lenvalue (in) valid character of value */ /*-----------------------------------------------------------------*/ int SCSCP_omnode_setattr(SCSCP_omdocptr doc, SCSCP_omnodeptr node, const char *name, const char *value, int lenvalue) { int retval=1; SCSCP_omattrptr attr = NULL; SCSCP_debugprint("SCSCP_omnode_setattr(%p,%p,%s,%.*s,%d) - enter\n", doc, node,name, lenvalue, value, lenvalue); attr = SCSCP_omdoc_allocateattr(doc,strlen(name)+1+lenvalue+1); if (attr) { attr->m_value = (char*)(attr+1); attr->next = NULL; attr->name = BAD_CAST (attr->m_value+lenvalue+1); strcpy((char *) attr->name, name); memcpy(attr->m_value, value, lenvalue*sizeof(char)); attr->m_value[lenvalue] ='\0'; /*add to tail of the attribute of node */ if (node->properties==NULL) node->properties = attr; else { while (node->properties->next!=NULL) node->properties = node->properties->next; node->properties->next = attr; } } else retval = 0; SCSCP_debugprint("SCSCP_omnode_setattr() - return %d\n", retval); return retval; } /*-----------------------------------------------------------------*/ /*! set the content of the node using the value @param doc (inout) document @param node (inout) node @param value (in) value of the content @param lenvalue (in) valid character of value */ /*-----------------------------------------------------------------*/ int SCSCP_omnode_setcontent(SCSCP_omdocptr doc, SCSCP_omnodeptr node, const char *value, int lenvalue) { SCSCP_omnodeptr childtext; int retval = 1; SCSCP_debugprint("SCSCP_omnode_setcontent(%p,%p,%.*s,%d) - enter\n", doc, node, lenvalue, value, lenvalue); childtext = SCSCP_omnode_inittoken0(doc,0); if (childtext) { childtext->xmltype = XML_TEXT_NODE; SCSCP_omnode_attachchild(node, childtext); childtext->m_content = (char*)SCSCP_omdoc_allocateinnode(doc,lenvalue+1); if (childtext->m_content) { memcpy(childtext->m_content, value, lenvalue*sizeof(char)); childtext->m_content[lenvalue]='\0'; } else retval = 0; } else retval = 0; SCSCP_debugprint("SCSCP_omnode_setcontent() - return %d\n", retval); return retval; } /*----------------------------------------------------------------------------------------------*/ /*! read the content of the current node in the current xml node @param curnode (in) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ const char *SCSCP_omnode_getcontent(SCSCP_omnodeptr node) { return node->m_content; } /*-----------------------------------------------------------------*/ /*! set the binary of the node using the value @param doc (inout) document @param node (inout) node @param value (in) value @param lenvalue (in) size in bytes of value */ /*-----------------------------------------------------------------*/ int SCSCP_omnode_setbinary(SCSCP_omdocptr doc, SCSCP_omnodeptr node, void *value, int lenvalue) { int retval = 1; SCSCP_debugprint("SCSCP_omnode_setbinary(%p,%p,%p,%d) - enter\n", doc, node, value, lenvalue); node->m_binarycontent = SCSCP_omdoc_allocateinnode(doc,lenvalue); if (node->m_binarycontent) { memcpy(node->m_binarycontent, value, lenvalue); } else retval = 0; SCSCP_debugprint("SCSCP_omnode_setbinary() - return %d\n", retval); return retval; } /*-----------------------------------------------------------------*/ /*! create a new node inside the document doc. its parent is owner and set its attributes @param doc (inout) XML document to build @param owner (inout) parent node of this object @param token (in) token @param nattr (in) number of elements in attrname and attrvalue @param attrname (in) name of the attributes last one in the array must be "id" @param attrvalue (in) value of the attribute @param attrvaluelen (in) length of the strings of attrvalue */ /*-----------------------------------------------------------------*/ SCSCP_omnodeptr SCSCP_omnode_inittokenattr(SCSCP_omdocptr doc, SCSCP_omnodeptr owner, unsigned char token, int nattr, const char *attrname[], char *attrvalue[], int attrvaluelen[] ) { SCSCP_omnodeptr node; int j; SCSCP_debugprint("SCSCP_omnode_inittokenattr(,%u,) - enter\n",(unsigned int)token); node = SCSCP_omnode_inittoken(doc,owner, token); if (node && nattr>=1) { int retval=1; for (j=0;jm_rawdata = NULL; node->m_lenrawdata = 0; node->m_content = NULL; node->m_binarycontent = NULL; node->next = NULL; node->properties = NULL; node->children = NULL; node->omtype = (SCSCP_omnodetype)SCSCP_binary_removelongflag(token); node->xmltype = XML_ELEMENT_NODE; } SCSCP_debugprint("SCSCP_omnode_inittoken0() - return %p\n", node); return node; } /*-----------------------------------------------------------------*/ /*! create a new node inside the document doc. its parent is owner @param doc (inout) XML document to build @param owner (inout) parent node of this object @param name (in) name of the node */ /*-----------------------------------------------------------------*/ SCSCP_omnodeptr SCSCP_omnode_initname(SCSCP_omdocptr doc, SCSCP_omnodeptr owner, const char* name) { SCSCP_omnodeptr node=NULL; unsigned char token; SCSCP_debugprint("SCSCP_omnode_initname(,%s) - enter\n",name); token = (unsigned char)SCSCP_omnode_typefromname(name); if (token!=0) node = SCSCP_omnode_inittoken(doc,owner, token); SCSCP_debugprint("SCSCP_omnode_initname () - return %p\n", node); return node; } /*-----------------------------------------------------------------*/ /*! create the first node inside the document doc. initialize to the default value @param doc (inout) XML document to build @param token (in) token */ /*-----------------------------------------------------------------*/ static void SCSCP_omnode_attachchild(SCSCP_omnodeptr parent, SCSCP_omnodeptr child) { SCSCP_omnodeptr children; if (parent->children==NULL) parent->children = child; else { children = parent->children; while(children->next!=NULL) children=children->next; children->next = child; } } /*-----------------------------------------------------------------*/ /*! dump the content of the node @param file (inout) output stream @param node (in) node */ /*-----------------------------------------------------------------*/ void SCSCP_omnode_dump(FILE* file, SCSCP_omnodeptr node) { if (node!=NULL) { if (node->xmltype==XML_TEXT_NODE) { fputs(node->m_content, file); } else if (node->xmltype==XML_ELEMENT_NODE) { const char *name = SCSCP_omnode_namefromtype(node->omtype); SCSCP_omnodeptr childnode; SCSCP_omattrptr attrnode; fputs("<", file); fputs(name, file); for (attrnode = node->properties; attrnode!=NULL; attrnode=attrnode->next) { fputs(" ", file); SCSCP_omattr_dump(file, attrnode); } childnode = node->children; if (childnode) { fputs(">", file); for (;childnode!=NULL; childnode=childnode->next) { SCSCP_omnode_dump(file, childnode); } /* close the element */ fputs("", file); } else { /* no child : close the element */ fputs("/>", file); } } else fputs("unknown XML node type\n", file); } } /*-----------------------------------------------------------------*/ /*! dump the content of the node to a string @param buffer (inout) output buffer @param node (in) node */ /*-----------------------------------------------------------------*/ static char* SCSCP_omnode_sdump(char* buffer, SCSCP_omnodeptr node) { char* retbuffer = buffer; if (node!=NULL) { if (node->xmltype==XML_TEXT_NODE) { strcpy(retbuffer, node->m_content); retbuffer+=strlen(node->m_content); } else if (node->xmltype==XML_ELEMENT_NODE) { const char *name = SCSCP_omnode_namefromtype(node->omtype); SCSCP_omnodeptr childnode; SCSCP_omattrptr attrnode; strcpy(retbuffer,"<"); retbuffer++; strcpy(retbuffer, name); retbuffer+=strlen(name); for (attrnode = node->properties; attrnode!=NULL; attrnode=attrnode->next) { strcpy(retbuffer," "); retbuffer++; retbuffer = SCSCP_omattr_sdump(retbuffer, attrnode); } childnode = node->children; if (childnode) { strcpy(retbuffer, ">"); retbuffer++; for (;childnode!=NULL; childnode=childnode->next) { retbuffer = SCSCP_omnode_sdump(retbuffer, childnode); } /* close the element */ strcpy(retbuffer, ""); retbuffer++; } else { /* no child : close the element */ strcpy(retbuffer, "/>"); retbuffer+=2; } } } *retbuffer='\0'; return retbuffer; } /*-----------------------------------------------------------------*/ /*! compute the required size of the node to write it as a string @param node (in) node */ /*-----------------------------------------------------------------*/ static size_t SCSCP_omnode_getrawstring_computesize(SCSCP_omnodeptr node) { size_t len = 0; if (node!=NULL) { if (node->xmltype==XML_TEXT_NODE) { len = strlen(node->m_content); } else if (node->xmltype==XML_ELEMENT_NODE) { const char *name = SCSCP_omnode_namefromtype(node->omtype); SCSCP_omnodeptr childnode; SCSCP_omattrptr attrnode; len = 1+strlen(name); for (attrnode = node->properties; attrnode!=NULL; attrnode=attrnode->next) { len++; /*" "*/ len+=SCSCP_omattr_getrawstring_computesize(attrnode); } childnode = node->children; if (childnode) { len++; /*">"*/ for (;childnode!=NULL; childnode=childnode->next) { len+=SCSCP_omnode_getrawstring_computesize(childnode); } /* close the element */ len+=3+strlen(name); /* "" */ } else { /* no child : close the element */ len+=2; /*"/>"*/ } } } return len; } /*----------------------------------------------------------------------------------------------*/ /*! return the xml encoding as a string @param node (in) current node. mustn't be NULL @param status (inout) error code */ /*----------------------------------------------------------------------------------------------*/ char *SCSCP_omnode_getrawstring(SCSCP_omnodeptr node, SCSCP_status* status) { size_t len = SCSCP_omnode_getrawstring_computesize(node); char* buffer; buffer = (char *)SCSCP_malloc((len+1)*sizeof(char),status); if (buffer!=NULL) { char *bufferret; bufferret = SCSCP_omnode_sdump(buffer,node); } return buffer; } /*----------------------------------------------------------------------------------------------*/ /*! get the content of the attribute return 0 on failure and non-zero on success @param attr (in) current attribute. mustn't be NULL @param name (out) name of this attribute @param value (out) value of this attribute */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_omattr_getvalue(SCSCP_omattrptr attr, const char **name, const char **value) { *name = (const char*)(attr->name); *value = attr->m_value; return 1; } /*-----------------------------------------------------------------*/ /*! dump the content of the attribute @param file (inout) output stream @param attr (in) attribute */ /*-----------------------------------------------------------------*/ void SCSCP_omattr_dump(FILE* file, SCSCP_omattrptr attr) { if (attr!=NULL) { fprintf(file,"%s=\"%s\"", attr->name, attr->m_value); } } /*-----------------------------------------------------------------*/ /*! dump the content of the attribute @param buffer (inout) output buffer @param attr (in) attribute */ /*-----------------------------------------------------------------*/ static char* SCSCP_omattr_sdump(char* buffer, SCSCP_omattrptr attr) { char *retbuf=buffer; if (attr!=NULL) { int n=sprintf(buffer,"%s=\"%s\"", attr->name, attr->m_value); if (n>0) retbuf+=n; } return retbuf; } /*-----------------------------------------------------------------*/ /*! compute the required size of the attribute to write it as a string @param attr (in) attribute */ /*-----------------------------------------------------------------*/ static size_t SCSCP_omattr_getrawstring_computesize(SCSCP_omattrptr attr) { size_t len=0; if (attr!=NULL) { len = 3+strlen((char*)attr->name)+strlen(attr->m_value); /* "%s=\"%s\"", attr->name, attr->m_value*/ } return len; } scscp-imcce-1.0.0+ds/src/scscpomdoc.h000066400000000000000000000274101215622604100174030ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpomdoc.h \brief OpenMath documents \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPOMDOC_H__ #define __SCSCPOMDOC_H__ #include #include #if defined (__cplusplus) extern "C" { #endif /* (__cplusplus) */ /*-----------------------------------------------------------------*/ /* OpenMath attributes */ /*-----------------------------------------------------------------*/ /*! pointer to SCSCP OpenMath attribute */ typedef struct SCSCP_omattr_t* SCSCP_omattrptr; /*! SCSCP OpenMath attribute */ typedef struct SCSCP_omattr_t { char *m_value; /*!< value of the attribute */ /* following field should have the same name as filed in xmlNode */ SCSCP_omattrptr next; /*!< next attribute */ xmlChar *name; /*!< name of the attribute */ } SCSCP_omattr; void SCSCP_omattr_dump(FILE* file, SCSCP_omattrptr attr); int SCSCP_omattr_getvalue(SCSCP_omattrptr attr, const char **name, const char **value); /*-----------------------------------------------------------------*/ /* OpenMath node */ /*-----------------------------------------------------------------*/ /*! possible type of the OpenMath nodes */ typedef enum { SCSCP_omnodetype_OMIchar=1U, /*!< OMI between -128 and 127 */ SCSCP_omnodetype_OMIint32=1U|128U, /*!< OMI on 4 bytes */ SCSCP_omnodetype_OMIstr=2U, /*!< OMI as string */ SCSCP_omnodetype_OMF=3U, /*!< OMF hexdecimal on 8 bytes */ SCSCP_omnodetype_OMV=5U, /*!< OMVAR */ SCSCP_omnodetype_OMS=8U, /*!< OMS */ SCSCP_omnodetype_OMSTRlatin1=6U, /*!< OMSTR - latin 1 */ SCSCP_omnodetype_OMSTRUTF16=7U, /*!< OMSTR - utf16 */ SCSCP_omnodetype_OMB=4U, /*!< OMB */ SCSCP_omnodetype_OMFOREIGN=12U, /*!< OMFOREIGN */ SCSCP_omnodetype_OMA=16U, /*!< OMA */ SCSCP_omnodetype_OMBIND=26U, /*!< OMBIND */ SCSCP_omnodetype_OMATTR=18U, /*!< OMATTR */ SCSCP_omnodetype_OME=22U, /*!< OME */ SCSCP_omnodetype_OMATP=20U, /*!< OMATP */ SCSCP_omnodetype_OMOBJ=24U, /*!< OMOBJ */ SCSCP_omnodetype_OMBVAR=28U, /*!< OMBVAR */ SCSCP_omnodetype_OMRinternal=30U, /*!< OMR internal */ SCSCP_omnodetype_OMR=31U, /*!< OMR external */ /* extra values: not in binary encoding */ SCSCP_omnodetype_OMFdec=3U|256U, /*!< float as decimal stringg */ } SCSCP_omnodetype; /*! pointer to SCSCP OpenMath node */ typedef struct SCSCP_omnode_t* SCSCP_omnodeptr; /*! SCSCP OpenMath node */ typedef struct SCSCP_omnode_t { unsigned char *m_rawdata; /*!< raw data (not zero terminated string) */ size_t *m_lenrawdata; /*!< length in bytes of the m_rawdata */ char *m_content; /*!< content */ SCSCP_omnodetype omtype; /*!< OpenMath type */ xmlElementType xmltype; /*!< xml type */ void *m_binarycontent; /*!< binary value to fast access in binary mode */ /* following field should have the same name as filed in xmlNode */ SCSCP_omnodeptr next; /*!< next node */ SCSCP_omattrptr properties; /*!< attributes */ SCSCP_omnodeptr children; /*!< children nodes */ } SCSCP_omnode; const char *SCSCP_omnode_getname(SCSCP_omnodeptr node); const char *SCSCP_omnode_getcontent(SCSCP_omnodeptr node); SCSCP_omtype SCSCP_omnode_getexternaltype(SCSCP_omnodeptr node); void SCSCP_omnode_dump(FILE* file, SCSCP_omnodeptr node); char *SCSCP_omnode_getrawstring(SCSCP_omnodeptr node, SCSCP_status* status); int SCSCP_omnode_movetotag(SCSCP_omnodeptr* curnode, const char *string, int children, int gotochildnode); const char *SCSCP_omnode_namefromtype(SCSCP_omnodetype omtype); /*-----------------------------------------------------------------*/ /*! SCSCP OpenMath document */ /*-----------------------------------------------------------------*/ typedef struct { SCSCP_buffer_list *m_rawom; /*!< raw openmathobject */ SCSCP_buffer_list *m_nodes; /*!< storage to build the tree */ SCSCP_omnodeptr m_rootnode; /*!< root node of the tree */ size_t m_Writepos_nodes; /*!< position for writing in the head of m_nodes */ } SCSCP_omdoc; /*! pointer to SCSCP OpenMath node */ typedef SCSCP_omdoc* SCSCP_omdocptr; SCSCP_omdocptr SCSCP_omdoc_init(void); void SCSCP_omdoc_clear(SCSCP_omdocptr doc); void SCSCP_omdoc_dump(FILE* file, SCSCP_omdocptr doc); SCSCP_omnodeptr SCSCP_omdoc_getrootnode(SCSCP_omdocptr doc); SCSCP_omnodeptr SCSCP_omnode_inittoken(SCSCP_omdocptr doc, SCSCP_omnodeptr owner, unsigned char token); SCSCP_omnodeptr SCSCP_omnode_initname(SCSCP_omdocptr doc, SCSCP_omnodeptr owner, const char* name); SCSCP_omnodeptr SCSCP_omnode_inittokenattr(SCSCP_omdocptr doc, SCSCP_omnodeptr owner, unsigned char token, int nattr, const char *attrname[], char *attrvalue[], int attrvaluelen[]); SCSCP_omnodeptr SCSCP_omnode_inittokenattrcontent(SCSCP_omdocptr doc, SCSCP_omnodeptr owner, unsigned char token, int nattr, const char *attrname[], char *attrvalue[], int attrvaluelen[], char *content, int contentlen); SCSCP_omnodeptr SCSCP_omnode_inittokenattrbinary(SCSCP_omdocptr doc, SCSCP_omnodeptr owner, unsigned char token, int nattr, const char *attrname[], char *attrvalue[], int attrvaluelen[], void *binary, int binarylen); int SCSCP_omnode_setcontent(SCSCP_omdocptr doc, SCSCP_omnodeptr node, const char *value, int lenvalue); int SCSCP_omnode_setbinary(SCSCP_omdocptr doc, SCSCP_omnodeptr node, void *value, int lenvalue); int SCSCP_omnode_setattr(SCSCP_omdocptr doc, SCSCP_omnodeptr node, const char *name, const char *value, int lenvalue); SCSCP_omnodetype SCSCP_omnode_typefromname(const char *string); SCSCP_omnodeptr SCSCP_omnode_initroottoken(SCSCP_omdocptr doc, unsigned char token); /*-----------------------------------------------------------------*/ /*! SAX or DOM parser/tree */ /*-----------------------------------------------------------------*/ /* choose the type of the parser : SAX or DOM */ #define SCSCP_PARSERDOM 0 #define SCSCP_PARSERSAX 1 #define SCSCP_PARSERTYPE SCSCP_PARSERSAX #if SCSCP_PARSERTYPE==SCSCP_PARSERDOM typedef xmlAttrPtr SCSCP_xmlattrptr; typedef xmlNodePtr SCSCP_xmlnodeptr; typedef xmlDocPtr SCSCP_xmldocptr; #define SCSCP_xmldoc_free(doc) xmlFreeDoc(doc) #define SCSCP_xmldoc_getrootnode xmlDocGetRootElement #define SCSCP_xmldoc_init xmlNewDoc #define SCSCP_xmldoc_dump xmlDocDump xmlNodePtr xmlNodePtr_inittoken(xmlDocPtr doc, xmlNodePtr owner, unsigned char token); xmlNodePtr xmlNodePtr_initname(xmlDocPtr doc, xmlNodePtr owner, const char *name); xmlNodePtr xmlNodePtr_inittokenattr(xmlDocPtr doc, xmlNodePtr owner, unsigned char token, int nattr, const char *attrname[], char *attrvalue[], int attrvaluelen[]); xmlNodePtr xmlNodePtr_inittokenattrcontent(xmlDocPtr doc, xmlNodePtr owner, unsigned char token, int nattr, const char *attrname[], char *attrvalue[], int attrvaluelen[], char *content, int contentlen); xmlNodePtr xmlNodePtr_initroottoken(xmlDocPtr doc, unsigned char token); int xmlNodePtr_setcontent(xmlDocPtr doc, xmlNodePtr node, const char *value, int lenvalue); int xmlNodePtr_setattr(xmlDocPtr doc, xmlNodePtr node, const char *name, const char *value, int lenvalue); #define SCSCP_xmlnode_inittoken xmlNodePtr_inittoken #define SCSCP_xmlnode_inittokenattr xmlNodePtr_inittokenattr #define SCSCP_xmlnode_inittokenattrcontent xmlNodePtr_inittokenattrcontent #define SCSCP_xmlnode_initroottoken xmlNodePtr_initroottoken #define SCSCP_xmlnode_initname xmlNodePtr_initname #define SCSCP_xmlnode_clear(node) { xmlUnlinkNode(node); xmlFreeNode(node); } #define SCSCP_xmldoc_setrootnode xmlDocSetRootElement #define SCSCP_xmlnode_setcontent xmlNodePtr_setcontent #define SCSCP_xmlnode_setattr xmlNodePtr_setattr #elif SCSCP_PARSERTYPE==SCSCP_PARSERSAX typedef SCSCP_omdocptr SCSCP_xmldocptr; #define SCSCP_xmldoc_init(version) SCSCP_omdoc_init() #define SCSCP_xmldoc_free SCSCP_omdoc_clear #define SCSCP_xmldoc_getrootnode SCSCP_omdoc_getrootnode #define SCSCP_xmldoc_setrootnode(doc, rootnode) {} #define SCSCP_xmldoc_dump SCSCP_omdoc_dump #define SCSCP_xmlnode_inittoken SCSCP_omnode_inittoken #define SCSCP_xmlnode_inittokenattr SCSCP_omnode_inittokenattr #define SCSCP_xmlnode_inittokenattrcontent SCSCP_omnode_inittokenattrcontent #define SCSCP_xmlnode_initroottoken SCSCP_omnode_initroottoken #define SCSCP_xmlnode_initname SCSCP_omnode_initname #define SCSCP_xmlnode_clear(node) {} #define SCSCP_xmlnode_setcontent SCSCP_omnode_setcontent #define SCSCP_xmlnode_setattr SCSCP_omnode_setattr #define SCSCP_xmlnode_getexternaltype SCSCP_omnode_getexternaltype #else ... #endif /*-----------------------------------------------------------------*/ /*! node function */ /*-----------------------------------------------------------------*/ const char* SCSCP_xmlnode_findattr(SCSCP_xmlnodeptr curnode, const char *value); int SCSCP_xmlnode_readOMIsizet(SCSCP_xmlnodeptr* curnode, size_t *value); int SCSCP_xmlnode_readbeginOMOBJ(SCSCP_xmlnodeptr* curnode); int SCSCP_xmlnode_readbeginOMA(SCSCP_xmlnodeptr* curnode); int SCSCP_xmlnode_readbeginOMATTR(SCSCP_xmlnodeptr* curnode); int SCSCP_xmlnode_readbeginOMATP(SCSCP_xmlnodeptr* curnode); int SCSCP_xmlnode_readpairOMSOMIsizet(SCSCP_xmlnodeptr* curnode, const char *cdname, const char *symbolname, size_t *value); int SCSCP_xmlnode_readpairOMSOMIint(SCSCP_xmlnodeptr* curnode, const char *cdname, const char *symbolname, int *value); int SCSCP_xmlnode_readcheckOMS(SCSCP_xmlnodeptr* curnode, const char *cdname, const char *symbolname); int SCSCP_xmlnode_movetotag(SCSCP_xmlnodeptr* curnode, const char *string, int explorechildren, int gotochildnode); #if defined (__cplusplus) } #endif #endif /*__SCSCPOMDOC_H__*/ scscp-imcce-1.0.0+ds/src/scscpoptions.c000066400000000000000000000354631215622604100177770ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpoptions.cxx \brief SCSCP options for messages \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #if HAVE_STRING_H #include #endif #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpdebug.h" #include "scscptags.h" #include "scscpfileclient.h" #include "scscpoptions.h" #include "scscpfileserver.h" /*-----------------------------------------------------------------*/ /*! write the object to the stream @param stream (inout) output stream */ /*-----------------------------------------------------------------*/ int SCSCP_ro_write(SCSCP_io *stream, const SCSCP_returnoptions options, SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_ro_write() - enter\n"); res = SCSCP_io_writebeginOMATP(stream, NULL, status); //write call id res &= SCSCP_callid_write(stream, &options->m_callid, status); //write runtime limit if (options->m_set_used_runtime) res &=SCSCP_io_writePairOMSOMIsizet(stream, SCSCP_TAGS_cdname, SCSCP_TAGS_info_runtime, options->m_runtime, status); //write used memory if (options->m_set_used_memory) res &=SCSCP_io_writePairOMSOMIsizet(stream, SCSCP_TAGS_cdname, SCSCP_TAGS_info_memory, options->m_used_memory, status); //write information message if (options->m_set_used_message) res &=SCSCP_io_writePairOMSOMSTR(stream, SCSCP_TAGS_cdname, SCSCP_TAGS_info_message, options->m_message, status); res &= SCSCP_io_writeendOMATP(stream, status); SCSCP_debugprint("SCSCP_ro_write(,%d) - returns %d\n", SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! read the object from the stream @param stream (inout) input stream @param iterchild (out) iterator on the input stream @param msgtype (out) type of message @param status (inout) status information */ /*-----------------------------------------------------------------*/ int SCSCP_ro_read(SCSCP_io *stream, SCSCP_returnoptions options, SCSCP_xmlnodeptr* iterchild, SCSCP_msgtype *msgtype, SCSCP_status* status) { int res; SCSCP_xmlnodeptr iter; SCSCP_debugprint("SCSCP_ro_read() - enter\n"); res = SCSCP_io_readxmldoc(stream, &iter, status); if (res) { SCSCP_debugprint("SCSCP_ro_read() - ReadXmlDoc returns 1\n"); res = SCSCP_xmlnode_readbeginOMOBJ(&iter); // parse attributes res &= SCSCP_ro_readoptions(stream, options, &iter, status); //parse the name of the procedure res &= SCSCP_xmlnode_readbeginOMA(&iter); if (res) { const char *cdname=NULL, *symbolname=NULL; *iterchild = iter; res = SCSCP_xmlnode_readOMS(iterchild, &cdname, &symbolname); if (res) { if (strcmp(symbolname,SCSCP_TAGS_procedure_completed)==0 && strcmp(cdname,SCSCP_TAGS_cdname)==0) *msgtype = SCSCP_msgtype_ProcedureCompleted; else if (strcmp(symbolname,SCSCP_TAGS_procedure_terminated)==0 && strcmp(cdname,SCSCP_TAGS_cdname)==0) *msgtype = SCSCP_msgtype_ProcedureTerminated; else { SCSCP_debugprint("SCSCP_ro_read() - return unknown symbol '%s' '%s'\n", cdname, symbolname); SCSCP_status_seterror(status, SCSCP_STATUS_OPENMATHNOTVALID); res = 0; } } else { SCSCP_debugprint("SCSCP_ro_read() - return unknown symbol '%s' '%s'\n", cdname, symbolname); SCSCP_status_seterror(status, SCSCP_STATUS_OPENMATHNOTVALID); res = 0; } } else { SCSCP_debugprint("SCSCP_ro_read() - can't find symbol\n"); SCSCP_status_seterror(status, SCSCP_STATUS_OPENMATHNOTVALID); } } SCSCP_debugprint("SCSCP_ro_read() - returns %d\n", res); return res; } /*-----------------------------------------------------------------*/ /*! read the options from the stream @param stream (inout) input stream @param iter (inout) iterator @param status (inout) eror code */ /*-----------------------------------------------------------------*/ int SCSCP_ro_readoptions(SCSCP_io *stream, SCSCP_returnoptions options, SCSCP_xmlnodeptr* iter, SCSCP_status* status) { int res, res1, res3; SCSCP_xmlnodeptr iter2; SCSCP_xmlnodeptr iterchild; SCSCP_debugprint("SCSCP_ro_readoptions() - enter\n"); iter2 = *iter; res3 = SCSCP_xmlnode_readbeginOMATTR(iter); iterchild = *iter; res = SCSCP_xmlnode_readbeginOMATP(&iterchild); /* try to read all attributes */ if (res) { if (options) { const_SCSCP_string infomessage; SCSCP_time timer; SCSCP_memory mem; /* read call id */ res = SCSCP_callid_read(&iterchild, &options->m_callid, status); /* read runtime */ res1 = SCSCP_xmlnode_readpairOMSOMIsizet(&iterchild, SCSCP_TAGS_cdname, SCSCP_TAGS_info_runtime, &timer); if (res1) res &=SCSCP_ro_set_runtime(&options, timer, status); /* read information memory */ res1 = SCSCP_xmlnode_readpairOMSOMIsizet(&iterchild, SCSCP_TAGS_cdname, SCSCP_TAGS_info_memory, &mem); if (res1) res &= SCSCP_ro_set_memory(&options, mem, status); /* read information message */ res1 = SCSCP_xmlnode_readpairOMSOMSTR(&iterchild, SCSCP_TAGS_cdname, SCSCP_TAGS_info_message, &infomessage); if (res1) res &= SCSCP_ro_set_message(&options, infomessage, status); } *iter = SCSCP_xmlnode_getnext(*iter); } else if (res3==0) { res = 1; *iter = iter2; } else { res = 1; } SCSCP_debugprint("SCSCP_ro_readoptions() - returns %d\n", res); return res; } /*-----------------------------------------------------------------*/ /*! checks if options is null and returns 0 on error @param options (in) object to be checked @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_ro_checkNULL(SCSCP_returnoptions* options, SCSCP_status* status) { int res = 1; if (options==NULL || *options==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_RETURNOPTIONSOBJECTNULL); res = 0; } return res; } /*-----------------------------------------------------------------*/ /*! initialize the object options and set status if an error occurs @param options (out) options @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ro_init(SCSCP_returnoptions* options, SCSCP_status* status) { int res = 1; if (options==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_RETURNOPTIONSOBJECTNULL); res = 0; } else { *options = (struct SCSCP_optionsprocedurereturn*)SCSCP_malloc(sizeof(struct SCSCP_optionsprocedurereturn),status); if (*options==NULL) { res = 0; } else { SCSCP_callid_init(&(*options)->m_callid); (*options)->m_set_used_runtime =0; (*options)->m_set_used_memory =0; (*options)->m_set_used_message =0; } } return res; } /*-----------------------------------------------------------------*/ /*! clear the object options previously initialized by SCSCP_ro_init @param options (inout) options @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ro_clear(SCSCP_returnoptions* options, SCSCP_status* status) { int res = SCSCP_ro_checkNULL(options, status); if (res) { SCSCP_callid_clear(&(*options)->m_callid); free(*options); } return res; } /*-----------------------------------------------------------------*/ /*! set the procedure call ID (buffer can't be released before calling SCSCP_ro_clear) @param options (inout) options @param buffer (in) string buffer @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ro_set_callid(SCSCP_returnoptions* options, const char *buffer, SCSCP_status* status) { int res = SCSCP_ro_checkNULL(options, status); if (res) { SCSCP_callid_set(&((*options)->m_callid), buffer); } return res; } /*-----------------------------------------------------------------*/ /*! get the procedure call ID @param options (inout) options @param buffer (out) string buffer @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ro_get_callid(SCSCP_returnoptions* options, const char **buffer, SCSCP_status* status) { int res = SCSCP_ro_checkNULL(options, status); if (res) *buffer = SCSCP_callid_get(&((*options)->m_callid)); return res; } /*-----------------------------------------------------------------*/ /*! set the runtime usage @param options (inout) options @param time (in) time usage @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ro_set_runtime(SCSCP_returnoptions* options, size_t time, SCSCP_status* status) { int res = SCSCP_ro_checkNULL(options, status); if (res) { (*options)->m_set_used_runtime = 1; (*options)->m_runtime = time; } return res; } /*-----------------------------------------------------------------*/ /*! get the runtime usage if the runtime usage is unknown => it returns 0 and status is set to SCSCP_STATUS_USAGEUNKNOWNRUNTIME @param options (inout) options @param time (out) time usage. can't be NULL @param status (inout) status error if the runtime usage is unknown => status is set to SCSCP_STATUS_USAGEUNKNOWNRUNTIME */ /*-----------------------------------------------------------------*/ int SCSCP_ro_get_runtime(SCSCP_returnoptions* options, size_t* time, SCSCP_status* status) { int res = SCSCP_ro_checkNULL(options, status); if (res) { res = (*options)->m_set_used_runtime; if (!res) { SCSCP_status_seterror(status, SCSCP_STATUS_USAGEUNKNOWNRUNTIME); *time = 0; } else { *time = (*options)->m_runtime; } } return res; } /*-----------------------------------------------------------------*/ /*! set the memory usage @param options (inout) options @param memsize (in) memory usage @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ro_set_memory(SCSCP_returnoptions* options, size_t memsize, SCSCP_status* status) { int res = SCSCP_ro_checkNULL(options, status); if (res) { (*options)->m_set_used_memory = 1; (*options)->m_used_memory = memsize; } return res; } /*-----------------------------------------------------------------*/ /*! get the memory usage if the runtime usage is unknown => it returns 0 and status is set to SCSCP_STATUS_USAGEUNKNOWNMEM @param options (inout) options @param memsize (out) memory usage. can't be NULL @param status (inout) status error if the runtime usage is unknown => status is set to SCSCP_STATUS_USAGEUNKNOWNMEM */ /*-----------------------------------------------------------------*/ int SCSCP_ro_get_memory(SCSCP_returnoptions* options, size_t* memsize, SCSCP_status* status) { int res = SCSCP_ro_checkNULL(options, status); if (res) { res = (*options)->m_set_used_memory; if (!res) { SCSCP_status_seterror(status, SCSCP_STATUS_USAGEUNKNOWNMEM); *memsize = 0; } else { *memsize = (*options)->m_used_memory; } } return res; } /*-----------------------------------------------------------------*/ /*! set the information message @param options (inout) options @param buffer (in) string buffer @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ro_set_message(SCSCP_returnoptions* options, const char *buffer, SCSCP_status* status) { int res = SCSCP_ro_checkNULL(options, status); if (res) { (*options)->m_message = buffer; (*options)->m_set_used_message = 1; } return res; } /*-----------------------------------------------------------------*/ /*! get the information message if the runtime usage is unknown => it returns 0 and status is set to SCSCP_STATUS_USAGEUNKNOWNMESSAGE @param options (inout) options @param buffer (out) string buffer @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ro_get_message(SCSCP_returnoptions* options, const char **buffer, SCSCP_status* status) { int res = SCSCP_ro_checkNULL(options, status); if (res) { res = ((*options)->m_set_used_message==1); if (!res) { SCSCP_status_seterror(status, SCSCP_STATUS_USAGEUNKNOWNMESSAGE); *buffer = NULL; } else { *buffer = (*options)->m_message; } } return res; } scscp-imcce-1.0.0+ds/src/scscpoptions.h000066400000000000000000000076371215622604100200060ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpoptions.h \brief SCSCP options for messages \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPOPTIONS_H__ #define __SCSCPOPTIONS_H__ #include "scscpcallid.h" #if defined (__cplusplus) extern "C" { #endif /* (__cplusplus) */ /*-----------------------------------------------------------------*/ /*! handle common option of procedurecompleted and procedureterminated */ /*-----------------------------------------------------------------*/ struct SCSCP_optionsprocedurereturn { /*-----------------------------------------------------------------*/ /* attributes */ /*-----------------------------------------------------------------*/ SCSCP_call_id m_callid; //!< call identifier SCSCP_time m_runtime; //!< runtime in milliseconds SCSCP_memory m_used_memory; //!< used memory in bytes const_SCSCP_string m_message; //!< information message /* specify if attributes are set */ int m_set_used_runtime; //!< = true => m_runtime is valid int m_set_used_memory; //!< = true => m_used_memory is valid int m_set_used_message; //!< = true => m_message is valid }; int SCSCP_ro_write(SCSCP_io *stream, const SCSCP_returnoptions options, SCSCP_status* status); int SCSCP_ro_read(SCSCP_io *stream, SCSCP_returnoptions options, SCSCP_xmlnodeptr* node, SCSCP_msgtype *msgtype, SCSCP_status* status); int SCSCP_ro_readoptions(SCSCP_io *stream, SCSCP_returnoptions options, SCSCP_xmlnodeptr* iter, SCSCP_status* status); #if defined (__cplusplus) } #endif #endif /*__SCSCPOPTIONS_H__*/ scscp-imcce-1.0.0+ds/src/scscpprocedurecall.c000066400000000000000000000715051215622604100211250ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpprocedurecall.cxx \brief SCSCP message : procedure call. class SCSCP_procedurecalloptions, SCSCP_procedurecall types SCSCP_option_return \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012 M. Gastineau, CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 12/09/08 : update for SCSCP 1.2 \bug M. GASTINEAU 21/04/09 : update for SCSCP 1.3 \bug M. GASTINEAU 29/03/12 : correct message if type of action is missing (SCSCP_option_return_???) (ticket #8275) */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #include #if HAVE_STRING_H #include #endif #if HAVE_TIME_H #include #endif #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpprocedurecall.h" #include "scscpoptions.h" #include "scscpdebug.h" #include "scscptags.h" /*-----------------------------------------------------------------*/ /*! write the object to the stream @param options (in) object to be checked @param stream (inout) output stream @param status (inout) error code */ /*-----------------------------------------------------------------*/ int SCSCP_co_write(SCSCP_io *stream, const SCSCP_calloptions options, SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_co_write() - enter\n"); res = SCSCP_io_writebeginOMATP(stream, NULL, status); //write call id if (options->m_set_callid) res &= SCSCP_callid_write(stream, &options->m_callid, status); else { SCSCP_status_seterror(status, SCSCP_STATUS_CALLIDISNOTSET); res = 0; } //write runtime limit if (options->m_set_runtime_limit) res &=SCSCP_io_writePairOMSOMIsizet(stream,SCSCP_TAGS_cdname, SCSCP_TAGS_option_runtime, options->m_runtime_limit, status); //write min memory if (options->m_set_minimal_memory) res &=SCSCP_io_writePairOMSOMIsizet(stream,SCSCP_TAGS_cdname, SCSCP_TAGS_option_min_memory, options->m_minimal_memory, status); //write max memory if (options->m_set_maximal_memory) res &=SCSCP_io_writePairOMSOMIsizet(stream,SCSCP_TAGS_cdname, SCSCP_TAGS_option_max_memory, options->m_maximal_memory, status); //write debug level if (options->m_set_minimal_memory) res &=SCSCP_io_writePairOMSOMIint(stream,SCSCP_TAGS_cdname, SCSCP_TAGS_option_debuglevel, options->m_debuglevel, status); //write return type if (options->m_set_returntype) { const char* returntype = NULL; if (options->m_returntype==SCSCP_option_return_object) returntype = SCSCP_TAGS_option_return_object; if (options->m_returntype==SCSCP_option_return_cookie) returntype = SCSCP_TAGS_option_return_cookie; if (options->m_returntype==SCSCP_option_return_nothing) returntype = SCSCP_TAGS_option_return_nothing; res &=SCSCP_io_writePairOMSOMSTR(stream,SCSCP_TAGS_cdname, returntype, NULL,status); } else { SCSCP_status_seterror(status, SCSCP_STATUS_RETURNTYPEISNOTSET); res = 0; } res &= SCSCP_io_writeendOMATP(stream, status); SCSCP_debugprint("SCSCP_co_write(,%d) - returns %d\n", SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! read the object from the stream @param stream (inout) output stream @param iter (inout) iterator on the stream @bug M. GASTINEAU 12/09/08 : update for SCSCP 1.2 @bug M. GASTINEAU 29/03/12 : correct message if type of action (SCSCP_option_return_???) is missing */ /*-----------------------------------------------------------------*/ static int SCSCP_co_readoptions(SCSCP_io *stream, SCSCP_calloptions options, SCSCP_xmlnodeptr* iter, SCSCP_status* status) { int res = 1; int bresfinal = 1; SCSCP_xmlnodeptr iterend; SCSCP_xmlnodeptr iterchild1, iterchild2, iterchild3; SCSCP_debugprint("SCSCP_co_readoptions() - enter\n"); SCSCP_xmlnode_readbeginOMATTR(iter); iterend = *iter; bresfinal = res = SCSCP_xmlnode_readbeginOMATP(iter); /* try to read all attributes */ if (res) { SCSCP_xmlnodeptr iterchild = *iter; SCSCP_time timer; SCSCP_memory mem; SCSCP_debuglevel debuglevel; res = SCSCP_callid_read(&iterchild, &options->m_callid, status); iterchild = *iter; res = SCSCP_xmlnode_readpairOMSOMIsizet(&iterchild, SCSCP_TAGS_cdname, SCSCP_TAGS_option_runtime, &timer); if (res) res = SCSCP_co_set_runtimelimit(&options, timer, status); iterchild = *iter; res = SCSCP_xmlnode_readpairOMSOMIsizet(&iterchild, SCSCP_TAGS_cdname, SCSCP_TAGS_option_min_memory, &mem); if (res) res = SCSCP_co_set_minmemory(&options, mem, status); iterchild = *iter; res = SCSCP_xmlnode_readpairOMSOMIsizet(&iterchild, SCSCP_TAGS_cdname, SCSCP_TAGS_option_max_memory, &mem); if (res) res = SCSCP_co_set_maxmemory(&options, mem, status); iterchild = *iter; res = SCSCP_xmlnode_readpairOMSOMIint(&iterchild, SCSCP_TAGS_cdname, SCSCP_TAGS_option_debuglevel, &debuglevel); if (res) res = SCSCP_co_set_debuglevel(&options, mem, status); iterchild = *iter; iterchild1 = iterchild; iterchild2 = iterchild; iterchild3 = iterchild; if (SCSCP_xmlnode_readcheckOMS(&iterchild1, SCSCP_TAGS_cdname, SCSCP_TAGS_option_return_object)) { res = SCSCP_co_set_returntype(&options,SCSCP_option_return_object, status); } else if (SCSCP_xmlnode_readcheckOMS(&iterchild2, SCSCP_TAGS_cdname, SCSCP_TAGS_option_return_cookie)) { res = SCSCP_co_set_returntype(&options,SCSCP_option_return_cookie, status); } else if (SCSCP_xmlnode_readcheckOMS(&iterchild3, SCSCP_TAGS_cdname, SCSCP_TAGS_option_return_nothing)) { res = SCSCP_co_set_returntype(&options,SCSCP_option_return_nothing, status); } else { int mandatory = 0; int j; bresfinal = res = 0; /* check if we use the version 1.3 or later */ for (j=0; j<(*stream)->m_allowedversionscount; j++) { if (strcmp((*stream)->m_allowedversions[j], SCSCP_PROTOCOL_VERSION_1_3)==0) mandatory=1; } if (mandatory==1) { SCSCP_status_seterror(status, SCSCP_STATUS_USAGEUNKNOWNRETURNTYPE); bresfinal = res = 0; } else { /* SCSCP_TAGS_option_return_??? a re optional in older version of the protocol */ bresfinal = res = 1; } } iterend = SCSCP_xmlnode_getnext(iterend); } *iter = iterend; SCSCP_debugprint("SCSCP_co_readoptions() - returns %d\n", bresfinal); return bresfinal; } /*-----------------------------------------------------------------*/ /*! checks if options is null and returns 0 on error @param options (in) object to be checked @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_co_checkNULL(SCSCP_calloptions* options, SCSCP_status* status) { int res = 1; if (options==NULL || *options==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_CALLOPTIONSOBJECTNULL); res = 0; } return res; } /*-----------------------------------------------------------------*/ /*! initialize the object options and set status if an error occurs @param options (out) options @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_init(SCSCP_calloptions* options, SCSCP_status* status) { int res; if (options==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_CALLOPTIONSOBJECTNULL); res = 0; } else { *options = (struct SCSCP_procedurecalloptions*)SCSCP_malloc(sizeof(struct SCSCP_procedurecalloptions), status); res = (*options!=NULL); if (res) { SCSCP_callid_init(&(*options)->m_callid); (*options)->m_set_callid = 0; (*options)->m_set_runtime_limit = 0; (*options)->m_set_minimal_memory = 0; (*options)->m_set_maximal_memory = 0; (*options)->m_set_debuglevel = 0; (*options)->m_encodingtype = SCSCP_encodingtype_XML; res = SCSCP_co_set_returntype(options, SCSCP_option_return_object, SCSCP_STATUS_IGNORE); res &= SCSCP_co_generateunique_callid(options, status); } } return res; } /*-----------------------------------------------------------------*/ /*! clear the object options previously initialized by SCSCP_co_init @param options (inout) options @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_clear(SCSCP_calloptions* options, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { SCSCP_callid_clear(&(*options)->m_callid); free( (*options)); } return res; } /*-----------------------------------------------------------------*/ /*! set the procedure call ID (buffer can't be released before calling SCSCP_co_clear) @param options (inout) options @param buffer (in) string buffer @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_set_callid(SCSCP_calloptions* options, const char *buffer, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { (*options)->m_set_callid = 1; SCSCP_callid_set(&(*options)->m_callid, buffer); } return res; } /*-----------------------------------------------------------------*/ /*! set the procedure call ID (buffer can't be used after ) @param options (inout) options @param buffer (inout) string buffer (not duplicated) @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_set_writablecallid(SCSCP_calloptions* options, char *buffer, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { (*options)->m_set_callid = 1; SCSCP_callid_setwritable(&(*options)->m_callid, buffer); } return res; } /*-----------------------------------------------------------------*/ /*! \internal generate and set the procedure call ID. To be thread-safe, it will use address of options, current time, large counter @param options (inout) options @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_generateunique_callid(SCSCP_calloptions* options, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { static long long counter = 0; const char *prefix="libSCSCP"; size_t ncount = strlen(prefix)+100; /* for time, address and counter */ char *buffer = (char *)SCSCP_malloc(ncount*sizeof(char), status); if (buffer) { time_t ltime; time(<ime); if (snprintf(buffer, ncount, "%s:%p:%lld:%lld", prefix, options, (long long)ltime, counter)<=0) { SCSCP_status_seterror(status,SCSCP_STATUS_ERRNO); res = 0; } else { (*options)->m_set_callid = 1; SCSCP_callid_setwritable(&(*options)->m_callid, buffer); counter++; } } else { res = 0; } } return res; } /*-----------------------------------------------------------------*/ /*! get the procedure call ID @param options (inout) options @param buffer (out) string buffer @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_get_callid(SCSCP_calloptions* options, const char **buffer, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); SCSCP_debugprint("SCSCP_co_get_callid() -enter\n"); if (res) *buffer = SCSCP_callid_get(&((*options)->m_callid)); SCSCP_debugprint("SCSCP_co_get_callid(,'%s',%d) - returns %d\n",buffer==NULL?"NULL":*buffer, SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! set the runtime limit @param options (inout) options @param p_time (in) runtime limit @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_set_runtimelimit(SCSCP_calloptions* options, size_t p_time, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { (*options)->m_set_runtime_limit = 1; (*options)->m_runtime_limit = p_time; } return res; } /*-----------------------------------------------------------------*/ /*! get the runtime limit if the runtime limit is unknown => it returns 0 and status is set to SCSCP_STATUS_USAGEUNKNOWNRUNTIMELIMIT @param options (inout) options @param p_time (out) runtime limit @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_get_runtimelimit(SCSCP_calloptions* options, size_t* p_time, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { res = (*options)->m_set_runtime_limit; if (!res) SCSCP_status_seterror(status, SCSCP_STATUS_USAGEUNKNOWNRUNTIMELIMIT); *p_time = (*options)->m_runtime_limit; } return res; } /*-----------------------------------------------------------------*/ /*! set the minimal memory @param options (inout) options @param memsize (in) minimal memory required @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_set_minmemory(SCSCP_calloptions* options, size_t memsize, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { (*options)->m_set_minimal_memory = 1; (*options)->m_minimal_memory = memsize; } return res; } /*-----------------------------------------------------------------*/ /*! get the minimal memory if the minimal memory is unknown => it returns 0 and status is set to SCSCP_STATUS_USAGEUNKNOWNMINMEMORY @param options (inout) options @param memsize (out) minimal memory required @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_get_minmemory(SCSCP_calloptions* options, size_t* memsize, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { res = (*options)->m_set_minimal_memory; if (!res) SCSCP_status_seterror(status, SCSCP_STATUS_USAGEUNKNOWNMINMEMORY); *memsize = (*options)->m_minimal_memory; } return res; } /*-----------------------------------------------------------------*/ /*! set the maximal memory @param options (inout) options @param memsize (in) maximal memory required @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_set_maxmemory(SCSCP_calloptions* options, size_t memsize, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { (*options)->m_set_maximal_memory = 1; (*options)->m_maximal_memory = memsize; } return res; } /*-----------------------------------------------------------------*/ /*! get the maximal memory if the minimal memory is unknown => it returns 0 and status is set to SCSCP_STATUS_USAGEUNKNOWNMAXMEMORY @param options (inout) options @param memsize (out) maximal memory required @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_get_maxmemory(SCSCP_calloptions* options, size_t* memsize, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { res = (*options)->m_set_maximal_memory; if (!res) SCSCP_status_seterror(status, SCSCP_STATUS_USAGEUNKNOWNMAXMEMORY); *memsize = (*options)->m_maximal_memory; } return res; } /*-----------------------------------------------------------------*/ /*! set the return type @param options (inout) options @param returntype (in) return type @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_set_returntype(SCSCP_calloptions* options, SCSCP_option_return returntype, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { (*options)->m_set_returntype = 1; (*options)->m_returntype = returntype; } return res; } /*-----------------------------------------------------------------*/ /*! get the return type if the minimal memory is unknown => it returns 0 and status is set to SCSCP_STATUS_USAGEUNKNOWNRETURNTYPE @param options (inout) options @param returntype (out) return type @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_get_returntype(SCSCP_calloptions* options, SCSCP_option_return* returntype, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { res = (*options)->m_set_returntype; if (!res) SCSCP_status_seterror(status, SCSCP_STATUS_USAGEUNKNOWNRETURNTYPE); *returntype = (*options)->m_returntype; } return res; } /*-----------------------------------------------------------------*/ /*! set the debug level @param options (inout) options @param debuglevel (in) debug level @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_set_debuglevel(SCSCP_calloptions* options, int debuglevel, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { (*options)->m_set_debuglevel = 1; (*options)->m_debuglevel = debuglevel; } return res; } /*-----------------------------------------------------------------*/ /*! get the debug level if the minimal memory is unknown => it returns 0 and status is set to SCSCP_STATUS_USAGEUNKNOWNDEBUGLEVEL @param options (inout) options @param debuglevel (out) debug level @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_get_debuglevel(SCSCP_calloptions* options, int* debuglevel, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { res = (*options)->m_set_debuglevel; if (!res) SCSCP_status_seterror(status, SCSCP_STATUS_USAGEUNKNOWNDEBUGLEVEL); *debuglevel = (*options)->m_debuglevel; } return res; } /*-----------------------------------------------------------------*/ /*! set the current encoding for the OpenMath objects of this call @param client (inout) scscp client @param encodingtype (out) current encoding @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_co_set_encodingtype(SCSCP_calloptions* options, SCSCP_encodingtype encodingtype, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { (*options)->m_encodingtype = encodingtype; } return res; } /*-----------------------------------------------------------------*/ /*! get the current encoding for the OpenMath objects of this call @param client (inout) scscp client @param encodingtype (out) current encoding @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_co_get_encodingtype(SCSCP_calloptions* options, SCSCP_encodingtype* encodingtype, SCSCP_status* status) { int res = SCSCP_co_checkNULL(options, status); if (res) { *encodingtype = (*options)->m_encodingtype; } return res; } /*-----------------------------------------------------------------*/ /*! read the header of the object from the stream @param stream (inout) output stream @param option (inout) options @param iter (out) iterator on the stream @param status (inout) status information */ /*-----------------------------------------------------------------*/ int SCSCP_procedurecall_read(SCSCP_io *stream, SCSCP_calloptions options, SCSCP_xmlnodeptr* iter, SCSCP_status* status) { int res = 1; SCSCP_debugprint("SCSCP_procedurecall_read(%p) - enter\n", stream); res = SCSCP_io_readxmldoc(stream, iter, status); if (res) { SCSCP_debugprint("SCSCP_procedurecall_read() - ReadXmlDoc returns 1\n"); res = SCSCP_xmlnode_readbeginOMOBJ(iter); // parse attributes if (options) { SCSCP_co_set_encodingtype(&options, (*stream)->m_recvencodingtype, status); SCSCP_co_set_returntype(&options, SCSCP_option_return_object, status); SCSCP_co_set_callid(&options,"N/A", status); res &= SCSCP_co_readoptions(stream, options, iter, status); } //parse the name of the procedure res &= SCSCP_xmlnode_readbeginOMA(iter); if (res) { res = SCSCP_xmlnode_readcheckOMS(iter, SCSCP_TAGS_cdname, SCSCP_TAGS_procedure_call); } } else { *iter = NULL; } SCSCP_debugprint("SCSCP_procedurecall_read() - returns %d\n", res); return res; } /*-----------------------------------------------------------------*/ /*! send the beginning of the procedure call to the SCSCP server with some options until the arguments of the procedure call @param stream (inout) scscp stream @param options (in) options of the call @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_procedurecall_write_start(SCSCP_io *stream, SCSCP_calloptions options, SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_procedurecall_write_start(%p) - enter\n", stream); res = SCSCP_io_writeSCSCPSTART(stream, status); res &= SCSCP_io_writebeginOMOBJ(stream, status); res &= SCSCP_io_writebeginOMATTR(stream, NULL, status); //write the options if (options) { res &= SCSCP_co_write(stream, options, status); } else if (res) { /* generate a unique call ID and the call returns nothing */ SCSCP_calloptions localoptions; res = SCSCP_co_init(&localoptions, status); if (res) res = SCSCP_co_set_returntype(&localoptions, SCSCP_option_return_nothing,status); if (res) res = SCSCP_co_write(stream, localoptions, status); SCSCP_co_clear(&localoptions, status); } res &= SCSCP_io_writebeginOMA(stream, NULL, status); //write procedure name res &= SCSCP_io_writeOMS(stream, SCSCP_TAGS_cdname, SCSCP_TAGS_procedure_call, NULL, status); SCSCP_debugprint("SCSCP_procedurecall_write_start() - return %d\n", res); return res; } /*-----------------------------------------------------------------*/ /*! send the end of the procedure call to the SCSCP server : when all is ok ! @param stream (inout) scscp stream @param options (in) options of the call @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_procedurecall_write_finish(SCSCP_io *stream, SCSCP_status* status) { int res; res = SCSCP_io_writeendOMA(stream, status); res &= SCSCP_io_writeendOMATTR(stream, status); res &= SCSCP_io_writeendOMOBJ(stream, status); res &= SCSCP_io_writeSCSCPEND(stream, status); SCSCP_debugprint("SCSCP_procedurecall_write_finish() - return %d\n", res); return res; } /*-----------------------------------------------------------------*/ /*! send the end of the procedure call to the SCSCP server : when the procedure call is cancelled @param stream (inout) scscp stream @param options (in) options of the call @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_procedurecall_write_cancel(SCSCP_io *stream, SCSCP_status* status) { return SCSCP_io_writeSCSCPCANCEL(stream, status); } /*-----------------------------------------------------------------*/ /*! send a procedure call to the SCSCP server with some options The parameter of the procedure call are written by the callback function "callbackwriteargs" @param stream (inout) scscp stream @param options (in) options of the call @param callbackwriteargs (in) callback function to write the parameters of the procedure call can be NULL. @param param (inout) opaque data given to callbackwriteargs. can be NULL. @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_procedurecall_write(SCSCP_io *stream, SCSCP_calloptions options, int (*callbackwriteargs)(SCSCP_io* client, void *param, SCSCP_status* status), void *param, SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_procedurecall_write(%p) - enter\n", stream); res = SCSCP_procedurecall_write_start(stream, options, status); if (res && callbackwriteargs!=NULL) res = callbackwriteargs(stream, param, status); if (res) { res = SCSCP_procedurecall_write_finish(stream, status); } else { /*error => generate a cancel to the server */ res = SCSCP_procedurecall_write_cancel(stream, status); } SCSCP_debugprint("SCSCP_procedurecall_write() - returns %d\n", res); return res; } /*-----------------------------------------------------------------*/ /*! read the attribute of the answer for the procedure call and the type of the answer message @param client (inout) scscp client @param options (inout) options of the procedure return @param msgtype (out) type of returned message @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_callrecvheader(SCSCP_socketclient* client, SCSCP_returnoptions* options, SCSCP_msgtype *msgtype, SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_sc_callrecvheader() - start\n"); res = SCSCP_sc_checkNULL(client, status); if (res) { char bufferPI[SCSCP_PI_MAXLENBUFFER]; /* lecture du nouveau PI */ res = SCSCP_io_ReadPI(client, msgtype, bufferPI, status); /* read the header of the procedure call */ if (res && *msgtype == SCSCP_msgtype_ProcedureCall) { res = SCSCP_ro_read(client, options==SCSCP_RETURNOPTIONS_IGNORE?NULL:*options, SCSCP_sc_getxmlnodeptr(client, status), msgtype, status); } } SCSCP_debugprint("SCSCP_sc_callrecvheader(%d) - returns %d\n",SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! read the answer of the procedure call and store it in a string buffer @param client (inout) scscp client @param options (inout) options of the procedure return @param msgtype (out) type of returned message @param openmathbuffer (out) openmath buffer. This buffer must be freed with 'free' @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_callrecvstr(SCSCP_socketclient* client, SCSCP_returnoptions* options, SCSCP_msgtype *msgtype, char **openmathbuffer, SCSCP_status* status) { int res = SCSCP_sc_callrecvheader(client, options, msgtype, status); if (res) { *openmathbuffer = SCSCP_sc_getxmlnoderawstring(client, SCSCP_sc_getxmlnode(client, status), status); } return res; } scscp-imcce-1.0.0+ds/src/scscpprocedurecall.h000066400000000000000000000121321215622604100211210ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpprocedurecall.h \brief SCSCP message : procedure call. class SCSCP_procedurecalloptions, SCSCP_procedurecall \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 12/09/08 : update for SCSCP 1.2 \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPPROCEDURECALL_H__ #define __SCSCPPROCEDURECALL_H__ #include "scscpcallid.h" #if defined (__cplusplus) extern "C" { #endif /* (__cplusplus) */ /*! debug level type */ typedef int SCSCP_debuglevel; /*-----------------------------------------------------------------*/ /*! manage the message Procedure call */ /*-----------------------------------------------------------------*/ struct SCSCP_procedurecalloptions { /*-----------------------------------------------------------------*/ /* attributes */ /*-----------------------------------------------------------------*/ SCSCP_call_id m_callid; //!< call identifier SCSCP_option_return m_returntype; //!< type of the return SCSCP_time m_runtime_limit; //!< runtime limit in milliseconds SCSCP_memory m_minimal_memory; //!< minimal memory required in bytes SCSCP_memory m_maximal_memory; //!< maximal memory required in bytes SCSCP_debuglevel m_debuglevel; //!< debug level SCSCP_encodingtype m_encodingtype; //!< encoding type of the message // specify if attributes are set int m_set_callid; //! = true => m_callid is valid int m_set_returntype; //! = true => m_returntype is valid int m_set_runtime_limit; //! = true => m_runtime_limit is valid int m_set_minimal_memory; //! = true => m_minimal_memory is valid int m_set_maximal_memory; //! = true => m_maximal_memory is valid int m_set_debuglevel; //! = true => m_debuglevel is valid } ; int SCSCP_co_write(SCSCP_io *stream, const SCSCP_calloptions options, SCSCP_status* status); int SCSCP_co_set_writablecallid(SCSCP_calloptions* options, char *buffer, SCSCP_status* status); /*! generate and set the procedure call ID (prefixed by libSCSCP:) */ int SCSCP_co_generateunique_callid(SCSCP_calloptions* options, SCSCP_status* status); int SCSCP_procedurecall_read(SCSCP_io *stream, SCSCP_calloptions options, SCSCP_xmlnodeptr* iterchild, SCSCP_status* status); int SCSCP_procedurecall_write(SCSCP_io *stream, SCSCP_calloptions options, int (*callbackwriteargs)(SCSCP_io* client, void *param, SCSCP_status* status), void *param, SCSCP_status* status); int SCSCP_procedurecall_write_start(SCSCP_io *stream, SCSCP_calloptions options, SCSCP_status* status); int SCSCP_procedurecall_write_finish(SCSCP_io *stream, SCSCP_status* status); int SCSCP_procedurecall_write_cancel(SCSCP_io *stream, SCSCP_status* status); #if defined (__cplusplus) } #endif /* (__cplusplus) */ #endif /*__SCSCPPROCEDURECALL_H__*/ scscp-imcce-1.0.0+ds/src/scscpprocedurecompleted.c000066400000000000000000000154101215622604100221570ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpprocedurecompleted.cxx \brief SCSCP message : procedure completed. class SCSCP_procedurecompleted \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #include #if HAVE_STRING_H #include #endif #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpdebug.h" #include "scscptags.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpprocedurecompleted.h" /*-----------------------------------------------------------------*/ /*! start to send the "procedure completed" message to the client. @param client (inout) scscp client @param options (in) options of the call @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_procedurecompleted_write_start(SCSCP_io* stream, SCSCP_procedurecompletedoptions* options, SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_procedurecompleted_write_start(%p,%p, %p) - enter\n", stream, options, status); res = SCSCP_io_writeSCSCPSTART(stream, status); res &= SCSCP_io_writebeginOMOBJ(stream, status); res &= SCSCP_io_writebeginOMATTR(stream, NULL, status); /*write the options*/ res &= SCSCP_ro_write(stream, options, status); res &= SCSCP_io_writebeginOMA(stream, NULL, status); /*write procedure name */ res &= SCSCP_io_writeOMS(stream, SCSCP_TAGS_cdname, SCSCP_TAGS_procedure_completed,NULL, status); SCSCP_debugprint("SCSCP_procedurecompleted_write_start(,%d) - returns %d\n", SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! finish to send the "procedure completed" message to the client. @param client (inout) scscp client @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_procedurecompleted_write_finish(SCSCP_io* stream, SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_procedurecompleted_write_finish(%p, %p) - enter\n", stream, status); res = SCSCP_io_writeendOMA(stream, status); res &= SCSCP_io_writeendOMATTR(stream, status); res &= SCSCP_io_writeendOMOBJ(stream, status); res &= SCSCP_io_writeSCSCPEND(stream, status); SCSCP_debugprint("SCSCP_procedurecompleted_write_finish(,%d) - returns %d\n", SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! send the "procedure completed" message to the client. The arguments are written by callbackwriteargs @param client (inout) scscp client @param options (in) options of the call @param callbackwriteargs (in) callback function to write the parameters of the procedure call @param param (inout) opaque data given to callbackwriteargs @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_procedurecompleted_write(SCSCP_io* stream, SCSCP_procedurecompletedoptions* options, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_procedurecompleted_write(%p,%p,%p, %p, %p) - enter\n", stream, options, callbackwriteargs,param, status); res = SCSCP_procedurecompleted_write_start(stream, options, status); /*write returned object */ if (res) res = callbackwriteargs(stream, param, status); if (res) res = SCSCP_procedurecompleted_write_finish(stream, status); SCSCP_debugprint("SCSCP_procedurecompleted_write(,%d) - returns %d\n", SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! read the content of a "procedure completed message" and store it in openmathbuffer @param client (inout) scscp client @param openmathbuffer (out) openmath buffer. This buffer must be freed with 'free' @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_callrecvcompleted(SCSCP_socketclient* client, char **openmathbuffer, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); if (res) { *openmathbuffer = SCSCP_sc_getxmlnoderawstring(client, SCSCP_sc_getxmlnode(client, status), status); } return res; } scscp-imcce-1.0.0+ds/src/scscpprocedurecompleted.h000066400000000000000000000064121215622604100221660ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpprocedurecompleted.h \brief SCSCP message : procedure completed. class SCSCP_procedurecompletedoptions, SCSCP_procedurecompletedoptions \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPPROCEDURECOMPLETED_H__ #define __SCSCPPROCEDURECOMPLETED_H__ #include "scscpoptions.h" typedef struct SCSCP_optionsprocedurereturn SCSCP_procedurecompletedoptions; #if defined (__cplusplus) extern "C" { #endif int SCSCP_procedurecompleted_write(SCSCP_io* stream, SCSCP_procedurecompletedoptions* options, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, SCSCP_status* status); int SCSCP_procedurecompleted_write_start(SCSCP_io* stream, SCSCP_procedurecompletedoptions* options, SCSCP_status* status); int SCSCP_procedurecompleted_write_finish(SCSCP_io* stream, SCSCP_status* status); #if defined (__cplusplus) } #endif #endif /*__SCSCPPROCEDURECOMPLETED_H__*/ scscp-imcce-1.0.0+ds/src/scscpprocedureterminated.c000066400000000000000000000250051215622604100223400ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpprocedureterminated.cxx \brief SCSCP message : procedure terminated. class SCSCP_procedureterminatedoptions, SCSCP_procedureterminated \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #if HAVE_STRING_H #include #endif #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpdebug.h" #include "scscptags.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpprocedureterminated.h" /*-----------------------------------------------------------------*/ /* inlined functions */ /*-----------------------------------------------------------------*/ /*! return the cd */ static const char* SCSCP_procedureterminated_getcd(const SCSCP_procedureterminated* procterm) { return procterm->m_cdname; } /*! return the symbol */ static const char* SCSCP_procedureterminated_getsymbol(const SCSCP_procedureterminated* procterm) { return procterm->m_symbolname; } /*-----------------------------------------------------------------*/ /*! constructor @param procterm (inout) procedure terminated @param options (inout) options of the procedure completed @param errormsg (inout) error message (not duplicated) @param symbolname (in) name of the symbol @param cdname (in) name of the CD @param status (inout) error code */ /*-----------------------------------------------------------------*/ int SCSCP_procedureterminated_init(SCSCP_procedureterminated* procterm, SCSCP_procedureterminatedoptions* options, const_SCSCP_string cdname, const_SCSCP_string symbolname, SCSCP_string errormsg, SCSCP_status *status) { procterm->m_ProcedureOptions = options; procterm->m_errormsg = errormsg; procterm->m_symbolname = symbolname; procterm->m_cdname = cdname; procterm->m_consterrormsg = NULL; return 1; } /*-----------------------------------------------------------------*/ /*! constructor @param procterm (inout) procedure terminated @param options (inout) options of the procedure completed @param errormsg (in) error message @param symbolname (in) name of the symbol @param cdname (in) name of the CD @param status (inout) error code */ /*-----------------------------------------------------------------*/ int SCSCP_procedureterminated_init2(SCSCP_procedureterminated* procterm, SCSCP_procedureterminatedoptions* options, const_SCSCP_string cdname, const_SCSCP_string symbolname, const_SCSCP_string errormsg, SCSCP_status *status) { procterm->m_ProcedureOptions = options; procterm->m_errormsg = NULL; procterm->m_symbolname = symbolname; procterm->m_cdname = cdname; procterm->m_consterrormsg = errormsg; return 1; } /*-----------------------------------------------------------------*/ /*! destructor @param procterm (inout) procedure terminated @param status (inout) error code */ /*-----------------------------------------------------------------*/ int SCSCP_procedureterminated_clear(SCSCP_procedureterminated* procterm, SCSCP_status *status) { if (procterm->m_errormsg) free(procterm->m_errormsg); return 1; } /*-----------------------------------------------------------------*/ /*! return the error message @param procterm (inout) procedure terminated @param status (inout) error code */ /*-----------------------------------------------------------------*/ const char* SCSCP_procedureterminated_getmessage(const SCSCP_procedureterminated* procterm) { return procterm->m_errormsg!=NULL?procterm->m_errormsg:procterm->m_consterrormsg; } /*-----------------------------------------------------------------*/ /*! write the object to the stream @param stream (inout) output stream @param status (inout) error code @param procterm (in) procedure terminated code */ /*-----------------------------------------------------------------*/ int SCSCP_procedureterminated_write(SCSCP_io *stream, const SCSCP_procedureterminated* procterm, SCSCP_status *status) { int res; SCSCP_debugprint("SCSCP_procedureterminated_write(%p,%p,%p) - enter\n", stream, procterm, status); res = SCSCP_io_writeSCSCPSTART(stream, status); res &= SCSCP_io_writebeginOMOBJ(stream, status); res &= SCSCP_io_writebeginOMATTR(stream, NULL, status); //write the options res &= SCSCP_ro_write(stream, procterm->m_ProcedureOptions, status); res &= SCSCP_io_writebeginOMA(stream, NULL, status); //write procedure name res &= SCSCP_io_writeOMS(stream, SCSCP_TAGS_cdname, SCSCP_TAGS_procedure_terminated, NULL, status); res &= SCSCP_io_writeOMEwithOMSOMSTR(stream, procterm->m_cdname!=NULL?procterm->m_cdname:SCSCP_TAGS_cdname, procterm->m_symbolname, SCSCP_procedureterminated_getmessage(procterm), status); res &= SCSCP_io_writeendOMA(stream, status); res &= SCSCP_io_writeendOMATTR(stream, status); res &= SCSCP_io_writeendOMOBJ(stream, status); res &= SCSCP_io_writeSCSCPEND(stream, status); SCSCP_debugprint("SCSCP_procedureterminated_write(,%d) - returns %d\n", SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! read the object from the stream @param client (inout) scscp client @param node (in) current valid node. mustn't be NULL @param procterm (inout) procedure terminated @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_procedureterminated_read(SCSCP_socketclient* client, SCSCP_xmlnodeptr* curnode, SCSCP_procedureterminated* procterm, SCSCP_status *status) { int res; SCSCP_debugprint("SCSCP_procedureterminated_read(%p, %p) - enter\n", curnode, procterm); res = SCSCP_sc_xmlnodereadOMEstr(client, curnode, &procterm->m_cdname, &procterm->m_symbolname, &procterm->m_errormsg, status); SCSCP_debugprint("SCSCP_procedureterminated_read(,%d) - returns %d\n", SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! read the content of a "procedure terminated message" and the error message is stored in errortype and messagebuffer @param client (inout) scscp client @param cdname (out) name of the cd for the error This buffer must be freed with 'free' @param symbolname (out) name of the symbole for the error This buffer must be freed with 'free' @param messagebuffer (out) openmath buffer. This buffer must be freed with 'free' @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_sc_callrecvterminated(SCSCP_socketclient* client, char **cdname, char **symbolname, char **messagebuffer, SCSCP_status* status) { int res = SCSCP_sc_checkNULL(client, status); SCSCP_debugprint("SCSCP_procedureterminated_read(%p, %p, %p, %p, %p) - enter\n", client, cdname, symbolname, messagebuffer, status); if (res) { SCSCP_procedureterminatedoptions options; SCSCP_procedureterminated localterm; SCSCP_xmlnodeptr node; res = SCSCP_procedureterminated_init(&localterm, &options, NULL, NULL, NULL, status); node = SCSCP_sc_getxmlnode(client, status); res &= (node!=NULL); res &= SCSCP_procedureterminated_read(client, &node, &localterm, status); if (res) { const char *msgbuf = SCSCP_procedureterminated_getmessage(&localterm); *messagebuffer = SCSCP_strdup(msgbuf==NULL?"":msgbuf, status); *cdname = SCSCP_strdup(SCSCP_procedureterminated_getcd(&localterm), status); *symbolname = SCSCP_strdup(SCSCP_procedureterminated_getsymbol(&localterm), status); res = (*cdname && *symbolname && *messagebuffer); } SCSCP_procedureterminated_clear(&localterm, status); } SCSCP_debugprint("SCSCP_procedureterminated_read(%s,%s,%s,%d) - returns %d\n", *cdname, *symbolname, *messagebuffer, SCSCP_status_is(status), res); return res; } scscp-imcce-1.0.0+ds/src/scscpprocedureterminated.h000066400000000000000000000121501215622604100223420ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpprocedureterminated.h \brief SCSCP message : procedure terminated. class SCSCP_procedureterminatedoptions, SCSCP_procedureterminated \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPPROCEDURETERMINATED_H__ #define __SCSCPPROCEDURETERMINATED_H__ #include "scscpoptions.h" /*-----------------------------------------------------------------*/ /*! structure to manage the option of "Procedure terminated" */ /*-----------------------------------------------------------------*/ typedef struct SCSCP_optionsprocedurereturn SCSCP_procedureterminatedoptions; /*-----------------------------------------------------------------*/ /*! structure to manage the Procedure termiated */ /*-----------------------------------------------------------------*/ typedef struct { /*-----------------------------------------------------------------*/ /* attributes */ /*-----------------------------------------------------------------*/ SCSCP_procedureterminatedoptions* m_ProcedureOptions; /*!< options of the procedure */ SCSCP_string m_errormsg; /*!< writeable error message */ const_SCSCP_string m_consterrormsg; /*!< read-only error message */ const_SCSCP_string m_symbolname; /*!< symbol name */ const_SCSCP_string m_cdname; /*!< cd name */ } SCSCP_procedureterminated; /*-----------------------------------------------------------------*/ /* functions */ /*-----------------------------------------------------------------*/ #if defined (__cplusplus) extern "C" { #endif int SCSCP_procedureterminated_init(SCSCP_procedureterminated* procterm, SCSCP_procedureterminatedoptions* options, const_SCSCP_string cdname, const_SCSCP_string symbolname, SCSCP_string errormsg, SCSCP_status *status); int SCSCP_procedureterminated_init2(SCSCP_procedureterminated* procterm, SCSCP_procedureterminatedoptions* options, const_SCSCP_string cdname, const_SCSCP_string symbolname, const_SCSCP_string errormsg, SCSCP_status *status); int SCSCP_procedureterminated_clear(SCSCP_procedureterminated* procterm, SCSCP_status *status); int SCSCP_procedureterminated_write(SCSCP_io *stream, const SCSCP_procedureterminated* procterm, SCSCP_status *status); int SCSCP_procedureterminated_read(SCSCP_socketclient* client, SCSCP_xmlnodeptr* curnode, SCSCP_procedureterminated* procterm, SCSCP_status *status); const char* SCSCP_procedureterminated_getmessage(const SCSCP_procedureterminated* procterm); #if defined (__cplusplus) } #endif #endif /*__SCSCPPROCEDURETERMINATED_H__*/ scscp-imcce-1.0.0+ds/src/scscpremoteobject.c000066400000000000000000000215001215622604100207510ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpremoteobject.cxx \brief SCSCP remote object functions \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #if HAVE_STRING_H #include #endif #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpdebug.h" #include "scscpfileserver.h" #include "scscpfileclient.h" /*-----------------------------------------------------------------*/ /*! store during a session a remote object and returns its reference name @param client (inout) client session @param status (inout) error type @param callbackwriteargs (in) function to write arguments @param param (in) opaque object given to callbackwriteargs @param cookiename (out) name of the remote object */ /*-----------------------------------------------------------------*/ int SCSCP_sc_remoteobjectstoresessionhook(SCSCP_socketclient* client, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, char ** cookiename, SCSCP_status* status) { int res; SCSCP_xmlnodeptr node; const char *buf; SCSCP_debugprint("SCSCP_sc_remoteobjectstoresessionhook(%p, %p, %p, %p, %p) - enter\n", client, callbackwriteargs, param,cookiename, status); res = SCSCP_sc_executehookxmlnode(client, SCSCP_option_return_cookie, "scscp2", "store_session", callbackwriteargs, param, &node, status); if (res) { res = SCSCP_xmlnode_readOMR(&node, &buf); if (res==0) SCSCP_status_seterror(status, SCSCP_STATUS_OPENMATHNOTVALID); } *cookiename = res?SCSCP_strdup(buf,status):NULL; SCSCP_debugprint("SCSCP_sc_remoteobjectstoresessionhook( %s, %d) - return\n", *cookiename==NULL?"NULL":*cookiename, SCSCP_status_is(status)); return res; } /*-----------------------------------------------------------------*/ /*! store a remote object and returns its reference name This object will useable for multiple session. @param client (inout) client session @param status (inout) error type @param callbackwriteargs (in) function to write arguments @param param (in) opaque object given to callbackwriteargs @param cookiename (out) name of the remote object */ /*-----------------------------------------------------------------*/ int SCSCP_sc_remoteobjectstorepersistenthook(SCSCP_socketclient* client, int (*callbackwriteargs)(SCSCP_io* stream, void *param, SCSCP_status* status), void *param, char ** cookiename, SCSCP_status* status) { int res; SCSCP_xmlnodeptr node; const char *buf; SCSCP_debugprint("SCSCP_sc_remoteobjectstoresessionhook(%p, %p, %p, %p, %p) - enter\n", client, callbackwriteargs, param,cookiename, status); res = SCSCP_sc_executehookxmlnode(client, SCSCP_option_return_cookie, "scscp2", "store_persistent", callbackwriteargs, param, &node, status); if (res) res = SCSCP_xmlnode_readOMR(&node, &buf); *cookiename = res?SCSCP_strdup(buf,status):NULL; SCSCP_debugprint("SCSCP_sc_remoteobjectstoresessionhook( %s, %d) - return %d\n", *cookiename==NULL?"NULL":*cookiename, SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! write the name of the cookie as an OpenMath string @param stream (inout) stream session @param status (inout) error type @param param (in) name of the remote object */ /*-----------------------------------------------------------------*/ static int SCSCP_sc_remoteobjecthookwrite(SCSCP_io* stream, void *param, SCSCP_status *status) { const char *cookiename = (const char*)param; return SCSCP_io_writeOMR(stream, cookiename, status); } /*-----------------------------------------------------------------*/ /*! retrieve the value of a remote object and returns its reference name @param client (inout) client session @param status (inout) error type @param node (out) xml node @param cookiename (in) name of the remote object */ /*-----------------------------------------------------------------*/ int SCSCP_sc_remoteobjectretrievexmlnode(SCSCP_socketclient* client, const char * cookiename, SCSCP_xmlnodeptr* node,SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_sc_remoteobjectretrievexmlnode(%p, %s, %p, %p) - enter\n", client, cookiename, node, status); res = SCSCP_sc_executehookxmlnode(client, SCSCP_option_return_object, "scscp2", "retrieve", SCSCP_sc_remoteobjecthookwrite, (void *)cookiename , node, status); SCSCP_debugprint("SCSCP_sc_remoteobjectretrievexmlnode( %p, %d) - returns %d\n", *node, SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! retrieve the value of a remote object and returns its reference name @param client (inout) client session @param status (inout) error type @param openmathbuffer (out) openmath string @param cookiename (in) name of the remote object */ /*-----------------------------------------------------------------*/ int SCSCP_sc_remoteobjectretrievestr(SCSCP_socketclient* client, const char * cookiename, char** openmathbuffer,SCSCP_status* status) { int res; SCSCP_debugprint("SCSCP_sc_remoteobjectretrievestr(%p, %s, %p, %p) - enter\n", client, cookiename, openmathbuffer, status); res = SCSCP_sc_executehookstr(client, SCSCP_option_return_object, "scscp2", "retrieve", SCSCP_sc_remoteobjecthookwrite, (void *)cookiename , openmathbuffer, status); SCSCP_debugprint("SCSCP_sc_remoteobjectretrievestr( %p, %d) - returns %d\n", *openmathbuffer, SCSCP_status_is(status), res); return res; } /*-----------------------------------------------------------------*/ /*! unbind a remote object @param client (inout) client session @param status (inout) error type @param cookiename (in) name of the remote object */ /*-----------------------------------------------------------------*/ int SCSCP_sc_remoteobjectunbind(SCSCP_socketclient* client, const char * cookiename, SCSCP_status* status) { int res; SCSCP_xmlnodeptr node; SCSCP_debugprint("SCSCP_sc_remoteobjectunbind(%p, %s, %p) - enter\n", client, cookiename, status); res = SCSCP_sc_executehookxmlnode(client, SCSCP_option_return_nothing, "scscp2", "unbind", SCSCP_sc_remoteobjecthookwrite, (void*)cookiename, &node, status); SCSCP_debugprint("SCSCP_sc_remoteobjectunbind(%d) - return %d\n", SCSCP_status_is(status),res); return res; } scscp-imcce-1.0.0+ds/src/scscpserver.c000066400000000000000000000133641215622604100176060ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpserver.cxx \brief SCSCP server \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008,2009, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpserver.h" #include "scscpfileclient.h" #include "scscpfileserver.h" static int SCSCP_ss_clearallowedversions(SCSCP_server* server, SCSCP_status* status); /*-----------------------------------------------------------------*/ /*! initialize the common data of the servers @param server (inout) object to be cleared @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_initcmn(SCSCP_server* server, SCSCP_status* status) { int res = 1; if (server==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_SERVEROBJECTNULL); res = 0; } else { server->m_servicename = NULL; server->m_serviceversion = NULL; server->m_serviceid = NULL; server->m_allowedversions = NULL; server->m_allowedversionscount = 0; } return res; } /*-----------------------------------------------------------------*/ /*! clear the server @param pserver (inout) object to be cleared @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_clearcmn(SCSCP_server* pserver, SCSCP_status* status) { if (pserver->m_servicename) free(pserver->m_servicename); if (pserver->m_serviceversion) free(pserver->m_serviceversion); if (pserver->m_serviceid) free(pserver->m_serviceid); return SCSCP_ss_clearallowedversions(pserver, status); } /*-----------------------------------------------------------------*/ /*! clear the allowed version to be negiotiated to the server @param server (inout) object to be cleared @param status (inout) status error */ /*-----------------------------------------------------------------*/ static int SCSCP_ss_clearallowedversions(SCSCP_server* server, SCSCP_status* status) { int res = 1; if (server==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_SERVEROBJECTNULL); res = 0; } else { /* clear the elements of versions */ if (server->m_allowedversions!=NULL) { size_t cpt; for(cpt=0; cptm_allowedversionscount; cpt++) { free(server->m_allowedversions[cpt]); } free(server->m_allowedversions); server->m_allowedversions = NULL; server->m_allowedversionscount = 0; } } return res; } /*-----------------------------------------------------------------*/ /*! initialize the object server with the service strings @param server (inout) object to be initialized @param servicename (in) name of service @param serviceversion (in) service version @param serviceid (in) service identifier @param status (inout) status error */ /*-----------------------------------------------------------------*/ int SCSCP_ss_setservice(SCSCP_server* server, const char *servicename, const char *serviceversion, const char *serviceid, SCSCP_status* status) { int res = 1; server->m_servicename = SCSCP_strdup(servicename, status); res = (server->m_servicename!=NULL); if (res) server->m_serviceversion = SCSCP_strdup(serviceversion, status); res = (server->m_serviceversion!=NULL); if (res) server->m_serviceid = SCSCP_strdup(serviceid, status); res = (server->m_serviceid!=NULL); return res; } scscp-imcce-1.0.0+ds/src/scscpserver.h000066400000000000000000000066651215622604100176210ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpserver.h \brief SCSCP server. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPSERVER_H__ #define __SCSCPSERVER_H__ /*-----------------------------------------------------------------*/ /*! common data to handle SCSCP server */ /*-----------------------------------------------------------------*/ typedef struct { /*-----------------------------------------------------------------*/ /* attributes */ /*-----------------------------------------------------------------*/ SCSCP_string *m_allowedversions; /*!< allowed versions */ size_t m_allowedversionscount; /*!< number of elements of m_allowedversions */ SCSCP_string m_servicename; /*!< name of the service */ SCSCP_string m_serviceversion; /*!< version of the service */ SCSCP_string m_serviceid; /*!< unique identifier of the service */ } SCSCP_server; int SCSCP_ss_initcmn(SCSCP_server* server, SCSCP_status* status); int SCSCP_ss_clearcmn(SCSCP_server* pserver, SCSCP_status* status); int SCSCP_ss_setservice(SCSCP_server* server, const char *servicename, const char *serviceversion, const char *serviceid, SCSCP_status* status); #endif /*__SCSCPSERVER_H__*/ scscp-imcce-1.0.0+ds/src/scscpstatus.c000066400000000000000000000226771215622604100176320ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpstatus.c \brief SCSCP status functions \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 12/09/08 : update for SCSCP 1.2 \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #include #else #if HAVE_SYS_SOCKET_H #include #endif #endif /*HAVE_WINDOWS_H*/ #if HAVE_STRING_H #include #endif #include #include #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpdebug.h" #include "scscpinternal.h" #include "scscpfileclient.h" #include "scscpfileserver.h" /*-----------------------------------------------------------------*/ /*! clear the status object @param status (inout) status to be updated */ /*-----------------------------------------------------------------*/ __SCSCP_DECLSPEC void SCSCP_status_clear(SCSCP_status* status) { if (status) { SCSCP_debugprint("SCSCP_status_clear(%p) - enter\n", status); if (SCSCP_status_is(status)==SCSCP_STATUS_EXECFAILED) { if (status->m_cdname) free(status->m_cdname); if (status->m_symbolname) free(status->m_symbolname); if (status->m_message) free(status->m_message); if (status->m_fullformattedmessage) free(status->m_fullformattedmessage); } *status = SCSCP_STATUS_INITIALIZER; SCSCP_debugprint("SCSCP_status_clear() - return\n"); } } /*-----------------------------------------------------------------*/ /*! set the error to value @param status (in) status to be updated @param value (in) error value (must be SCSCP_STATUS_xxxx) */ /*-----------------------------------------------------------------*/ void SCSCP_status_seterror(SCSCP_status* status, int value) { SCSCP_status_clear(status); if (status) { status->m_code = value; } } /*-----------------------------------------------------------------*/ /*! set the error to value : EXECFAILED @param status (in) status to be updated @param cdname (in) name of the cd @param symbolname (in) name of the symbol @param msg (in) message */ /*-----------------------------------------------------------------*/ void SCSCP_status_setexecfailed(SCSCP_status* status, const char *cdname, const char *symbolname, const char *msg) { SCSCP_status_seterror(status, SCSCP_STATUS_EXECFAILED); if (status) { const char *format = "Remote execution failed. Reason : cd='%s' name='%s' message='%s'\n"; status->m_cdname = SCSCP_strdup(cdname, SCSCP_STATUS_IGNORE); status->m_symbolname = SCSCP_strdup(symbolname, SCSCP_STATUS_IGNORE); status->m_message = SCSCP_strdup(msg, SCSCP_STATUS_IGNORE); status->m_fullformattedmessage=(char*)SCSCP_malloc((strlen(cdname)+strlen(symbolname)+strlen(msg)+strlen(format)+2)*sizeof(char), SCSCP_STATUS_IGNORE); if (status->m_fullformattedmessage) { sprintf(status->m_fullformattedmessage,format, cdname, symbolname, msg); } if (status->m_cdname==NULL || status->m_symbolname==NULL || status->m_message==NULL || status->m_fullformattedmessage==NULL) { SCSCP_status_seterror(status, SCSCP_STATUS_ERRNO); } } } /*-----------------------------------------------------------------*/ /*! copy the error code from src to dst @param dst (out) status to be updated @param src (in) status to be copied */ /*-----------------------------------------------------------------*/ void SCSCP_status_copy(SCSCP_status* dst, const SCSCP_status *src) { SCSCP_debugprint("SCSCP_status_copy(%p, %p) - enter\n", dst, src); if (dst && src) { *dst = *src; if (dst->m_fullformattedmessage) { dst->m_fullformattedmessage=SCSCP_strdup(dst->m_fullformattedmessage, SCSCP_STATUS_IGNORE); } if (dst->m_cdname) dst->m_cdname = SCSCP_strdup(dst->m_cdname, SCSCP_STATUS_IGNORE); if (dst->m_symbolname) dst->m_symbolname = SCSCP_strdup(dst->m_symbolname, SCSCP_STATUS_IGNORE); if (dst->m_message) dst->m_message = SCSCP_strdup(dst->m_message, SCSCP_STATUS_IGNORE); } SCSCP_debugprint("SCSCP_status_copy() - return\n"); } /*-----------------------------------------------------------------*/ /*! copythe error code from src to dst @param dst (out) status to be updated @param src (in) status to be copied */ /*-----------------------------------------------------------------*/ SCSCP_status SCSCP_status_getinitializer() { SCSCP_status status = {SCSCP_STATUS_OK, NULL, NULL, NULL, NULL}; return status; } /*-----------------------------------------------------------------*/ /*! return a pointer to the corresponding message string @param status (out) error code */ /*-----------------------------------------------------------------*/ __SCSCP_DECLSPEC const char* SCSCP_status_strerror(const SCSCP_status* status) { int j; #define SCSCP_STATUS_MAXERR 21 struct st_msg { int value; /*!< value of the error code */ const char *msg; /*!< message string */ } armsg[SCSCP_STATUS_MAXERR]={ { SCSCP_STATUS_OK ,"Success" }, { SCSCP_STATUS_NOMEM ,"Not enough memory"}, { SCSCP_STATUS_CLIENTOBJECTNULL,"The object client passed to the function is NULL"}, { SCSCP_STATUS_CALLOPTIONSOBJECTNULL,"The call options passed to the function is NULL"}, { SCSCP_STATUS_RECVCANCEL ,"The interrupt message ' was received"}, { SCSCP_STATUS_RECVQUIT ,"The interrupt message ' was received"}, { SCSCP_STATUS_RETURNOPTIONSOBJECTNULL ,"The return options passed to the function is NULL"}, { SCSCP_STATUS_SERVEROBJECTNULL ,"The object server passed to the function is NULL"}, { SCSCP_STATUS_STREAMOBJECTNULL ,"The object stream passed to the function is NULL"}, { SCSCP_STATUS_CALLIDISNOTSET ,"The call identifier isn't defined in the options"}, { SCSCP_STATUS_RETURNTYPEISNOTSET ,"The return type isn't defined in the options"}, { SCSCP_STATUS_USAGEUNKNOWNRUNTIME ," The runtime usage isn't available in the procedure return message"}, { SCSCP_STATUS_USAGEUNKNOWNMEM ,"The memory usage isn't available in the procedure return message"}, { SCSCP_STATUS_USAGEUNKNOWNMESSAGE ,"The information message isn't available in the procedure return message"}, { SCSCP_STATUS_USAGEUNKNOWNRUNTIMELIMIT,"The runtime limit usage isn't available in the procedure call message"}, { SCSCP_STATUS_USAGEUNKNOWNMINMEMORY ,"The min memory isn't available in the procedure call message"}, { SCSCP_STATUS_USAGEUNKNOWNMAXMEMORY ,"The max memory isn't available in the procedure call message"}, { SCSCP_STATUS_USAGEUNKNOWNDEBUGLEVEL ,"The debug level isn't available in the procedure call message"}, { SCSCP_STATUS_USAGEUNKNOWNRETURNTYPE ,"The return type isn't available in the procedure call message"}, { SCSCP_STATUS_VERSIONNEGOTIATIONFAILED ,"The version negotiation fails"}, { SCSCP_STATUS_OPENMATHNOTVALID, "The OpenMath expression isn't valid"} }; const char *msg; if (status==NULL) msg = ""; else if (SCSCP_status_is(status)==SCSCP_STATUS_EXECFAILED) msg = status->m_fullformattedmessage; else if (SCSCP_status_is(status)==SCSCP_STATUS_ERRNO) msg=strerror(errno); else { msg=NULL; for (j=0; j #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #include #else #if HAVE_SYS_SOCKET_H #include #endif #endif /*HAVE_WINDOWS_H*/ #if HAVE_STRING_H #include #endif #include #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpdebug.h" #include "scscpinternal.h" #include "scscpfileclient.h" #include "scscpfileserver.h" /*-----------------------------------------------------------------*/ /* private functions */ /*-----------------------------------------------------------------*/ static int hostissameorderasnetwork(void); /*-----------------------------------------------------------------*/ /*! initialize the windows socket DLL return 1 on success */ /*-----------------------------------------------------------------*/ int SCSCP_initsocket() { #if HAVE_WINDOWS_H WORD wVersionRequested; WSADATA wsaData; int err; SCSCP_debugprint("SCSCP_initsocket() - enter\n"); wVersionRequested = MAKEWORD( 2, 2 ); err = WSAStartup( wVersionRequested, &wsaData ); if ( err != 0 ) { /* Tell the user that we could not find a usable WinSock DLL. */ SCSCP_debugprint("SCSCP_initsocket() - returns 0 (WSAStartup failed) \n"); return 0; } /* Confirm that the WinSock DLL supports 2.2.*/ if ( LOBYTE( wsaData.wVersion ) != 2 ||HIBYTE( wsaData.wVersion ) != 2 ) { /* Tell the user that we could not find a usable WinSock DLL. */ WSACleanup( ); SCSCP_debugprint("SCSCP_initsocket() - returns 0 (version !=2.2) \n"); return 0; } #endif SCSCP_debugprint("SCSCP_initsocket() - returns 1\n"); return 1; } /*-----------------------------------------------------------------*/ /*! allocate memory of ncount bytes (similar to malloc) @param ncount (in) size in bytes to allocate @param status (inout) status */ /*-----------------------------------------------------------------*/ void* SCSCP_malloc(size_t ncount, SCSCP_status* status) { void *pres = malloc(ncount); if (pres==NULL) SCSCP_status_seterror(status, SCSCP_STATUS_NOMEM); return pres; } /*-----------------------------------------------------------------*/ /*! duplicate a string (similar to strdup) @param src (in) string to duplicate (could be NULL) @param status (inout) status */ /*-----------------------------------------------------------------*/ char* SCSCP_strdup(const char* src, SCSCP_status* status) { char *dst = NULL; if (src) { dst = (char*)SCSCP_malloc(strlen(src)+1, status); if (dst) strcpy(dst, src); } return dst; } /*------------------------------------------------------------------*/ /* snprintf */ /*------------------------------------------------------------------*/ #if !HAVE_SNPRINTF int snprintf(char *string, size_t n, const char *format, ...) { int res; va_list args; va_start(args, format); res = vsprintf(string, format, args); va_end(args); return res; } #endif /*-----------------------------------------------------------------*/ /*! find the beginning of the version string in c. replace the last " of the versions by '\0'. return the address just after version=" return NULL on error. @param c (in) status to be updated @param scscp_versions (in) name of string version */ /*-----------------------------------------------------------------*/ char * SCSCP_findPIstring(char *c, const char*versionname) { char *psubstr = NULL; char *lastquote; const char *begin="0) @param len (in) length of buffer */ /*-----------------------------------------------------------------*/ const char *SCSCP_findstr(const char *buffer, const char *substr, int len) { const char *pos; int curpos = 0; int bfound = 1; size_t lensubstr; SCSCP_debugprint("SCSCP_findstr(%p,%s, %d) - enter\n", buffer, substr, len); lensubstr = strlen(substr); do { pos = (const char *)memchr(buffer+curpos, substr[0], len-curpos); if (pos!=NULL) { curpos = pos-buffer; if (len-curpos>=lensubstr) bfound = memcmp(pos,substr, lensubstr*sizeof(char)); curpos++; } } while (bfound!=0 && pos!=NULL); SCSCP_debugprint("SCSCP_findstr() -returns %p\n", pos); return pos; } /*-----------------------------------------------------------------*/ /*! allocate the buffer list and set the next field to next @param next (inout) buffer to attach at the end @param minsize (in) minimal size of the buffer */ /*-----------------------------------------------------------------*/ SCSCP_buffer_listptr SCSCP_buffer_list_init(SCSCP_buffer_listptr next, size_t minsize) { const size_t len = minsize+2*sizeof(SCSCP_buffer_list)<16000*4?16000*4:(minsize+sizeof(SCSCP_buffer_list)+2); SCSCP_buffer_listptr node; SCSCP_debugprint("SCSCP_buffer_list_init(%p, %lu) - enter len=%lu\n",next, (unsigned long) minsize, (unsigned long)len); node = (SCSCP_buffer_listptr)SCSCP_malloc(len, SCSCP_STATUS_IGNORE); if (node) { node->m_next = next; node->m_len = len-sizeof(SCSCP_buffer_list); node->m_data = node+1; } SCSCP_debugprint("SCSCP_buffer_list_init() - return %p m_data=%p\n", node, node->m_data); return node; } /*-----------------------------------------------------------------*/ /*! clear the buffer list @param buffer (inout) buffer to be destroyed */ /*-----------------------------------------------------------------*/ void SCSCP_buffer_list_clear(SCSCP_buffer_list *buffer) { SCSCP_buffer_list *tmp; SCSCP_debugprint("SCSCP_buffer_list_clear(%p) - enter\n",buffer); while (buffer!=NULL) { tmp = buffer->m_next; free(buffer); buffer = tmp; } SCSCP_debugprint("SCSCP_buffer_list_clear() - exit\n"); } /*-----------------------------------------------------------------*/ /*! return 1 if host has same byte order as network byteorder */ /*-----------------------------------------------------------------*/ static int hostissameorderasnetwork(void) { union { long l; char c[sizeof (long)]; } u; u.l = 1; return (u.c[sizeof (long) - 1] == 1); } /*-----------------------------------------------------------------*/ /*! swap the bytes in network byte order of the double x @param x (inout) double */ /*-----------------------------------------------------------------*/ double SCSCP_htond(double x) { double res; /* tests for big-endian : same as network order */ if (hostissameorderasnetwork()) { /* already in network order : no swap */ res = x; } else { /* little endian => network order : swap */ unsigned char *cx=(unsigned char*) &x; unsigned char *cres=(unsigned char*) &res; int j; for (j=0; j little endian : swap */ unsigned char *cx=(unsigned char*) &x; unsigned char *cres=(unsigned char*) &res; int j; for (j=0; j #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscputil.h" /*-----------------------------------------------------------------*/ /*! return the SCSCP library version as string */ /*-----------------------------------------------------------------*/ const char* SCSCP_get_libversionstr() { return SCSCP_STRINGIFY(SCSCP_VERSION_MAJOR) "." SCSCP_STRINGIFY(SCSCP_VERSION_MINOR) "." SCSCP_STRINGIFY(SCSCP_VERSION_PATCH) ; } /*-----------------------------------------------------------------*/ /*! return the SCSCP library version as numbers @param major (out) major version @param minor (out) minor revision @param patch (out) patch level */ /*-----------------------------------------------------------------*/ void SCSCP_get_libversionnum(unsigned int *major, unsigned int *minor, unsigned int *patch) { if (major) *major = SCSCP_VERSION_MAJOR; if (minor) *minor = SCSCP_VERSION_MINOR; if (patch) *patch = SCSCP_VERSION_PATCH; } /*-----------------------------------------------------------------*/ /*! check the SCSCP library compatibility return 0 if library are not compatible return 1 if library are compatible and are equal return 2 if library are compatible and are not equal @param major (in) major value to check @param minor (in) minor value to check @param patch (in) patch value to check */ /*-----------------------------------------------------------------*/ int SCSCP_check_libversion(unsigned int major, unsigned int minor, unsigned int patch) { int ret = 0; if (major #if HAVE_STRING_H #include #endif #if HAVE_STDINT_H #include #endif #if HAVE_LIMITS_H #include #endif #include #include #include #include #include #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpdebug.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpbinary.h" /***************************************************************************/ /* macros locales aux fichiers */ /***************************************************************************/ /*! conversion de xmlchar en char */ #define xmlChar2char(x) ((const char*)(x)) /*----------------------------------------------------------------------------------------------*/ /*! private functions */ /*----------------------------------------------------------------------------------------------*/ /* specific for DOM parser */ static const char* xmlNodePtr_getname(xmlNodePtr curnode); static const char* xmlNodePtr_getcontent(xmlNodePtr curnode); static int xmlAttrPtr_getvalue(xmlAttrPtr attr, const char **name, const char **value); static int xmlNodePtr_movetotag(xmlNodePtr* curnode, const char *string, int children, int gotochildnode); static int xmlNodePtr_SetProp(xmlNodePtr node, const char *name, const char *value, int lenvalue); static int xmlNodePtr_SetPropID(xmlNodePtr node, unsigned char token, const char *value, int lenvalue); /*----------------------------------------------------------------------------------------------*/ /*! return the next node after the current xml node. return NULL if curnode is the last node. @param curnode (in) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ SCSCP_xmlnodeptr SCSCP_xmlnode_getnext(SCSCP_xmlnodeptr curnode) { return curnode->next; } /*----------------------------------------------------------------------------------------------*/ /*! return the name after the current xml node. @param curnode (in) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ const char* SCSCP_xmlnode_getname(SCSCP_xmlnodeptr curnode) { #if SCSCP_PARSERTYPE==SCSCP_PARSERDOM return xmlNodePtr_getname(curnode); #elif SCSCP_PARSERTYPE==SCSCP_PARSERSAX return SCSCP_omnode_getname(curnode); #else ... #endif } /*----------------------------------------------------------------------------------------------*/ /*! read the id of the current node. could return NULL if unset @param curnode (in) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ const char * SCSCP_xmlnode_getid(SCSCP_xmlnodeptr node) { const char* name = NULL; const char* szType; const char* szContent; SCSCP_xmlattrptr pattAttribut; SCSCP_debugprint("SCSCP_xmlnode_getid(%p) - enter\n", node); pattAttribut = SCSCP_xmlnode_getattr(node); while (pattAttribut!=NULL && name==NULL) { SCSCP_xmlattr_getvalue(pattAttribut, &szType, &szContent); if (strcmp(szType,"id")==0) { name = szContent; } pattAttribut=SCSCP_xmlattr_getnext(pattAttribut); } SCSCP_debugprint("SCSCP_xmlnode_getid() - returns %p\n", name); return name; } /*----------------------------------------------------------------------------------------------*/ /*! read the content of the current node in the current xml node @param curnode (in) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ const char * SCSCP_xmlnode_getcontent(SCSCP_xmlnodeptr curnode) { #if SCSCP_PARSERTYPE==SCSCP_PARSERDOM return xmlNodePtr_getcontent(curnode); #elif SCSCP_PARSERTYPE==SCSCP_PARSERSAX return SCSCP_omnode_getcontent(curnode); #else ... #endif } /*----------------------------------------------------------------------------------------------*/ /*! return the first child node the current xml node. return NULL if no child present @param curnode (in) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ SCSCP_xmlnodeptr SCSCP_xmlnode_getchild(SCSCP_xmlnodeptr curnode) { return curnode->children; } /*----------------------------------------------------------------------------------------------*/ /*! read the first attribute of the current node return NULL if no attribute present @param curnode (in) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ SCSCP_xmlattrptr SCSCP_xmlnode_getattr(SCSCP_xmlnodeptr curnode) { return curnode->properties; } /*----------------------------------------------------------------------------------------------*/ /*! get the content of the attribute return 0 on failure and non-zero on success @param attr (in) current attribute. mustn't be NULL @param name (out) name of this attribute @param value (out) value of this attribute */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlattr_getvalue(SCSCP_xmlattrptr attr, const char **name, const char **value) { #if SCSCP_PARSERTYPE==SCSCP_PARSERDOM return xmlAttrPtr_getvalue(attr, name, value); #elif SCSCP_PARSERTYPE==SCSCP_PARSERSAX return SCSCP_omattr_getvalue(attr, name, value); #else ... #endif } /*-----------------------------------------------------------------*/ /*! return the associated value to the attributes specified by the name return NULL if not found @param iter (in) iterator on the xml doc @param p_pszName (in) name of the attribute */ /*-----------------------------------------------------------------*/ const char* SCSCP_xmlnode_findattr(SCSCP_xmlnodeptr iter, const char *p_pszName) { const char* attr = NULL; const char* value = NULL; const char* szType; SCSCP_xmlattrptr pattAttribut=iter->properties; SCSCP_debugprint("OML_FindAttributes(%p,%s) -enter\n", iter, p_pszName); while (pattAttribut && attr==NULL) { SCSCP_xmlattr_getvalue(pattAttribut,&szType,&value); if (strcmp(szType,p_pszName)==0) attr = value; pattAttribut=pattAttribut->next; } SCSCP_debugprint("OML_FindAttributes() -returns %p\n", attr); return attr; } /*----------------------------------------------------------------------------------------------*/ /*! return the next attribute after attr return NULL if attr is the last attribute @param attr (in) current valid attribute. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ SCSCP_xmlattrptr SCSCP_xmlattr_getnext(SCSCP_xmlattrptr attr) { return attr->next; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath Symbol and return its name and its cd. return 0 on error @param node (in) current valid node. mustn't be NULL @param cdname (out) name of CD @param symbolname (out) name of the symbol */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readOMS(SCSCP_xmlnodeptr* curnode, const char **cdname, const char **symbolname) { int res ; const char* szContent; const char* szType; SCSCP_xmlattrptr pattAttribut; SCSCP_debugprint("SCSCP_xmlnode_readOMS(%p,%p,%p) - enter\n", *curnode, cdname, symbolname); *cdname = NULL; *symbolname = NULL; pattAttribut = SCSCP_xmlnode_getattr(*curnode); while (pattAttribut!=NULL) { SCSCP_xmlattr_getvalue(pattAttribut, &szType, &szContent); if (strcmp(szType,"cd")==0) { *cdname = szContent; } else if (strcmp(xmlChar2char(szType),"name")==0) { *symbolname = szContent; } pattAttribut=SCSCP_xmlattr_getnext(pattAttribut); } res = (*symbolname!=NULL)?1:0; *curnode = SCSCP_xmlnode_getnext(*curnode); SCSCP_debugprint("SCSCP_xmlnode_readOMS(%p,%s,%s) - returns %d\n", *curnode, *cdname, *symbolname,res); return res; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath integer and return its value. return 0 on error @param node (in) current valid node. mustn't be NULL @param value (out) value of the integer */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readOMIstr(SCSCP_xmlnodeptr* curnode, const char **value) { int res; *value = SCSCP_xmlnode_getcontent(SCSCP_xmlnode_getchild(*curnode)); *curnode = SCSCP_xmlnode_getnext(*curnode); res =(*value!=NULL); SCSCP_debugprint("SCSCP_xmlnode_readOMIstr(%p,%s) - returns %d\n", *curnode, *value,res); return res; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath integer and return its value. return 0 on error @param node (in) current valid node. mustn't be NULL @param value (out) value of the integer */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readOMIint(SCSCP_xmlnodeptr* curnode, int* value) { int res; const char *buffer; #if SCSCP_PARSERTYPE==SCSCP_PARSERSAX if ((*curnode)->m_binarycontent!=NULL) { if ((*curnode)->omtype==SCSCP_omnodetype_OMIchar || (*curnode)->omtype==SCSCP_omnodetype_OMIint32) { *value = *(int32_t*)(*curnode)->m_binarycontent; res = 1; } else { SCSCP_debugprint("SCSCP_xmlnode_readOMIint() - bad value %d\n", (*curnode)->omtype); res = 0; } *curnode = SCSCP_xmlnode_getnext(*curnode); } else #endif { res = SCSCP_xmlnode_readOMIstr(curnode, &buffer); if (res) { long lval; errno = 0; lval = strtol(buffer, (char **)NULL, 10); *value = (int)lval; res = (errno==0 && ((long)*value)==lval); } } SCSCP_debugprint("SCSCP_xmlnode_readOMIint(%p,%d) - returns %d\n", *curnode, *value,res); return res; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath integer and return its value. return 0 on error @param node (in) current valid node. mustn't be NULL @param value (out) value of the integer */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readOMIsizet(SCSCP_xmlnodeptr* curnode, size_t* value) { int res; const char *buffer; #if SCSCP_PARSERTYPE==SCSCP_PARSERSAX if ((*curnode)->m_binarycontent!=NULL) { if ((*curnode)->omtype==SCSCP_omnodetype_OMIchar || (*curnode)->omtype==SCSCP_omnodetype_OMIint32) { *value = *(int32_t*)(*curnode)->m_binarycontent; res = 1; } else { SCSCP_debugprint("SCSCP_xmlnode_readOMIint() - bad value %d\n", (*curnode)->omtype); res = 0; } *curnode = SCSCP_xmlnode_getnext(*curnode); } else #endif { res = SCSCP_xmlnode_readOMIstr(curnode, &buffer); if (res) { unsigned long long lval; errno = 0; lval = strtoull(buffer, (char **)NULL, 10); *value = (size_t)lval; res = (errno==0 && ((unsigned long long)*value)==lval); } } SCSCP_debugprint("SCSCP_xmlnode_readOMIsizet(%p,%d) - returns %d\n", *curnode, (int)*value,res); return res; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath error and return the optional arguments as a raw string. return 0 on error @param client (in) client session @param node (in) current valid node. mustn't be NULL return the node just after the head symbol @param cdname (out) name of the CD @param symbolname (out) name of the symbol @param value (out) openmath expression (after the 1st symbol). ust be freed by the user using free */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_sc_xmlnodereadOMEstr(SCSCP_socketclient* client, SCSCP_xmlnodeptr* curnode, const char **cdname, const char **symbolname, char **value, SCSCP_status *status) { int res; SCSCP_xmlnodeptr child; SCSCP_debugprint("SCSCP_xmlnode_readOMEstr(%p, %p, %p,%p,%p) -enter\n", client, curnode, cdname, symbolname, value); child = SCSCP_xmlnode_getchild(*curnode); if (child==NULL) { res = 0; SCSCP_status_seterror(status, SCSCP_STATUS_OPENMATHNOTVALID); } else { res = SCSCP_xmlnode_readOMS(&child, cdname, symbolname); if (res) { *value = SCSCP_sc_getxmlnoderawstring(client, child, status); *curnode = SCSCP_xmlnode_getnext(*curnode); res = (*value!=NULL); } } SCSCP_debugprint("SCSCP_xmlnode_readOMEstr(,%s,%d) - returns %d\n", *value, SCSCP_status_is(status), res); return res; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath floating-point and return its value. return 0 on error @param curnode (inout) current valid node. mustn't be NULL @param value (out) value of the float @param base (out) base ( 16 for "hex", 10 for "dec" or 0 on error) */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readOMFstr(SCSCP_xmlnodeptr* curnode, const char **value, int *base) { int res = 0; *base = 0; *value = SCSCP_xmlnode_findattr(*curnode, "dec"); if (*value!=NULL) { *base = 10; res = 1; } else { *value = SCSCP_xmlnode_findattr(*curnode, "hex"); if (*value!=NULL) { *base = 16; res = 1; } } if (res) *curnode = SCSCP_xmlnode_getnext(*curnode); SCSCP_debugprint("SCSCP_xmlnode_readOMFstr(%p, %s,%d) - returns %d\n", *curnode, *value, *base, res); return res; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath floating-point and return its value. return 0 on error @param curnode (inout) current valid node. mustn't be NULL @param value (out) value of the float */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readOMFdouble(SCSCP_xmlnodeptr* curnode, double *value) { int res, j; const char *valuestr; valuestr = SCSCP_xmlnode_findattr(*curnode, "dec"); if (valuestr!=NULL) { *value = strtod(valuestr, (char **)NULL); } else { valuestr = SCSCP_xmlnode_findattr(*curnode, "hex"); if (valuestr!=NULL) { /*convert from hexa to double */ char *valuec = (char *)value; if (strlen(valuestr)==16) { for (j=0; j<8; j++) { char c; c = valuestr[2*j]; valuec[j]=(isdigit(c)?(c-'0'):c-'A'+10)<<4; c = valuestr[2*j+1]; valuec[j]|= isdigit(c)?(c-'0'):c-'A'+10; } *value = SCSCP_ntohd(*value); } } } res = (valuestr!=NULL); if (res) *curnode = SCSCP_xmlnode_getnext(*curnode); SCSCP_debugprint("SCSCP_xmlnode_readOMFdouble(%p, %23.16E) - returns %d\n", *curnode, *value, res); return res; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath string and return its value. return 0 on error @param curnode (inout) current valid node. mustn't be NULL @param value (out) value of the integer */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readOMSTR(SCSCP_xmlnodeptr* curnode, const char **value) { int res; SCSCP_xmlnodeptr child = SCSCP_xmlnode_getchild(*curnode); *value = (child==NULL)? NULL: SCSCP_xmlnode_getcontent(child); if (*value==NULL || strlen(*value)==0) res = 0; else { *curnode = SCSCP_xmlnode_getnext(*curnode); res=1; } SCSCP_debugprint("SCSCP_xmlnode_readOMSTR(%p, %s) - returns %d\n", *curnode, *value, res); return res; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath reference and return its value. return 0 on error @param curnode (inout) current valid node. mustn't be NULL @param value (out) reference name */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readOMR(SCSCP_xmlnodeptr* curnode, const char **value) { int res; SCSCP_debugprint("SCSCP_xmlnode_readOMR(%p, %p) -enter\n", *curnode, value); *value = SCSCP_xmlnode_findattr(*curnode, "href"); if (*value==NULL) { res=0; } else { *curnode = SCSCP_xmlnode_getnext(*curnode); res = 1; } SCSCP_debugprint("SCSCP_xmlnode_readOMR(%p,%s) - returns %d\n",*curnode, *value, res); return res; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath variable and return its value. return 0 on error @param curnode (inout) current valid node. mustn't be NULL @param value (out) value of the integer */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readOMV(SCSCP_xmlnodeptr* curnode, const char **value) { int res; SCSCP_xmlnodeptr child; SCSCP_debugprint("SCSCP_xmlnode_readOMV(%p, %p) - enter\n", *curnode, value); child = SCSCP_xmlnode_getchild(*curnode); *value = SCSCP_xmlnode_findattr(*curnode, "name"); if (*value==NULL && child!=NULL) { *value = SCSCP_xmlnode_getcontent(child); } res = (*value!=NULL); *curnode = SCSCP_xmlnode_getnext(*curnode); SCSCP_debugprint("SCSCP_xmlnode_readOMV(%p, %s) - returns %d\n", *curnode, *value, res); return res; } /*----------------------------------------------------------------------------------------------*/ /*! find the first , look in child node return 0 on error @param node (inout) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readbeginOMOBJ(SCSCP_xmlnodeptr* curnode) { return SCSCP_xmlnode_movetotag(curnode, "OMOBJ", 1,1); } /*----------------------------------------------------------------------------------------------*/ /*! find the first , look in child node return 0 on error @param node (inout) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readbeginOMA(SCSCP_xmlnodeptr* curnode) { return SCSCP_xmlnode_movetotag(curnode, "OMA", 1,1); } /*----------------------------------------------------------------------------------------------*/ /*! find the first , look in child node return 0 on error @param node (inout) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readbeginOMATTR(SCSCP_xmlnodeptr* curnode) { return SCSCP_xmlnode_movetotag(curnode, "OMATTR", 1,1); } /*----------------------------------------------------------------------------------------------*/ /*! find the first , look in child node return 0 on error @param node (inout) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readbeginOMATP(SCSCP_xmlnodeptr* curnode) { return SCSCP_xmlnode_movetotag(curnode, "OMATP", 1,1); } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath Symbol, check the symbol name with symbolname and the CD anme and return the next OpenMath string. return 0 on error @param node (in) current valid node. mustn't be NULL @param value (out) value of the integer */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readpairOMSOMSTR(SCSCP_xmlnodeptr* curnode, const char *cdname, const char *symbolname, const char **buffer) { int res = SCSCP_xmlnode_readcheckOMS(curnode, cdname, symbolname); if (res) res = SCSCP_xmlnode_readOMSTR(curnode, buffer); return res; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath Symbol, check the symbol name with symbolname and the CD anme and return the next OpenMath integer. return 0 on error @param node (in) current valid node. mustn't be NULL @param value (out) value of the integer */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readpairOMSOMIsizet(SCSCP_xmlnodeptr* curnode, const char *cdname, const char *symbolname, size_t *value) { int res = SCSCP_xmlnode_readcheckOMS(curnode, cdname, symbolname); if (res) res = SCSCP_xmlnode_readOMIsizet(curnode, value); return res; } /*----------------------------------------------------------------------------------------------*/ /*! read an OpenMath Symbol, check the symbol name with symbolname and the CD anme and return the next OpenMath integer. return 0 on error @param node (in) current valid node. mustn't be NULL @param value (out) value of the integer */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readpairOMSOMIint(SCSCP_xmlnodeptr* curnode, const char *cdname, const char *symbolname, int *value) { int res = SCSCP_xmlnode_readcheckOMS(curnode, cdname, symbolname); if (res) res = SCSCP_xmlnode_readOMIint(curnode, value); return res; } /*----------------------------------------------------------------------------------------------*/ /*! move the current node pointer to the specified symbol read an OpenMath Symbol, check the symbol name with symbolname and the CD anme return 0 on error @param node (in) current valid node. mustn't be NULL @param value (out) value of the integer */ /*----------------------------------------------------------------------------------------------*/ int SCSCP_xmlnode_readcheckOMS(SCSCP_xmlnodeptr* curnode, const char *cdname, const char *symbolname) { int res = 1; int bfound = 0; SCSCP_debugprint("SCSCP_xmlnode_readcheckOMS(%p,%s, %s ) - enter\n", curnode, cdname, symbolname); while (!bfound && res) { if (SCSCP_xmlnode_movetotag(curnode, "OMS", 0, 0)) { /* check cdname and name */ const char *cdread, *symbolread; if ((res=SCSCP_xmlnode_readOMS(curnode, &cdread, &symbolread))==1) { bfound = (strcmp(cdname,cdread)==0 && strcmp(symbolname, symbolread)==0); } } else { break; /* exit from loop */ } } res = res & bfound; SCSCP_debugprint("SCSCP_xmlnode_readcheckOMS(%p) - returns %d\n", curnode, res); return res; } /*-----------------------------------------------------------------*/ /*!move the current node pointer to the first specified item return true on success @param curnode (inout) iterator on the xml doc @param string (in) string to find @param children (in) = true => look only in the children @param gotochildnode (in) = 0 => return the looking node = 1 => return the first child node */ /*-----------------------------------------------------------------*/ int SCSCP_xmlnode_movetotag(SCSCP_xmlnodeptr* curnode, const char *string, int children, int gotochildnode) { #if SCSCP_PARSERTYPE==SCSCP_PARSERDOM return xmlNodePtr_movetotag(curnode,string, children, gotochildnode); #elif SCSCP_PARSERTYPE==SCSCP_PARSERSAX return SCSCP_omnode_movetotag(curnode,string, children, gotochildnode); #else ... #endif } /*-----------------------------------------------------------------*/ /*!move the current node pointer to the first specified item return true on success @param curnode (inout) iterator on the xml doc @param string (in) string to find @param children (in) = true => look only in the children @param gotochildnode (in) = 0 => return the looking node = 1 => return the first child node */ /*-----------------------------------------------------------------*/ static int xmlNodePtr_movetotag(xmlNodePtr* curnode, const char *string, int children, int gotochildnode) { int res = 0; #if SCSCP_PARSERTYPE==SCSCP_PARSERDOM xmlNodePtr itertmp = *curnode; xmlNodePtr iter = *curnode; SCSCP_debugprint("xmlNodePtr_movetotag(%p,%s,%d) - enter\n", *curnode, string, children); if (children) { if (iter) { if (iter->type==XML_TEXT_NODE) { // cas de texte entre les noeuds SCSCP_xmlnodeptr next = SCSCP_xmlnode_getnext(iter); res = SCSCP_xmlnode_movetotag(&next, string, children, gotochildnode); } else if (iter->type == XML_ELEMENT_NODE) { SCSCP_debugprint("xmlNodePtr_movetotag() - node %s type XML_ELEMENT_NODE \n", iter->name); res = (xmlStrcmp(BAD_CAST string, iter->name)==0); if (res == 0 && xmlStrncasecmp(BAD_CAST "om:", iter->name,3)==0) res = (xmlStrcmp(BAD_CAST string, iter->name+3)==0); } if (!res) { itertmp = SCSCP_xmlnode_getchild(iter); res = SCSCP_xmlnode_movetotag(&itertmp, string, children, gotochildnode); if (res) *curnode = itertmp; } } } else { while (iter!=NULL && !res) { if (iter->type == XML_ELEMENT_NODE) { SCSCP_debugprint("xmlNodePtr_movetotag() - node %s type XML_ELEMENT_NODE \n", iter->name); res = (xmlStrcmp(BAD_CAST string, iter->name)==0); if (res == 0 && xmlStrncasecmp(BAD_CAST "om:", iter->name,3)==0) res = (xmlStrcmp(BAD_CAST string, iter->name+3)==0); } if (!res) iter = SCSCP_xmlnode_getnext(iter); } *curnode = iter; } if (res && gotochildnode) *curnode = SCSCP_xmlnode_getchild(*curnode); #endif /*SCSCP_PARSERTYPE==SCSCP_PARSERDOM*/ SCSCP_debugprint("xmlNodePtr_movetotag(%p,) - returns %d\n", *curnode, res); return res; } /*-----------------------------------------------------------------*/ /*! set the id of the node if the token contains an id using the followed value @param node (inout) node @param token (in) token of the current @param value (in) value of id (only the lenvalue first characters are valid) @param lenvalue (in) valid character of value */ /*-----------------------------------------------------------------*/ static int xmlNodePtr_SetPropID(xmlNodePtr node, unsigned char token, const char *value, int lenvalue) { int retval = 1; if (SCSCP_binary_isidflagset(token)) { retval = xmlNodePtr_SetProp(node, "id", value, lenvalue); } return retval; } /*-----------------------------------------------------------------*/ /*! set the attribute of the node using the value @param node (inout) node @param token (in) token of the current @param name (in) name of the attribute @param value (in) value of id (only the lenvalue first characters are valid) @param lenvalue (in) valid character of value */ /*-----------------------------------------------------------------*/ static int xmlNodePtr_SetProp(xmlNodePtr node, const char *name, const char *value, int lenvalue) { int retval = 1; xmlChar *xmlvalue = xmlCharStrndup(value, lenvalue); if (xmlvalue==NULL) retval=0; else { if (xmlSetProp(node, BAD_CAST name, xmlvalue)==NULL) retval = 0; xmlFree(xmlvalue); } return retval; } /*-----------------------------------------------------------------*/ /*! create a new node inside the document doc. its parent is owner and set its attributes @param doc (inout) XML document to build @param owner (inout) parent node of this object @param token (in) token @param nattr (in) number of elements in attrname and attrvalue @param attrname (in) name of the attributes last one in the array must be "id" @param attrvalue (in) value of the attribute @param attrvaluelen (in) length of the strings of attrvalue */ /*-----------------------------------------------------------------*/ xmlNodePtr xmlNodePtr_inittokenattr(xmlDocPtr doc, xmlNodePtr owner, unsigned char token, int nattr, const char *attrname[], char *attrvalue[], int attrvaluelen[] ) { xmlNodePtr node; int j; SCSCP_debugprint("xmlNodePtr_inittokenattr(,%u,) - enter\n",(unsigned int)token); node = xmlNewChild(owner,NULL, BAD_CAST SCSCP_omnode_namefromtype((SCSCP_omnodetype)SCSCP_binary_gettoken(token)), NULL); if (node && nattr>=1) { int retval=1; for (j=0;jname); } /*----------------------------------------------------------------------------------------------*/ /*! read the content of the current node in the current xml node @param curnode (in) current valid node. mustn't be NULL */ /*----------------------------------------------------------------------------------------------*/ static const char * xmlNodePtr_getcontent(xmlNodePtr curnode) { return xmlChar2char(XML_GET_CONTENT(curnode)); } /*-----------------------------------------------------------------*/ /*! set the content of the node using the value @param doc (inout) document @param node (inout) node @param value (in) value of the content @param lenvalue (in) valid character of value */ /*-----------------------------------------------------------------*/ int xmlNodePtr_setcontent(xmlDocPtr doc, xmlNodePtr node, const char *value, int lenvalue) { xmlNodePtr child = xmlNewTextLen(BAD_CAST value, lenvalue); if (child) { xmlAddChild(node, child); return 1; } else return 0; } /*----------------------------------------------------------------------------------------------*/ /*! get the content of the attribute return 0 on failure and non-zero on success @param attr (in) current attribute. mustn't be NULL @param name (out) name of this attribute @param value (out) value of this attribute */ /*----------------------------------------------------------------------------------------------*/ static int xmlAttrPtr_getvalue(xmlAttrPtr attr, const char **name, const char **value) { *name = xmlChar2char(attr->name); *value = xmlChar2char(attr->children->content); return 1; } /*-----------------------------------------------------------------*/ /*! set the attribute of the node using the value @param doc (inout) document @param node (inout) node @param token (in) token of the current @param name (in) name of the attribute @param value (in) value of id (only the lenvalue first characters are valid) @param lenvalue (in) valid character of value */ /*-----------------------------------------------------------------*/ int xmlNodePtr_setattr(xmlDocPtr doc, xmlNodePtr node, const char *name, const char *value, int lenvalue) { xmlChar *chdup = xmlStrndup(BAD_CAST value, lenvalue); xmlAttrPtr attrptr; if (chdup) { attrptr = xmlNewProp(node,BAD_CAST name, chdup); xmlFree(chdup); return (attrptr!=NULL); } else return 0; } scscp-imcce-1.0.0+ds/src/scscpxmlparser.c000066400000000000000000000204511215622604100203100ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpxmlparser.c \brief parser - support of the xml encoding for OpenMath objects \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010,2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #if HAVE_STRING_H #include #endif #include #include #include #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpdebug.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpxmlparser.h" #include "scscpomdoc.h" /*-----------------------------------------------------------------*/ /*! read a token and choose the appropriate function @param doc (inout) XML document to build @param owner (inout) parent node of this object @param reader (inout) stream reader @param status (inout) status for the document parsing */ /*-----------------------------------------------------------------*/ static SCSCP_xmlnodeptr SCSCP_DOMxmlReadIO_parse(SCSCP_xmldocptr doc, SCSCP_xmlnodeptr owner, xmlTextReaderPtr reader, SCSCP_status* status) { SCSCP_xmlnodeptr node=NULL; int retval; SCSCP_debugprint("SCSCP_DOMxmlReadIO_parse() - enter\n"); retval = xmlTextReaderRead(reader); if (retval) { const xmlChar *name; const xmlChar *value = xmlTextReaderConstValue(reader); int xmltype = xmlTextReaderNodeType(reader); /*printf("read=%s %d\n", xmlTextReaderConstName(reader), xmltype);*/ switch (xmltype) { case XML_READER_TYPE_SIGNIFICANT_WHITESPACE: case XML_READER_TYPE_TEXT: if (SCSCP_xmlnode_setcontent(doc, owner, (const char*)value,strlen((const char*)value))) node = owner; break; case XML_READER_TYPE_ELEMENT: name = xmlTextReaderConstName(reader); SCSCP_debugprint("XML_READER_TYPE_ELEMENT : %s\n", name); node = SCSCP_xmlnode_initname(doc, owner, (const char *)name); if (node) { int havechildren = xmlTextReaderIsEmptyElement(reader); /* content */ if (value!=NULL) SCSCP_xmlnode_setcontent(doc, node, (const char*)value,strlen((const char*)value)); /* attributes */ if (xmlTextReaderHasAttributes(reader)) { if (xmlTextReaderMoveToFirstAttribute(reader)) { do { name = xmlTextReaderConstName(reader); value = xmlTextReaderConstValue(reader); SCSCP_debugprint("attribute : %s %s\n", name, value); SCSCP_xmlnode_setattr(doc, node, (const char *)name, (const char *)value, strlen((const char *)value) ); } while(xmlTextReaderMoveToNextAttribute(reader)==1); } } /* if !empty => parse all children nodes */ if (!havechildren) { SCSCP_xmlnodeptr childnode; do { childnode = SCSCP_DOMxmlReadIO_parse(doc, node, reader, status); } while (/*xmlTextReaderIsValid(reader) &&*/ childnode!=NULL); } } else { SCSCP_debugprint("invalid name= %s => set error = 1\n", name); SCSCP_status_seterror(status, SCSCP_STATUS_OPENMATHNOTVALID); } break; case XML_READER_TYPE_END_ELEMENT: SCSCP_debugprint("end=%s\n", xmlTextReaderConstName(reader)); break; default: SCSCP_debugprint("type= %d other=%s\n", xmltype, xmlTextReaderConstName(reader)); break; } } SCSCP_debugprint("SCSCP_DOMxmlReadIO_parse() - return %p\n", node); return node; } /*-----------------------------------------------------------------*/ /*! read the start statement . provide the user_data to streamread. update the XML document @param doc (inout) XML document to update @param reader (inout) stream reader @param status (inout) status for the document parsing */ /*-----------------------------------------------------------------*/ static SCSCP_xmlnodeptr SCSCP_DOMxmlReadIO_OMOBJ(SCSCP_xmldocptr doc, xmlTextReaderPtr reader, SCSCP_status* status) { int retval; SCSCP_xmlnodeptr rootnode = NULL; SCSCP_xmlnodeptr node = NULL; SCSCP_debugprint("SCSCP_DOMxmlReadIO_OMOBJ() - enter\n"); /* read the start statement */ retval = xmlTextReaderRead(reader); if (retval!=1 || SCSCP_omnode_typefromname((const char *)xmlTextReaderConstName(reader))!=SCSCP_omnodetype_OMOBJ) { SCSCP_debugprint("token=%s retval=%d\n", xmlTextReaderConstName(reader), retval); retval = 0; } else { rootnode = SCSCP_xmlnode_initroottoken(doc, SCSCP_omnodetype_OMOBJ); if (rootnode) { node = SCSCP_DOMxmlReadIO_parse(doc, rootnode, reader, status); } if (!node) {SCSCP_debugprint("clear %p\n",rootnode); SCSCP_xmlnode_clear(rootnode); rootnode = NULL; } } SCSCP_debugprint("SCSCP_DOMxmlReadIO_OMOBJ( %d) - return %p\n", SCSCP_status_is(status), rootnode); return rootnode; } /*-----------------------------------------------------------------*/ /*! read the openmath stream encoded in xml. provide the user_data to streamread. return an XML document @param streamread (in) function to read to stream @param user_data (in) user data (provided to streamread) @param status (inout) status for the document parsing */ /*-----------------------------------------------------------------*/ SCSCP_xmldocptr SCSCP_DOMxmlReadIO(xmlInputReadCallback streamread, SCSCP_status* status, void *user_data) { SCSCP_xmldocptr pdoc = NULL; SCSCP_xmlnodeptr rootnode = NULL; xmlTextReaderPtr reader; SCSCP_debugprint("SCSCP_DOMxmlReadIO() -enter\n"); reader = xmlReaderForIO(streamread,NULL, user_data, NULL, NULL, XML_PARSE_NOERROR|XML_PARSE_NOWARNING| XML_PARSE_NOBLANKS); if (reader) { /* start processing */ pdoc = SCSCP_xmldoc_init((xmlChar*)"1.0"); if (pdoc!=NULL) { rootnode = SCSCP_DOMxmlReadIO_OMOBJ(pdoc, reader, status); /* set root document */ if (rootnode==NULL) { SCSCP_xmldoc_free(pdoc); pdoc =NULL; } else { #if !defined(SCSCP_DISABLE_DEBUG) SCSCP_xmldoc_dump(stdout, pdoc); #endif } } xmlFreeTextReader(reader); } SCSCP_debugprint("SCSCP_DOMxmlReadIO(,%d) - return %p\n", SCSCP_status_is(status), pdoc); return pdoc; } scscp-imcce-1.0.0+ds/src/scscpxmlparser.h000066400000000000000000000053221215622604100203150ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpxmlparser.h \brief parser - support of the xml encoding for OpenMath objects \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010, 2010 M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPXMLPARSER_H__ #define __SCSCPXMLPARSER_H__ #if defined (__cplusplus) extern "C" { #endif /* (__cplusplus) */ SCSCP_xmldocptr SCSCP_DOMxmlReadIO(xmlInputReadCallback streamread, SCSCP_status* status, void *user_data); #if defined (__cplusplus) } #endif #endif /*__SCSCPXMLPARSER_H__*/ scscp-imcce-1.0.0+ds/srcxx/000077500000000000000000000000001215622604100154515ustar00rootroot00000000000000scscp-imcce-1.0.0+ds/srcxx/Makefile.am000066400000000000000000000065241215622604100175140ustar00rootroot00000000000000#/*-----------------------------------------------------------------*/ #/*! # \file Makefile.am # \brief Makefile for automake # \author M. Gastineau # Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. # # Copyright, 2008, 2009, 2010, 2011, 2012, 2013, M. Gastineau, CNRS # email of the author : gastineau@imcce.fr # #*/ #/*-----------------------------------------------------------------*/ # #/*-----------------------------------------------------------------*/ #/* License of this file : # This file is "dual-licensed", you have to choose one of the two licenses # below to apply on this file. # # CeCILL-C # The CeCILL-C license is close to the GNU LGPL. # ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) # # or CeCILL v2.0 # The CeCILL license is compatible with the GNU GPL. # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) # # # This library is governed by the CeCILL-C or the CeCILL license under # French law and abiding by the rules of distribution of free software. # You can use, modify and/ or redistribute the software under the terms # of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA # at the following URL "http://www.cecill.info". # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # In this respect, the user's attention is drawn to the risks associated # with loading, using, modifying and/or developing or reproducing the # software by the user in light of its specific status of free software, # that may mean that it is complicated to manipulate, and that also # therefore means that it is reserved for developers and experienced # professionals having in-depth computer knowledge. Users are therefore # encouraged to load and test the software's suitability as regards their # requirements in conditions enabling the security of their systems and/or # data to be ensured and, more generally, to use and operate it in the # same conditions as regards security. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-C or CeCILL license and that you accept its terms. # */ # /*-----------------------------------------------------------------*/ ## Makefile.am -- Process this file with automake to produce Makefile.in # # skeleton for Makefile # lib_LTLIBRARIES = libscscpxx.la AM_CPPFLAGS = -I$(top_srcdir)/src $(XML_CPPFLAGS) libscscpxx_la_LD_VERSION_SCRIPT= if HAVE_LD_VERSION_SCRIPT libscscpxx_la_LD_VERSION_SCRIPT+= -Wl,--version-script=$(top_srcdir)/srcxx/scscpxx.sym endif ################################################################### # library libscscpxx.la ################################################################### libscscpxx_la_LIBADD = $(top_builddir)/src/libscscp.la $(XML_LIBS) libscscpxx_la_LDFLAGS = -version-info $(LIBSCSCP_LT_VERSION) $(libscscpxx_la_LD_VERSION_SCRIPT) libscscpxx_la_SOURCES = scscpclientxx.cpp scscpcomputationxx.cpp scscpstream.cpp \ scscpexception.cpp scscpserverxx.cpp noinst_HEADERS= scscpstream.h include_HEADERS = scscpxx.h EXTRA_DIST = Makefile.vc scscpxx.sym scscp-imcce-1.0.0+ds/srcxx/scscpclientxx.cpp000066400000000000000000000137321215622604100210550ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpclientxx.cpp \brief C++ client over file or socket \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010, 2011, 2012 M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #include #include "scscpxx.h" namespace SCSCP { /*-----------------------------------------------------------------*/ /*! Default constructor */ /*-----------------------------------------------------------------*/ Client::Client() { m_status = SCSCP_STATUS_INITIALIZER; SCSCP_sc_init(&m_client, &m_status, SCSCP_PROTOCOL_VERSION_1_3, SCSCP_PROTOCOL_VERSION_1_2, NULL); } /*-----------------------------------------------------------------*/ /*! destructor */ /*-----------------------------------------------------------------*/ Client::~Client() { SCSCP_sc_clear(&m_client, &m_status); SCSCP_status_clear(&m_status); } /*-----------------------------------------------------------------*/ /*! connect the client to a server on the specified host and port @param machine (in) computer name or IP address @param port (in) port on the remote computer */ /*-----------------------------------------------------------------*/ int Client::connect( const char *machine, int port) throw (Exception) { int res; res = SCSCP_sc_connect(&m_client, machine, port, &m_status); if (!res) throw Exception(&m_status); return res; } /*-----------------------------------------------------------------*/ /*! close the connection of the client to a server previously opened by SCSCP_sc_connect @param machine (in) computer name or IP address @param port (in) port on the remote computer */ /*-----------------------------------------------------------------*/ int Client::close() throw (Exception) { int res; res = SCSCP_sc_close(&m_client, &m_status); if (res==0 && SCSCP_status_is(&m_status)==SCSCP_STATUS_RECVQUIT) { res=1; } if (!res) throw Exception(&m_status); return res; } /*-----------------------------------------------------------------*/ /*! return true if the conection is closed */ /*-----------------------------------------------------------------*/ bool Client::eof() const { return (SCSCP_status_is(&m_status)==SCSCP_STATUS_RECVQUIT); } /*-----------------------------------------------------------------*/ /*! set the status of the client */ /*-----------------------------------------------------------------*/ void Client::set_status(SCSCP_status* status) { SCSCP_status_copy(&m_status, status); } /*-----------------------------------------------------------------*/ /*! Default constructor client (inout) incoming client on the server side (not duplicated) */ /*-----------------------------------------------------------------*/ IncomingClient::IncomingClient(SCSCP_incomingclient* client) : m_client(*client) { m_status = SCSCP_STATUS_INITIALIZER; } /*-----------------------------------------------------------------*/ /*! destructor */ /*-----------------------------------------------------------------*/ IncomingClient::~IncomingClient() { SCSCP_sc_clear(&m_client, &m_status); SCSCP_status_clear(&m_status); } /*-----------------------------------------------------------------*/ /*! return true if the conection is closed */ /*-----------------------------------------------------------------*/ bool IncomingClient::eof() const { return (SCSCP_status_is(&m_status)==SCSCP_STATUS_RECVQUIT); } /*-----------------------------------------------------------------*/ /*! set the status of the client */ /*-----------------------------------------------------------------*/ void IncomingClient::set_status(SCSCP_status* status) { SCSCP_status_copy(&m_status, status); } } /*namespace SCSCP*/ scscp-imcce-1.0.0+ds/srcxx/scscpcomputationxx.cpp000066400000000000000000000623111215622604100221360ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpcomputationxx.cpp \brief C++ computation \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009,2010,2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #include #if HAVE_STRING_H #include #endif #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpprocedurecall.h" #include "scscpprocedurecompleted.h" #include "scscpdebug.h" #include "scscpomdoc.h" #include "scscpbinary.h" #include "scscpxmlparser.h" #include "scscpxx.h" namespace SCSCP { #include "scscpstream.h" /*-----------------------------------------------------------------*/ /*! Default constructor */ /*-----------------------------------------------------------------*/ ProcedureCall::ProcedureCall(Client& session) throw (Exception) : m_client(&session.m_client), m_clientsession(&session), m_serversession(NULL), m_postream(NULL), m_punfostream(NULL), m_punfistream(NULL) { m_status = SCSCP_STATUS_INITIALIZER; if (!SCSCP_co_init(&m_calloptions, &m_status)) throw Exception(&m_status); if (!SCSCP_ro_init(&m_returnoptions, &m_status)) throw Exception(&m_status); } /*-----------------------------------------------------------------*/ /*! Default constructor */ /*-----------------------------------------------------------------*/ ProcedureCall::ProcedureCall(IncomingClient& session) throw (Exception) : m_client(&session.m_client), m_clientsession(NULL), m_serversession(&session), m_postream(NULL), m_punfostream(NULL), m_punfistream(NULL) { m_status = SCSCP_STATUS_INITIALIZER; if (!SCSCP_co_init(&m_calloptions, &m_status)) throw Exception(&m_status); if (!SCSCP_ro_init(&m_returnoptions, &m_status)) throw Exception(&m_status); } /*-----------------------------------------------------------------*/ /*! destructor */ /*-----------------------------------------------------------------*/ ProcedureCall::~ProcedureCall() { SCSCP_debugprint("ProcedureCall::~ProcedureCall() -enter\n"); SCSCP_co_clear(&m_calloptions, &m_status); SCSCP_ro_clear(&m_returnoptions, &m_status); SCSCP_status_clear(&m_status); if (m_postream) { delete m_postream; m_postream = NULL; } if (m_punfostream) { delete m_punfostream; m_punfostream = NULL; } if (m_punfistream) { delete m_punfistream; m_punfistream = NULL; } SCSCP_debugprint("ProcedureCall::~ProcedureCall() - return\n"); } /*-----------------------------------------------------------------*/ /*! set the runtime limit @param p_time (in) runtime limit */ /*-----------------------------------------------------------------*/ int ProcedureCall::set_runtimelimit(size_t p_time) { return SCSCP_co_set_runtimelimit(&m_calloptions, p_time, &m_status); } /*-----------------------------------------------------------------*/ /*! get the runtime limit if the runtime limit is unknown => it returns 0 @param p_time (out) runtime limit */ /*-----------------------------------------------------------------*/ int ProcedureCall::get_runtimelimit(size_t& p_time) { return SCSCP_co_get_runtimelimit(&m_calloptions, &p_time, &m_status); } /*-----------------------------------------------------------------*/ /*! set the minimal memory @param memsize (in) minimal memory required */ /*-----------------------------------------------------------------*/ int ProcedureCall::set_minmemory(size_t memsize) { return SCSCP_co_set_minmemory(&m_calloptions, memsize, &m_status); } /*-----------------------------------------------------------------*/ /*! get the minimal memory if the minimal memory is unknown => it returns 0 @param memsize (out) minimal memory required */ /*-----------------------------------------------------------------*/ int ProcedureCall::get_minmemory(size_t& memsize) { return SCSCP_co_get_minmemory(&m_calloptions, &memsize, &m_status); } /*-----------------------------------------------------------------*/ /*! set the maximal memory @param options (inout) options @param memsize (in) maximal memory required @param status (inout) status error */ /*-----------------------------------------------------------------*/ int ProcedureCall::set_maxmemory(size_t memsize) { return SCSCP_co_set_maxmemory(&m_calloptions, memsize, &m_status); } /*-----------------------------------------------------------------*/ /*! get the maximal memory if the minimal memory is unknown => it returns 0 @param memsize (out) maximal memory required */ /*-----------------------------------------------------------------*/ int ProcedureCall::get_maxmemory(size_t& memsize) { return SCSCP_co_get_maxmemory(&m_calloptions, &memsize, &m_status); } /*-----------------------------------------------------------------*/ /*! set the debug level @param debuglevel (in) debug level */ /*-----------------------------------------------------------------*/ int ProcedureCall::set_debuglevel(int debuglevel) { return SCSCP_co_set_debuglevel(&m_calloptions, debuglevel, &m_status); } /*-----------------------------------------------------------------*/ /*! get the debug level if the minimal memory is unknown => it returns 0 @param debuglevel (out) debug level */ /*-----------------------------------------------------------------*/ int ProcedureCall::get_debuglevel(int& debuglevel) { return SCSCP_co_get_debuglevel(&m_calloptions, &debuglevel, &m_status); } /*-----------------------------------------------------------------*/ /*! set the current encoding for the OpenMath objects @param encodingtype (in) new encoding (XML or binary) */ /*-----------------------------------------------------------------*/ int ProcedureCall::set_encodingtype(SCSCP_encodingtype encodingtype) { return SCSCP_sc_set_encodingtype(m_client, encodingtype, &m_status); } /*-----------------------------------------------------------------*/ /*! get the current encoding for the OpenMath objects @param encodingtype (out) current encoding (XML or binary) */ /*-----------------------------------------------------------------*/ int ProcedureCall::get_encodingtype(SCSCP_encodingtype& encoding) { return SCSCP_sc_get_encodingtype(m_client, &encoding, &m_status); } /*-----------------------------------------------------------------*/ /*! get the return type of the procedure call @param returntype (out) return type */ /*-----------------------------------------------------------------*/ int ProcedureCall::get_returntype(SCSCP_option_return& returntype) { return SCSCP_co_get_returntype(&m_calloptions, &returntype, &m_status); } /*-----------------------------------------------------------------*/ /*! get the call id @param callid (out) string of the call id */ /*-----------------------------------------------------------------*/ int ProcedureCall::get_callid(const char*& callid) { return SCSCP_co_get_callid(&m_calloptions, &callid, &m_status); } /*-----------------------------------------------------------------*/ /*! set the runtime usage @param time (in) time usage */ /*-----------------------------------------------------------------*/ int ProcedureCall::set_runtime(size_t p_time) { return SCSCP_ro_set_runtime(&m_returnoptions, p_time, &m_status); } /*-----------------------------------------------------------------*/ /*! get the runtime usage if the runtime usage is unknown => it returns 0 @param time (out) time usage. can't be NULL */ /*-----------------------------------------------------------------*/ int ProcedureCall::get_runtime(size_t& p_time) { return SCSCP_ro_get_runtime(&m_returnoptions, &p_time, &m_status); } /*-----------------------------------------------------------------*/ /*! set the memory usage @param options (inout) options @param memsize (in) memory usage @param status (inout) status error */ /*-----------------------------------------------------------------*/ int ProcedureCall::set_memory(size_t mem) { return SCSCP_ro_set_memory(&m_returnoptions, mem, &m_status); } /*-----------------------------------------------------------------*/ /*! get the memory usage if the runtime usage is unknown => it returns 0 @param memsize (out) memory usage. can't be NULL */ /*-----------------------------------------------------------------*/ int ProcedureCall::get_memory(size_t& mem) { return SCSCP_ro_get_memory(&m_returnoptions, &mem, &m_status); } /*-----------------------------------------------------------------*/ /*! set the information message @param buffer (in) string buffer */ /*-----------------------------------------------------------------*/ int ProcedureCall::set_message(const char *buffer) { return SCSCP_ro_set_message(&m_returnoptions, buffer, &m_status); } /*-----------------------------------------------------------------*/ /*! get the information message if the runtime usage is unknown => it returns 0 @param buffer (out) string buffer */ /*-----------------------------------------------------------------*/ int ProcedureCall::get_message(const char *& buffer) { return SCSCP_ro_get_message(&m_returnoptions, &buffer, &m_status); } /*-----------------------------------------------------------------*/ /*! flush the output stream */ /*-----------------------------------------------------------------*/ void ProcedureCall::flushostream() { if (m_postream) { m_postream->flush(); delete m_postream; m_postream = NULL; } if (m_punfostream) { delete m_punfostream; m_punfostream = NULL; } } /*-----------------------------------------------------------------*/ /*! create an output unformatted stream */ /*-----------------------------------------------------------------*/ Ounfstream* ProcedureCall::createounfstream() throw() { m_punfostream = new Ounfstream(m_client, &m_status); return m_punfostream; } /*-----------------------------------------------------------------*/ /*! create an output unformatted stream */ /*-----------------------------------------------------------------*/ Ofmtstream* ProcedureCall::createofmtstream() throw() { m_postream = new Ofmtstream(m_client, &m_status); return m_postream; } /*-----------------------------------------------------------------*/ /*! create an input unformatted stream @param node (inout) root node of the stream */ /*-----------------------------------------------------------------*/ Iunfstream* ProcedureCall::createiunfstream(SCSCP_xmlnodeptr node) throw() { m_punfistream = new Iunfstream( node, &m_status); return m_punfistream; } /*-----------------------------------------------------------------*/ /*! send a information message @param buffer (inout) message */ /*-----------------------------------------------------------------*/ int ProcedureCall::sendinfomessage(const char *buffer) { return SCSCP_sc_infomessagesend(get_client(),buffer,&m_status); } /*-----------------------------------------------------------------*/ /*! report error if res=0 and raise an exception @param res (in) value of the previous call */ /*-----------------------------------------------------------------*/ void ProcedureCall::report_error(int res) throw(Exception) { if (!res) { if (SCSCP_status_is(&m_status)==SCSCP_STATUS_RECVQUIT) { if (m_serversession) m_serversession->set_status(&m_status); if (m_clientsession) m_clientsession->set_status(&m_status); } throw Exception(&m_status); } } /*-----------------------------------------------------------------*/ /*! Default constructor */ /*-----------------------------------------------------------------*/ ClientComputation::ClientComputation(Client& session) throw (Exception) : ProcedureCall(session) { } /*-----------------------------------------------------------------*/ /*! destructor */ /*-----------------------------------------------------------------*/ ClientComputation::~ClientComputation() { } /*-----------------------------------------------------------------*/ /*! perform a procedure call : send an openmath buffer to the server @param openmathbuffer (in) openmath buffer @param lenbuffer (in) number of valid bytes in openmathbuffer @param returntype (in) return type of the call */ /*-----------------------------------------------------------------*/ int ClientComputation::send(const char *openmathbuffer, size_t lenbuffer, SCSCP_option_return returntype) throw (Exception) { int res; res = SCSCP_co_set_returntype(get_calloptions(),returntype, get_status()); if (res) res = SCSCP_sc_callsendstr(get_client(), get_calloptions(), openmathbuffer, get_status()); report_error(res); return res; } /*-----------------------------------------------------------------*/ /*! wait and receive an answer of a procedure call from the server @param openmathbuffer (out) openmath result @param lenbuffer (out) number of valid bytes in openmathbuffer @param msgtype (out) type of the answer */ /*-----------------------------------------------------------------*/ int ClientComputation::recv(SCSCP_msgtype& msgtype, char*& openmathbuffer, size_t& lenbuffer) throw (Exception) { char *cdnameerr; char *symbolnameerr; char *msg; int res; res = SCSCP_sc_callrecvheader(get_client(), get_returnoptions(), &msgtype, get_status()); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureCompleted : res = SCSCP_sc_callrecvcompleted(get_client() , &openmathbuffer, get_status()); lenbuffer = ::strlen(openmathbuffer); break; case SCSCP_msgtype_ProcedureTerminated : if (res) res = SCSCP_sc_callrecvterminated(get_client(), &cdnameerr, &symbolnameerr, &msg, get_status()); lenbuffer = 0; SCSCP_status_setexecfailed(get_status(), cdnameerr, symbolnameerr, msg); res = 0; break; default : openmathbuffer = NULL; lenbuffer=0; break; } } report_error(res); return res; } /*-----------------------------------------------------------------*/ /*! perform a procedure call : send an openmath buffer to the server It returns a stream. The application will write Openmath expression in the stream. .e.g: stream<<"1"; @param returntype (in) return type of the call @param pstream (out) pointer to a stream */ /*-----------------------------------------------------------------*/ int ClientComputation::send(SCSCP_option_return returntype, std::ostream*& pstream) throw (Exception) { int res = SCSCP_co_set_returntype(get_calloptions(),returntype, get_status()); if (res) res = SCSCP_procedurecall_write_start(get_client() , *get_calloptions(), get_status()); if (res) { pstream = createofmtstream(); } else { pstream = NULL; report_error(res); } return res; } /*-----------------------------------------------------------------*/ /*! perform a procedure call : unformatted output to the server It returns a stream. The application will write baisc objects (int, str, OMobject) in the stream. .e.g: stream<1"; return 0 on error @param returntype (in) return type of the call */ /*-----------------------------------------------------------------*/ int ServerComputation::sendcompleted(std::ostream*& stream) throw (Exception) { int res; stream = NULL; res = SCSCP_procedurecompleted_write_start(get_client() , *get_returnoptions(), get_status()); if (res) { stream = createofmtstream(); } else { report_error(res); } return res; } /*-----------------------------------------------------------------*/ /*! send a completed message using a stream to the client (format to OpenMath) It returns a stream. The application will write baisc objects (int, str, OMobject) in the stream. .e.g: stream< #endif /*HAVE_CONFIG_H*/ #include #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpprocedurecall.h" #include "scscpdebug.h" #include "scscpomdoc.h" #include "scscpbinary.h" #include "scscpxmlparser.h" #include "scscpxx.h" namespace SCSCP { #include "scscpstream.h" /*-----------------------------------------------------------------*/ /*! constructor @param stream (inout) socket stream (not NULL) @param status (inout) status error (not NULL) */ /*-----------------------------------------------------------------*/ Exception::Exception(const SCSCP_status* status) { m_status = SCSCP_STATUS_INITIALIZER; SCSCP_status_copy(&m_status, status); } /*-----------------------------------------------------------------*/ /*! constructor @param e (in) exception */ /*-----------------------------------------------------------------*/ Exception::Exception(const Exception& e) { m_status = SCSCP_STATUS_INITIALIZER; SCSCP_status_copy(&m_status, &e.m_status); } /*-----------------------------------------------------------------*/ /*! destructor */ /*-----------------------------------------------------------------*/ Exception::~Exception() throw () { SCSCP_status_clear(&m_status); } /*-----------------------------------------------------------------*/ /*! information about the error */ /*-----------------------------------------------------------------*/ const char * Exception::what() const throw() { return SCSCP_status_strerror(&m_status); } } /* namespace SCSCP */ scscp-imcce-1.0.0+ds/srcxx/scscpserverxx.cpp000066400000000000000000000122701215622604100211010ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpserverxx.cpp \brief C++ server over file or socket \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009,2010,2011,2012,2013 M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #include #define __SCSCP_WITHIN_SCSCP #include "scscpxx.h" #include "scscpdebug.h" #include "scscpfileserver.h" namespace SCSCP { /*-----------------------------------------------------------------*/ /*! Default constructor @param servicename (in) service name @param serviceversion (in) service version @param serviceid (in) service id */ /*-----------------------------------------------------------------*/ Server::Server(const char* servicename, const char* serviceversion, const char* serviceid) { m_status = SCSCP_STATUS_INITIALIZER; SCSCP_ss_init(&m_server, &m_status, servicename, serviceversion, serviceid, SCSCP_PROTOCOL_VERSION_1_3, SCSCP_PROTOCOL_VERSION_1_2, NULL); } /*-----------------------------------------------------------------*/ /*! destructor */ /*-----------------------------------------------------------------*/ Server::~Server() { SCSCP_ss_clear(&m_server, &m_status); SCSCP_status_clear(&m_status); } /*-----------------------------------------------------------------*/ /*! the object server listen on the specified port @param port (in) port number */ /*-----------------------------------------------------------------*/ int Server::listen(int port) throw (Exception) { int res; res = SCSCP_ss_listen(&m_server, port, 1, &m_status); if (!res) throw Exception(&m_status); return res; } /*-----------------------------------------------------------------*/ /*! the object server terminates to listen */ /*-----------------------------------------------------------------*/ int Server::close() throw (Exception) { int res; res = SCSCP_ss_close(&m_server, &m_status); if (!res) throw Exception(&m_status); return res; } /*-----------------------------------------------------------------*/ /*! waits for an incoming connection and accepts a incoming client connection */ /*-----------------------------------------------------------------*/ IncomingClient* Server::acceptclient() throw (Exception) { int res; IncomingClient *pclient = NULL; SCSCP_incomingclient incomingclient; SCSCP_debugprint("Server::acceptclient() - enter\n"); res = SCSCP_ss_acceptclient(&m_server, &incomingclient, &m_status); if (!res) { throw Exception(&m_status); } else { pclient = new IncomingClient(&incomingclient); } SCSCP_debugprint("Server::acceptclient() - return %p\n", pclient); return pclient; } /*-----------------------------------------------------------------*/ /*! return the port used by the server. If listen was not called, the function returns -1. */ /*-----------------------------------------------------------------*/ int Server::getport() { return SCSCP_ss_getport(&m_server); } } /*namespace SCSCP*/ scscp-imcce-1.0.0+ds/srcxx/scscpstream.cpp000066400000000000000000000537001215622604100205110ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpstream.cpp \brief Stream implementation \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009,2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #if HAVE_WINDOWS_H #include #endif /*HAVE_CONFIG_H*/ #include #if HAVE_STRING_H #include #endif #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpinternal.h" #include "scscpfileclient.h" #include "scscpfileserver.h" #include "scscpprocedurecall.h" #include "scscpdebug.h" #include "scscpomdoc.h" #include "scscpbinary.h" #include "scscpxmlparser.h" #include "scscpxx.h" namespace SCSCP { #include "scscpstream.h" /*-----------------------------------------------------------------*/ /*! constructor @param stream (inout) socket stream (not NULL) @param status (inout) status error (not NULL) */ /*-----------------------------------------------------------------*/ Ofmtstreambuffer::Ofmtstreambuffer( SCSCP_io* stream, SCSCP_status *status) : m_stream(stream), m_status(status), m_inbuffer(new char[SCSCP_PI_MAXLENBUFFER]), m_outbuffer(new char[SCSCP_PI_MAXLENBUFFER]) { setg(0, 0, 0); setp(m_outbuffer, m_outbuffer + SCSCP_PI_MAXLENBUFFER - 1); } /*-----------------------------------------------------------------*/ /*! destructor */ /*-----------------------------------------------------------------*/ Ofmtstreambuffer::~Ofmtstreambuffer() { delete [] m_inbuffer; delete [] m_outbuffer; } /*-----------------------------------------------------------------*/ /*! overload overflow of basic_streambuf put characters to sockets */ /*-----------------------------------------------------------------*/ int Ofmtstreambuffer::overflow( int c) { char* ibegin = this->m_outbuffer; char* iend = this->pptr(); /* add eof at the end */ if(!traits_type::eq_int_type(c, traits_type::eof())) { *iend++ = traits_type::to_char_type(c); } /*reset the new empty data */ setp(m_outbuffer, m_outbuffer + SCSCP_PI_MAXLENBUFFER - 1); int_type ilen = iend - ibegin; /* write the data to the socket */ SCSCP_io_writelen(m_stream, m_outbuffer, ilen, m_status); return traits_type::not_eof(c); } /*-----------------------------------------------------------------*/ /*! overload underflow of basic_streambuf get characters from sockets */ /*-----------------------------------------------------------------*/ int Ofmtstreambuffer::underflow() { // data from socket std::streamsize len = 0; /*std::streamsize len = SCSCP_io_read(m_stream, SCSCP_PI_MAXLENBUFFER);*/ //set the new valid data setg(m_inbuffer, m_inbuffer, m_inbuffer + len); // nothing was read => eof if(len == 0) return traits_type::eof(); // return the first character return traits_type::not_eof(m_inbuffer[0]); } /*-----------------------------------------------------------------*/ /*! overload sync of basic_streambuf */ /*-----------------------------------------------------------------*/ int Ofmtstreambuffer::sync() { return traits_type::eq_int_type(overflow(traits_type::eof()), traits_type::eof()) ? -1 : 0; } /*-----------------------------------------------------------------*/ /*! constructor @param stream (inout) socket stream (not NULL) @param status (inout) status error (not NULL) */ /*-----------------------------------------------------------------*/ Ounfstream::Ounfstream(SCSCP_io* stream, SCSCP_status* status) : m_stream(stream), m_status(status) { } /*-----------------------------------------------------------------*/ /*! destructor */ /*-----------------------------------------------------------------*/ Ounfstream::~Ounfstream() { } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : write the beginning of an OpenMath Application @param out (inout) SCSCP stream */ /*-----------------------------------------------------------------*/ Ounfstream& beginOMA(Ounfstream& out) throw (Exception) { int res = SCSCP_io_writebeginOMA(out.m_stream,NULL, out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : write the end of an OpenMath Application @param out (inout) SCSCP stream */ /*-----------------------------------------------------------------*/ Ounfstream& endOMA(Ounfstream& out) throw (Exception) { int res = SCSCP_io_writeendOMA(out.m_stream,out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : write the beginning of an OpenMath ATP @param out (inout) SCSCP stream */ /*-----------------------------------------------------------------*/ Ounfstream& beginOMATP(Ounfstream& out) throw (Exception) { int res = SCSCP_io_writebeginOMATP(out.m_stream,NULL, out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : write the end of an OpenMath ATP @param out (inout) SCSCP stream */ /*-----------------------------------------------------------------*/ Ounfstream& endOMATP(Ounfstream& out) throw (Exception) { int res = SCSCP_io_writeendOMATP(out.m_stream,out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : write the beginning of an OpenMath ATTR @param out (inout) SCSCP stream */ /*-----------------------------------------------------------------*/ Ounfstream& beginOMATTR(Ounfstream& out) throw (Exception) { int res = SCSCP_io_writebeginOMATTR(out.m_stream,NULL, out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : write the end of an OpenMath ATTR @param out (inout) SCSCP stream */ /*-----------------------------------------------------------------*/ Ounfstream& endOMATTR(Ounfstream& out) throw (Exception) { int res = SCSCP_io_writeendOMATTR(out.m_stream,out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : write the beginning of an OpenMath error @param out (inout) SCSCP stream */ /*-----------------------------------------------------------------*/ Ounfstream& beginOME(Ounfstream& out) throw (Exception) { int res = SCSCP_io_writebeginOME(out.m_stream,NULL, out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : write the end of an OpenMath error @param out (inout) SCSCP stream */ /*-----------------------------------------------------------------*/ Ounfstream& endOME(Ounfstream& out) throw (Exception) { int res = SCSCP_io_writeendOME(out.m_stream,out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : write the beginning of an OpenMath object @param out (inout) SCSCP stream */ /*-----------------------------------------------------------------*/ Ounfstream& beginOMOBJ(Ounfstream& out) throw (Exception) { int res = SCSCP_io_writebeginOMOBJ(out.m_stream,out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : write the end of an OpenMath object @param out (inout) SCSCP stream */ /*-----------------------------------------------------------------*/ Ounfstream& endOMOBJ(Ounfstream& out) throw (Exception) { int res = SCSCP_io_writeendOMOBJ(out.m_stream,out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert x in a Openmath format @param pf (in) pointer function */ /*-----------------------------------------------------------------*/ Ounfstream& Ounfstream::operator<< (Ounfstream& ( *pf )(Ounfstream&) ) { return pf(*this); } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert x in a Openmath format @param out (inout) SCSCP stream @param x (in) value */ /*-----------------------------------------------------------------*/ Ounfstream& operator <<(Ounfstream& out, int x) throw (Exception) { int res = SCSCP_io_writeOMIint(out.m_stream,x, NULL, out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert x in a Openmath format @param out (inout) SCSCP stream @param x (in) value */ /*-----------------------------------------------------------------*/ Ounfstream& operator <<(Ounfstream& out, double x) throw (Exception) { int res = SCSCP_io_writeOMFdouble(out.m_stream,x, NULL, out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert str in a Openmath format @param out (inout) SCSCP stream @param str(in) value */ /*-----------------------------------------------------------------*/ Ounfstream& operator <<(Ounfstream& out, const char* str) throw (Exception) { int res = SCSCP_io_writeOMSTR(out.m_stream,str, NULL, out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert x in a Openmath format @param out (inout) SCSCP stream @param x (in) value */ /*-----------------------------------------------------------------*/ Ounfstream& operator <<(Ounfstream& out, const OMF& x) throw (Exception) { int res = SCSCP_io_writeOMFstr(out.m_stream, x.get_value(), x.get_id(), out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert x in a Openmath format @param out (inout) SCSCP stream @param x (in) value */ /*-----------------------------------------------------------------*/ Ounfstream& operator <<(Ounfstream& out, const OMI& x) throw (Exception) { int res = SCSCP_io_writeOMIstr(out.m_stream, x.get_value(), x.get_id(), out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert x in a Openmath format @param out (inout) SCSCP stream @param x (in) value */ /*-----------------------------------------------------------------*/ Ounfstream& operator <<(Ounfstream& out, const OMS& x) throw (Exception) { int res = SCSCP_io_writeOMS(out.m_stream, x.get_cdname(), x.get_symbolname(), x.get_id(), out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert x in a Openmath format @param out (inout) SCSCP stream @param x (in) value */ /*-----------------------------------------------------------------*/ Ounfstream& operator <<(Ounfstream& out, const OMR& x) throw (Exception) { int res = SCSCP_io_writeOMR(out.m_stream, x.get_reference(),out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert x in a Openmath format @param out (inout) SCSCP stream @param x (in) value */ /*-----------------------------------------------------------------*/ Ounfstream& operator <<(Ounfstream& out, const OMV& x) throw (Exception) { int res = SCSCP_io_writeOMV(out.m_stream, x.get_name(), x.get_id(), out.m_status); if (!res) throw Exception(out.m_status); return out; } /*-----------------------------------------------------------------*/ /*! constructor @param attr (inout) first attributes */ /*-----------------------------------------------------------------*/ Iunfstream_iterator_attr::Iunfstream_iterator_attr(SCSCP_xmlattrptr attr) : m_attr(attr) {} /*-----------------------------------------------------------------*/ /*! jump to the next attribute */ /*-----------------------------------------------------------------*/ void Iunfstream_iterator_attr::operator++() { m_attr = SCSCP_xmlattr_getnext(m_attr); } /*-----------------------------------------------------------------*/ /*! get the name of the attribute */ /*-----------------------------------------------------------------*/ const char * Iunfstream_iterator_attr::get_name() const { const char *name, *value; if (m_attr && SCSCP_xmlattr_getvalue(m_attr,&name,&value)) { return name; } else { return NULL; } } /*-----------------------------------------------------------------*/ /*! get the name of the attribute */ /*-----------------------------------------------------------------*/ const char * Iunfstream_iterator_attr::get_value() const { const char *name, *value; if (m_attr && SCSCP_xmlattr_getvalue(m_attr,&name,&value)) { return value; } else { return NULL; } } /*-----------------------------------------------------------------*/ /*! constructor @param node (inout) node stream (not NULL) @param status (inout) status error (not NULL) */ /*-----------------------------------------------------------------*/ Iunfstream::Iunfstream(SCSCP_xmlnodeptr node, SCSCP_status* status) : m_node(node), m_status(status) { } /*-----------------------------------------------------------------*/ /*! constructor */ /*-----------------------------------------------------------------*/ Iunfstream::Iunfstream() : m_node(NULL), m_status(NULL) { } /*-----------------------------------------------------------------*/ /*! destructor */ /*-----------------------------------------------------------------*/ Iunfstream::~Iunfstream() { } /*-----------------------------------------------------------------*/ /*! get the type of the current node */ /*-----------------------------------------------------------------*/ Iunfstream::omtype Iunfstream::get_type() const { return SCSCP_xmlnode_getexternaltype(m_node); } /*-----------------------------------------------------------------*/ /*! get the name of the current node */ /*-----------------------------------------------------------------*/ const char* Iunfstream::get_typename() const { return SCSCP_xmlnode_getname(m_node); } /*-----------------------------------------------------------------*/ /*! get the content of the current node */ /*-----------------------------------------------------------------*/ const char* Iunfstream::get_content() const { return SCSCP_xmlnode_getcontent(m_node); } /*-----------------------------------------------------------------*/ /*! get the list of attributes of the current node */ /*-----------------------------------------------------------------*/ Iunfstream::iterator_attr Iunfstream::get_attr() { return SCSCP_xmlnode_getattr(m_node); } /*-----------------------------------------------------------------*/ /*! return the stream to parse the content of a derived OM */ /*-----------------------------------------------------------------*/ Iunfstream Iunfstream::beginOM() { if (eof()) { return Iunfstream(NULL, m_status); } else { SCSCP_xmlnodeptr pnode = SCSCP_xmlnode_getchild(m_node); m_node = SCSCP_xmlnode_getnext(m_node); return Iunfstream(pnode, m_status); } } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert the current OpenMath node to x @param x (out) value */ /*-----------------------------------------------------------------*/ Iunfstream& Iunfstream::operator >>(int& x) throw (Exception) { int res = SCSCP_xmlnode_readOMIint(&m_node, &x); if (!res) throw Exception(m_status); return *this; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert the current OpenMath node to x @param x (out) value */ /*-----------------------------------------------------------------*/ Iunfstream& Iunfstream::operator >>(double& x) throw (Exception) { int res = SCSCP_xmlnode_readOMFdouble(&m_node, &x); if (!res) throw Exception(m_status); return *this; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert the current OpenMath node to str @param str (out) value */ /*-----------------------------------------------------------------*/ Iunfstream& Iunfstream::operator >>( const char*& str) throw (Exception) { int res = SCSCP_xmlnode_readOMSTR(&m_node, &str); if (!res) throw Exception(m_status); return *this; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert the current OpenMath node to x @param x (out) value */ /*-----------------------------------------------------------------*/ Iunfstream& Iunfstream::operator >>(OMI& x) throw (Exception) { const char * value; const char * id; id = SCSCP_xmlnode_getid(m_node); int res = SCSCP_xmlnode_readOMIstr(&m_node, &value); if (!res) throw Exception(m_status); else { x.set_value(value); x.set_id(id); } return *this; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert the current OpenMath node to x @param x (out) value */ /*-----------------------------------------------------------------*/ Iunfstream& Iunfstream::operator >>(OMF& x) throw (Exception) { const char * value; int base; const char * id; id = SCSCP_xmlnode_getid(m_node); int res = SCSCP_xmlnode_readOMFstr(&m_node, &value, &base); if (!res) throw Exception(m_status); else { x.set_value(value, base); x.set_id(id); } return *this; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert the current OpenMath node to x @param x (out) value */ /*-----------------------------------------------------------------*/ Iunfstream& Iunfstream::operator >>(OMS& x) throw (Exception) { const char * cdname; const char * symbolname; const char * id; id = SCSCP_xmlnode_getid(m_node); int res = SCSCP_xmlnode_readOMS(&m_node, &cdname, &symbolname); if (!res) throw Exception(m_status); else { x.set_symbolname(symbolname); x.set_cdname(cdname); x.set_id(id); } return *this; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert the current OpenMath node to x @param x (out) value */ /*-----------------------------------------------------------------*/ Iunfstream& Iunfstream::operator >>(OMR& x) throw (Exception) { const char * href; int res = SCSCP_xmlnode_readOMR(&m_node, &href); if (!res) throw Exception(m_status); else x.set_reference(href); return *this; } /*-----------------------------------------------------------------*/ /*! unformatted stream operation : convert the current OpenMath node to x @param x (out) value */ /*-----------------------------------------------------------------*/ Iunfstream& Iunfstream::operator >>(OMV& x) throw (Exception) { const char * name; const char * symbolname; const char * id; id = SCSCP_xmlnode_getid(m_node); int res = SCSCP_xmlnode_readOMV(&m_node, &name); if (!res) throw Exception(m_status); else { x.set_name(name); x.set_id(id); } return *this; } /*-----------------------------------------------------------------*/ /*! return the stream to parse the content of a derived OM */ /*-----------------------------------------------------------------*/ Iunfstream OMBasenode::beginOM() { if (m_node==NULL) { return Iunfstream(NULL, NULL); } else { SCSCP_xmlnodeptr pnode = SCSCP_xmlnode_getchild(m_node); return Iunfstream(pnode, NULL); } } } /*namespace SCSCP*/ scscp-imcce-1.0.0+ds/srcxx/scscpstream.h000066400000000000000000000114731215622604100201570ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpstream.h \brief Stream definition \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class Ofmtstreambuffer \brief Buffer for formatted stream */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ //////////////////////////////////////////////////////////////////////////// // formatted stream //////////////////////////////////////////////////////////////////////////// class Ofmtstreambuffer : public std::basic_streambuf { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// Ofmtstreambuffer( SCSCP_io* stream, SCSCP_status *status); ~Ofmtstreambuffer(); protected: //////////////////////////////////////////////////////////////////////////// // overload operation //////////////////////////////////////////////////////////////////////////// virtual int overflow( int c = EOF ); virtual int underflow(); virtual int sync(); private: //////////////////////////////////////////////////////////////////////////// // private members //////////////////////////////////////////////////////////////////////////// SCSCP_io* m_stream; //!< input stream SCSCP_status* m_status; //!< status char * m_inbuffer; //!< input buffer char * m_outbuffer; //!< output buffer }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class Ofmtstream \brief formatted stream */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class Ofmtstream : public std::basic_ostream { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// Ofmtstream(SCSCP_io* stream, SCSCP_status *status) : std::basic_ostream( new Ofmtstreambuffer( stream,status ) ) {} ~Ofmtstream() { delete rdbuf(); } }; scscp-imcce-1.0.0+ds/srcxx/scscpxx.h000066400000000000000000001231111215622604100173140ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpxx.h \brief SCSCP library - C++ interface. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #ifndef __SCSCPXX_H__ #define __SCSCPXX_H__ #include #include /*----------------------------------------------------------------------------------------------*/ /* define the SCSCP namespace */ /*----------------------------------------------------------------------------------------------*/ namespace SCSCP { class ProcedureCall; class ClientComputation; class Client; class Server; class ServerComputation; class Ofmtstream; class Iunfstream; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class Exception \brief SCSCP C++ exception */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class Exception : public std::exception { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor explicit Exception(const SCSCP_status* status) ; Exception(const Exception& e); virtual ~Exception() throw (); //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! information about the error virtual const char * what() const throw(); private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// SCSCP_status m_status; //!< status }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class Client \brief SCSCP C++ client */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class Client { public: //////////////////////////////////////////////////////////////////////////// // types //////////////////////////////////////////////////////////////////////////// typedef ClientComputation Computation; //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor Client(); ~Client(); //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// /*! connect the client to a server on the specified host and port */ int connect( const char *machine, int port=SCSCP_PROTOCOL_DEFAULTPORT) throw (Exception); //! close the connection of the client to a server previously opened by Connect int close() throw (Exception); //! return true if the connection is closed bool eof() const; private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// SCSCP_socketclient m_client; //!< client SCSCP_status m_status; //!< status //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! set the status void set_status(SCSCP_status* status); //////////////////////////////////////////////////////////////////////////// //friends //////////////////////////////////////////////////////////////////////////// friend class ClientComputation; friend class ProcedureCall; }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class IncomingClient \brief SCSCP C++ incoming client for the server */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class IncomingClient { public: //////////////////////////////////////////////////////////////////////////// // types //////////////////////////////////////////////////////////////////////////// typedef ServerComputation Computation; //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// ~IncomingClient(); //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! return true if the connection is closed bool eof() const; private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// SCSCP_incomingclient m_client; //!< client SCSCP_status m_status; //!< status //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor IncomingClient(SCSCP_incomingclient* client); //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! set the status void set_status(SCSCP_status* status); //////////////////////////////////////////////////////////////////////////// //friends //////////////////////////////////////////////////////////////////////////// friend class ClientComputation; friend class ProcedureCall; friend class Server; }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class Server \brief SCSCP C++ server */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class Server { public: //////////////////////////////////////////////////////////////////////////// // types //////////////////////////////////////////////////////////////////////////// typedef ServerComputation Computation; //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor Server(const char* servicename, const char* serviceversion, const char* serviceid); ~Server(); //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! listen on the specified port int listen(int port=SCSCP_PROTOCOL_DEFAULTPORT) throw (Exception); //! stop to listen int close() throw (Exception); //! waits for an incoming connection and accepts a incoming client connection IncomingClient* acceptclient() throw (Exception); //! return the port int getport(); private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// SCSCP_socketserver m_server; //!< server SCSCP_status m_status; //!< status }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class OMBase \brief OpenMath base */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class OMBase { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! constructor OMBase(const char *id=NULL) : m_id(id) {}; //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! get the sharing id const char *get_id() const { return m_id; } //! set the sharing id void set_id(const char *id) { m_id = id; } private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// const char* m_id; //!< sharing id }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! \ internal @class OMBasenode \brief OpenMath base for complex construction must not be used by user application */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class OMBasenode : public OMBase { protected: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor OMBasenode(SCSCP_xmlnodeptr node, const char *id=NULL) : OMBase(id), m_node(node) {}; //! return the stream to parse the content of a derived OM Iunfstream beginOM(); private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// SCSCP_xmlnodeptr m_node; //!< value }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class OMA \brief OpenMath application */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class OMA : public OMBasenode { private: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor OMA(SCSCP_xmlnodeptr node, const char *id=NULL) : OMBasenode(node, id) {}; }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class OMB \brief OpenMath array of bytes */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class OMB : public OMBase { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor OMB(const void *value=NULL, size_t len=0, const char *id=NULL) : OMBase(id), m_value(value), m_len(len) {}; //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! get the value const void *get_value() const { return m_value; } //! get the length size_t get_size() const { return m_len; } //! set the value void set_value(const void *value, size_t len) { m_value = value; m_len = len; } private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// const void* m_value; //!< value size_t m_len; //! length of m_value }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class OMBIND \brief OpenMath bind */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class OMBIND : public OMBasenode { private: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor OMBIND(SCSCP_xmlnodeptr node, const char *id=NULL) : OMBasenode(node, id) {}; }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class OME \brief OpenMath error */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class OME : public OMBasenode { private: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor OME(SCSCP_xmlnodeptr node, const char *id=NULL) : OMBasenode(node, id) {}; }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class OMF \brief OpenMath float */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class OMF : public OMBase { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor OMF(const char *value=NULL, const char *id=NULL) : OMBase(id), m_value(value), m_base(10) {}; //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! get the value const char *get_value() const { return m_value; } //! get the base int get_base() const { return m_base; } //! get the value as a double //operator double() const; //! set the value void set_value(const char *value) { m_value = value; m_base= 10; } private: //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! set the value void set_value(const char *value, int base) { m_value = value; m_base= base; } //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// const char* m_value; //!< value int m_base; //!< base friend class Iunfstream; }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class OMI \brief OpenMath integer */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class OMI : public OMBase { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor OMI(const char *value=NULL, const char *id=NULL) : OMBase(id), m_value(value) {}; //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! get the value const char *get_value() const { return m_value; } //! set the value void set_value(const char *value) { m_value = value; } private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// const char* m_value; //!< value }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class OMR \brief OpenMath reference */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class OMR : public OMBase { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor OMR(const char *name=NULL) : OMBase(NULL), m_name(name) {}; //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! get the reference const char *get_reference() const { return m_name; } //! set the reference void set_reference(const char *href) { m_name = href; } private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// const char* m_name; //!< name }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class OMS \brief OpenMath symbol */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class OMS : public OMBase { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! constructor OMS(const char *cd=NULL, const char *symbol=NULL, const char *id=NULL) : OMBase(id), m_cdname(cd), m_symbolname(symbol) {}; //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! get the cd name const char *get_cdname() const { return m_cdname; } //! set the cd name void set_cdname(const char *cdname) { m_cdname = cdname; } //! get the symbol name const char *get_symbolname() const { return m_symbolname; } //! set the symbol name void set_symbolname(const char *symbolname) { m_symbolname = symbolname; } private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// const char* m_cdname; //!< cdname const char* m_symbolname; //!< symbolname }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class OMV \brief OpenMath variable */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class OMV : public OMBase { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor OMV(const char *name=NULL, const char *id=NULL) : OMBase(id), m_name(name){}; //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! get the name const char *get_name() const { return m_name; } //! set the name void set_name(const char *name) { m_name = name; } private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// const char* m_name; //!< name }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class Ounfstream \brief unformatted OpenMath output stream */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class Ounfstream { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor Ounfstream(SCSCP_io* stream, SCSCP_status* status); ~Ounfstream(); //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// Ounfstream& operator<< (Ounfstream& ( *pf )(Ounfstream&) ); private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// SCSCP_io* m_stream; //!< input stream SCSCP_status* m_status; //!< status //////////////////////////////////////////////////////////////////////////// // private members //////////////////////////////////////////////////////////////////////////// // friends friend Ounfstream& operator <<(Ounfstream& out, int x) throw (Exception); friend Ounfstream& operator <<(Ounfstream& out, double x) throw (Exception); friend Ounfstream& operator <<(Ounfstream& out, const char* str) throw (Exception); friend Ounfstream& operator <<(Ounfstream& out, const OMS& x) throw (Exception); friend Ounfstream& operator <<(Ounfstream& out, const OMR& x) throw (Exception); friend Ounfstream& operator <<(Ounfstream& out, const OMV& x) throw (Exception); friend Ounfstream& operator <<(Ounfstream& out, const OMI& x) throw (Exception); friend Ounfstream& operator <<(Ounfstream& out, const OMF& x) throw (Exception); friend Ounfstream& operator <<(Ounfstream& out, const OMB& x) throw (Exception); friend Ounfstream& beginOMA(Ounfstream& out) throw (Exception); friend Ounfstream& endOMA(Ounfstream& out) throw (Exception); friend Ounfstream& beginOMATP(Ounfstream& out) throw (Exception); friend Ounfstream& endOMATP(Ounfstream& out) throw (Exception); friend Ounfstream& beginOMATTR(Ounfstream& out) throw (Exception); friend Ounfstream& endOMATTR(Ounfstream& out) throw (Exception); friend Ounfstream& beginOME(Ounfstream& out) throw (Exception); friend Ounfstream& endOME(Ounfstream& out) throw (Exception); friend Ounfstream& beginOMOBJ(Ounfstream& out) throw (Exception); friend Ounfstream& endOMOBJ(Ounfstream& out) throw (Exception); }; /* unformatted stream operation */ Ounfstream& operator <<(Ounfstream& out, int x) throw (Exception); Ounfstream& operator <<(Ounfstream& out, double x) throw (Exception); Ounfstream& operator <<(Ounfstream& out, const char* str) throw (Exception); Ounfstream& operator <<(Ounfstream& out, const OMS& x) throw (Exception); Ounfstream& operator <<(Ounfstream& out, const OMR& x) throw (Exception); Ounfstream& operator <<(Ounfstream& out, const OMV& x) throw (Exception); Ounfstream& operator <<(Ounfstream& out, const OMI& x) throw (Exception); Ounfstream& operator <<(Ounfstream& out, const OMF& x) throw (Exception); Ounfstream& operator <<(Ounfstream& out, const OMB& x) throw (Exception); Ounfstream& beginOMA(Ounfstream& out) throw (Exception); Ounfstream& endOMA(Ounfstream& out) throw (Exception); Ounfstream& beginOMATP(Ounfstream& out) throw (Exception); Ounfstream& endOMATP(Ounfstream& out) throw (Exception); Ounfstream& beginOMATTR(Ounfstream& out) throw (Exception); Ounfstream& endOMATTR(Ounfstream& out) throw (Exception); Ounfstream& beginOME(Ounfstream& out) throw (Exception); Ounfstream& endOME(Ounfstream& out) throw (Exception); Ounfstream& beginOMOBJ(Ounfstream& out) throw (Exception); Ounfstream& endOMOBJ(Ounfstream& out) throw (Exception); /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class Iunfstream_iterator_attr \brief iterator on atributes of the OpenMath object This class must only used through Iunfstream::iterator_attr */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class Iunfstream_iterator_attr { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor Iunfstream_iterator_attr(SCSCP_xmlattrptr attr); //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! return false if eof bool end() const { return m_attr!=NULL; } //! jump to the next attribute void operator++(); //! get the name of the attribute const char *get_name() const; //! get the value of the attribute const char *get_value() const; private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// SCSCP_xmlattrptr m_attr; //!< attributes }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class Iunfstream \brief unformatted OpenMath input stream */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class Iunfstream { public: //////////////////////////////////////////////////////////////////////////// // types //////////////////////////////////////////////////////////////////////////// //! iterator on attributes typedef Iunfstream_iterator_attr iterator_attr; //! OpenMath node type typedef SCSCP_omtype omtype; //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor Iunfstream(); ~Iunfstream(); //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! return true if eof bool eof() const { return m_node==NULL; } //! get the list of attributes iterator_attr get_attr(); //! get the type of the current node omtype get_type() const; //! get the name of the current node const char* get_typename() const; //! get the content of the current node const char* get_content() const; //! return the stream to parse the content of a derived OM Iunfstream beginOM(); /* unformatted stream operation */ Iunfstream& operator >>(int& x) throw (Exception); Iunfstream& operator >>(double& x) throw (Exception); Iunfstream& operator >>(const char*& str) throw (Exception); Iunfstream& operator >>(OMA& x) throw (Exception); Iunfstream& operator >>(OMB& x) throw (Exception); Iunfstream& operator >>(OMBIND& x) throw (Exception); Iunfstream& operator >>(OME& x) throw (Exception); Iunfstream& operator >>(OMF& x) throw (Exception); Iunfstream& operator >>(OMI& x) throw (Exception); Iunfstream& operator >>(OMR& x) throw (Exception); Iunfstream& operator >>(OMS& x) throw (Exception); Iunfstream& operator >>(OMV& x) throw (Exception); private: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor Iunfstream(SCSCP_xmlnodeptr node, SCSCP_status* status); //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// SCSCP_xmlnodeptr m_node; //!< input stream SCSCP_status* m_status; //!< status friend class ProcedureCall; friend class OMBasenode; }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class ProcedureCall \brief SCSCP C++ Procedure Call : common part on server or client */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class ProcedureCall { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor ProcedureCall(Client& session) throw (Exception); ProcedureCall(IncomingClient& session) throw (Exception); ~ProcedureCall(); //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// /* for send options */ /*! set the runtime limit */ int set_runtimelimit(size_t p_time); /*! get the runtime limit */ int get_runtimelimit(size_t& p_time) ; /*! set the minimum memory */ int set_minmemory(size_t memsize); /*! get the minimum memory */ int get_minmemory(size_t& memsize); /*! set the maximum memory */ int set_maxmemory(size_t memsize); /*! get the maximum memory */ int get_maxmemory(size_t& memsize); /*! set the debug level */ int set_debuglevel(int debuglevel); /*! get the debug level */ int get_debuglevel(int& debuglevel); //! set encoding XML or binary int set_encodingtype(SCSCP_encodingtype encodingtype); //! get encoding type int get_encodingtype(SCSCP_encodingtype& encoding); //! get the return type int get_returntype(SCSCP_option_return& returntype); //! get the call id int get_callid(const char*& callid); /* for return options */ /*! set the runtime usage */ int set_runtime(size_t p_time); /*! get the runtime usage */ int get_runtime(size_t& p_time); /*! set the memory usage */ int set_memory(size_t mem); /*! get the memory usage */ int get_memory(size_t& mem); /*! set the information message */ int set_message(const char *buffer); /*! get the information message */ int get_message(const char *& buffer); /*! send a information message */ int sendinfomessage(const char *buffer); protected : //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! fush the output stream void flushostream(); //! create an unformatted output stream Ounfstream* createounfstream() throw(); //! create a formatted output stream Ofmtstream* createofmtstream() throw(); //! create an unformatted input stream Iunfstream* createiunfstream(SCSCP_xmlnodeptr node) throw(); //! get call options SCSCP_calloptions *get_calloptions() { return &m_calloptions; } //! get return options SCSCP_returnoptions *get_returnoptions() { return &m_returnoptions; } //! get status SCSCP_status *get_status() { return &m_status; } //! get client SCSCP_socketclient *get_client() { return m_client; } //! report error if res=0 and raise an exception void report_error(int res) throw(Exception); private: //////////////////////////////////////////////////////////////////////////// // attributes //////////////////////////////////////////////////////////////////////////// SCSCP_socketclient* m_client; //!< client Client* m_clientsession; //!< session client side IncomingClient* m_serversession; //!< session client side SCSCP_calloptions m_calloptions; //!< options of the call SCSCP_returnoptions m_returnoptions; //!< options of the reply SCSCP_status m_status; //!< status Ofmtstream *m_postream; //!< output formatted stream Ounfstream *m_punfostream; //!< output unformatted stream Iunfstream *m_punfistream; //!< input unformatted stream }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class ClientComputation \brief SCSCP C++ computation task for client side */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class ClientComputation : public ProcedureCall { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor ClientComputation(Client& session) throw (Exception); ~ClientComputation(); //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //! send an interruption of the call int interrupt(); //////////////////////////////////////////////////////////////////////////// //procedure call using buffer //////////////////////////////////////////////////////////////////////////// //! send a procedure call using an openmath buffer to the server int send(const char *openmathbuffer, size_t lenbuffer, SCSCP_option_return returntype) throw (Exception) ; //! wait and receive an answer from the server int recv(SCSCP_msgtype& msgtype, char*& openmathbuffer, size_t& lenbuffer) throw (Exception) ; //////////////////////////////////////////////////////////////////////////// //procedure call using streams //////////////////////////////////////////////////////////////////////////// //! send a procedure call using a stream to the server (direct output OpenMath) int send(SCSCP_option_return returntype, std::ostream*& stream) throw (Exception) ; //! send a procedure call using a stream to the server (format to OpenMath) int send(SCSCP_option_return returntype, Ounfstream*& stream) throw (Exception) ; //! discard the procedure call to the server (after send...formattedstream) int discard() throw (Exception) ; //! complete the procedure call to the server (after send...formattedstream) int finish() throw (Exception) ; //! wait and receive an answer from the server int recv(SCSCP_msgtype& msgtype, Iunfstream* &stream) throw (Exception) ; }; /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ /*! @class ServerComputation \brief SCSCP C++ computation task for server side */ /*----------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------*/ class ServerComputation : public ProcedureCall { public: //////////////////////////////////////////////////////////////////////////// // constructor destructor //////////////////////////////////////////////////////////////////////////// //! default constructor ServerComputation(IncomingClient& session) throw (Exception); ~ServerComputation(); //////////////////////////////////////////////////////////////////////////// // operation //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //procedure call using buffer //////////////////////////////////////////////////////////////////////////// //! wait and receive an command from the client int recv(SCSCP_msgtype& msgtype, char*& openmathbuffer, size_t& lenbuffer) throw (Exception) ; //! send a completed message using an openmath buffer to the client int sendcompleted(const char* openmathbuffer=NULL, size_t lenbuffer=0) throw (Exception) ; //! send a terminated message using an openmath buffer to the client int sendterminated(const char * cdname, const char * symbolname, const char * message) throw (Exception) ; //////////////////////////////////////////////////////////////////////////// //procedure call using streams //////////////////////////////////////////////////////////////////////////// //! wait and receive an command from the client int recv(SCSCP_msgtype& msgtype, Iunfstream*& stream) throw (Exception) ; //! send a completed message using a stream to the client (direct output OpenMath) int sendcompleted(std::ostream*& stream) throw (Exception) ; //! send a completed message using a stream to the client (format to OpenMath) int sendcompleted(Ounfstream*& stream) throw (Exception) ; //! complete the completed or terminated message to the client (after sendcompleted) int finish() throw (Exception) ; }; } /*namespace SCSCP */ #endif /*__SCSCPXX_H__*/ scscp-imcce-1.0.0+ds/srcxx/scscpxx.sym000066400000000000000000000066161215622604100177070ustar00rootroot00000000000000#/*-----------------------------------------------------------------*/ #/*! # \file scscpxx.sym # \brief Exported C++ symbols for the gnu ld linkers # \author M. Gastineau # Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. # # Copyright, 2008, 2009, 2010, 2011, 2012, 2013, M. Gastineau, CNRS # email of the author : gastineau@imcce.fr # # #/*-----------------------------------------------------------------*/ # # # initial version generated with the following command : # objdump -T -C .libs/libscscpxx.so.0 | grep text | sed -e 's/^[^:]*:/SCSCP:/g' | sort | sed 's/([^$]*$/*;/g' | uniq # LIBSCSCPXX_1.0.0 { global: extern "C++" { SCSCP::beginOMA*; SCSCP::beginOMATP*; SCSCP::beginOMATTR*; SCSCP::beginOME*; SCSCP::beginOMOBJ*; SCSCP::Client::?Client*; SCSCP::Client::Client*; SCSCP::Client::close*; SCSCP::ClientComputation::?ClientComputation*; SCSCP::ClientComputation::ClientComputation*; SCSCP::ClientComputation::discard*; SCSCP::ClientComputation::finish*; SCSCP::ClientComputation::interrupt*; SCSCP::ClientComputation::recv*; SCSCP::ClientComputation::send*; SCSCP::Client::connect*; SCSCP::Client::eof*; SCSCP::endOMA*; SCSCP::endOMATP*; SCSCP::endOMATTR*; SCSCP::endOME*; SCSCP::endOMOBJ*; *SCSCP::Exception; #export typeinfo SCSCP::Exception::?Exception*; SCSCP::Exception::Exception*; SCSCP::Exception::what*; SCSCP::IncomingClient::eof*; SCSCP::IncomingClient::?IncomingClient*; SCSCP::Iunfstream::beginOM*; SCSCP::Iunfstream::get_attr*; SCSCP::Iunfstream::get_content*; SCSCP::Iunfstream::get_type*; SCSCP::Iunfstream::get_typename*; SCSCP::Iunfstream_iterator_attr::get_name*; SCSCP::Iunfstream_iterator_attr::get_value*; SCSCP::Iunfstream_iterator_attr::Iunfstream_iterator_attr*; SCSCP::Iunfstream_iterator_attr::operator*; SCSCP::Iunfstream::?Iunfstream*; SCSCP::Iunfstream::Iunfstream*; SCSCP::Iunfstream::operator*; SCSCP::Ofmtstreambuffer::?Ofmtstreambuffer*; SCSCP::Ofmtstreambuffer::Ofmtstreambuffer*; SCSCP::Ofmtstreambuffer::overflow*; SCSCP::Ofmtstreambuffer::sync*; SCSCP::Ofmtstreambuffer::underflow*; SCSCP::Ofmtstream::?Ofmtstream*; SCSCP::OMBasenode::beginOM*; SCSCP::operator*; SCSCP::Ounfstream::operator*; SCSCP::Ounfstream::?Ounfstream*; SCSCP::Ounfstream::Ounfstream*; SCSCP::ProcedureCall::get_callid*; SCSCP::ProcedureCall::get_debuglevel*; SCSCP::ProcedureCall::get_encodingtype*; SCSCP::ProcedureCall::get_maxmemory*; SCSCP::ProcedureCall::get_memory*; SCSCP::ProcedureCall::get_message*; SCSCP::ProcedureCall::get_minmemory*; SCSCP::ProcedureCall::get_returntype*; SCSCP::ProcedureCall::get_runtimelimit*; SCSCP::ProcedureCall::get_runtime*; SCSCP::ProcedureCall::?ProcedureCall*; SCSCP::ProcedureCall::ProcedureCall*; SCSCP::ProcedureCall::sendinfomessage*; SCSCP::ProcedureCall::set_debuglevel*; SCSCP::ProcedureCall::set_encodingtype*; SCSCP::ProcedureCall::set_maxmemory*; SCSCP::ProcedureCall::set_memory*; SCSCP::ProcedureCall::set_message*; SCSCP::ProcedureCall::set_minmemory*; SCSCP::ProcedureCall::set_runtimelimit*; SCSCP::ProcedureCall::set_runtime*; SCSCP::Server::acceptclient*; SCSCP::Server::close*; SCSCP::Server::getport*; SCSCP::ServerComputation::finish*; SCSCP::ServerComputation::recv*; SCSCP::ServerComputation::sendcompleted*; SCSCP::ServerComputation::sendterminated*; SCSCP::ServerComputation::?ServerComputation*; SCSCP::ServerComputation::ServerComputation*; SCSCP::Server::listen*; SCSCP::Server::?Server*; SCSCP::Server::Server*; }; local: *; }; scscp-imcce-1.0.0+ds/tests/000077500000000000000000000000001215622604100154445ustar00rootroot00000000000000scscp-imcce-1.0.0+ds/tests/Makefile.am000066400000000000000000000126261215622604100175070ustar00rootroot00000000000000#/*-----------------------------------------------------------------*/ #/*! # \file Makefile.am # \brief Makefile for automake # \author M. Gastineau # Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. # # Copyright, 2008, 2009, 2010, 2011,2012, M. Gastineau, CNRS # email of the author : gastineau@imcce.fr # # \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 #*/ #/*-----------------------------------------------------------------*/ # #/*-----------------------------------------------------------------*/ #/* License of this file : # This file is "dual-licensed", you have to choose one of the two licenses # below to apply on this file. # # CeCILL-C # The CeCILL-C license is close to the GNU LGPL. # ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) # # or CeCILL v2.0 # The CeCILL license is compatible with the GNU GPL. # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) # # # This library is governed by the CeCILL-C or the CeCILL license under # French law and abiding by the rules of distribution of free software. # You can use, modify and/ or redistribute the software under the terms # of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA # at the following URL "http://www.cecill.info". # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # In this respect, the user's attention is drawn to the risks associated # with loading, using, modifying and/or developing or reproducing the # software by the user in light of its specific status of free software, # that may mean that it is complicated to manipulate, and that also # therefore means that it is reserved for developers and experienced # professionals having in-depth computer knowledge. Users are therefore # encouraged to load and test the software's suitability as regards their # requirements in conditions enabling the security of their systems and/or # data to be ensured and, more generally, to use and operate it in the # same conditions as regards security. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-C or CeCILL license and that you accept its terms. # */ # /*-----------------------------------------------------------------*/ ## Makefile.am -- Process this file with automake to produce Makefile.in LDADD = $(top_builddir)/src/libscscp.la $(XML_LIBS) AM_CPPFLAGS = -I$(top_srcdir)/src/ $(XML_CPPFLAGS) checkfailed = scscpscinitfailed1 scscpscconnectfailed1 scscpscconnectfailed2 \ scscpcofailed1 scscpssinitfailed1 scscprofailed1 scscpnegotiationfailed1 checkok = scscpcheckversion scscpgetversion scscpscconnect scscpsendgetallowheads \ scscpreturnoptions scscpterminated scscpcompleted1 \ scscpcompleted2 scscpssinit scscpsendserveroption scscpserversendinfo scscpclientsendinfo \ scscpinterrupt scscprawstring scscpremote1 scscpremote2 scscpomf scscpomv scscpnsomi \ scscpomvbin scscpomibin scscpomfbin scscpomstrbin scscpomrbin scscpinvalidcmd scscpmconnect \ scscptversion check_PROGRAMS = $(checkfailed) $(checkok) TESTS = $(checkfailed) $(checkok) XFAIL_TESTS = $(checkfailed) noinst_PROGRAMS = scscpservertest scscpscinitfailed1_SOURCES = scscpscinitfailed1.c scscpscconnectfailed1_SOURCES = scscpscconnectfailed1.c scscpscconnectfailed2_SOURCES = scscpscconnectfailed2.c scscpscconnect_SOURCES = scscpscconnect.c scscpsscommon.c scscpsendgetallowheads_SOURCES = scscpsendgetallowheads.c scscpsscommon.c cmncalloption.c scscpreturnoptions_SOURCES = scscpreturnoptions.c scscpsscommon.c scscprofailed1_SOURCES = scscprofailed1.c scscpcofailed1_SOURCES = scscpcofailed1.c scscpterminated_SOURCES = scscpterminated.c scscpsscommon.c scscpinvalidcmd_SOURCES = scscpinvalidcmd.c scscpsscommon.c scscpcompleted1_SOURCES = scscpcompleted1.c scscpsscommon.c scscpcompleted2_SOURCES = scscpcompleted2.c scscpsscommon.c scscpmconnect_SOURCES = scscpmconnect.c scscpsscommon.c scscpssinit_SOURCES = scscpssinit.c scscpservertest_SOURCES = scscpservertest.c scscpsscommon.c scscpsendserveroption_SOURCES = scscpsendserveroption.c scscpsscommon.c cmncalloption.c scscpnegotiationfailed1_SOURCES = scscpnegotiationfailed1.c scscpsscommon.c scscpserversendinfo_SOURCES = scscpserversendinfo.c scscpsscommon.c scscpclientsendinfo_SOURCES = scscpclientsendinfo.c scscpsscommon.c scscpinterrupt_SOURCES = scscpinterrupt.c scscpsscommon.c scscprawstring_SOURCES = scscprawstring.c scscpsscommon.c scscpremote1_SOURCES = scscpremote1.c scscpsscommon.c scscpremote2_SOURCES = scscpremote2.c scscpsscommon.c scscpomf_SOURCES = scscpomf.c scscpsscommon.c scscpomv_SOURCES = scscpomv.c scscpsscommon.c scscpnsomi_SOURCES = scscpnsomi.c scscpsscommon.c scscpomvbin_SOURCES = scscpomvbin.c scscpsscommon.c scscpomibin_SOURCES = scscpomibin.c scscpsscommon.c scscpomfbin_SOURCES = scscpomfbin.c scscpsscommon.c scscpomstrbin_SOURCES = scscpomstrbin.c scscpsscommon.c scscpomrbin_SOURCES = scscpomrbin.c scscpsscommon.c scscptversion_SOURCES = scscptversion.c scscpcheckversion_SOURCES = scscpcheckversion.c scscpgetversion_SOURCES = scscpgetversion.c noinst_HEADERS = scscpsscommon.h EXTRA_DIST = Makefile.vc scscp-imcce-1.0.0+ds/tests/cmncalloption.c000066400000000000000000000152741215622604100204630ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file cmncalloption.c \brief check the call options. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include "scscp.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ int decodeanswer(SCSCP_socketclient *client, SCSCP_status *status) { int res; SCSCP_msgtype msgtype; char *openmathbuffer; res =SCSCP_sc_callrecvstr(client, SCSCP_RETURNOPTIONS_IGNORE, &msgtype, &openmathbuffer, status); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : SCSCP_debugprint("Procedure Terminated\n"); break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); break; default : res=0; break; } SCSCP_debugprint("buffer:'%s'\n",openmathbuffer); free(openmathbuffer); } else { printf("SCSCP_sc_callrecvstr returns 0 !!!!\n"); } return res; } int mainsend(int port) { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; SCSCP_calloptions options; int res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); if (res) res = SCSCP_sc_callsendstr(&client, SCSCP_CALLOPTIONS_DEFAULT, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_co_init(&options, &status); if (res) res = SCSCP_sc_callsendstr(&client, &options, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_co_set_callid(&options, "call 1", &status); if (res) res = SCSCP_sc_callsendstr(&client, &options, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_co_set_runtimelimit(&options, 1000, &status); if (res) res = SCSCP_sc_callsendstr(&client, &options, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_co_set_minmemory(&options, 0, &status); if (res) res = SCSCP_sc_callsendstr(&client, &options, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_co_set_maxmemory(&options, 10000, &status); if (res) res = SCSCP_sc_callsendstr(&client, &options, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_co_set_debuglevel(&options, 0, &status); if (res) res = SCSCP_sc_callsendstr(&client, &options, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_co_set_returntype(&options, SCSCP_option_return_object, &status); if (res) res = SCSCP_sc_callsendstr(&client, &options, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_co_set_returntype(&options, SCSCP_option_return_nothing, &status); if (res) res = SCSCP_sc_callsendstr(&client, &options, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_sc_close(&client, &status); if (res) SCSCP_co_clear(&options, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); return res; } scscp-imcce-1.0.0+ds/tests/scscpcheckversion.c000066400000000000000000000072761215622604100213430ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpcheckversion.c \brief check SCSCP_CHECK_VERSION \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" #define EXPECTED_RES(x,y,z,r) \ if ((n = SCSCP_check_libversion(x, y, z))!=r) \ { \ printf("send %d %d %d expected %d get %d\n", x,y,z, r, n); \ res=1; \ } int main() { int res = 0, n; unsigned int major, minor, patch; if (SCSCP_CHECK_LIBVERSION()!=1) res = 1; /* check that the linked library is compatible */ EXPECTED_RES(SCSCP_VERSION_MAJOR, SCSCP_VERSION_MINOR, SCSCP_VERSION_PATCH+1,2); EXPECTED_RES(SCSCP_VERSION_MAJOR, SCSCP_VERSION_MINOR, SCSCP_VERSION_PATCH-1,2); if (SCSCP_VERSION_MAJOR>0) EXPECTED_RES(SCSCP_VERSION_MAJOR-1, SCSCP_VERSION_MINOR, SCSCP_VERSION_PATCH,2); if (SCSCP_VERSION_MINOR>0) EXPECTED_RES(SCSCP_VERSION_MAJOR, SCSCP_VERSION_MINOR-1, 0,2); /* check that the linked library is not compatible */ EXPECTED_RES(SCSCP_VERSION_MAJOR+1, SCSCP_VERSION_MINOR, SCSCP_VERSION_PATCH,0); EXPECTED_RES(SCSCP_VERSION_MAJOR+1, 0, 0,0); EXPECTED_RES(SCSCP_VERSION_MAJOR, SCSCP_VERSION_MINOR+1, 0,0); EXPECTED_RES(SCSCP_VERSION_MAJOR, SCSCP_VERSION_MINOR+1, SCSCP_VERSION_PATCH,0); EXPECTED_RES(SCSCP_VERSION_MAJOR, SCSCP_VERSION_MINOR+1, SCSCP_VERSION_PATCH+1,0); return res; } scscp-imcce-1.0.0+ds/tests/scscpclientsendinfo.c000066400000000000000000000112221215622604100216460ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpserversendinfo.c \brief check that the client sends an info message before its answer. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(SCSCP_socketclient *client, SCSCP_status *status) { int res; SCSCP_msgtype msgtype; char *openmathbuffer; res =SCSCP_sc_callrecvstr(client, SCSCP_RETURNOPTIONS_IGNORE, &msgtype, &openmathbuffer, status); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : SCSCP_debugprint("Procedure Terminated\n"); break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); break; default : res=0; break; } SCSCP_debugprint("buffer:'%s'\n",openmathbuffer); free(openmathbuffer); } else { printf ("SCSCP_sc_callrecvstr : failed status=%d\n", SCSCP_status_is(status)); } return res; } /*-----------------------------------------------------------------*/ /* send the command to the server */ /*-----------------------------------------------------------------*/ static int mainsend(int port) { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); if (res) res = SCSCP_sc_infomessagesend(&client, "client send a specific info message", &status); if (res) res = SCSCP_sc_callsendstr(&client, SCSCP_CALLOPTIONS_DEFAULT, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); return res; } int main() { int reserver; int res; int port; startbackgroundserver(0, &port); res = mainsend(port); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpcofailed1.c000066400000000000000000000052471215622604100205030ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpcofailed1.c \brief check the error : SCSCP_co_set_callid returns SCSCP_STATUS_CALLOPTIONSOBJECTNULL \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" int main() { SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res; res = SCSCP_co_set_callid(NULL, "N/A", &status); return (res==0 && SCSCP_status_is(&status)==SCSCP_STATUS_CALLOPTIONSOBJECTNULL); } scscp-imcce-1.0.0+ds/tests/scscpcompleted1.c000066400000000000000000000114531215622604100207050ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpcompleted1.c \brief check that client could decode the completed message with simple parse \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(SCSCP_socketclient *client, SCSCP_status *status) { int res; SCSCP_msgtype msgtype; SCSCP_returnoptions options; char *messagebuffer; res = SCSCP_ro_init(&options, status); if (!res) return res; res = SCSCP_sc_callrecvheader(client, &options, &msgtype, status); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated=> can't be possible\n"); res=0; break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); res = SCSCP_sc_callrecvcompleted(client, &messagebuffer, status); if (res) { SCSCP_debugprint("message='%s'\n", messagebuffer); free(messagebuffer); } break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; res = startbackgroundserver(2, &port); /* open connection with the server on port 26133 */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); /* send an invalid symbol */ if (res) res = SCSCP_sc_callsendstr(&client, SCSCP_CALLOPTIONS_DEFAULT, "", &status); /* receive the answer */ if (res) res = decodeanswer(&client, &status); /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpcompleted2.c000066400000000000000000000125721215622604100207110ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpcompleted1.c \brief check that client could decode the completed message with complex parse \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* print the xml tree */ /*-----------------------------------------------------------------*/ static void printelements(SCSCP_xmlnodeptr node, int tab) { #define PRINTAB(x) for(j=0; j can't be possible\n"); res=0; break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); printelements(SCSCP_sc_getxmlnode(client, status), 0); break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; res = startbackgroundserver(2, &port); /* open connection with the server on port */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); /* send a valid symbol */ if (res) res = SCSCP_sc_callsendstr(&client, SCSCP_CALLOPTIONS_DEFAULT, "", &status); /* receive the answer */ if (res) res = decodeanswer(&client, &status); /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpgetversion.c000066400000000000000000000053311215622604100210330ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpgetversion.c \brief check SCSCP_CHECK_VERSION \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" int main() { unsigned int major=0, minor = 0, patch = 0; int res = 0; /* retrieve and check linked library version numbers */ SCSCP_get_libversionnum(&major,&minor,&patch); if (major != SCSCP_VERSION_MAJOR) res=1; if (minor != SCSCP_VERSION_MINOR) res=1; if (patch != SCSCP_VERSION_PATCH) res=1; return res; } scscp-imcce-1.0.0+ds/tests/scscpinterrupt.c000066400000000000000000000121751215622604100207060ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpinterrupt.c \brief check that client could send an interrupt signal \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(SCSCP_socketclient *client, SCSCP_status *status) { int res; SCSCP_msgtype msgtype; SCSCP_returnoptions options; char *messagebuffer; res = SCSCP_ro_init(&options, status); if (!res) return res; res = SCSCP_sc_callrecvheader(client, &options, &msgtype, status); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated=> can't be possible\n"); res=0; break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); res = SCSCP_sc_callrecvcompleted(client, &messagebuffer, status); if (res) { SCSCP_debugprint("message='%s'\n", messagebuffer); free(messagebuffer); } break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; SCSCP_calloptions calloptions; int res, reserver, port; const char *callid=NULL; res = startbackgroundserver(7, &port); /* open connection with the server on port */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); if (res) res = SCSCP_co_init(&calloptions, &status); if (res) res = SCSCP_co_get_callid(&calloptions, &callid, &status); /* send an invalid symbol */ if (res) res = SCSCP_sc_callsendstr(&client, &calloptions, "", &status); if (callid) SCSCP_debugprint("send an interrupt for '%s'\n", callid); if (res) res = SCSCP_sc_callsendinterrupt(&client, callid, &status); /* receive the answer */ if (res) res = decodeanswer(&client, &status); /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); if (res) res = SCSCP_co_clear(&calloptions, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpinvalidcmd.c000066400000000000000000000121301215622604100207530ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpinvalidcmd.c \brief check that server could decode the invalid openmath command if an invalid commad is send. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(SCSCP_socketclient *client, SCSCP_status *status) { int res; SCSCP_msgtype msgtype; SCSCP_returnoptions options; char *messagebuffer; char *cdname; char *symbolname; res = SCSCP_ro_init(&options, status); if (!res) return res; res = SCSCP_sc_callrecvheader(client, &options, &msgtype, status); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : SCSCP_debugprint("Procedure Terminated\n"); res = SCSCP_sc_callrecvterminated(client, &cdname, &symbolname, &messagebuffer, status); if (res) { SCSCP_debugprint("cd=%s\n", cdname); SCSCP_debugprint("symbolname=%s\n", symbolname); SCSCP_debugprint("message='%s'\n", messagebuffer); free(messagebuffer); } break; case SCSCP_msgtype_ProcedureCompleted : printf("Procedure Completed => can't be possible\n"); res=0; break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; res = startbackgroundserver(28, &port); if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); /*send an invalid symbol */ if (res) res = SCSCP_sc_callsendstr(&client, SCSCP_CALLOPTIONS_DEFAULT, "11110x10", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpmconnect.c000066400000000000000000000116011215622604100204510ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpmconnect.c \brief check that client supports multiple connections/close ticket [#8448] example decode client.c returns a status error \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(SCSCP_socketclient *client, SCSCP_status *status) { int res; SCSCP_msgtype msgtype; SCSCP_returnoptions options; char *messagebuffer; res = SCSCP_ro_init(&options, status); if (!res) return res; res = SCSCP_sc_callrecvheader(client, &options, &msgtype, status); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated=> can't be possible\n"); res=0; break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); res = SCSCP_sc_callrecvcompleted(client, &messagebuffer, status); if (res) { SCSCP_debugprint("message='%s'\n", messagebuffer); free(messagebuffer); } break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, k, port; res = startbackgroundserver(2, &port); /* open connection with the server on port 26133 */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); for (k=1; k<=5 && res!=0; k++) { res = SCSCP_sc_connect(&client, "localhost", port, &status); /* send an invalid symbol */ if (res) res = SCSCP_sc_callsendstr(&client, SCSCP_CALLOPTIONS_DEFAULT, "", &status); /* receive the answer */ if (res) res = decodeanswer(&client, &status); /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); } SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpnegotiationfailed1.c000066400000000000000000000057261215622604100224240ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpnegotiationfailed1.c \brief check that the negotiation aborts. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" #include "scscpsscommon.h" int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res; int port; res = startbackgroundserver(5, &port); /* open connection with the server on port */ if (res) res = SCSCP_sc_init(&client, &status, "0.0000", NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); stopbackgroundserver(); return (res==0); } scscp-imcce-1.0.0+ds/tests/scscpnsomi.c000066400000000000000000000104461215622604100177760ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpnsomi.c \brief check that client could decode an the namespace or ticket #6399 \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscpsscommon.h" static int writeexec(SCSCP_io *stream, void *param, SCSCP_status *status) { return SCSCP_io_writeOMIint(stream, *(int*)param, NULL, status); } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; int n=5; SCSCP_xmlnodeptr node; int value=-1; res = startbackgroundserver(12, &port); /* open connection with the server on port */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); /* send a valid symbol */ if (res) res = SCSCP_sc_executehookxmlnode(&client, SCSCP_option_return_object, "arith1", "unary_minus", writeexec, &n, &node, &status); if (res) { res = SCSCP_xmlnode_readOMIint(&node, &value); if (res==0 || value!=1) { res=0; } } /* send a valid symbol */ if (res) res = SCSCP_sc_executehookxmlnode(&client, SCSCP_option_return_object, "arith1", "unary_minus", writeexec, &n, &node, &status); if (res) { res = SCSCP_xmlnode_readOMIint(&node, &value); if (res==0 || value!=2) { res=0; } } /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpomf.c000066400000000000000000000076361215622604100174410ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpomf.c \brief check that client could decode an OMF \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscpsscommon.h" static int writeexec(SCSCP_io *stream, void *param, SCSCP_status *status) { return SCSCP_io_writeOMFdouble(stream, *(double*)param, NULL, status); } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; double n=5; SCSCP_xmlnodeptr node; const char *value; int base; res = startbackgroundserver(10, &port); /* open connection with the server on port */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); /* send a valid symbol */ if (res) res = SCSCP_sc_executehookxmlnode(&client, SCSCP_option_return_object, "arith1", "plus", writeexec, &n, &node, &status); if (res) { res = SCSCP_xmlnode_readOMFstr(&node, &value, &base); if (res==0 || strcmp(value,"1.0")!=0 || base!=10) res=0; } /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpomfbin.c000066400000000000000000000067271215622604100201320ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpomfbin.c \brief check that server could decode an OMF in binary encoding \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscpsscommon.h" static int writeexec(SCSCP_io *stream, void *param, SCSCP_status *status) { int res = SCSCP_io_writebeginOMA(stream, NULL, status); res &= SCSCP_io_writeOMFdouble(stream, *(double *)param, NULL, status); res &= SCSCP_io_writeendOMA(stream, status); return res; } static int writeexecstr(SCSCP_io *stream, void *param, SCSCP_status *status) { int res = SCSCP_io_writebeginOMA(stream, NULL, status); res &= SCSCP_io_writeOMFstr(stream, (const char *)param, NULL, status); res &= SCSCP_io_writeendOMA(stream, status); return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { double n; int res=0; n=1.0E-10; res = startserverandsendbincheck(23, writeexec, &n); if (!res) res = startserverandsendbincheck(23, writeexecstr, (void*)"1.0E-10"); return res; } scscp-imcce-1.0.0+ds/tests/scscpomibin.c000066400000000000000000000077201215622604100201270ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpomibin.c \brief check that server could decode an OMI in binary encoding \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscpsscommon.h" static int writeexec(SCSCP_io *stream, void *param, SCSCP_status *status) { int res = SCSCP_io_writebeginOMA(stream, NULL, status); res &= SCSCP_io_writeOMIint(stream, *(int *)param, NULL, status); res &= SCSCP_io_writeendOMA(stream, status); return res; } static int writeexecstr(SCSCP_io *stream, void *param, SCSCP_status *status) { int res = SCSCP_io_writebeginOMA(stream, NULL, status); res &= SCSCP_io_writeOMIstr(stream, (const char *)param, NULL, status); res &= SCSCP_io_writeendOMA(stream, status); return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { int n; int res=0; n=1; res = startserverandsendbincheck(15, writeexec, &n); n=127; if (!res) res = startserverandsendbincheck(16, writeexec, &n); n=32768; if (!res) res = startserverandsendbincheck(17, writeexec, &n); n=2147483647; if (!res) res = startserverandsendbincheck(18, writeexec, &n); n=(-2147483647 - 1); if (!res) res = startserverandsendbincheck(19, writeexec, &n); if (!res) res = startserverandsendbincheck(20, writeexecstr, (void*)"1125899906842624"); if (!res) res = startserverandsendbincheck(21, writeexecstr, (void*)"-1125899906842624"); if (!res) res = startserverandsendbincheck(22, writeexecstr, (void*)"+1125899906842624"); return res; } scscp-imcce-1.0.0+ds/tests/scscpomrbin.c000066400000000000000000000062671215622604100201450ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpomrbin.c \brief check that server could decode an OMR in binary encoding \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscpsscommon.h" static int writeexec(SCSCP_io *stream, void *param, SCSCP_status *status) { int res = SCSCP_io_writebeginOMA(stream, NULL, status); res &= SCSCP_io_writeOMR(stream, (const char *)param, status); res &= SCSCP_io_writeendOMA(stream, status); return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { int res; res = startserverandsendbincheck(26, writeexec, "scscp://test1"); if (!res) res = startserverandsendbincheck(27, writeexec, (void *)getlongstring()); return res; } scscp-imcce-1.0.0+ds/tests/scscpomstrbin.c000066400000000000000000000063071215622604100205070ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpomstrbin.c \brief check that server could decode an OMSTR in binary encoding \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscpsscommon.h" static int writeexec(SCSCP_io *stream, void *param, SCSCP_status *status) { int res = SCSCP_io_writebeginOMA(stream, NULL, status); res &= SCSCP_io_writeOMSTR(stream, (const char *)param, NULL, status); res &= SCSCP_io_writeendOMA(stream, status); return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { int res; res = startserverandsendbincheck(24, writeexec, (void*)"1234567890"); if (!res) res = startserverandsendbincheck(25, writeexec, (void *)getlongstring()); return res; } scscp-imcce-1.0.0+ds/tests/scscpomv.c000066400000000000000000000075431215622604100174560ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpomv.c \brief check that client could decode an OMV \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscpsscommon.h" static int writeexec(SCSCP_io *stream, void *param, SCSCP_status *status) { return SCSCP_io_writeOMV(stream, "xy", NULL, status); } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; SCSCP_xmlnodeptr node; const char *value; res = startbackgroundserver(11, &port); /* open connection with the server on port */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); /* send a valid symbol */ if (res) res = SCSCP_sc_executehookxmlnode(&client, SCSCP_option_return_object, "arith1", "plus", writeexec, NULL, &node, &status); if (res) { res = SCSCP_xmlnode_readOMV(&node, &value); if (res==0 || strcmp(value,"myvar")!=0) res=0; } /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpomvbin.c000066400000000000000000000062641215622604100201460ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpomvbin.c \brief check that server could decode an OMV in binary encoding \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscpsscommon.h" static int writeexec(SCSCP_io *stream, void *param, SCSCP_status *status) { int res = SCSCP_io_writebeginOMA(stream, NULL, status); res &= SCSCP_io_writeOMV(stream, (const char *)param, NULL, status); res &= SCSCP_io_writeendOMA(stream, status); return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { int res = startserverandsendbincheck(13, writeexec, (void *)"xy"); if (!res) res = startserverandsendbincheck(14,writeexec, (void *) getlongstring()); return res; } scscp-imcce-1.0.0+ds/tests/scscprawstring.c000066400000000000000000000106651215622604100206740ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscprawstring.c \brief check that client could get a rawstring \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(SCSCP_socketclient *client, SCSCP_status *status) { int res; SCSCP_msgtype msgtype; SCSCP_returnoptions options; res = SCSCP_ro_init(&options, status); if (!res) return res; res = SCSCP_sc_callrecvheader(client, &options, &msgtype, status); if (res) { SCSCP_xmlnodeptr node = SCSCP_sc_getxmlnode(client, status); if (node!=NULL) { char *buffer = SCSCP_sc_getxmlnoderawstring(client, node,status); if (buffer) { SCSCP_debugprint("buffer='%s'\n", buffer); free(buffer); } else res = 0; } else res = 0; } if (res==0) printf("error=%s\n", SCSCP_status_strerror(status)); return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; res = startbackgroundserver(2, &port); /* open connection with the server on port */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); /* send an invalid symbol */ if (res) res = SCSCP_sc_callsendstr(&client, SCSCP_CALLOPTIONS_DEFAULT, "", &status); /* receive the answer */ if (res) res = decodeanswer(&client, &status); /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpremote1.c000066400000000000000000000113021215622604100202150ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpremote1.c \brief check that client could send, retrieve and delete a remote object using string \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscpsscommon.h" /*-----------------------------------------------------------------*/ /* hook function */ /*-----------------------------------------------------------------*/ static int writehook(SCSCP_io *stream, void *param, SCSCP_status *status) { return SCSCP_io_writeOMIstr(stream, (const char*)param, NULL, status); } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; char *cookiename=NULL; char *openmathbuffer = NULL; SCSCP_xmlnodeptr node = NULL; res = startbackgroundserver(8, &port); /* open connection with the server on port */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); /* store */ if (res) res = SCSCP_sc_remoteobjectstoresessionhook(&client, writehook, (void*)"2", &cookiename, &status); /* get str */ if (res) res = SCSCP_sc_remoteobjectretrievestr(&client, cookiename, &openmathbuffer, &status); if (res && strcmp(openmathbuffer,"2")!=0) { printf("received openmath object : '%s'\n", openmathbuffer); res = 0; } if (openmathbuffer) free(openmathbuffer); /* get node */ if (res) res = SCSCP_sc_remoteobjectretrievexmlnode(&client, cookiename, &node, &status); openmathbuffer = SCSCP_sc_getxmlnoderawstring(&client, SCSCP_sc_getxmlnode(&client, &status), &status); if (res && strcmp(openmathbuffer,"2")!=0) { printf("received openmath object node : '%s'\n", openmathbuffer); res = 0; } if (openmathbuffer) free(openmathbuffer); /*delete */ if (res) res = SCSCP_sc_remoteobjectunbind(&client, cookiename, &status); /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); if( cookiename) free(cookiename); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpremote2.c000066400000000000000000000126671215622604100202350ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpremote1.c \brief check that client could receive EXECFAILED error \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* hook function */ /*-----------------------------------------------------------------*/ static int writehook(SCSCP_io *stream, void *param, SCSCP_status *status) { return SCSCP_io_writeOMIstr(stream, (const char*)param, NULL, status); } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; char *cookiename=NULL; char *openmathbuffer = NULL; SCSCP_xmlnodeptr node = NULL; res = startbackgroundserver(9, &port); /* open connection with the server on port 26133 */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); /* store */ if (res) res = SCSCP_sc_remoteobjectstoresessionhook(&client, writehook, (void*)"2", &cookiename, &status); /* get str */ if (res) res = SCSCP_sc_remoteobjectretrievestr(&client, "invalid name", &openmathbuffer, &status); if (res==0) { if (SCSCP_status_is(&status)==SCSCP_STATUS_EXECFAILED) { SCSCP_debugprint("error message : %s ==>ok!\n", SCSCP_status_strerror(&status)); res = 1; } else { printf("invalid error message for SCSCP_sc_remoteobjectretrievestr : %s ==>failed!\n", SCSCP_status_strerror(&status)); res = 0; } } else { printf("res = 1 for SCSCP_sc_remoteobjectretrievestr !!\n"); res = 0; } /* get node */ if (res) res = SCSCP_sc_remoteobjectretrievexmlnode(&client,"invalid name", &node, &status); if (res==0) { if (SCSCP_status_is(&status)==SCSCP_STATUS_EXECFAILED) { SCSCP_debugprint("error message : %s ==>ok!\n", SCSCP_status_strerror(&status)); res = 1; } else { printf("invalid error message for SCSCP_sc_remoteobjectretrievexmlnode : %s ==>failed!\n", SCSCP_status_strerror(&status)); res = 0; } } else { printf("res = 1 for SCSCP_sc_remoteobjectretrievexmlnode !!\n"); res = 0; } /*delete */ if (res) res = SCSCP_sc_remoteobjectunbind(&client, "invalid name", &status); if (res==0) { if (SCSCP_status_is(&status)==SCSCP_STATUS_EXECFAILED) { SCSCP_debugprint("error message : %s ==>ok!\n", SCSCP_status_strerror(&status)); res = 1; } else { printf("invalid error message for SCSCP_sc_remoteobjectunbind : %s ==>failed!\n", SCSCP_status_strerror(&status)); res = 0; } } else { printf("res = 1 for SCSCP_sc_remoteobjectunbind !!\n"); res = 0; } /* close the connection */ if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpreturnoptions.c000066400000000000000000000133501215622604100216010ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpreturnoptions.c \brief check that client could decode the return options. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(SCSCP_socketclient *client, SCSCP_status *status) { int res, res2; SCSCP_msgtype msgtype; SCSCP_returnoptions options; size_t memsize, timeusage; const char *buffer; res = SCSCP_ro_init(&options, status); if (!res) return res; res = SCSCP_sc_callrecvheader(client, &options, &msgtype, status); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : SCSCP_debugprint("Procedure Terminated\n"); break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); break; default : printf("unknown message type !!!\n"); res = 0; break; } if (res) { res2 = SCSCP_ro_get_runtime(&options, &timeusage, status); if (res2) SCSCP_debugprint("time usage = %lld\n", (long long)timeusage); else if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNRUNTIME) SCSCP_debugprint("time usage not available\n"); else { printf("unknown status!!!\n"); res = 0; } res2 = SCSCP_ro_get_memory(&options, &memsize, status); if (res2) SCSCP_debugprint("memory usage = %lld\n", (long long)memsize); else if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNMEM) SCSCP_debugprint("memory usage not available\n"); else { printf("unknown status!!!\n"); res = 0; } res2 = SCSCP_ro_get_message(&options, &buffer, status); if (res2) SCSCP_debugprint("message = '%s'\n", buffer); else if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNMESSAGE) SCSCP_debugprint("message not available\n"); else { printf("unknown status!!!\n"); res = 0; } if (res) res = SCSCP_ro_get_callid(&options, &buffer, status); SCSCP_debugprint("call id='%s'\n", buffer); } } return res; } int main() { int reserver; SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; SCSCP_calloptions options; int res; int port; res = startbackgroundserver(1, &port); /* open connection with the server on port 26133 */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); if (res) res = SCSCP_co_init(&options, &status); if (res) res = SCSCP_co_set_callid(&options, "call 1", &status); if (res) res = SCSCP_sc_callsendstr(&client, &options, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_sc_close(&client, &status); if (res) SCSCP_co_clear(&options, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscprofailed1.c000066400000000000000000000052741215622604100205220ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscprofailed1.c \brief check the error : SCSCP_ro_get_callid returns SCSCP_STATUS_RETURNOPTIONSOBJECTNULL \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" int main() { SCSCP_status status = SCSCP_STATUS_INITIALIZER; const char *buffer; int res; res = SCSCP_ro_get_callid(NULL, &buffer, &status); return (res==0 && SCSCP_status_is(&status)==SCSCP_STATUS_RETURNOPTIONSOBJECTNULL); } scscp-imcce-1.0.0+ds/tests/scscpscconnect.c000066400000000000000000000061211215622604100206230ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpscconnect.c \brief check that client could connect with a valid SCSCP server \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" #include "scscpsscommon.h" int main() { int reserver, res, port; SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; res = startbackgroundserver(0, &port); /* open connection with the server on port 26133 */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpscconnectfailed1.c000066400000000000000000000054141215622604100220550ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpscconnectfailed1.c \brief check the error : SCSCP_sc_connect failed on invalid host name \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res = SCSCP_sc_init(&client, &status, NULL); if (res) res = SCSCP_sc_connect(&client, "my invalid name", 26133, &status); SCSCP_sc_clear(&client, &status); return (res==0 && SCSCP_status_is(&status)!=SCSCP_STATUS_OK); } scscp-imcce-1.0.0+ds/tests/scscpscconnectfailed2.c000066400000000000000000000053761215622604100220650ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpscconnectfailed2.c \brief check the error : SCSCP_sc_connect failed on invalid port \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res = SCSCP_sc_init(&client, &status, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", -1, &status); SCSCP_sc_clear(&client,&status); return (res==0 && SCSCP_status_is(&status)!=SCSCP_STATUS_OK); } scscp-imcce-1.0.0+ds/tests/scscpscinitfailed1.c000066400000000000000000000052141215622604100213650ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpscinitfailed1.c \brief check the error : SCSCP_sc_init returns SCSCP_STATUS_CLIENTOBJECTNULL \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" int main() { SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res = SCSCP_sc_init(NULL, &status, NULL); return (res==0 && SCSCP_status_is(&status)==SCSCP_STATUS_CLIENTOBJECTNULL); } scscp-imcce-1.0.0+ds/tests/scscpsendgetallowheads.c000066400000000000000000000054601215622604100223460ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpsendgetallowheads.c \brief check that client could connect and send a basic command to a valid SCSCP server (symbol : get_allowed_heads, cd: scscp2) check the call options. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" #include "scscpsscommon.h" int mainsend(int port); int main() { int reserver; int res; int port; startbackgroundserver(0, &port); res = mainsend(port); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpsendserveroption.c000066400000000000000000000053011215622604100222540ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpsendserveroption.c \brief check that server could decode the call options. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" #include "scscpsscommon.h" extern int mainsend(int port); int main() { int reserver; int res; int port; startbackgroundserver(4, &port); res = mainsend(port); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpserversendinfo.c000066400000000000000000000111561215622604100217040ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpserversendinfo.c \brief check that the server sends an info message before its answer. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(SCSCP_socketclient *client, SCSCP_status *status) { int res; SCSCP_msgtype msgtype; char *openmathbuffer; res =SCSCP_sc_callrecvstr(client, SCSCP_RETURNOPTIONS_IGNORE, &msgtype, &openmathbuffer, status); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated\n"); res =0; break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); break; default : res=0; break; } SCSCP_debugprint("buffer:'%s'\n",openmathbuffer); free(openmathbuffer); } else { printf ("SCSCP_sc_callrecvstr : failed status=%d\n", SCSCP_status_is(status)); } return res; } /*-----------------------------------------------------------------*/ /* send the command to the server */ /*-----------------------------------------------------------------*/ int mainsend(int port) { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res; int res1 = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); res = res1; if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); if (res) res = SCSCP_sc_callsendstr(&client, SCSCP_CALLOPTIONS_DEFAULT, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_sc_close(&client, &status); if (res1) res1 = SCSCP_sc_clear(&client, &status); if (res) res1 = res; SCSCP_status_clear(&status); return res; } int main() { int reserver; int res; int port; startbackgroundserver(6, &port); res = mainsend(port); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscpservertest.c000066400000000000000000000541211215622604100210550ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpservertest.c \brief default server tests \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, 2013, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 \bug M. GASTINEAU 27/08/09 : test for ticket [#6399] openmath encoded with namespaces are rejected \bug M. GASTINEAU 01/10/12 : ticket [#8521] tests hangs or are too long */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #if HAVE_STRING_H #include #endif #include #define __SCSCP_WITHIN_SCSCP #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" #include "scscpfileserver.h" #if defined(SIGUSR2) #define SIGNALINTERRUPT SIGUSR2 #else #define SIGNALINTERRUPT SIGINT #endif /* SCSCP server */ static SCSCP_socketserver server; static int closesig=0; /* =1 if SIGUSR2 is received */ static int processcall(SCSCP_incomingclient *incomingclient, SCSCP_status *status, int typeanswer); static int server_sendreplycheck(SCSCP_incomingclient *incomingclient, SCSCP_returnoptions* returnopt, SCSCP_status *status, int res1, const char *value, const char *valueref); static int server_sendreplycheckint(SCSCP_incomingclient *incomingclient, SCSCP_returnoptions* returnopt, SCSCP_status *status, int res1, int value, int valueref); static int server_sendreplycheckdouble(SCSCP_incomingclient *incomingclient, SCSCP_returnoptions* returnopt, SCSCP_status *status, int res1, double value, double valueref); /*-----------------------------------------------------------------*/ /*! stop the server when it receive SIGUSR2 */ /*-----------------------------------------------------------------*/ static void stopserver(int sig) { SCSCP_status status = SCSCP_STATUS_INITIALIZER; SCSCP_debugprint("server receive SIGUSR2\n"); closesig=1; /* close the connection */ SCSCP_ss_close(&server, &status); /* exit the server */ exit(0); } /*-----------------------------------------------------------------*/ /*! start the server and listen on a port. the server finds an random available port */ /*-----------------------------------------------------------------*/ static int runserver(int typeanswer, int fd) { SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res; SCSCP_incomingclient incomingclient; int port = SCSCP_PROTOCOL_DEFAULTPORT; /*printf("server thread started\n");*/ /* register stopserver for the signal SIGUSR2 */ signal(SIGNALINTERRUPT, stopserver); /*initialization of the server */ res = SCSCP_ss_init(&server, &status, "MYCAS","1","myid", SCSCP_PROTOCOL_VERSION_1_3, "1.001", NULL); if (res) { if (fd==-1) { port = SCSCP_PROTOCOL_DEFAULTPORT; res = SCSCP_ss_listen(&server, port, 0, &status); } else { /* choose a random port */ port = 0; res = SCSCP_ss_listen(&server, port, 0, &status); /* write the port used by the server to the client */ if (res!=0) { port = SCSCP_ss_getport(&server); SCSCP_debugprint("fd=%d -> port:%d\n", fd, port); write(fd,&port, sizeof(port)); } close(fd); } } if (res) { while (res!=0 && SCSCP_ss_acceptclient(&server, &incomingclient, &status)) { SCSCP_debugprint("new client accepted !\n"); while (res>0) res = processcall(&incomingclient, &status,typeanswer); SCSCP_ss_closeincoming(&incomingclient, &status); status = SCSCP_STATUS_INITIALIZER; res = 1; } } if (res==0) printf("error message= %s\n", SCSCP_status_strerror(&status)); if (res==0) printf("destroy server\n"); /* destroy the server */ SCSCP_ss_close(&server, &status); res = SCSCP_ss_clear(&server, &status); SCSCP_status_clear(&status); SCSCP_debugprint("server exit %d typeanswer=%d\n", closesig, typeanswer); if (res!=-1 && closesig==0) { printf("server thread crash => exit with value 1\n"); printf("----------------------------------------\n"); printf(" reports this bug to %s \n", PACKAGE_BUGREPORT); printf("----------------------------------------\n"); return 1; } else { return 0; } } /*-----------------------------------------------------------------*/ /*! send the answer : if value==valueref then send a completed message */ /*-----------------------------------------------------------------*/ static int server_sendreplycheck(SCSCP_incomingclient *incomingclient, SCSCP_returnoptions* returnopt, SCSCP_status *status, int res1, const char *value, const char *valueref) { int res; if (res1!=1 || strcmp(value,valueref)!=0) { SCSCP_ss_sendterminatedstr(incomingclient, returnopt, "scscp1", "error_system_specific", value!=NULL?value:"null", status); res = 0; } else { res = SCSCP_ss_sendcompletedstr(incomingclient, returnopt, "1", status); } return res; } /*-----------------------------------------------------------------*/ /*! send the answer : if value==valueref then send a completed message */ /*-----------------------------------------------------------------*/ static int server_sendreplycheckint(SCSCP_incomingclient *incomingclient, SCSCP_returnoptions* returnopt, SCSCP_status *status, int res1, int value, int valueref) { int res; if (res1!=1 || value!=valueref) { char buffer[128]; sprintf(buffer, "%d %d", value, valueref); SCSCP_ss_sendterminatedstr(incomingclient, returnopt, "scscp1", "error_system_specific", buffer, status); res = 0; } else { res = SCSCP_ss_sendcompletedstr(incomingclient, returnopt, "1", status); } return res; } /*-----------------------------------------------------------------*/ /*! send the answer : if value==valueref then send a completed message */ /*-----------------------------------------------------------------*/ static int server_sendreplycheckdouble(SCSCP_incomingclient *incomingclient, SCSCP_returnoptions* returnopt, SCSCP_status *status, int res1, double value, double valueref) { int res; if (res1!=1 || value!=valueref) { char buffer[128]; sprintf(buffer, "%23.16E %23.16E", value, valueref); SCSCP_ss_sendterminatedstr(incomingclient, returnopt, "scscp1", "error_system_specific", buffer, status); res = 0; } else { res = SCSCP_ss_sendcompletedstr(incomingclient, returnopt, "1", status); } return res; } /*-----------------------------------------------------------------*/ /*! process the procedure call */ /*-----------------------------------------------------------------*/ static int processcall(SCSCP_incomingclient *incomingclient, SCSCP_status *status,int typeanswer) { int res, resopt; int res1=0; SCSCP_calloptions options, options2; SCSCP_returnoptions returnopt; SCSCP_msgtype msgtype; size_t timeusage, memsize; int debuglevel; SCSCP_option_return returntype; static char *buffer; static int counter=0; SCSCP_xmlnodeptr ptr; const char *valuestr; int valueint, valueintref; const char *valuestrref; double valuedbl; res = SCSCP_co_init(&options, status); res = SCSCP_ro_init(&returnopt, status); if (res) { res = SCSCP_ss_callrecvheader(incomingclient, &options, &msgtype, status); if (res || typeanswer==28) { const char *callid; if (!SCSCP_co_get_callid(&options, &callid, status)) callid="N/A client id"; SCSCP_ro_set_callid(&returnopt, callid, status); switch(msgtype) { case SCSCP_msgtype_ProcedureCall : /*printf("Procedure Call '%s'\n", callid);*/ switch(typeanswer) { case 0: res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "0", status); break; case 1: SCSCP_ro_set_runtime(&returnopt, 55, status); SCSCP_ro_set_memory(&returnopt, 100, status); SCSCP_ro_set_message(&returnopt, "my information message from libSCSCP", status); res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "0", status); if (res==0) printf("SCSCP_ss_sendcompletedstr failed! status=%d.\n",SCSCP_status_is(status)); break; case 2: res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "", status); if (res==0) printf("SCSCP_ss_sendcompletedstr failed! status=%d.\n",SCSCP_status_is(status)); break; case 3: res = SCSCP_ss_sendterminatedstr(incomingclient, &returnopt, "scscp1", "error_system_specific", "unknown symbol", status); if (res==0) printf("SCSCP_ss_sendterminatedstr failed! status=%d.\n",SCSCP_status_is(status)); break; case 4: resopt = SCSCP_co_get_runtimelimit(&options, &timeusage, status); if (resopt) SCSCP_debugprint("runtime limit = %lld\n", (long long)timeusage); else { if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNRUNTIME) SCSCP_debugprint("runtime limit not available\n"); else res = 0; } resopt = SCSCP_co_get_minmemory(&options, &memsize, status); if (resopt) SCSCP_debugprint("minimum memory = %lld\n", (long long)memsize); else { if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNMINMEMORY) SCSCP_debugprint("minimum memory not available\n"); else res = 0; } resopt = SCSCP_co_get_maxmemory(&options, &memsize, status); if (resopt) SCSCP_debugprint("maximum memory = %lld\n", (long long)memsize); else { if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNMAXMEMORY) SCSCP_debugprint("maximum memory not available\n"); else res = 0; } resopt = SCSCP_co_get_debuglevel(&options, &debuglevel, status); if (resopt) SCSCP_debugprint("debug level = %d\n", debuglevel); else { if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNDEBUGLEVEL) SCSCP_debugprint("debug level not available\n"); else res = 0; } resopt = SCSCP_co_get_returntype(&options, &returntype, status); if (resopt) SCSCP_debugprint("return type = %d\n", (int)returntype); else { if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNRETURNTYPE) SCSCP_debugprint("return type not available\n"); else res = 0; } res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "0", status); if (res==0) printf("SCSCP_ss_sendcompletedstr failed! status=%d.\n",SCSCP_status_is(status)); break; case 6: res = SCSCP_ss_infomessagesend(incomingclient,"debugging command from server", status); if (res==0) printf("SCSCP_ss_infomessagesend failed! status=%d.\n",SCSCP_status_is(status)); if (strncmp(callid,"libSCSCP",strlen("libSCSCP"))==0) { res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "0", status); } else { res = SCSCP_ss_sendterminatedstr(incomingclient, &returnopt, "scscp1", "error_system_specific", "bad call ID name", status); } break; case 7: SCSCP_co_init(&options2, status); res = SCSCP_ss_callrecvheader(incomingclient, &options2, &msgtype, status); if (msgtype!=SCSCP_msgtype_Interrupt ) { res = SCSCP_ss_sendterminatedstr(incomingclient, &returnopt, "scscp1", "error_system_specific", "msgtype must be SCSCP_msgtype_Interrupt", status); } else { const char *newcallidinter; res = SCSCP_co_get_callid(&options2, &newcallidinter, status); if (strcmp(newcallidinter,callid)!=0) { printf("invalid call id: %s %s\n", newcallidinter,callid); res = 0; } res1 = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "0", status); if (res) res = res1; } SCSCP_co_clear(&options2, status); break; case 8: if (counter==0) { buffer = SCSCP_ss_getxmlnoderawstring(incomingclient, SCSCP_xmlnode_getnext(SCSCP_xmlnode_getchild(SCSCP_ss_getxmlnode(incomingclient, status))), status); res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "", status); counter++; } else if (counter<=2) { res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, buffer, status); counter++; } else { res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "", status); } break; case 9: if (counter==0) { buffer = SCSCP_ss_getxmlnoderawstring(incomingclient, SCSCP_xmlnode_getnext(SCSCP_xmlnode_getchild(SCSCP_ss_getxmlnode(incomingclient, status))), status); res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "", status); counter++; } else { res = SCSCP_ss_sendterminatedstr(incomingclient, &returnopt, "scscp1", "error_system_specific", "unknown symbol", status); } break; case 10: res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "", status); break; case 11: res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "", status); break; case 12: if (counter==0) { res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "1", status); counter++; } else { res = SCSCP_ss_sendcompletedstr(incomingclient, &returnopt, "2", status); } break; case 13: ptr = SCSCP_xmlnode_getchild(SCSCP_ss_getxmlnode(incomingclient, status)); if (ptr!=NULL) res1 = SCSCP_xmlnode_readOMV( &ptr, &valuestr); res = server_sendreplycheck(incomingclient, &returnopt, status, res1, valuestr, "xy"); break; case 14: ptr = SCSCP_xmlnode_getchild(SCSCP_ss_getxmlnode(incomingclient, status)); if (ptr!=NULL) res1 = SCSCP_xmlnode_readOMV(&ptr, &valuestr); res = server_sendreplycheck(incomingclient, &returnopt, status, res1, valuestr, getlongstring()); break; case 15: valueintref = 1; case 16: if (typeanswer==16) valueintref = 127; case 17: if (typeanswer==17) valueintref = 32768; case 18: if (typeanswer==18) valueintref = 2147483647; case 19: if (typeanswer==19) valueintref = -2147483647-1; /*-2147483648; : remove a warning from gcc */ ptr = SCSCP_xmlnode_getchild(SCSCP_ss_getxmlnode(incomingclient, status)); if (ptr!=NULL) res1 = SCSCP_xmlnode_readOMIint(&ptr, &valueint); res = server_sendreplycheckint(incomingclient, &returnopt, status, res1, valueint, valueintref); break; case 20: valuestrref = "+1125899906842624"; case 21: if (typeanswer==21) valuestrref = "-1125899906842624"; case 22: if (typeanswer==22) valuestrref = "+1125899906842624"; ptr = SCSCP_xmlnode_getchild(SCSCP_ss_getxmlnode(incomingclient, status)); if (ptr!=NULL) res1 = SCSCP_xmlnode_readOMIstr(&ptr, &valuestr); res = server_sendreplycheck(incomingclient, &returnopt, status, res1, valuestr, valuestrref); break; case 23: ptr = SCSCP_xmlnode_getchild(SCSCP_ss_getxmlnode(incomingclient, status)); if (ptr!=NULL) res1 = SCSCP_xmlnode_readOMFdouble(&ptr, &valuedbl); res = server_sendreplycheckdouble(incomingclient, &returnopt, status, res1, valuedbl, 1.0E-10); break; case 24: valuestrref = "1234567890"; case 25: if (typeanswer==25) valuestrref = getlongstring(); ptr = SCSCP_xmlnode_getchild(SCSCP_ss_getxmlnode(incomingclient, status)); if (ptr!=NULL) res1 = SCSCP_xmlnode_readOMSTR(&ptr, &valuestr); res = server_sendreplycheck(incomingclient, &returnopt, status, res1, valuestr, valuestrref); break; case 26: valuestrref = "scscp://test1"; case 27: if (typeanswer==27) valuestrref = getlongstring(); ptr = SCSCP_xmlnode_getchild(SCSCP_ss_getxmlnode(incomingclient, status)); if (ptr!=NULL) res1 = SCSCP_xmlnode_readOMR(&ptr, &valuestr); res = server_sendreplycheck(incomingclient, &returnopt, status, res1, valuestr, valuestrref); break; case 28: if (SCSCP_status_is(status)==SCSCP_STATUS_OPENMATHNOTVALID) { res = SCSCP_ss_sendterminatedstr(incomingclient, &returnopt, "scscp1", "error_system_specific", SCSCP_status_strerror(status), status); if (res==0) printf("SCSCP_ss_sendterminatedstr failed! status=%d.\n",SCSCP_status_is(status)); } break; } break; default : if (typeanswer!=28) printf("unknown message type !!!\n"); res = 0; break; } } else { /* if client close the connection => return -1 */ /*printf("SCSCP_ss_callrecvheader failed! status=%d.\n",SCSCP_status_is(status));*/ if (SCSCP_status_is(status)==SCSCP_STATUS_RECVQUIT) res = -1; if (typeanswer==28 && SCSCP_status_is(status)==SCSCP_STATUS_OPENMATHNOTVALID) { printf("detect SCSCP_STATUS_OPENMATHNOTVALID\n"); res = 1; } } SCSCP_co_clear(&options, status); SCSCP_ro_clear(&returnopt, status); } else { printf("SCSCP_ro_init failed status=%d.\n",SCSCP_status_is(status)); } return res; } /*-----------------------------------------------------------------*/ /*! main program */ /*-----------------------------------------------------------------*/ int main(int argc, char *argv[]) { /* printf("scscpservertest started with %d\n", atoi(argv[1]));*/ return runserver(atoi(argv[1]), argc==3?atoi(argv[2]):-1); } scscp-imcce-1.0.0+ds/tests/scscpsscommon.c000066400000000000000000000243541215622604100205120ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpsscommon.c \brief common subroutine for server tests \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 01/10/12 : ticket [#8521] tests hangs or are too long */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include #if HAVE_SYS_WAIT_H #include #endif #if HAVE_UNISTD_H #include #endif #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" #if HAVE_FORK typedef pid_t ospid_t; #elif HAVE_WIN32API typedef PROCESS_INFORMATION ospid_t; #endif /* id of the server */ static ospid_t pserverid; /*-----------------------------------------------------------------*/ /*! synchronization between client and server. The client waits until the server is listening and accepts client @param port (in) SCSCP port */ /*-----------------------------------------------------------------*/ static int writesync(int port) { int res; int sleeptime = 1; SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); do { mysleep(sleeptime); res = SCSCP_sc_connect(&client, "localhost", port, &status); /*printf("writesync %d '%s'\n", res, SCSCP_status_strerror(&status));*/ } while (res==0); SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); return 1; } /*-----------------------------------------------------------------*/ /*! start a new thread which will run the server. update pserverid return the port used by the server */ /*-----------------------------------------------------------------*/ int startbackgroundserver(int typeanswer, int *port) { int res = 0; char bufanswer[10]; char sfd[10]; int fd[2], nr; sprintf(bufanswer, "%d",typeanswer); #if HAVE_FORK if (pipe(fd)<0) { printf("Can't create pipe!\n"); return res; } pserverid = fork(); switch(pserverid) { case -1: res = 0; break; case 0: /* child */ close(fd[0]); sprintf(sfd, "%d", fd[1]); if (execl("scscpservertest", "scscpservertest", bufanswer, sfd, NULL)==-1) { res = 0; printf("startbackgroundserver failed on exec\n"); } break; default: /* parent */ close(fd[1]); res = 1; /*printf("parent process : child pid= %d\n",(int)pserverid);*/ break; } /* read the port by the server */ nr = (int)read(fd[0], port,sizeof(*port)); if (nr!=(int)sizeof(*port)) { printf("Can't read pipe : can't read the port sent by the server!\n"); printf ("debug info : nr=%d size=%d\n", nr, (int)sizeof(*port)); res = 0; return res; } #elif HAVE_WIN32API { STARTUPINFO siStartInfo; BOOL bFuncRetn = FALSE; char cmd[1024]; sprintf(cmd,"scscpservertest.exe %d", typeanswer); ZeroMemory( &pserverid, sizeof(PROCESS_INFORMATION) ); ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) ); siStartInfo.cb = sizeof(STARTUPINFO); res = CreateProcess(NULL, cmd, /* command line */ NULL, /* process security attributes */ NULL, /* primary thread security attributes */ FALSE, /* handles are inherited */ CREATE_NEW_PROCESS_GROUP, /* creation flags */ NULL, /* use parent's environment */ NULL, /* use parent's current directory */ &siStartInfo, /* STARTUPINFO pointer */ &pserverid); /* receives PROCESS_INFORMATION */ if (res==0) { printf("res=%d\n",res); printf( "CreateProcess failed (%d)\n", GetLastError() ); } *port = SCSCP_PROTOCOL_DEFAULTPORT; } #endif /*HAVE_WIN32API*/ SCSCP_debugprint("port=%d\n", *port); writesync(*port); SCSCP_debugprint("synchronization performed on port=%d\n", *port); return res; } /*-----------------------------------------------------------------*/ /*! send the stop action to the thread of the server @bug M. GASTINEAU 13/01/2009 : send CTRL+BREAK to stop the server on windows */ /*-----------------------------------------------------------------*/ int stopbackgroundserver() { int res = 0; int status; #if HAVE_FORK /*printf("send kill to pid= %d\n",(int)pserverid);*/ kill(pserverid, SIGUSR2); waitpid(pserverid, &status, WUNTRACED); if (WIFEXITED(status)) { res = (WEXITSTATUS(status) != 0); } #elif HAVE_WIN32API GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pserverid.dwProcessId); WaitForSingleObject( pserverid.hProcess, INFINITE ); CloseHandle(pserverid.hProcess); CloseHandle(pserverid.hThread); #endif return res; } /*-----------------------------------------------------------------*/ /*! sleep for some seconds @param sec (in) number of seconds */ /*-----------------------------------------------------------------*/ void mysleep(int sec) { #if HAVE_FORK sleep(sec); #elif HAVE_WIN32API Sleep(sec*1000); #endif } /*-----------------------------------------------------------------*/ /*! send a procedure call and check that the answer is 1 @param client (inout) client connection @param status (inout) error code @param callbackwrite (in) call back function write the arguments of the procedure call @param param (in) opaque user data given to callbackwrite */ /*-----------------------------------------------------------------*/ int sendprocedurecallcheck(SCSCP_socketclient* client, SCSCP_status* status, int (*callbackwrite)(SCSCP_io* stream, void *param, SCSCP_status *status), void *param) { int res; char *openmathbuffer; SCSCP_msgtype msgtype; res = SCSCP_sc_callsendhook(client, SCSCP_CALLOPTIONS_DEFAULT, callbackwrite, param, status); if (res) res = SCSCP_sc_callrecvstr(client, SCSCP_RETURNOPTIONS_IGNORE, &msgtype, &openmathbuffer, status); if (res) { res = (strcmp(openmathbuffer,"1")==0); if (res==0) printf("openmathbuffer='%s'\n", openmathbuffer); free(openmathbuffer); } else { printf("sendprocedurecallcheck failed ='%s'\n", SCSCP_status_strerror(status)); } return res; } /*-----------------------------------------------------------------*/ /*! start the server and send a procedure call message and check the reply that must be 1 @param typeserver (in) value to start the server @param callbackwrite (in) call back function write the arguments of the procedure call @param param (in) opaque user data given to callbackwrite */ /*-----------------------------------------------------------------*/ int startserverandsendbincheck(int typeserver, int (*callbackwrite)(SCSCP_io* stream, void *param, SCSCP_status *status), void *param) { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; res = startbackgroundserver(typeserver, &port); /* open connection with the server on port 26133 */ if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); if (res) res = SCSCP_sc_set_encodingtype(&client, SCSCP_encodingtype_Binary, &status); /* send a valid symbol */ if (res) res = sendprocedurecallcheck(&client, &status, callbackwrite, param); if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } /*-----------------------------------------------------------------*/ /*! return a long string >256 characters */ /*-----------------------------------------------------------------*/ const char *getlongstring(void) { return "azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890"; } scscp-imcce-1.0.0+ds/tests/scscpsscommon.h000066400000000000000000000065101215622604100205110ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpsscommon.h \brief definition of the common subroutine for server tests \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012 M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ /* start a new thread which will run the server and return the port used by the server. */ int startbackgroundserver(int typeanswer, int *port); /* send the stop action to the thread of the server */ int stopbackgroundserver(); /* sleep */ void mysleep(int sec); /* send a procedure call and check that the answer is 1 */ int sendprocedurecallcheck(SCSCP_socketclient* client, SCSCP_status* status, int (*callbackwrite)(SCSCP_io* stream, void *param, SCSCP_status *status), void *param); /*start the server and send a procedure call message and check the reply that must be 1*/ int startserverandsendbincheck(int typeserver, int (*callbackwrite)(SCSCP_io* stream, void *param, SCSCP_status *status), void *param); /*! return a long string (length <256) */ const char *getlongstring(void); scscp-imcce-1.0.0+ds/tests/scscpssinit.c000066400000000000000000000054331215622604100201620ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpssinit.c \brief check SCSCP_ss_init and SCSCP_ss_clear \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" int main() { SCSCP_status status = SCSCP_STATUS_INITIALIZER; SCSCP_socketserver server; int res; res = SCSCP_ss_init(&server, &status, "MYCAS","1","myid", SCSCP_PROTOCOL_VERSION_1_3, "1.001", NULL); res = SCSCP_ss_clear(&server, &status); SCSCP_status_clear(&status); return (res!=1); } scscp-imcce-1.0.0+ds/tests/scscpssinitfailed1.c000066400000000000000000000052271215622604100214110ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpssinitfailed1.c \brief check the error : SCSCP_ss_init returns SCSCP_STATUS_SERVEROBJECTNULL \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscp.h" int main() { SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res = SCSCP_ss_init(NULL, &status, "","","", NULL); return (res==0 && SCSCP_status_is(&status)==SCSCP_STATUS_SERVEROBJECTNULL); } scscp-imcce-1.0.0+ds/tests/scscpterminated.c000066400000000000000000000113331215622604100210010ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpterminated.c \brief check that client could decode the terminated message. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include "scscp.h" #include "scscpsscommon.h" #include "scscpdebug.h" /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(SCSCP_socketclient *client, SCSCP_status *status) { int res; SCSCP_msgtype msgtype; SCSCP_returnoptions options; char *messagebuffer; char *cdname; char *symbolname; res = SCSCP_ro_init(&options, status); if (!res) return res; res = SCSCP_sc_callrecvheader(client, &options, &msgtype, status); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : SCSCP_debugprint("Procedure Terminated\n"); res = SCSCP_sc_callrecvterminated(client, &cdname, &symbolname, &messagebuffer, status); if (res) { SCSCP_debugprint("cd=%s\n", cdname); SCSCP_debugprint("symbolname=%s\n", symbolname); SCSCP_debugprint("message='%s'\n", messagebuffer); free(messagebuffer); } break; case SCSCP_msgtype_ProcedureCompleted : printf("Procedure Completed => can't be possible\n"); res=0; break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; res = startbackgroundserver(3, &port); if (res) res = SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); if (res) res = SCSCP_sc_connect(&client, "localhost", port, &status); /*send an invalid symbol */ if (res) res = SCSCP_sc_callsendstr(&client, SCSCP_CALLOPTIONS_DEFAULT, "", &status); if (res) res = decodeanswer(&client, &status); if (res) res = SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); SCSCP_status_clear(&status); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/tests/scscptversion.c000066400000000000000000000055051215622604100205220ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscptversion.c \brief check SCSCP_get_version \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #if HAVE_STRING_H #include #endif #include "scscp.h" #include "scscputil.h" int main() { int res; char libversion[]="MM.mm.pp"; snprintf(libversion,8,"%ud.%ud.%ud",SCSCP_VERSION_MAJOR,SCSCP_VERSION_MINOR,SCSCP_VERSION_PATCH); #if 0 printf("version :'%s'\n", SCSCP_get_libversionstr()); #endif res = strcmp(libversion,SCSCP_get_libversionstr()); return (res==0); } scscp-imcce-1.0.0+ds/testsxx/000077500000000000000000000000001215622604100160245ustar00rootroot00000000000000scscp-imcce-1.0.0+ds/testsxx/Makefile.am000066400000000000000000000114431215622604100200630ustar00rootroot00000000000000 #/*-----------------------------------------------------------------*/ #/*! # \file Makefile.am # \brief Makefile for automake # \author M. Gastineau # Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. # # Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, CNRS # email of the author : gastineau@imcce.fr # # \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 #*/ #/*-----------------------------------------------------------------*/ # #/*-----------------------------------------------------------------*/ #/* License of this file : # This file is "dual-licensed", you have to choose one of the two licenses # below to apply on this file. # # CeCILL-C # The CeCILL-C license is close to the GNU LGPL. # ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) # # or CeCILL v2.0 # The CeCILL license is compatible with the GNU GPL. # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) # # # This library is governed by the CeCILL-C or the CeCILL license under # French law and abiding by the rules of distribution of free software. # You can use, modify and/ or redistribute the software under the terms # of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA # at the following URL "http://www.cecill.info". # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # In this respect, the user's attention is drawn to the risks associated # with loading, using, modifying and/or developing or reproducing the # software by the user in light of its specific status of free software, # that may mean that it is complicated to manipulate, and that also # therefore means that it is reserved for developers and experienced # professionals having in-depth computer knowledge. Users are therefore # encouraged to load and test the software's suitability as regards their # requirements in conditions enabling the security of their systems and/or # data to be ensured and, more generally, to use and operate it in the # same conditions as regards security. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-C or CeCILL license and that you accept its terms. # */ # /*-----------------------------------------------------------------*/ ## Makefile.am -- Process this file with automake to produce Makefile.in LDADD = $(top_builddir)/srcxx/libscscpxx.la $(top_builddir)/src/libscscp.la $(XML_LIBS) AM_CPPFLAGS = -I$(top_srcdir)/src/ -I$(top_srcdir)/srcxx/ $(XML_CPPFLAGS) checkfailed = scscpscconnectfailed1xx scscpscconnectfailed2xx checkok = scscpscconnectxx scscpsendgetallowheadsxx scscpreturnoptionsxx scscpterminatedxx scscpcompleted1xx \ scscpcompleted2xx scscpssinitxx scscpsendserveroptionxx scscpserversendinfoxx scscpclientsendinfoxx \ scscpinterruptxx scscpomfxx scscpomvxx \ scscpomvbinxx scscpomibinxx scscpomfbinxx scscpomstrbinxx scscpomrbinxx check_PROGRAMS = $(checkfailed) $(checkok) TESTS = $(checkfailed) $(checkok) XFAIL_TESTS = $(checkfailed) noinst_PROGRAMS = scscpservertest scscpscconnectfailed1xx_SOURCES = scscpscconnectfailed1xx.cpp scscpscconnectfailed2xx_SOURCES = scscpscconnectfailed2xx.cpp scscpscconnectxx_SOURCES = scscpscconnectxx.cpp scscpsscommonxx.cpp scscpsendgetallowheadsxx_SOURCES = scscpsendgetallowheadsxx.cpp scscpsscommonxx.cpp cmncalloptionxx.cpp scscpreturnoptionsxx_SOURCES = scscpreturnoptionsxx.cpp scscpsscommonxx.cpp scscpterminatedxx_SOURCES = scscpterminatedxx.cpp scscpsscommonxx.cpp scscpcompleted1xx_SOURCES = scscpcompleted1xx.cpp scscpsscommonxx.cpp scscpcompleted2xx_SOURCES = scscpcompleted2xx.cpp scscpsscommonxx.cpp scscpssinitxx_SOURCES = scscpssinitxx.cpp scscpservertest_SOURCES = scscpservertestxx.cpp scscpsscommonxx.cpp scscpsendserveroptionxx_SOURCES = scscpsendserveroptionxx.cpp scscpsscommonxx.cpp cmncalloptionxx.cpp scscpserversendinfoxx_SOURCES = scscpserversendinfoxx.cpp scscpsscommonxx.cpp scscpclientsendinfoxx_SOURCES = scscpclientsendinfoxx.cpp scscpsscommonxx.cpp scscpinterruptxx_SOURCES = scscpinterruptxx.cpp scscpsscommonxx.cpp scscpomfxx_SOURCES = scscpomfxx.cpp scscpsscommonxx.cpp scscpomvxx_SOURCES = scscpomvxx.cpp scscpsscommonxx.cpp scscpomvbinxx_SOURCES = scscpomvbinxx.cpp scscpsscommonxx.cpp scscpomibinxx_SOURCES = scscpomibinxx.cpp scscpsscommonxx.cpp scscpomfbinxx_SOURCES = scscpomfbinxx.cpp scscpsscommonxx.cpp scscpomstrbinxx_SOURCES = scscpomstrbinxx.cpp scscpsscommonxx.cpp scscpomrbinxx_SOURCES = scscpomrbinxx.cpp scscpsscommonxx.cpp noinst_HEADERS = scscpsscommon.h EXTRA_DIST = Makefile.vc scscp-imcce-1.0.0+ds/testsxx/cmncalloptionxx.cpp000066400000000000000000000107551215622604100217620ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file cmncalloptionxx.cpp \brief check the call options. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include #if HAVE_STRING_H #include #endif #include "scscpxx.h" #include "scscpdebug.h" using namespace SCSCP; /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ int decodeanswer(Client::Computation& mytask) { int res; SCSCP_msgtype msgtype; char *openmathbuffer; size_t len; res =mytask.recv(msgtype, openmathbuffer, len); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : SCSCP_debugprint("Procedure Terminated\n"); break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); break; default : res=0; break; } SCSCP_debugprint("buffer:'%s'\n",openmathbuffer); free(openmathbuffer); } else { printf("Client::Computation::recv returns 0 !!!!\n"); } return res; } int mainsend(int port) { Client client; int res; const char *cmd = ""; size_t len=::strlen(cmd); try { res = client.connect("localhost", port); Client::Computation mytask(client); res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = decodeanswer(mytask); mytask.set_runtimelimit(1000); res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = decodeanswer(mytask); mytask.set_minmemory(0); res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = decodeanswer(mytask); mytask.set_maxmemory(10000); res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = decodeanswer(mytask); mytask.set_debuglevel(0); res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = decodeanswer(mytask); res = mytask.send(cmd, len, SCSCP_option_return_nothing); if (res) res = decodeanswer(mytask); if (res) res = client.close(); } catch(Exception e) { res = 0; std::cout<<"SCSCP::Exception "< #include #include #if HAVE_STRING_H #include #endif #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" using namespace SCSCP; /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(Client::Computation& mytask) { int res; SCSCP_msgtype msgtype; char *openmathbuffer; size_t len; res =mytask.recv(msgtype, openmathbuffer, len); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated=> can't be possible\n"); res=0; break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); SCSCP_debugprint("message='%s'\n", openmathbuffer); free(openmathbuffer); break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } /*-----------------------------------------------------------------*/ /* send the command to the server */ /*-----------------------------------------------------------------*/ static int mainsend(int port) { int res; Client client; const char *cmd = ""; size_t len=::strlen(cmd); try { res = client.connect("localhost", port); Client::Computation mytask(client); mytask.sendinfomessage("client send a specific info message"); if (res) res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = decodeanswer(mytask); if (res) res = client.close(); } catch(Exception e) { res = 0; std::cout<<"SCSCP::Exception "< #include #include #if HAVE_STRING_H #include #endif #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" using namespace SCSCP; /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(Client::Computation& mytask) { int res; SCSCP_msgtype msgtype; char *openmathbuffer; size_t len; res =mytask.recv(msgtype, openmathbuffer, len); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated=> can't be possible\n"); res=0; break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); SCSCP_debugprint("message='%s'\n", openmathbuffer); free(openmathbuffer); break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { int reserver; int res; int port; res = startbackgroundserver(2, port); if (res) { Client client; const char *cmd = ""; size_t len=::strlen(cmd); try { res = client.connect("localhost", port); Client::Computation mytask(client); if (res) res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = decodeanswer(mytask); if (res) res = client.close(); } catch(Exception e) { res = 0; std::cout<<"SCSCP::Exception "< #include #include #if HAVE_STRING_H #include #endif #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" using namespace SCSCP; using namespace std; /*-----------------------------------------------------------------*/ /* print the answer */ /*-----------------------------------------------------------------*/ static void printelements(Iunfstream& stream, int tab) { #define PRINTAB(x) for(j=0; j> v; SCSCP_debugprint("integer = %d\n", v); break; case SCSCP_omtype_OMF : double f; stream>> f; SCSCP_debugprint("floating-point = %g\n",f);break; case SCSCP_omtype_OMV : stream >> var; SCSCP_debugprint("variable = '%s'\n", var.get_name()); break; case SCSCP_omtype_OMS : stream>> symbol; SCSCP_debugprint("symbol = name : %s cd : %s\n", symbol.get_symbolname(), symbol.get_cdname()); break; case SCSCP_omtype_OMSTR: const char *s; stream>> s; SCSCP_debugprint("string = '%s'\n", s); break; case SCSCP_omtype_OMB: SCSCP_debugprint("OMB\n"); parsechild=1; break; case SCSCP_omtype_OMFOREIGN: SCSCP_debugprint("OMFOREIGN\n"); parsechild=1; break; case SCSCP_omtype_OMA: SCSCP_debugprint("OMA\n"); parsechild=1; break; case SCSCP_omtype_OMBIND: SCSCP_debugprint("OMBIND\n"); parsechild=1; break; case SCSCP_omtype_OMATTR: SCSCP_debugprint("OMATTR\n"); parsechild=1; break; case SCSCP_omtype_OME: SCSCP_debugprint("OME\n"); parsechild=1; break; case SCSCP_omtype_OMATP: SCSCP_debugprint("OMATP\n"); parsechild=1; break; case SCSCP_omtype_OMOBJ: SCSCP_debugprint("OMOBJ\n"); parsechild=1; break; case SCSCP_omtype_OMBVAR: SCSCP_debugprint("OMBVAR\n"); parsechild=1; break; case SCSCP_omtype_OMR: stream>> href; SCSCP_debugprint("reference = '%s'\n", href.get_reference()); break; case SCSCP_omtype_CONTENT :SCSCP_debugprint("content node \n"); break; } if (content) { PRINTAB(tab+1); SCSCP_debugprint("content : %s\n", content ); } if (parsechild) { Iunfstream children = stream.beginOM(); printelements(children,tab+4); } } } /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(Client::Computation& mytask) { int res; SCSCP_msgtype msgtype; Iunfstream* inputstream; res = mytask.recv(msgtype, inputstream); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated=> can't be possible\n"); res=0; break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); printelements(*inputstream, 0); break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { int reserver; int res; int port; res = startbackgroundserver(2, port); if (res) { Client client; const char *cmd = ""; size_t len=::strlen(cmd); try { res = client.connect("localhost", port); Client::Computation mytask(client); if (res) res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = decodeanswer(mytask); if (res) res = client.close(); } catch(Exception e) { res = 0; std::cout<<"SCSCP::Exception "< #include #include #if HAVE_STRING_H #include #endif #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" using namespace SCSCP; /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(Client::Computation& mytask) { int res; SCSCP_msgtype msgtype; char *openmathbuffer; size_t len; res =mytask.recv(msgtype, openmathbuffer, len); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated=> can't be possible\n"); res=0; break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); SCSCP_debugprint("message='%s'\n", openmathbuffer); free(openmathbuffer); break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { int reserver; int res; int port; res = startbackgroundserver(7, port); if (res) { Client client; const char *cmd = ""; size_t len=::strlen(cmd); try { res = client.connect("localhost", port); Client::Computation mytask(client); if (res) res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = mytask.interrupt(); if (res) res = decodeanswer(mytask); res = client.close(); } catch(Exception e) { res = 0; std::cout<<"SCSCP::Exception "< #include #include "scscpxx.h" #include "scscpsscommon.h" using namespace SCSCP; static int writeexec(Ounfstream& stream, void *param) { stream << beginOMA<< *(double *)param < #include #include #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" using namespace SCSCP; /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { int reserver; int res; int port; double n=5; SCSCP_msgtype msgtype; res = startbackgroundserver(10, port); if (res) { Client client; try { res = client.connect("localhost", port); Client::Computation mytask(client); Ounfstream *stream; if (res) res = mytask.send(SCSCP_option_return_object, stream); if (stream) { *stream <>x; if (strcmp(x.get_value(),"1.0")!=0 || x.get_base()!=10) res = 0; } if (res) res = client.close(); } catch(Exception e) { res = 0; std::cout<<"SCSCP::Exception "< #include #include "scscpxx.h" #include "scscpsscommon.h" using namespace SCSCP; static int writeexec(Ounfstream& stream, void *param) { stream << beginOMA<< *(int *)param < #include #include "scscpxx.h" #include "scscpsscommon.h" using namespace SCSCP; static int writeexec(Ounfstream& stream, void *param) { stream << beginOMA<< OMR((const char *)param) < #include #include "scscpxx.h" #include "scscpsscommon.h" using namespace SCSCP; static int writeexec(Ounfstream& stream, void *param) { stream << beginOMA<< (const char *)param < #include #include #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" using namespace SCSCP; static int writeexec(Ounfstream& stream, void *param) { stream << beginOMA<< OMV((const char *)param)< #include #include #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" using namespace SCSCP; /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { int reserver; int res; int port; SCSCP_msgtype msgtype; res = startbackgroundserver(11, port); if (res) { Client client; try { res = client.connect("localhost", port); Client::Computation mytask(client); Ounfstream *stream; if (res) res = mytask.send(SCSCP_option_return_object, stream); if (stream) { *stream <>x; if (strcmp(x.get_name(),"myvar")!=0) res = 0; } if (res) res = client.close(); } catch(Exception e) { res = 0; std::cout<<"SCSCP::Exception "< #include #include #if HAVE_STRING_H #include #endif #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" using namespace SCSCP; /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(Client::Computation& mytask) { int res,res2; SCSCP_msgtype msgtype; char *openmathbuffer; size_t len; size_t memsize, timeusage; const char *buffer; res =mytask.recv(msgtype, openmathbuffer, len); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : SCSCP_debugprint("Procedure Terminated\n"); break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); break; default : res=0; break; } SCSCP_debugprint("buffer:'%s'\n",openmathbuffer); free(openmathbuffer); res2 = mytask.get_runtime(timeusage); if (res2) SCSCP_debugprint("time usage = %lld\n", (long long)timeusage); /* else if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNRUNTIME) SCSCP_debugprint("time usage not available\n"); else { printf("unknown status!!!\n"); res = 0; }*/ res2 = mytask.get_memory(memsize); if (res2) SCSCP_debugprint("memory usage = %lld\n", (long long)memsize); /*else if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNMEM) SCSCP_debugprint("memory usage not available\n"); else { printf("unknown status!!!\n"); res = 0; }*/ res2 = mytask.get_message(buffer); if (res2) SCSCP_debugprint("message = '%s'\n", buffer); /* else if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNMESSAGE) SCSCP_debugprint("message not available\n"); else { printf("unknown status!!!\n"); res = 0; }*/ if (res) res = mytask.get_callid(buffer); SCSCP_debugprint("call id='%s'\n", buffer); } else { printf("Client::Computation::recv returns 0 !!!!\n"); } return res; } int main() { int reserver; int res; int port; res = startbackgroundserver(1, port); if (res) { Client client; const char *cmd = ""; size_t len=::strlen(cmd); try { res = client.connect("localhost", port); Client::Computation mytask(client); if (res) res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = decodeanswer(mytask); if (res) res = client.close(); } catch(Exception e) { res = 0; std::cout<<"SCSCP::Exception "< #include "scscpxx.h" using namespace SCSCP; int main() { Client client; int res; try { res = client.connect( "my invalid name", 26133); } catch(Exception e) { res=0; } return (res==0); } scscp-imcce-1.0.0+ds/testsxx/scscpscconnectfailed2xx.cpp000066400000000000000000000051661215622604100233620ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpscconnectfailed2xx.cpp \brief check the error : SCSCP_sc_connect failed on invalid port \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscpxx.h" using namespace SCSCP; int main() { Client client; int res; try { res = client.connect("localhost", -1); } catch(Exception e) { res=0; } return (res==0); } scscp-imcce-1.0.0+ds/testsxx/scscpscconnectxx.cpp000066400000000000000000000055111215622604100221250ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpscconnectxx.cpp \brief check that client could connect with a valid SCSCP server \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscpxx.h" #include "scscpsscommon.h" using namespace SCSCP; int main() { Client client; int res, reserver=0; int port; res = startbackgroundserver(0, port); if (res) { try { res = client.connect("localhost", port); if (res) res = client.close(); } catch(Exception e) { res=0; } reserver = stopbackgroundserver(); } return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/testsxx/scscpsendgetallowheadsxx.cpp000066400000000000000000000054601215622604100236460ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpsendgetallowheadsxx.cpp \brief check that client could connect and send a basic command to a valid SCSCP server (symbol : get_allowed_heads, cd: scscp2) check the call options. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscpxx.h" #include "scscpsscommon.h" int mainsend(int port); int main() { int reserver; int res; int port; startbackgroundserver(0, port); res = mainsend(port); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/testsxx/scscpsendserveroptionxx.cpp000066400000000000000000000053001215622604100235530ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpsendserveroptionxx.cpp \brief check that server could decode the call options. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscpxx.h" #include "scscpsscommon.h" extern int mainsend(int port); int main() { int reserver; int res; int port; startbackgroundserver(4, port); res = mainsend(port); reserver = stopbackgroundserver(); return !(res==1 && reserver==0); } scscp-imcce-1.0.0+ds/testsxx/scscpserversendinfoxx.cpp000066400000000000000000000104601215622604100232010ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpserversendinfoxx.cpp \brief check that the server sends an info message before its answer. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include #if HAVE_STRING_H #include #endif #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" using namespace SCSCP; /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ static int decodeanswer(Client::Computation& mytask) { int res; SCSCP_msgtype msgtype; char *openmathbuffer; size_t len; res =mytask.recv(msgtype, openmathbuffer, len); if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : printf("Procedure Terminated=> can't be possible\n"); res=0; break; case SCSCP_msgtype_ProcedureCompleted : SCSCP_debugprint("Procedure Completed\n"); SCSCP_debugprint("message='%s'\n", openmathbuffer); free(openmathbuffer); break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } /*-----------------------------------------------------------------*/ /* main program */ /*-----------------------------------------------------------------*/ int main() { int reserver; int res; int port; res = startbackgroundserver(6, port); if (res) { Client client; const char *cmd = ""; size_t len=::strlen(cmd); try { res = client.connect("localhost", port); Client::Computation mytask(client); if (res) res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = decodeanswer(mytask); if (res) res = client.close(); } catch(Exception e) { res = 0; std::cout<<"SCSCP::Exception "< #include #include #include #include #if HAVE_UNISTD_H #include #endif #define __SCSCP_WITHIN_SCSCP #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" #include "scscpfileserver.h" using namespace SCSCP; using namespace std; #if defined(SIGUSR2) #define SIGNALINTERRUPT SIGUSR2 #else #define SIGNALINTERRUPT SIGINT #endif /*! SCSCP server */ static Server *server; static int closesig=0; /* =1 if signal received */ static int processcall(IncomingClient *incomingclient, int typeanswer); static int server_sendreplycheck(IncomingClient::Computation& task, const char *value, const char *valueref); static int server_sendreplycheckint(IncomingClient::Computation& task, int value, int valueref); static int server_sendreplycheckdouble(IncomingClient::Computation& task, double value, double valueref); /*-----------------------------------------------------------------*/ /*! stop the server when it receive SIGUSR2 */ /*-----------------------------------------------------------------*/ static void stopserver(int sig) { SCSCP_debugprint("server receive SIGUSR2\n"); closesig=1; /* close the connection */ server->close(); /* exit the server */ exit(0); } /*-----------------------------------------------------------------*/ /*! start the server and listen on default port */ /*-----------------------------------------------------------------*/ static int runserver(int typeanswer, int fd) { int res=0; IncomingClient *incomingclient; int port = SCSCP_PROTOCOL_DEFAULTPORT; /*printf("server thread started\n");*/ /* register stopserver for the signal SIGUSR2 */ signal(SIGNALINTERRUPT, stopserver); /*initialization of the server */ try { server = new Server("MYCAS","1","myid"); if (fd==-1) { port = SCSCP_PROTOCOL_DEFAULTPORT; res = server->listen(port); } else { /* choose a random port */ port = 0; res = server->listen(port); /* write the port used by the server to the client */ if (res) { port = server->getport(); SCSCP_debugprint("fd=%d -> port:%d\n", fd, port); write(fd,&port, sizeof(port)); } close(fd); } if (res) { while ((incomingclient=server->acceptclient())!=NULL) { SCSCP_debugprint("new client accepted !\n"); try { while (res>0) res = processcall(incomingclient,typeanswer); } catch (Exception e) { /*cout <<"SCSCP::Exception1 "<eof()) res = 1; /*-1;*/ } delete incomingclient; incomingclient = NULL; } } if (res==0) printf("error \n"); } catch (Exception e) { if (closesig==0) cout <<"SCSCP::Exception "<close(); delete server; if (res!=-1 && closesig==0) { printf("server thread crash => exit with value 1\n"); printf("----------------------------------------\n"); printf(" reports this bug to %s \n", PACKAGE_BUGREPORT); printf("----------------------------------------\n"); return 1; } else { return 0; } } /*-----------------------------------------------------------------*/ /*! send the answer : if value==valueref then send a completed message */ /*-----------------------------------------------------------------*/ static int server_sendreplycheck(IncomingClient::Computation& task, const char *value, const char *valueref) { int res; if (strcmp(value,valueref)!=0) { task.sendterminated("scscp1", "error_system_specific", value!=NULL?value:"null"); res = 0; } else { res = task.sendcompleted("1"); } return res; } /*-----------------------------------------------------------------*/ /*! send the answer : if value==valueref then send a completed message */ /*-----------------------------------------------------------------*/ static int server_sendreplycheckint(IncomingClient::Computation& task, int value, int valueref) { int res; if (value!=valueref) { char buffer[128]; sprintf(buffer, "%d %d", value, valueref); task.sendterminated("scscp1", "error_system_specific", buffer); res = 0; } else { res = task.sendcompleted("1"); } return res; } /*-----------------------------------------------------------------*/ /*! send the answer : if value==valueref then send a completed message */ /*-----------------------------------------------------------------*/ static int server_sendreplycheckdouble(IncomingClient::Computation& task, double value, double valueref) { int res; if (value!=valueref) { char buffer[128]; sprintf(buffer, "%23.16E %23.16E", value, valueref); task.sendterminated("scscp1", "error_system_specific", buffer); res = 0; } else { res = task.sendcompleted("1"); } return res; } /*-----------------------------------------------------------------*/ /*! process the procedure call */ /*-----------------------------------------------------------------*/ static int processcall(IncomingClient *incomingclient,int typeanswer) { int res, resopt; int res1=0; SCSCP_msgtype msgtype; size_t timeusage, memsize; int debuglevel; SCSCP_option_return returntype; static char *buffer; static int counter=0; const char *valuestr; int valueint, valueintref; const char *valuestrref; double valuedbl; static char *openmathbuffer; size_t len; OMV v; OMI entier; OMF f; int entiercourt; OMR refer; IncomingClient::Computation task(*incomingclient); IncomingClient::Computation task2(*incomingclient); Iunfstream *stream = NULL; res = task.recv(msgtype, stream); if (res) { const char *callid; task.get_callid(callid); switch(msgtype) { case SCSCP_msgtype_ProcedureCall : /*printf("Procedure Call '%s'\n", callid);*/ switch(typeanswer) { case 0: res = task.sendcompleted("0"); break; case 1: task.set_runtime( 55); task.set_memory(100); task.set_message("my information message from libSCSCP"); res = task.sendcompleted("0"); if (res==0) printf("sendcompleted failed!\n"); break; case 2: res = task.sendcompleted(""); if (res==0) printf("SCSCP_ss_sendcompletedstr failed! \n"); break; case 3: res = task.sendterminated("scscp1", "error_system_specific", "unknown symbol"); if (res==0) printf("SCSCP_ss_sendterminatedstr failed! .\n"); break; case 4: resopt = task.get_runtimelimit(timeusage); if (resopt) SCSCP_debugprint("runtime limit = %lld\n", (long long)timeusage); /* else { if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNRUNTIME) SCSCP_debugprint("runtime limit not available\n"); else res = 0; }*/ resopt = task.get_minmemory(memsize); if (resopt) SCSCP_debugprint("minimum memory = %lld\n", (long long)memsize); /* else { if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNMINMEMORY) SCSCP_debugprint("minimum memory not available\n"); else res = 0; }*/ resopt = task.get_maxmemory(memsize); if (resopt) SCSCP_debugprint("maximum memory = %lld\n", (long long)memsize); /* else { if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNMAXMEMORY) SCSCP_debugprint("maximum memory not available\n"); else res = 0; }*/ resopt = task.get_debuglevel(debuglevel); if (resopt) SCSCP_debugprint("debug level = %d\n", debuglevel); /*else { if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNDEBUGLEVEL) SCSCP_debugprint("debug level not available\n"); else res = 0; }*/ resopt = task.get_returntype(returntype); if (resopt) SCSCP_debugprint("return type = %d\n", (int)returntype); /*else { if (SCSCP_status_is(status)==SCSCP_STATUS_USAGEUNKNOWNRETURNTYPE) SCSCP_debugprint("return type not available\n"); else res = 0; }*/ res = task.sendcompleted("0"); if (res==0) printf("SCSCP_ss_sendcompletedstr failed! \n"); break; case 6: res = task.sendinfomessage("debugging command from server"); if (res==0) printf("sendinfomessage failed!\n"); if (strncmp(callid,"libSCSCP",strlen("libSCSCP"))==0) { res = task.sendcompleted("0"); } else { res = task.sendterminated( "scscp1", "error_system_specific", "bad call ID name"); } break; case 7: res = task2.recv(msgtype, openmathbuffer, len); if (msgtype!=SCSCP_msgtype_Interrupt ) { res = task.sendterminated("scscp1", "error_system_specific", "msgtype must be SCSCP_msgtype_Interrupt"); } else { const char *newcallidinter; res = task2.get_callid(newcallidinter); if (strcmp(newcallidinter,callid)!=0) { printf("invalid call id: %s %s\n", newcallidinter,callid); res = 0; } res1 = task.sendcompleted("0"); if (res) res = res1; } break; case 10: res = task.sendcompleted(""); break; case 11: res = task.sendcompleted(""); break; case 12: if (counter==0) { res = task.sendcompleted("1"); counter++; } else { res = task.sendcompleted("2"); } break; case 13: ( stream->beginOM()) >> v; res = server_sendreplycheck(task, v.get_name(), "xy"); break; case 14: ( stream->beginOM()) >> v; res = server_sendreplycheck(task, v.get_name(), getlongstring()); break; case 15: valueintref = 1; case 16: if (typeanswer==16) valueintref = 127; case 17: if (typeanswer==17) valueintref = 32768; case 18: if (typeanswer==18) valueintref = 2147483647; case 19: if (typeanswer==19) valueintref = -2147483647-1; /*-2147483648; : remove a warning from gcc */ ( stream->beginOM()) >> valueint; res = server_sendreplycheckint(task, valueint, valueintref); break; case 20: valuestrref = "+1125899906842624"; case 21: if (typeanswer==21) valuestrref = "-1125899906842624"; case 22: if (typeanswer==22) valuestrref = "+1125899906842624"; ( stream->beginOM()) >> entier; res = server_sendreplycheck(task, entier.get_value(), valuestrref); break; case 23: ( stream->beginOM()) >> valuedbl; res = server_sendreplycheckdouble(task, valuedbl, 1.0E-10); break; case 24: valuestrref = "1234567890"; case 25: if (typeanswer==25) valuestrref = getlongstring(); ( stream->beginOM()) >> valuestr; res = server_sendreplycheck(task, valuestr, valuestrref); break; case 26: valuestrref = "scscp://test1"; case 27: if (typeanswer==27) valuestrref = getlongstring(); ( stream->beginOM()) >> refer; res = server_sendreplycheck(task, refer.get_reference(), valuestrref); break; } break; default : printf("unknown message type !!!\n"); res = 0; break; } } else { /*printf("SCSCP_ss_callrecvheader failed!\n");*/ /* if client close the connection => return -1 */ /*if (incomingclient->eof()) res = -1; */ } return res; } /*-----------------------------------------------------------------*/ /*! main program */ /*-----------------------------------------------------------------*/ int main(int argc, char *argv[]) { /* printf("scscpservertest started with %d\n", atoi(argv[1]));*/ return runserver(atoi(argv[1]), argc==3?atoi(argv[2]):-1); } scscp-imcce-1.0.0+ds/testsxx/scscpsscommon.h000066400000000000000000000064231215622604100210740ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpsscommon.h \brief definition of the common subroutine for server tests \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012 M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ /* start a new thread which will run the server. */ int startbackgroundserver(int typeanswer, int& port); /* send the stop action to the thread of the server */ int stopbackgroundserver(); /* sleep */ void mysleep(int sec); /* send a procedure call and check that the answer is 1 */ int sendprocedurecallcheck(SCSCP::Client::Computation& mytask, SCSCP::Ounfstream& stream, int (*callbackwrite)(SCSCP::Ounfstream& stream, void *param), void *param); /*start the server and send a procedure call message and check the reply that must be 1*/ int startserverandsendbincheck(int typeserver, int (*callbackwrite)(SCSCP::Ounfstream& stream, void *param), void *param); /*! return a long string (length <256) */ const char *getlongstring(void); scscp-imcce-1.0.0+ds/testsxx/scscpsscommonxx.cpp000066400000000000000000000240651215622604100220110ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpsscommonxx.cpp \brief common subroutine for C++ server tests \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, 2010, 2011, 2012, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 01/10/12 : ticket [#8521] tests hangs or are too long */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #if HAVE_SYS_WAIT_H #include #endif #if HAVE_UNISTD_H #include #endif #include #include #include #include #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" using namespace SCSCP; #if HAVE_FORK typedef pid_t ospid_t; #elif HAVE_WIN32API typedef PROCESS_INFORMATION ospid_t; #endif /* id of the server */ static ospid_t pserverid; /*-----------------------------------------------------------------*/ /*! synchronization between client and server. The client waits until the server is listening and accepts client @param port (in) port of the connection */ /*-----------------------------------------------------------------*/ int writesync(int port) { int res; int sleeptime = 1; SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; SCSCP_sc_init(&client, &status, SCSCP_PROTOCOL_VERSION_1_3, NULL); do { mysleep(sleeptime); res = SCSCP_sc_connect(&client, "localhost", port, &status); /*printf("writesync %d '%s'\n", res, SCSCP_status_strerror(&status));*/ } while (res==0); SCSCP_sc_close(&client, &status); SCSCP_sc_clear(&client, &status); return 1; } /*-----------------------------------------------------------------*/ /*! start a new thread which will run the server. update pserverid */ /*-----------------------------------------------------------------*/ int startbackgroundserver(int typeanswer, int& port) { int res = 0; char bufanswer[10]; char sfd[10]; int fd[2], nr; sprintf(bufanswer, "%d",typeanswer); #if HAVE_FORK if (pipe(fd)<0) { printf("Can't create pipe!\n"); return res; } pserverid = fork(); switch(pserverid) { case -1: res = 0; break; case 0: /* child */ close(fd[0]); sprintf(sfd, "%d", fd[1]); if (execl("scscpservertest", "scscpservertest", bufanswer, sfd, NULL)==-1) { res = 0; printf("startbackgroundserver failed on exec\n"); } break; default: /* parent */ close(fd[1]); res = 1; /*printf("parent process : child pid= %d\n",(int)pserverid);*/ break; } /* read the port by the server */ nr = (int)read(fd[0], &port,sizeof(port)); if (nr!=(int)sizeof(port)) { printf("Can't read pipe : can't read the port sent by the server!\n"); printf ("debug info : nr=%d size=%d\n", nr, (int)sizeof(port)); res = 0; return res; } #elif HAVE_WIN32API { STARTUPINFO siStartInfo; BOOL bFuncRetn = FALSE; char cmd[1024]; sprintf(cmd,"scscpservertest.exe %d", typeanswer); ZeroMemory( &pserverid, sizeof(PROCESS_INFORMATION) ); ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) ); siStartInfo.cb = sizeof(STARTUPINFO); res = CreateProcess(NULL, cmd, /* command line */ NULL, /* process security attributes */ NULL, /* primary thread security attributes */ FALSE, /* handles are inherited */ CREATE_NEW_PROCESS_GROUP, /* creation flags */ NULL, /* use parent's environment */ NULL, /* use parent's current directory */ &siStartInfo, /* STARTUPINFO pointer */ &pserverid); /* receives PROCESS_INFORMATION */ if (res==0) { printf("res=%d\n",res); printf( "CreateProcess failed (%d)\n", GetLastError() ); } port = SCSCP_PROTOCOL_DEFAULTPORT; } #endif /*HAVE_WIN32API*/ SCSCP_debugprint("port=%d\n", port); writesync(port); SCSCP_debugprint("synchronization performed on port=%d\n", port); return res; } /*-----------------------------------------------------------------*/ /*! send the stop action to the thread of the server @bug M. GASTINEAU 13/01/2009 : send CTRL+BREAK to stop the server on windows */ /*-----------------------------------------------------------------*/ int stopbackgroundserver() { int res = 0; int status; #if HAVE_FORK /*printf("send kill to pid= %d\n",(int)pserverid);*/ kill(pserverid, SIGUSR2); waitpid(pserverid, &status, WUNTRACED); if (WIFEXITED(status)) { res = (WEXITSTATUS(status) != 0); } #elif HAVE_WIN32API GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pserverid.dwProcessId); WaitForSingleObject( pserverid.hProcess, INFINITE ); CloseHandle(pserverid.hProcess); CloseHandle(pserverid.hThread); #endif return res; } /*-----------------------------------------------------------------*/ /*! sleep for some seconds @param sec (in) number of seconds */ /*-----------------------------------------------------------------*/ void mysleep(int sec) { #if HAVE_FORK sleep(sec); #elif HAVE_WIN32API Sleep(sec*1000); #endif } /*-----------------------------------------------------------------*/ /*! send a procedure call and check that the answer is 1 @param mytask (inout) task @param stream (inout) stream @param callbackwrite (in) call back function write the arguments of the procedure call @param param (in) opaque user data given to callbackwrite */ /*-----------------------------------------------------------------*/ int sendprocedurecallcheck(Client::Computation& mytask, Ounfstream& stream, int (*callbackwrite)(Ounfstream& stream, void *param), void *param) { int res; char *openmathbuffer; SCSCP_msgtype msgtype; size_t len; callbackwrite(stream, param); res = mytask.finish(); if (res) res = mytask.recv(msgtype, openmathbuffer, len); if (res) { res = (::strcmp(openmathbuffer,"1")==0); if (res==0) printf("openmathbuffer='%s'\n", openmathbuffer); free(openmathbuffer); } else { printf("sendprocedurecallcheck failed\n"); } return res; } /*-----------------------------------------------------------------*/ /*! start the server and send a procedure call message and check the reply that must be 1 @param typeserver (in) value to start the server @param callbackwrite (in) call back function write the arguments of the procedure call @param param (in) opaque user data given to callbackwrite */ /*-----------------------------------------------------------------*/ int startserverandsendbincheck(int typeserver, int (*callbackwrite)(Ounfstream& stream, void *param), void *param) { SCSCP_socketclient client; int res, reserver; int port; res = startbackgroundserver(typeserver, port); if (res) { Client client; try { res = client.connect("localhost", port); Client::Computation mytask(client); mytask.set_encodingtype(SCSCP_encodingtype_Binary); Ounfstream *stream; /* send a valid symbol */ if (res) res = mytask.send(SCSCP_option_return_object, stream); if (stream) { res = sendprocedurecallcheck(mytask, *stream, callbackwrite,param); mytask.finish(); } if (res) res = client.close(); } catch(Exception e) { res = 0; std::cout<<"SCSCP::Exception "<256 characters */ /*-----------------------------------------------------------------*/ const char *getlongstring(void) { return "azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890azertyuiopqsdfghjklmwxcvbn1234567890"; } scscp-imcce-1.0.0+ds/testsxx/scscpssinitxx.cpp000066400000000000000000000050601215622604100214560ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpssinitxx.cpp \brief check Server \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, M. Gastineau, IMCCE-CNRS email of the author : gastineau@imcce.fr */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #include #include "scscpxx.h" using namespace SCSCP; int main() { int res=1; try { Server server("MYCAS","1","myid"); } catch(Exception e) { res = 0; } return (res==0); } scscp-imcce-1.0.0+ds/testsxx/scscpterminatedxx.cpp000066400000000000000000000104701215622604100223020ustar00rootroot00000000000000/*-----------------------------------------------------------------*/ /*! \file scscpterminatedxx.cpp \brief check that client could decode the terminated message. \author M. Gastineau Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris. Copyright, 2008, 2009, , 2010, 2011, 2012, M. Gastineau, CNRS email of the author : gastineau@imcce.fr \bug M. GASTINEAU 20/04/09 : update for SCSCP 1.3 */ /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* License of this file : This file is "dual-licensed", you have to choose one of the two licenses below to apply on this file. CeCILL-C The CeCILL-C license is close to the GNU LGPL. ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) or CeCILL v2.0 The CeCILL license is compatible with the GNU GPL. ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) This library is governed by the CeCILL-C or the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C or CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-C or CeCILL license and that you accept its terms. */ /*-----------------------------------------------------------------*/ #if HAVE_CONFIG_H #include "scscpconfig.h" #endif /*HAVE_CONFIG_H*/ #include #include #include #if HAVE_STRING_H #include #endif #include "scscpxx.h" #include "scscpsscommon.h" #include "scscpdebug.h" using namespace SCSCP; /*-----------------------------------------------------------------*/ /* decode the answer of the server */ /*-----------------------------------------------------------------*/ int decodeanswer(Client::Computation& mytask) { int res; SCSCP_msgtype msgtype; Iunfstream *stream; try { res = mytask.recv(msgtype, stream); } catch(Exception e) { res = ::strcmp(e.what(),"Remote execution failed. Reason : cd='scscp1' name='error_system_specific' message='unknown symbol'\n")==0; } if (res) { switch(msgtype) { case SCSCP_msgtype_ProcedureTerminated : SCSCP_debugprint("Procedure Terminated\n"); break; case SCSCP_msgtype_ProcedureCompleted : printf("Procedure Completed => can't be possible\n"); res=0; break; default : printf("unknown message type !!!\n"); res = 0; break; } } return res; } int main() { SCSCP_socketclient client; SCSCP_status status = SCSCP_STATUS_INITIALIZER; int res, reserver, port; res = startbackgroundserver(3, port); if (res) { Client client; const char *cmd = ""; size_t len=::strlen(cmd); try { res = client.connect("localhost", port); Client::Computation mytask(client); res = mytask.send(cmd, len, SCSCP_option_return_object); if (res) res = decodeanswer(mytask); if (res) res = client.close(); } catch(Exception e) { res = 0; std::cout<<"SCSCP::Exception "<