stylish swap

Today I discovered a stylish way to swap two integers x and y without a temporary variable.

The code is:

x = x ^ y;
y = x ^ y;
x = x ^ y;

beautiful, isn’t it? ;)

Although it’s recommended to avoid in practice because it’s usually slower than the naive swap. The reason is that CPU can’t do pipeline instructions since the operations must be strictly executed in sequential order.

git merge + gvimdiff, wow!

It’s been a long time since I’ve merged with a lot of conflicts. I used to work with svn and it was really one hell of pains to merge. Admit it svn users, you’re afraid of merging, you do not want to merge, it appears frequently in your nightmare. Today I had to merge the master branch of LibreOffice with feature/cmis along with ton of conflicts. The nightmare flashed back and I was hesitating. But guess what, the git mergetool did automerge most of the conflicts. It only left me two conflicts for manual resolve. With gvimdiff, another great tool, I managed to resolve in about 20 seconds! So thanks a lot for Linus Torvald, J. Hamano and other git maintainers for creating such a great tool. If I have to vote for best linux softwares, it must be git and vim.

libCMIS 0.4.0 is released, brings support for Google Drive and Afresco in the cloud

libCMIS 0.4.0 is released yesterday, with the following new features and improvements:

* Support for Google Drive protocol as a binding
* Support for Alfresco in the cloud
* Added OAuth2 authentication support
* Added API to configure HTTP proxy
* Handle invalid SSL certificate problems
* Added API for renditions
* Moved the CMIS Atom binding unit tests to use libcurl mockup
* Added repository capabilities support (still missing
capabilityCreatablePropertyTypes and capabilityNewTypeSettableAttributes)

You can now use a C or C++ client to call the lib, manage CMIS files as well as Google Drive files. With this release LibreOffice will be able to integrate with Google Drive very soon.

Google Drive in LibreOffice

LibreOffice can now connect and browse Google Drive files (but not yet released nor merged ;) ). Although creation a session the first time takes around 3-4 seconds since we have to pass a number of steps of OAuth2 . Still, it doesn’t redirect you to a web browser like other applications. In case of Google Drive file formats, LO converts it automatically to ODF or other compatible formats before opening. Then when you save, it automatically converts back to Google formats. Handy, is n’t it? But there is currently a bug in CMIS file picker which prevents us from opening a file without an extension. We are working to fix it soon. You can also create file and folder directly in the file picker dialog.

gdriveFileBrowser 

In addition, we can now display, edit and save Google Drive document properties using the properties dialog. We can only edit updatable properties from server.

gdriveProperties

I still have some bugs to fix such as: file saving isn’t working yet due to several reasons; properties of document can have multiple values.

 

Connection to Google Drive through libCMIS

libCMIS is used in LibreOffice in order to enable the office suit connecting to CMIS service. In my GSoC proposal, it is used to connect Google Drive to LibreOffice. However, the implementation has been finished before the GSoC coding phase started. Thanks a lot to Cédric Bosdonnat for his great helps of the implementation. In the mean time, the following features have been developed:

  • OAuth2 authentication: OAuth2 is a three-legs authentication, involves an user, a resource provider and a third-party who wants to access user resource. Basically when an application want to access user’s data, it will be redirected to the service provider authentication’s site, get the access token and then use it to fetch data. It requires the application to register itself to the API provider, generate a client_id and client_secret, define access scope and redirect uri. Those information then permit the application to connect to the API provider, get the access token and the refresh token. The access token must be included in the HTTP header each time the application want to fetch data. This token expires after a short period of time (normally one hour). The refresh token is then used to generate a new access key. The application can store the refresh token and reuse it to authenticate after that without user entering his username/password.
  • Google Drive automatic OAuth2: in libCMIS we treat OAuth2 as a basic authentication which requires only username/password. This allows users to have an automatic login without redirecting to the Google authentication web site. Authentication using refresh key is therefore disabled. Nevertheless since the access token expires after a short period of time,  the refresh key is still needed to get a new one.
  • JSON parser implementation: I used libjson to parse and create JSON objects. However there is some limited support of JSON in libboost, we are considering to switch to use boost since it’s already on the dependencies of libCMIS.
  • Since libCMIS is already integrated in LibreOffice and we want to reuse as much the code as possible, the Drive API was mapped to CMIS API including:
  1. Session: get object, get repository (since GDrive doesn’t have the notion of repository we created a fixed dummy one).
  2. Object: move to another folder, remove, update properties, get renditions.
  3. Document: get content stream, set content stream, get parents, get all versions.
  4. Folder: create document, create folder, get children, remove folder tree.

We expect to release libCMIS 0.4 soon to integrate it into LibreOffice. For folks who got frustrated by ODF support of Google Drive this can be a good news ;)

Next: properties dialog and version dialog will be implemented soon to allow user interact with his document entirely using LibreOffice.