int SyncMLProcessor::processAlertStatus(SyncSource& source, SyncML* syncml, ArrayList* alerts) { int ret = -1; const char* name = NULL; Status* s = NULL; SourceRef* sourceRef = NULL; if (alerts->size()) { ArrayList* list = syncml->getSyncBody()->getCommands(); for (int i = 0; i < list->size(); i++) { // is returned the pointer to the element not a new element name = ((AbstractCommand*)(list->get(i)))->getName(); if (name && strcmp(name, STATUS) == 0) { s = (Status*)list->get(i); if (strcmp(s->getCmd(), ALERT) == 0) { sourceRef = (SourceRef*)(s->getSourceRef()->get(0)); if (sourceRef) { if (strcmp(_wcc(source.getName()), sourceRef->getValue()) == 0) { ret = getAlertStatusCode(s, _wcc(source.getName())); break; } } else { // Server did not include <SourceRef>, which // is a violation of the standard for commands // which were sent with <SourceRef>. Happens // with Synthesis server if authentication // failed, in which case we can simply ignore // it. } } } } } // Fire a syncStatus event: Alert status from server fireSyncStatusEvent(ALERT, ret, source.getConfig().getName(), source.getConfig().getURI(), NULL, SERVER_STATUS); return ret; }
int SyncMLProcessor::processItemStatus(SyncSource& source, SyncBody* syncBody) { ArrayList* items = NULL; Item* item = NULL; SourceRef* sourceRef = NULL; Status* s = NULL; const char* name = NULL; Data* data = NULL; int ret = 0; ArrayList* list = getCommands(syncBody, STATUS); for (int i = 0; i < list->size(); i++) { s = (Status*)list->get(i); name = s->getCmd(); data = s->getData(); if (strcmp(name, SYNC) == 0){ char *srcname = toMultibyte(source.getName()); int alertStatus = getAlertStatusCode(s, srcname); delete [] srcname; /* * Try to find if the server send a message together the error code if any * The items in the status message should be always one... */ char *statusMessage = NULL; items = s->getItems(); for (int k = 0; k < items->size(); k++) { item = (Item*)items->get(k); if (item) { ComplexData* cd = item->getData(); if (cd) { statusMessage = stringdup(cd->getData()); } } } // Fire Sync Status Event: sync status from server fireSyncStatusEvent(SYNC, s->getStatusCode(), source.getConfig().getName(), source.getConfig().getURI(), NULL, SERVER_STATUS); if(alertStatus < 0 || alertStatus >=300){ if (statusMessage) { //strcpy(lastErrorMsg, statusMessage); setError( alertStatus, statusMessage); } else { //strcpy(lastErrorMsg, "Error in sync status sent by server."); setError( alertStatus, "Error in sync status sent by server."); } if ((ret = alertStatus) < 0) LOG.error("processItemStatus: status not found in SYNC"); else LOG.error("processItemStatus: server sent status %d in SYNC", alertStatus); break; } if (statusMessage) { delete [] statusMessage; } } else if (strcmp(name, ADD) == 0 || strcmp(name, REPLACE) == 0 || strcmp(name, DEL) == 0) { int k; items = s->getItems(); long val = strtol(data->getData() , NULL, 10); for (k = 0; k < items->size(); k++) { item = (Item*)items->get(k); if (item) { Source* itemSource = item->getSource(); if (itemSource) { WCHAR *uri = toWideChar(itemSource->getLocURI()); ComplexData* cd = item->getData(); WCHAR *statusMessage = NULL; if (cd) { statusMessage = toWideChar(cd->getData()); } // Fire Sync Status Event: item status from server fireSyncStatusEvent(s->getCmd(), s->getStatusCode(), source.getConfig().getName(), source.getConfig().getURI(), uri, SERVER_STATUS); // Update SyncReport source.getReport()->addItem(SERVER, s->getCmd(), uri, s->getStatusCode(), statusMessage); source.setItemStatus(uri, val, name); delete [] uri; if (statusMessage) delete [] statusMessage; } else { // the item might consist of additional information, as in: // <SourceRef>pas-id-44B544A600000092</SourceRef> // <Data>200</Data> // <Item><Data>Conflict resolved by server</Data></Item> } } } items = s->getSourceRef(); for (k = 0; k < items->size(); k++) { sourceRef = (SourceRef*)items->get(k); if (sourceRef) { WCHAR *srcref = toWideChar(sourceRef->getValue()); // Fire Sync Status Event: item status from server fireSyncStatusEvent(s->getCmd(), s->getStatusCode(), source.getConfig().getName(), source.getConfig().getURI(), srcref, SERVER_STATUS); // Update SyncReport source.getReport()->addItem(SERVER, s->getCmd(), srcref, s->getStatusCode(), NULL); source.setItemStatus(srcref, val, name); delete [] srcref; } } } } //deleteArrayList(&list); if (list){ delete list; list = NULL; } return ret; }