Exemple #1
0
static void	handle_init_start(LoadMibState *state, const char **atts)
{
	AmsMib			*mib;
	int			cnbr = 0;
	char			*ptsname = NULL;
	char			*pubkeyname = NULL;
	char			*privkeyname = NULL;
	char			**att;
	char			*name;
	char			*value;
	AmsMibParameters	parms;

	if (state->currentOperation != LoadDormant)
	{
		return noteLoadError(state, "Already in an operation.");
	}

	mib = _mib(NULL);
	if (mib) return noteLoadError(state, "Already initialized.");
	state->currentOperation = LoadInitializing;
	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "continuum_nbr") == 0)
		{
			cnbr = atoi(value);
		}
		else if (strcmp(name, "ptsname") == 0)
		{
			ptsname = value;
		}
		else if (strcmp(name, "pubkey") == 0)
		{
			pubkeyname = value;
		}
		else if (strcmp(name, "privkey") == 0)
		{
			privkeyname = value;
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	parms.continuumNbr = cnbr;
	parms.ptsName = ptsname;
	parms.publicKeyName = pubkeyname;
	parms.privateKeyName = privkeyname;
	mib = _mib(&parms);
	if (mib == NULL)
	{
		return putErrmsg("Couldn't create MIB.", NULL);
	}
}
Exemple #2
0
static void	handle_receiver_start(LoadMibState *state, const char **atts)
{
	char	*rolename = NULL;
	char	**att;
	char	*name;
	char	*value;

	if (noMibYet(state)) return;
	if (state->subject == NULL)
	{
		return noteLoadError(state, "Subject not specified.");
	}

	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "name") == 0)
		{
			rolename = value;
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	if (rolename == NULL)
	{
		return noteLoadError(state, "Need role name of receiver.");
	}

	switch (state->currentOperation)
	{
	case LoadAdding:
		if (addAuthorizedReceiver(state->venture, state->subject,
				rolename) < 0)
		{
			return putErrmsg("Couldn't add authorized receiver.",
						rolename);
		}

		break;

	case LoadChanging:
		return noteLoadError(state, "'Change' not applicable.");

	case LoadDeleting:
		state->target = rolename;	/*	May be target.	*/
		break;

	default:
		return noteLoadError(state, "Not in an operation.");
	}
}
Exemple #3
0
static void	handle_op_start(LoadMibState *state, LoadMibOp op)
{
	if (state->currentOperation != LoadDormant)
	{
		return noteLoadError(state, "Already in an operation.");
	}

	state->currentOperation = op;
	state->target = NULL;
}
Exemple #4
0
static int	noMibYet(LoadMibState *state)
{
	if (_mib(NULL) == NULL)
	{
		noteLoadError(state, "MIB not initialized.");
		return 1;
	}

	return 0;
}
Exemple #5
0
static void	handle_amsendpoint_start(LoadMibState *state, const char **atts)
{
	char		*tsname = NULL;
	char		*epspec = NULL;
	char		**att;
	char		*name;
	char		*value;
	LystElt		elt;

	if (noMibYet(state)) return;
	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "tsname") == 0)
		{
			tsname = value;
		}
		else if (strcmp(name, "epspec") == 0)
		{
			epspec = value;
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	if (tsname == NULL)
	{
		return noteLoadError(state, "Need name of transport service.");
	}

	if (epspec == NULL)
	{
		return noteLoadError(state, "Need AMS endpoint spec.");
	}

	switch (state->currentOperation)
	{
	case LoadAdding:
		elt = createAmsEpspec(tsname, epspec);
		if (elt == NULL)
		{
			return putErrmsg("Couldn't add AMS endpoint spec.",
					NULL);
		}

		break;

	case LoadChanging:
		return noteLoadError(state, "'Change' not yet implemented.");

	case LoadDeleting:
		return noteLoadError(state, "'Delete' not yet implemented.");

	default:
		return noteLoadError(state, "Not in an operation.");
	}
}
Exemple #6
0
void EvernoteSession::getNoteContent(NoteWrapper* note){
    qDebug() << "EvernoteSession :: auth" << endl;
    noteLoadStarted(note);
    try {
        note->note.tagGuids = DatabaseManager::instance()->getNoteTagGuids(note->note);
        note->note.resources = DatabaseManager::instance()->getNoteResources(note->note);


        if(!FileUtils::noteCached(note)){
            recreateSyncClient(false);
            std::string content = "";
            syncClient->getNoteContent(content, Settings::instance()->getAuthToken().toStdString(),note->getGuid());
            FileUtils::cacheNoteContent(note, QString::fromStdString(content));
        }
        if(cancelGetNote){
            return;
        }
        noteContentDownloaded(/*FileUtils::noteContentFilePath(note)*/note);
        sleep(1);
        for(int i=0;i<note->note.resources.size();i++){
            Resource r = note->note.resources.at(i);
            if(!FileUtils::resourceCached(r)){
                recreateSyncClient(false);
                syncClient->getResource(r, Settings::instance()->getAuthToken().toStdString(),r.guid, true, false, true, false);
                FileUtils::cacheResourceContent(r);
                r.data.bodyHash = ResourceWrapper::convertToHex(r.data.bodyHash).toStdString();
            }
            if(cancelGetNote){
                return;
            }
            ResourceWrapper* w = new ResourceWrapper(r);
            resourceDownloaded(w);
        }

        noteLoadFinished(note);
    } catch (TException &tx) {
        qDebug() << "EvernoteSession :: excetion while getNoteContent: " << tx.what();
        if(!cancelGetNote){
            noteLoadError(QString::fromLocal8Bit(tx.what()));
        }else{
            qDebug() << "note load canceled, supress errors";
        }
    }
}
Exemple #7
0
static void	handle_unit_start(LoadMibState *state, const char **atts)
{
	int	znbr = 0;
	char	*zname = NULL;
	int	rsp = 0;
	char	**att;
	char	*name;
	char	*value;
	Unit	*unit;

	if (noMibYet(state)) return;
	if (state->venture == NULL)
	{
		return noteLoadError(state, "Venture not specified.");
	}

	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "nbr") == 0)
		{
			znbr = atoi(value);
		}
		else if (strcmp(name, "name") == 0)
		{
			zname = value;
		}
		else if (strcmp(name, "resync_period") == 0)
		{
			rsp = atoi(value);
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	if (zname == NULL)
	{
		return noteLoadError(state, "Need name of unit.");
	}

	unit = lookUpUnit(state->venture, zname);
	switch (state->currentOperation)
	{
	case LoadAdding:
		if (unit == NULL)
		{
			unit = createUnit(state->venture, znbr, zname, rsp);
			if (unit == NULL)
			{
				return putErrmsg("Couldn't add unit.", zname);
			}
		}
		else
		{
			return noteLoadError(state, "Unit already in MIB.");
		}

		break;

	case LoadChanging:
		return noteLoadError(state, "'Change' not yet implemented.");

	case LoadDeleting:
		if (unit == NULL)
		{
			return noteLoadError(state, "No such unit.");
		}

		state->target = unit;	/*	May be deletion target.	*/
		break;

	default:
		return noteLoadError(state, "Not in an operation.");
	}
}
Exemple #8
0
static void	handle_subject_start(LoadMibState *state, const char **atts)
{
	int	subjnbr = 0;
	char	*subjname = NULL;
	char	*desc = NULL;
	char	*symkeyname = NULL;
	char	*marshalfnname = NULL;
	char	*unmarshalfnname = NULL;
	char	**att;
	char	*name;
	char	*value;

	if (noMibYet(state)) return;
	if (state->venture == NULL)
	{
		return noteLoadError(state, "Venture not specified.");
	}

	if (state->subject)
	{
		return noteLoadError(state, "Already working on a subject.");
	}

	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "nbr") == 0)
		{
			subjnbr = atoi(value);
		}
		else if (strcmp(name, "name") == 0)
		{
			subjname = value;
		}
		else if (strcmp(name, "desc") == 0)
		{
			desc = value;
		}
		else if (strcmp(name, "symkey") == 0)
		{
			symkeyname = value;
		}
		else if (strcmp(name, "marshal") == 0)
		{
			marshalfnname = value;
		}
		else if (strcmp(name, "unmarshal") == 0)
		{
			unmarshalfnname = value;
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	if (subjname == NULL)
	{
		return noteLoadError(state, "Need name of subject.");
	}

	state->subject = lookUpSubject(state->venture, subjname);
	switch (state->currentOperation)
	{
	case LoadAdding:
		if (state->subject == NULL)
		{
			state->subject = createSubject(state->venture, subjnbr,
					subjname, desc, symkeyname,
					marshalfnname, unmarshalfnname);
			if (state->subject == NULL)
			{
				return putErrmsg("Couldn't add subject.",
						subjname);
			}
		}

		break;

	case LoadChanging:
		return noteLoadError(state, "'Change' not yet implemented.");

	case LoadDeleting:
		if (state->subject == NULL)
		{
			return noteLoadError(state, "No such subject.");
		}

		state->target = state->subject;	/*	May be target.	*/
		break;

	default:
		break;				/*	Just context.	*/
	}
}
Exemple #9
0
static void	handle_role_start(LoadMibState *state, const char **atts)
{
	int	rolenbr = 0;
	char	*rolename = NULL;
	char	*pubkeyname = NULL;
	char	*privkeyname = NULL;
	char	**att;
	char	*name;
	char	*value;
	AppRole	*role;

	if (noMibYet(state)) return;
	if (state->venture == NULL)
	{
		return noteLoadError(state, "Venture not specified.");
	}

	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "nbr") == 0)
		{
			rolenbr = atoi(value);
		}
		else if (strcmp(name, "name") == 0)
		{
			rolename = value;
		}
		else if (strcmp(name, "pubkey") == 0)
		{
			pubkeyname = value;
		}
		else if (strcmp(name, "privkey") == 0)
		{
			privkeyname = value;
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	if (rolename == NULL)
	{
		return noteLoadError(state, "Need name of role.");
	}

	role = lookUpRole(state->venture, rolename);
	switch (state->currentOperation)
	{
	case LoadAdding:
		if (role == NULL)
		{
			role = createRole(state->venture, rolenbr, rolename,
					pubkeyname, privkeyname);
			if (role == NULL)
			{
				return putErrmsg("Couldn't add role.",
						rolename);
			}
		}
		else
		{
			return noteLoadError(state, "Role already in MIB.");
		}

		break;

	case LoadChanging:
		return noteLoadError(state, "'Change' not yet implemented.");

	case LoadDeleting:
		if (role == NULL)
		{
			return noteLoadError(state, "No such role.");
		}

		state->target = role;	/*	May be deletion target.	*/
		break;

	default:
		return noteLoadError(state, "Not in an operation.");
	}
}
Exemple #10
0
static void	handle_venture_start(LoadMibState *state, const char **atts)
{
	int	vnbr = 0;
	char	*appname = NULL;
	char	*authname = NULL;
	char	*gwEid = NULL;
	int	ramsNetIsTree = 0;
	int	rzrsp = 0;
	char	**att;
	char	*name;
	char	*value;

	if (noMibYet(state)) return;
	if (state->venture)
	{
		return noteLoadError(state, "Already working on a venture.");
	}

	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "nbr") == 0)
		{
			vnbr = atoi(value);
		}
		else if (strcmp(name, "appname") == 0)
		{
			appname = value;
		}
		else if (strcmp(name, "authname") == 0)
		{
			authname = value;
		}
		else if (strcmp(name, "gweid") == 0)
		{
			gwEid = value;
		}
		else if (strcmp(name, "net_config") == 0)
		{
			if (strcmp(value, "tree") == 0)
			{
				ramsNetIsTree = 1;
			}
			else	/*	Only other valid value is mesh.	*/
			{
				ramsNetIsTree = 0;
			}
		}
		else if (strcmp(name, "root_cell_resync_period") == 0)
		{
			rzrsp = atoi(value);
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	if (appname == NULL)
	{
		return writeMemo("[?] Need app name for venture.");
	}

	if (authname == NULL)
	{
		return writeMemo("[?] Need auth name for venture.");
	}

	state->venture = lookUpVenture(appname, authname);
	switch (state->currentOperation)
	{
	case LoadAdding:
		if (state->venture == NULL)
		{
			state->venture = createVenture(vnbr, appname,
					authname, gwEid, ramsNetIsTree, rzrsp);
			if (state->venture == NULL)
			{
				return putErrmsg("Couldn't add venture.",
						appname);
			}
		}

		break;

	case LoadChanging:
		return noteLoadError(state, "'Change' not yet implemented.");

	case LoadDeleting:
		if (state->venture == NULL)
		{
			return noteLoadError(state, "No such venture.");
		}

		state->target = state->venture;/*	May be target.	*/
		break;

	default:
		break;				/*	Just context.	*/
	}
}
Exemple #11
0
static void	handle_application_start(LoadMibState *state, const char **atts)
{
	char	*appname = NULL;
	char	*pubkeyname = NULL;
	char	*privkeyname = NULL;
	char	**att;
	char	*name;
	char	*value;
	LystElt	elt;

	if (noMibYet(state)) return;
	if (state->app)
	{
		return noteLoadError(state, "Already working on an app.");
	}

	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "name") == 0)
		{
			appname = value;
		}
		else if (strcmp(name, "pubkey") == 0)
		{
			pubkeyname = value;
		}
		else if (strcmp(name, "privkey") == 0)
		{
			privkeyname = value;
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	if (appname == NULL)
	{
		return noteLoadError(state, "Need name of application.");
	}

	state->app = lookUpApplication(appname);
	switch (state->currentOperation)
	{
	case LoadAdding:
		if (state->app == NULL)
		{
			elt = createApp(appname, pubkeyname, privkeyname);
			if (elt == NULL)
			{
				return putErrmsg("Couldn't add application.",
						appname);
			}

			state->app = (AmsApp *) lyst_data(elt);
		}

		break;

	case LoadChanging:
		return noteLoadError(state, "'Change' not yet implemented.");

	case LoadDeleting:
		if (state->app == NULL)
		{
			return noteLoadError(state, "No such application.");
		}

		state->target = state->app;	/*	May be target.	*/
		break;

	default:
		break;				/*	Just context.	*/
	}
}
Exemple #12
0
static void	handle_csendpoint_start(LoadMibState *state, const char **atts)
{
	int	after = -1;
	LystElt	elt = NULL;
	int	count;
	char	*epspec = NULL;
	char	**att;
	char	*name;
	char	*value;

	if (noMibYet(state)) return;
	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "after") == 0)
		{
			after = atoi(value);
			if (after < 0)
			{
				return noteLoadError(state, "'after' illegal");
			}

			count = after;
			for (elt = lyst_first((_mib(NULL))->csEndpoints); elt;
					elt = lyst_next(elt))
			{
				if (count == 0) break;
				count--;
			}

			if (count > 0)
			{
				return noteLoadError(state, "'after' invalid");
			}
		}
		else if (strcmp(name, "epspec") == 0)
		{
			epspec = value;
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	switch (state->currentOperation)
	{
	case LoadAdding:
		if (createCsEndpoint(epspec, elt) == NULL)
		{
			return putErrmsg("Couldn't add CS endpoint.", NULL);
		}

		break;

	case LoadChanging:
		return noteLoadError(state, "CS endpoints can only be added \
and deleted.");

	case LoadDeleting:
       		if (elt == NULL)
		{
			return putErrmsg("Couldn't delete CS endpoint.", NULL);
		}

		lyst_delete(elt);
		break;

	default:
		return noteLoadError(state, "Not in an operation.");
	}
}
Exemple #13
0
static void	handle_continuum_start(LoadMibState *state, const char **atts)
{
	int		contnbr = 0;
	char		*contname = NULL;
	int		isNeighbor = 1;
	char		*desc = NULL;
	char		**att;
	char		*name;
	char		*value;
	int		idx;
	Continuum	*contin;

	if (noMibYet(state)) return;
	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "nbr") == 0)
		{
			contnbr = atoi(value);
		}
		else if (strcmp(name, "name") == 0)
		{
			contname = value;
		}
		else if (strcmp(name, "neighbor") == 0)
		{
			isNeighbor = 1 - (0 == atoi(value));
		}
		else if (strcmp(name, "desc") == 0)
		{
			desc = value;
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	if (contname == NULL)
	{
		return noteLoadError(state, "Need name of continuum.");
	}

	idx = lookUpContinuum(contname);
	if (idx < 0)
	{
		contin = NULL;
	}
	else
	{
		if (contnbr == 0 || contnbr == idx)
		{
			contin = (_mib(NULL))->continua[idx];
		}
		else
		{
			return noteLoadError(state, "Continuum name/nbr \
mismatch.");
		}
	}

	switch (state->currentOperation)
	{
	case LoadAdding:
		if (contin == NULL)
		{
			contin = createContinuum(contnbr, contname, isNeighbor,
					desc);
			if (contin == NULL)
			{
				return putErrmsg("Couldn't add continuum.",
						contname);
			}
		}

		break;

	case LoadChanging:
		return noteLoadError(state, "'Change' not yet implemented.");

	case LoadDeleting:
		if (contin == NULL)
		{
			return noteLoadError(state, "No such continuum.");
		}

		return noteLoadError(state, "'Delete' not yet implemented.");

	default:
		return noteLoadError(state, "Not in an operation.");
	}
}
Exemple #14
0
static void		endElement(LoadMibState	*state, const char *name)
{
#else
static void XMLCALL	endElement(void *userData, const char *name)
{
	LoadMibState	*state = (LoadMibState *) userData;
#endif
	if (strcmp(name, "ams_mib_load") == 0)
	{
		return handle_load_end(state);
	}

	if (strcmp(name, "ams_mib_init") == 0)
	{
		return handle_init_end(state);
	}

	if (strcmp(name, "ams_mib_add") == 0)
	{
		return handle_op_end(state, LoadAdding);
	}

	if (strcmp(name, "ams_mib_change") == 0)
	{
		return handle_op_end(state, LoadChanging);
	}

	if (strcmp(name, "ams_mib_delete") == 0)
	{
		return handle_op_end(state, LoadDeleting);
	}

	if (strcmp(name, "continuum") == 0)
	{
		return handle_continuum_end(state);
	}

	if (strcmp(name, "csendpoint") == 0)
	{
		return handle_csendpoint_end(state);
	}

	if (strcmp(name, "amsendpoint") == 0)
	{
		return handle_amsendpoint_end(state);
	}

	if (strcmp(name, "application") == 0)
	{
		return handle_application_end(state);
	}

	if (strcmp(name, "role") == 0)
	{
		return handle_role_end(state);
	}

	if (strcmp(name, "subject") == 0)
	{
		return handle_subject_end(state);
	}

	if (strcmp(name, "sender") == 0)
	{
		return handle_sender_end(state);
	}

	if (strcmp(name, "receiver") == 0)
	{
		return handle_receiver_end(state);
	}

	if (strcmp(name, "venture") == 0)
	{
		return handle_venture_end(state);
	}

	if (strcmp(name, "unit") == 0)
	{
		return handle_unit_end(state);
	}

	if (strcmp(name, "msgspace") == 0)
	{
		return handle_msgspace_end(state);
	}

	noteLoadError(state, "Unknown element name.");
}
Exemple #15
0
static void	handle_msgspace_start(LoadMibState *state, const char **atts)
{
	int		contnbr = 0;
	char		*gwEid = NULL;
	char		*symkeyname = NULL;
	char		**att;
	char		*name;
	char		*value;
	Continuum	*contin;
	Subject		*msgspace;

	if (noMibYet(state)) return;
	if (state->venture == NULL)
	{
		return noteLoadError(state, "Venture not specified.");
	}

	if (state->subject)
	{
		return noteLoadError(state, "Already working on a subject.");
	}

	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "nbr") == 0)
		{
			contnbr = atoi(value);
		}
		else if (strcmp(name, "gweid") == 0)
		{
			gwEid = value;
		}
		else if (strcmp(name, "symkey") == 0)
		{
			symkeyname = value;
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	if (contnbr < 1 || contnbr > MAX_CONTIN_NBR)
	{
		return noteLoadError(state, "Need number of continuum.");
	}

	contin = (_mib(NULL))->continua[contnbr];
	if (contin == NULL)
	{
		return noteLoadError(state, "Unknown continuum.");
	}

	msgspace = state->venture->msgspaces[contnbr];
	switch (state->currentOperation)
	{
	case LoadAdding:
		if (msgspace == NULL)
		{
			msgspace = createMsgspace(state->venture, contnbr,
					gwEid, symkeyname);
			if (msgspace == NULL)
			{
				return putErrmsg("Couldn't add msgspace.",
						contin->name);
			}
		}

		break;

	case LoadChanging:
		return noteLoadError(state, "'Change' not yet implemented.");

	case LoadDeleting:
		if (msgspace == NULL)
		{
			return noteLoadError(state, "No such continuum.");
		}

		state->target = msgspace;	/*	May be target.	*/
		break;

	default:
		return noteLoadError(state, "Not in an operation.");
	}
}