[Solved] Auto update extension

The Application Programming Interface and the OASIS Open Document Format

[Solved] Auto update extension

Postby nsindhe » Sun Jul 08, 2012 9:08 am

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
Last edited by nsindhe on Thu Jul 12, 2012 12:53 am, edited 1 time in total.
OpenOffice 3.1 on Linux Mint 12
nsindhe
 
Posts: 7
Joined: Sun Jul 08, 2012 7:35 am

Re: Auto update extension

Postby hanya » Mon Jul 09, 2012 3:12 pm

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
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Auto update extension

Postby nsindhe » Tue Jul 10, 2012 12:09 am

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   Expand viewCollapse view
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
OpenOffice 3.1 on Linux Mint 12
nsindhe
 
Posts: 7
Joined: Sun Jul 08, 2012 7:35 am

Re: Auto update extension

Postby nsindhe » Tue Jul 10, 2012 3:48 am

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   Expand viewCollapse view
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??
OpenOffice 3.1 on Linux Mint 12
nsindhe
 
Posts: 7
Joined: Sun Jul 08, 2012 7:35 am

Re: Auto update extension

Postby hanya » Tue Jul 10, 2012 3:47 pm

When I tried to install extension by the method, it worked with the following code in Python:
Code: Select all   Expand viewCollapse view
    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   Expand viewCollapse view
    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 
Last edited by hanya on Tue Jul 10, 2012 6:56 pm, edited 1 time in total.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Auto update extension

Postby hanya » Tue Jul 10, 2012 3:49 pm

To restart the office could be done by OfficeRestartManager singleton, see:
http://www.openoffice.org/api/docs/comm ... nager.html
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Auto update extension

Postby nsindhe » Wed Jul 11, 2012 4:38 am

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.
OpenOffice 3.1 on Linux Mint 12
nsindhe
 
Posts: 7
Joined: Sun Jul 08, 2012 7:35 am

Re: Auto update extension

Postby hanya » Wed Jul 11, 2012 11:02 am

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.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Auto update extension

Postby nsindhe » Wed Jul 11, 2012 11:33 am

So how does the restart process work? I see that the restart has been requested ( using isRestartRequested method), but the never happens.
OpenOffice 3.1 on Linux Mint 12
nsindhe
 
Posts: 7
Joined: Sun Jul 08, 2012 7:35 am

Re: Auto update extension

Postby hanya » Wed Jul 11, 2012 2:17 pm

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.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Auto update extension

Postby nsindhe » Thu Jul 12, 2012 12:52 am

Ok. Thanks for all the help !
OpenOffice 3.1 on Linux Mint 12
nsindhe
 
Posts: 7
Joined: Sun Jul 08, 2012 7:35 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 2 guests