⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icalconverter.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            !wcscmp(vo->getProperty(i)->getValue(), TEXT("VALARM")))
            beginAlarm = i;
        if(endAlarm == -1 && !wcscmp(vo->getProperty(i)->getName(),TEXT("END")) &&
            vo->getProperty(i)->getValue() &&
            !wcscmp(vo->getProperty(i)->getValue(),TEXT("VALARM"))) {
                endAlarm = i;
                break;
            }
    }

    if(beginAlarm != -1 && endAlarm > beginAlarm)
        for(int i = beginAlarm; i <= endAlarm; i++) {
            vo->removeProperty(i);
            --i;
            --endAlarm;
        }
}

bool iCalConverter::validateEvent(Event* ev, WString& errorDescription, long* errorCode) {
  //validate BEGIN, END, UID
    if(wcscmp(ev->getProperty(0)->getName(), TEXT("BEGIN")) ||
        wcscmp(ev->getProperty(0)->getValue(), TEXT("VEVENT"))) {
            *errorCode = ERROR_KEY_PROPERTY_MISSING;
            errorDescription = TEXT("Invalid EVENT: 'BEGIN' property is missing");
            return false;
        }
    if(wcscmp(ev->getProperty(ev->propertiesCount()-1)->getName(), TEXT("END")) ||
        wcscmp(ev->getProperty(ev->propertiesCount()-1)->getValue(), TEXT("VEVENT"))) {
            *errorCode = ERROR_KEY_PROPERTY_MISSING;
            errorDescription = TEXT("Invalid EVENT: 'END' property is missing");
            return false;
        }
    if(!ev->containsProperty(TEXT("UID"))) {
        *errorCode = ERROR_KEY_PROPERTY_MISSING;
        errorDescription = TEXT("Invalid EVENT: 'UID' property is missing");
        return false;
    }
    for(int i = 0; i < ev->propertiesCount(); i++) {
        if(!wcsstr(EVENT_PROPERTIES_LIST, ev->getProperty(i)->getName()) &&
            wcsstr(ev->getProperty(i)->getName(),TEXT("X-")) != ev->getProperty(i)->getName()) {
                *errorCode = ERROR_ILLEGAL_PROPERTY_NAME;
                errorDescription = TEXT("EVENT - Illegal property name : %s");
                errorDescription += ev->getProperty(i)->getName();
                return false;
            }
        if(ev->getProperty(i)->getValue() && !validatePropery(ev->getProperty(i), errorDescription, errorCode))
            return false;
    }
    return true;
}
bool iCalConverter::validateTodo(ToDo* task, WString& errorDescription, long* errorCode) {
    //validate BEGIN, END, UID
    if(wcscmp(task->getProperty(0)->getName(), TEXT("BEGIN")) ||
        wcscmp(task->getProperty(0)->getValue(), TEXT("VTODO"))) {
            *errorCode = ERROR_KEY_PROPERTY_MISSING;
            errorDescription = TEXT("Invalid TODO: 'BEGIN' property is missing");
            return false;
        }
    if(wcscmp(task->getProperty(task->propertiesCount()-1)->getName(), TEXT("END")) ||
        wcscmp(task->getProperty(task->propertiesCount()-1)->getValue(), TEXT("VTODO"))) {
            *errorCode = ERROR_KEY_PROPERTY_MISSING;
            errorDescription = TEXT("Invalid TODO: 'END' property is missing");
            return false;
        }
    if(!task->containsProperty(TEXT("UID"))) {
        *errorCode = ERROR_KEY_PROPERTY_MISSING;
        errorDescription = TEXT("Invalid TODO: 'UID' property is missing");
        return false;
    }
    for(int i = 0; i < task->propertiesCount(); i++) {
        if(!wcsstr(TODO_PROPERTIES_LIST, task->getProperty(i)->getName()) &&
            wcsstr(task->getProperty(i)->getName(),TEXT("X-")) != task->getProperty(i)->getName()) {
                *errorCode = ERROR_ILLEGAL_PROPERTY_NAME;
                errorDescription = TEXT("TODO - Illegal property name : ");
                errorDescription += task->getProperty(i)->getName();
                return false;
            }
            if(task->getProperty(i)->getValue() && !validatePropery(task->getProperty(i), errorDescription, errorCode))
                return false;
    }
    return true;
}
bool iCalConverter::validatePropery(VProperty* vp, WString& errorDescription, long* errorCode) {

    if(!wcscmp(vp->getName(), TEXT("CLASS"))) {
        if(!wcsstr(CLASS_PROPERTY_VALUE, vp->getValue()) &&
            wcsstr(vp->getValue(),TEXT("X-")) != vp->getValue()) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property CLASS, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
    }
    else if(!wcscmp(vp->getName(), TEXT("CREATED"))) {
        if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property CREATED, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("DESCRIPTION"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(!wcsstr(COMMENT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property DESCRIPTION, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("DTSTART"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(DT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property DTSTART, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
        }
        if(vp->containsParameter(TEXT("VALUE")) && !wcscmp(vp->getParameterValue(TEXT("VALUE")), TEXT("DATE"))) {
            if(!validateDate(vp->getValue())) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property DTSTART, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
        else if(!validateDT(vp->getValue()) && !validateDate(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property DTSTART, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("GEO"))) {
        if(!validateGeo(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property GEO, Invalid value format : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("LAST-MODIFIED"))) {
        if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property LAST-MODIFIED, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("LOCATION"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(!wcsstr(COMMENT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property LOCATION, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("ORGANIZER"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(!wcsstr(ORGANIZER_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property ORGANIZER, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("PRIORITY"))) {
        if(vp->getValue()) {
            if(wcslen(vp->getValue()) > 1 || !isdigit(vp->getValue()[0])) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property PRIORITY, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("DTSTAMP"))) {
        if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property DTSTAMP, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("SUMMARY"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(!wcsstr(COMMENT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property SUMMARY, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("TRANSP"))) {
        if(wcscmp(vp->getName(), TEXT("OPAQUE")) && wcscmp(vp->getName(), TEXT("TRANSPARENT"))) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property TRANSP, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }

    else if(!wcscmp(vp->getName(), TEXT("RECURRENCE-ID"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(DT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i) &&
                wcscmp(vp->getParameter(i), TEXT("RANGE"))) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property RECURRENCE-ID, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
        }
        if(vp->containsParameter(TEXT("VALUE")) && !wcscmp(vp->getParameterValue(TEXT("VALUE")), TEXT("DATE"))) {
            if(!validateDate(vp->getValue())) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property RECURRENCE-ID, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
        else if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property RECURRENCE-ID, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("DTEND"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(DT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property DTEND, Invalid parameter: ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
        }
        if(vp->containsParameter(TEXT("VALUE")) && !wcscmp(vp->getParameterValue(TEXT("VALUE")), TEXT("DATE"))) {
            if(!validateDate(vp->getValue())) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property DTEND, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
        else if(!validateDT(vp->getValue()) && !validateDate(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property DTEND, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("DUE"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(DT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property DUE, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
        }
        if(vp->containsParameter(TEXT("VALUE")) && !wcscmp(vp->getParameterValue(TEXT("VALUE")), TEXT("DATE"))) {
            if(!validateDate(vp->getValue())) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property DUE, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
        else if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property DUE, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("COMPLETED"))) {
        if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property COMPLETED, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("PERCENT-COMPLETE"))) {
        if(wcslen(vp->getValue()) > 2 ||
            (wcslen(vp->getValue()) == 1 && !isdigit(vp->getValue()[0])) ||
            (wcslen(vp->getValue()) == 2 && (!isdigit(vp->getValue()[0]) || !isdigit(vp->getValue()[1])))) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property PERCENT, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
            }
    }
    else if(!wcscmp(vp->getName(), TEXT("ATTACH"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(ATTACH_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property ATTACH, Invalid parameter : ");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -