Fixed name has special characters
authorSoyoung Kim <sy037.kim@samsung.com>
Fri, 1 Feb 2013 07:43:36 +0000 (16:43 +0900)
committerSoyoung Kim <sy037.kim@samsung.com>
Fri, 1 Feb 2013 07:43:36 +0000 (16:43 +0900)
[Issue#] N/A
[Problem] if widget'name has special characters, crash occur during installation
[Cause] appid must not have special characters.
[Solution] if name has special characters, installer make temporary name for generating appid.
[SCMRequest] N/A

src/jobs/widget_install/job_widget_install.cpp

index 77184aa..3672c97 100644 (file)
@@ -87,6 +87,7 @@ const char * const WITH_OSP_XML = "res/wgt/config.xml";
 
 //allowed: a-z, A-Z, 0-9
 const char* REG_TIZENID_PATTERN = "^[a-zA-Z0-9]{10}.{1,}$";
+const char* REG_NAME_PATTERN = "^[a-zA-Z0-9._-]{1,}$";
 const size_t PACKAGE_ID_LENGTH = 10;
 
 static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption";
@@ -387,18 +388,28 @@ void JobWidgetInstall::setTizenId(
                 break;
             }
         }
-        if (!!name) {
-            LogDebug("Name : " << name);
-            std::ostringstream appid;
-            appid << m_installerContext.widgetConfig.tzPkgid << "." << name;
-            LogDebug("tizen appid was generated by WRT : " << appid.str());
-            m_installerContext.widgetConfig.tzAppid =
-                DPL::FromUTF8String(appid.str());
-        } else {
-            m_installerContext.widgetConfig.tzAppid =
-                m_installerContext.widgetConfig.tzPkgid;
+        regex_t regx;
+        if(regcomp(&regx, REG_NAME_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
+            LogDebug("Regcomp failed");
         }
-        DPL::OptionalString appid = m_installerContext.widgetConfig.tzAppid;
+
+        if (!name || (regexec(&regx, DPL::ToUTF8String(*name).c_str(),
+                        static_cast<size_t>(0), NULL, 0) != REG_NOERROR)) {
+            // TODO : generate name move to wrt-commons
+            std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+            std::ostringstream genName;
+
+            genName << "_" << allowedString[rand() % allowedString.length()];
+            name = DPL::FromUTF8String(genName.str());
+            LogDebug("name was generated by WRT" );
+        }
+        regfree(&regx);
+        LogDebug("Name : " << name);
+        std::ostringstream genid;
+        genid << m_installerContext.widgetConfig.tzPkgid << "." << name;
+        LogDebug("tizen appid was generated by WRT : " << genid.str());
+
+        DPL::OptionalString appid = DPL::FromUTF8String(genid.str());
         NormalizeAndTrimSpaceString(appid);
         m_installerContext.widgetConfig.tzAppid = *appid;
     }