Page 1 of 1

[Solved] Auto update extension

Posted: Sun Jul 08, 2012 9:08 am
by nsindhe
Hello Everyone,

Is there a way to get an extension to automatically update itself without the need for a user to download, install it and then restart open office? The developer guide seems to suggest that the online update is meant to check for updates and if one is available, the user has to download and install it.

The idea is to incorporate software protection schemes within the extension. A few of these schemes tend to protect the software by updating it regularly in such a way that the actual logic would be the same, but each time the software would use different instructions to execute them, thus making it difficult for an attacker to really guess what is happening.

Any help in this regard would be greatly appreciated.

Thanks,
Nitin

Re: Auto update extension

Posted: Mon Jul 09, 2012 3:12 pm
by hanya
Hi, welcome to the forum

If you want to invoke to install extension package to update installed one from outside of the office instance, consider unopkg program to use, see: http://wiki.services.openoffice.org/wik ... ons/unopkg

Re: Auto update extension

Posted: Tue Jul 10, 2012 12:09 am
by nsindhe
Hi hanya, Thanks for the reply.

Ideally I would want to do it from within the office instance and via code. After digging through the SDK, I found "PackageInformationProvider" and "ExtensionManager" in :: com :: sun :: star :: deployment.

I think using the ExtensionManager, it is possible to add an extension from code. Are there any samples on how to use these? I tried using the "PackageInformationProvider" singleton as shown below:

Code: Select all

Reference< XPackageInformationProvider > xInfoProvider( PackageInformationProvider::get( xContext ) );
std::cout << "Initialized XPackageInformationProvider" << std::endl;
OUString sLocation = xInfoProvider->getPackageLocation(convertToOUString( "com.my.package" ) );  // This works
Sequence< Sequence< OUString > > availableUpdates = xInfoProvider->getExtensionList();  // This also works
xInfoProvider->isUpdateAvailable("com.my.package"); // This does not
When I execute "xInfoProvider->isUpdateAvailable("com.my.package"); ", I get the following error:

"Unsatisfied query for interface of type com.sun.star.ucb.XCommandProcessor!".

I am unsure how to resolve this. I'm guessing it has something to do with instantiating UCB, but I have no idea and hence am reading through the developer guide on UCB.

If you can guide me in the right direction, it would be great help !!

Thanks,

Nitin

Re: Auto update extension

Posted: Tue Jul 10, 2012 3:48 am
by nsindhe
I was able to overcome the above mentioned exception by creating an instance of UCB. But, I am unable to add an extension using addExtension method of XExtensionManager interface. This is the code i am using:

Code: Select all

Sequence< NamedValue > properties;
		Reference< XPackage > updatedPackage = xExtensionManager->addExtension(convertToOUString("http://myextensionsite.com/update/myextension.oxt"),properties,convertToOUString("user"),Reference< XAbortChannel >(), Reference< XCommandEnvironment >());
On running this, I get an exception - "Error while adding : MyExtensionName".

Any idea what is going wrong??

Re: Auto update extension

Posted: Tue Jul 10, 2012 3:47 pm
by hanya
When I tried to install extension by the method, it worked with the following code in Python:

Code: Select all

    def install(self, command_env):
        if not self.file_exists(self.package_url):
            raise StandardError("Extension package lost.")
        manager = self.ctx.getByName(
            "/singletons/com.sun.star.deployment.ExtensionManager")
        ac = manager.createAbortChannel()
        try:
            package = manager.addExtension(
                self.package_url, 
                (), 
                "user", 
                ac, 
                command_env
            )
        except Exception, e:
            print(e)
            return False
        return True
Where command env is defined like:

Code: Select all

    class ProgressHandler(unohelper.Base, XProgressHandler):
        def push(self, status): pass
        def update(self, status): pass
        def pop(self): pass
    
    class Interactionhalder(unohelper.Base, XInteractionHandler):
        def __init__(self, act):
            self.act = act
        
        def handle(self, request):
            message = request.getRequest()
            if not isinstance(message, str):
                message = message.Message
            try:
                n = self.act.query(message)
                if n == 1:
                    type_name = "com.sun.star.task.XInteractionApprove"
                else:
                    type_name = "com.sun.star.task.XInteractionAbort"
                for continuation in request.getContinuations():
                    if continuation.queryInterface(uno.getTypeByName(type_name)):
                        continuation.select()
            except Exception, e:
                print(e)
    
    def query(self, message, buttons=2):
        return show_message(self.ctx, self.pages[6].getPeer(), 
            message, "", "querybox", buttons)
    
    
    class CommandEnv(unohelper.Base, XCommandEnvironment):
        def __init__(self, act):
            self.act = act
        
        def getInteractionHandler(self):
            return self.act.__class__.Interactionhalder(self.act)
        
        def getProgressHandler(self):
            return self.act.__class__.ProgressHandler()
I think working XCommandEnvironment interface is required to install. When I returned non-working XInteractionHandler by getInteractionHandler method of the XCommandEnvironment interface, it could not be installed.
The above code looks little bit funny because of PyUNO does not require interface query in most case but it does required in this case. In C++, query css::task::XInteractionApprove interface and select it to emulate to push OK button on the query dialog.
 Edit: Full code can be seen as dead code:
https://github.com/hanya/BookmarksMenu/ ... ge.py#L259
https://github.com/hanya/BookmarksMenu/ ... rd.py#L653 

Re: Auto update extension

Posted: Tue Jul 10, 2012 3:49 pm
by hanya
To restart the office could be done by OfficeRestartManager singleton, see:
http://www.openoffice.org/api/docs/comm ... nager.html

Re: Auto update extension

Posted: Wed Jul 11, 2012 4:38 am
by nsindhe
Thanks hanya. Things worked as expected !.. When i call requestRestart method of OfficeRestartManager, how is the behavior like? I passed the same interaction handler to this method and though I did not get any errors, I am unsure what is happening.

Re: Auto update extension

Posted: Wed Jul 11, 2012 11:02 am
by hanya
When i call requestRestart method of OfficeRestartManager, how is the behavior like?
Current implementation does not use passed interaction handler, so nothing happened with it.

Re: Auto update extension

Posted: Wed Jul 11, 2012 11:33 am
by nsindhe
So how does the restart process work? I see that the restart has been requested ( using isRestartRequested method), but the never happens.

Re: Auto update extension

Posted: Wed Jul 11, 2012 2:17 pm
by hanya
I am sorry, it only kills the desktop by terminate method, it does not invoke to restart the office.
So you need to restart the office yourself.

Re: Auto update extension

Posted: Thu Jul 12, 2012 12:52 am
by nsindhe
Ok. Thanks for all the help !