2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file command_parser.cpp
18 * @author Soyoung Kim (sy037.kim@samsung.com)
19 * @brief Implementation file for OptionParser.
22 #include <dpl/string.h>
23 #include <dpl/errno_string.h>
24 #include <installer_log.h>
25 #include "command_parser.h"
28 typedef std::pair<std::string, std::string> DataPair;
30 const char* const KEY_OP = "op";
31 const char* const KEY_PATH = "path";
32 const char* const KEY_REMOVABLE = "removable";
35 bool CommandParser::CscCommandParser(const std::string& arg, CscOption &option)
37 using namespace Command;
38 // path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true
39 // parsing CSC configuration string
40 _D("CscCommandParser");
44 DataMap cmdMap = ArgumentsParser(arg);
47 it = cmdMap.find(KEY_OP);
48 if (it == cmdMap.end()) {
52 if (it->second == VALUE_INSTALL) {
53 _D("operation = %s", it->second.c_str());
54 option.operation = VALUE_INSTALL;
55 it = cmdMap.find(KEY_PATH);
56 if (it == cmdMap.end()) {
59 option.path = it->second;
60 _D("path = %s", option.path.c_str());
62 it = cmdMap.find(KEY_REMOVABLE);
63 if (it == cmdMap.end()) {
67 option.removable = true;
68 if (0 == it->second.compare(VALUE_FALSE)) {
69 option.removable = false;
71 } else if (it->second == VALUE_UNINSTALL) {
72 _D("operation = %s", it->second.c_str());
73 // uninstall command isn't confirmed yet
74 it = cmdMap.find(KEY_PATH);
75 if (it == cmdMap.end()) {
78 option.path = it->second;
79 _D("operation = uninstall");
80 _D("path = %s", option.path.c_str());
82 _E("Unknown operation : %s", it->second.c_str());
83 _D("operation = %s", it->second.c_str());
90 bool CommandParser::FotaCommandParser(const std::string& arg, FotaOption
93 using namespace Command;
94 // path=pkgid:op=install
95 _D("FotaCommandParser");
96 DataMap cmdMap = ArgumentsParser(arg);
99 it = cmdMap.find(KEY_OP);
100 if (it == cmdMap.end()) {
103 option.operation = it->second;
105 it = cmdMap.find(KEY_PATH);
106 if (it == cmdMap.end()) {
110 option.pkgId = it->second;
111 _D("Fota : package_id [%s], operaion [%s]", option.pkgId.c_str(),
112 option.operation.c_str());
117 CommandParser::DataMap CommandParser::ArgumentsParser(const std::string& arg)
122 _D("Input argument is empty");
126 const char* ptr = strtok(const_cast<char*>(arg.c_str()),":");
127 while (ptr != NULL) {
128 std::string string = ptr;
129 ptr = strtok (NULL, ":");
130 size_t pos = string.find('=');
131 if (pos == std::string::npos) {
135 DataPair(string.substr(0, pos),
136 string.substr(pos+1)));