diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e5888b95..1fb65a4de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -315,6 +315,7 @@ if(WIN32) endif() set(PACKAGE_LOCALE_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}/locale") set(PACKAGE_DATA_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}") +set(PACKAGE_GRAMMAR_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}/belr/grammars") set(PACKAGE_SOUND_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}/sounds/linphone") set(PACKAGE_RING_DIR "${PACKAGE_SOUND_DIR}/rings") set(PACKAGE_FREEDESKTOP_DIR "${PACKAGE_DATA_DIR}/applications") diff --git a/config.h.cmake b/config.h.cmake index bfa18d6fe..50538b14b 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -35,6 +35,7 @@ #define PACKAGE_LOCALE_DIR "${PACKAGE_LOCALE_DIR}" #define PACKAGE_DATA_DIR "${PACKAGE_DATA_DIR}" +#define PACKAGE_GRAMMAR_DIR "${PACKAGE_GRAMMAR_DIR}" #define PACKAGE_SOUND_DIR "${PACKAGE_SOUND_DIR}" #define PACKAGE_RING_DIR "${PACKAGE_RING_DIR}" diff --git a/share/CMakeLists.txt b/share/CMakeLists.txt index b5f53099b..e50659463 100644 --- a/share/CMakeLists.txt +++ b/share/CMakeLists.txt @@ -42,6 +42,16 @@ if(ENABLE_ROOTCA_DOWNLOAD) ) endif() +set(GRAMMAR_FILES + cpim_grammar + vcard_grammar +) + +install(FILES ${GRAMMAR_FILES} + DESTINATION ${PACKAGE_GRAMMAR_DIR} + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +) + set(SOUND_FILES hello16000.wav hello8000.wav diff --git a/share/cpim_grammar b/share/cpim_grammar new file mode 100644 index 000000000..6f8b36d95 Binary files /dev/null and b/share/cpim_grammar differ diff --git a/share/vcard_grammar b/share/vcard_grammar new file mode 100644 index 000000000..48ceb8e37 Binary files /dev/null and b/share/vcard_grammar differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1bb99e7be..c3cca39ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,7 +60,6 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES chat/cpim/header/cpim-header-p.h chat/cpim/header/cpim-header.h chat/cpim/message/cpim-message.h - chat/cpim/parser/cpim-grammar.h chat/cpim/parser/cpim-parser.h chat/modifier/chat-message-modifier.h chat/modifier/cpim-chat-message-modifier.h @@ -189,7 +188,6 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES chat/cpim/header/cpim-generic-header.cpp chat/cpim/header/cpim-header.cpp chat/cpim/message/cpim-message.cpp - chat/cpim/parser/cpim-grammar.cpp chat/cpim/parser/cpim-parser.cpp chat/modifier/cpim-chat-message-modifier.cpp chat/modifier/encryption-chat-message-modifier.cpp diff --git a/src/chat/cpim/parser/cpim-grammar.h b/src/chat/cpim/parser/cpim-grammar.h deleted file mode 100644 index 0f261a885..000000000 --- a/src/chat/cpim/parser/cpim-grammar.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * cpim-grammar.h - * Copyright (C) 2010-2017 Belledonne Communications SARL - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef _L_CPIM_GRAMMAR_H_ -#define _L_CPIM_GRAMMAR_H_ - -#include "linphone/utils/general.h" - -// ============================================================================= - -LINPHONE_BEGIN_NAMESPACE - -namespace Cpim { - const char *getGrammar (); -} - -LINPHONE_END_NAMESPACE - -#endif // ifndef _L_CPIM_GRAMMAR_H_ diff --git a/src/chat/cpim/parser/cpim-parser.cpp b/src/chat/cpim/parser/cpim-parser.cpp index 2072e519e..be5becf30 100644 --- a/src/chat/cpim/parser/cpim-parser.cpp +++ b/src/chat/cpim/parser/cpim-parser.cpp @@ -24,7 +24,6 @@ #include "linphone/utils/utils.h" -#include "cpim-grammar.h" #include "content/content-type.h" #include "logger/logger.h" #include "object/object-p.h" @@ -37,6 +36,8 @@ using namespace std; LINPHONE_BEGIN_NAMESPACE +#define CPIM_GRAMMAR "cpim_grammar" + namespace Cpim { class Node { public: @@ -223,11 +224,9 @@ public: Cpim::Parser::Parser () : Singleton(*new ParserPrivate) { L_D(); - belr::ABNFGrammarBuilder builder; - - d->grammar = builder.createFromAbnf(getGrammar(), make_shared()); + d->grammar = belr::GrammarLoader::get().load(CPIM_GRAMMAR); if (!d->grammar) - lFatal() << "Unable to build CPIM grammar."; + lFatal() << "Unable to load CPIM grammar."; } // ----------------------------------------------------------------------------- diff --git a/src/chat/cpim/parser/cpim-grammar.cpp b/src/chat/cpim/parser/cpim-rules similarity index 75% rename from src/chat/cpim/parser/cpim-grammar.cpp rename to src/chat/cpim/parser/cpim-rules index 09a7c50c2..a0b866fee 100644 --- a/src/chat/cpim/parser/cpim-grammar.cpp +++ b/src/chat/cpim/parser/cpim-rules @@ -1,31 +1,3 @@ -/* - * cpim-grammar.cpp - * Copyright (C) 2010-2017 Belledonne Communications SARL - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "cpim-grammar.h" - -// ============================================================================= - -LINPHONE_BEGIN_NAMESPACE - -static const char *grammar = -// See: https://tools.ietf.org/html/rfc3862 -R"==GRAMMAR==( Message = Headers CRLF Headers CRLF [Headers CRLF] Headers = *Header @@ -93,10 +65,7 @@ UTF8-multi = %xC0-DF %x80-BF / %xFC-FD %x80-BF %x80-BF %x80-BF %x80-BF %x80-BF URI = absoluteURI -)==GRAMMAR==" -// See: https://tools.ietf.org/html/rfc2396 & https://tools.ietf.org/html/rfc2732 -R"==GRAMMAR==( absoluteURI = scheme ":" ( hier-part / opaque-part ) relativeURI = ( net-path / abs-path / rel-path ) [ "?" query ] @@ -153,17 +122,11 @@ mark = "-" / "_" / "." / "!" / "~" / "*" / "'" / "(" / ")" escaped = "%" HEXDIG HEXDIG alphanum = ALPHA / DIGIT -)==GRAMMAR==" -// See: https://tools.ietf.org/html/rfc3066 -R"==GRAMMAR==( Language-Tag = Primary-subtag *( "-" Subtag ) Primary-subtag = 1*8ALPHA Subtag = 1*8(ALPHA / DIGIT) -)==GRAMMAR==" -// See: https://tools.ietf.org/html/rfc3339 -R"==GRAMMAR==( date-fullyear = 4DIGIT date-month = 2DIGIT date-mday = 2DIGIT @@ -182,10 +145,3 @@ full-date = date-fullyear "-" date-month "-" date-mday full-time = partial-time time-offset date-time = full-date "T" full-time -)==GRAMMAR=="; - -const char *Cpim::getGrammar () { - return grammar; -} - -LINPHONE_END_NAMESPACE