Friday, October 22, 2010

Password for null GNOME keyring in SVN

Today I tried to commit my codes to the google code repository after working on my 3rd year project. But when commit it asked me this,

> Password for '(null)' GNOME keyring:

I didn't have any idea about it and I had't faced to a such prompt before. I typed my SVN account password but failed. I searched through web to find out what is this GNOME keyring and what's wrong with that. Finally I found that there are more people who had faced to such a problem.

There was a solution suggested to avoid the SVN prompting for a password for a keyring. That was putting commnd in the terminal.

> rm ~/.gnome2/keyrings/login.keyring

After giving this command in the terminal I committed and that keyring asking was gone. Usual username and password for SVN were asked and after entering them, the codes are successfully committed. But then suddenly a dialog box appeared and asked me to enter a new password for a keyring. I typed my login password there to face whatever happens.
No problem occurred up to now after doing that. However still I have no clear idea about what are those keyrings. :)

( It seems this link also useful. But I found this one after everything is over )

Tuesday, August 24, 2010

Linking C libraries to php extensions

After learning to create a simple php module it took a long time for me to understand the correct way of porting an existing C library to to a php module. Sometimes I thought it may be impossible for me. After all I have managed to understand the correct way of doing it. If you need to learn about creating a simple php module, follow this article. So, here's the procedure I followed to build the php module which is linked to a C library.

1) First step is creating a simple C library to link to a php module. So, write and save the following source files.

Here's the "asanka.c" file,

#include "asanka.h"

void setValue(int a){
value = a;

int getValue(){
return value;

void increment(){
value = value + 1;

void decrement(){
value = value - 1;

Here's the "asanka.h" file,


int value;

void setValue(int a);

int getValue();

void increment();

void decrement();

Now create the C library called "libasanka.a" by giving the command,

gcc -c asanka.c
ar -cr libasanka.a asanka.o

Ok, now we have the library. Create a directory in some place, lets's say in your home directory as the "library". Inside that directory, create two directories as "lib" and "include". Put the library file "libasanka.a" into the "lib" directory and "asanka.h" file to the "include" directory. So, now the paths to both should be,


There's a reason for giving the path's of the files. We have to give the path when we create the php module.

2) Now it's time to create the php module. Goto ext directory of the php source and give the command in the terminal,

./ext_skel --extname=asanka

3) Now go into the newly created directory "asanka" inside the ext directory and open the auto generated file "asanka.c" (this is not the file we created). Add the following entries in the appropriated places,

PHP_FE(asanka_setValue, NULL)
PHP_FE(asanka_getValue, NULL)
PHP_FE(asanka_increment, NULL)
PHP_FE(asanka_decrement, NULL)

Add the following entries also in the appropriate place in the file,

int locValue;
int argc = ZEND_NUM_ARGS();

if (zend_parse_parameters(argc TSRMLS_CC, "l", &locValue) == FAILURE) {
php_error_doc_ref(NULL TSRMLS_CC, E_ERROR, "Invalid Parameters");


int locValue;
locValue = getValue();



4) Now open the file "php_asanka.h" in the same directory and add the following to it,


5) Open the config.m4 file and add change it's content to be match with the following code,

dnl $Id$
dnl config.m4 for extension asanka

dnl Comments in this file start with the string 'dnl'.
dnl Remove where necessary. This file will not work
dnl without editing.

dnl If your extension references something external, use with:

PHP_ARG_WITH(asanka, for asanka support,
[ --with-asanka[=DIR] Include asanka support])

dnl Otherwise use enable:

dnl PHP_ARG_ENABLE(asanka, whether to enable asanka support,
dnl Make sure that the comment is aligned:
dnl [ --enable-asanka Enable asanka support])

if test "$PHP_ASANKA" != "no"; then
dnl Write more examples of tests here...

dnl # --with-asanka -> check with-path
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
dnl SEARCH_FOR="/include/asanka.h" # you most likely want to change this
if test -r $PHP_ASANKA/lib/libasanka.a; then # path given as parameter
else # search default path list
AC_MSG_CHECKING([for asanka files in default path])
for i in /usr/local /usr; do
if test -r $i/lib/libasanka.a; then
AC_MSG_RESULT(found in $i)
if test -z "$ASANKA_DIR"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please reinstall the libasanka distribution - asanka.h should be /include and libasanka.a should be in /lib])

dnl # --with-asanka -> add include path

dnl # --with-asanka -> check for lib and symbol presence
LIBNAME=asanka # you may want to change this
LIBSYMBOL=getValue # you most likely want to change this

AC_MSG_ERROR([wrong asanka lib version or lib not found])
-L$ASANKA_DIR/lib -lm

PHP_NEW_EXTENSION(asanka, asanka.c, $ext_shared)

6) Now run the following commands in terminal inside the "asanka" directory,


./configure --with-asanka=/home/username/library/

sudo make

7) Now our new module is ready. You can find it in the "modules" directory inside the "asanka" directory. Copy that "" shared object to the extensions directory of your installed php. If you don't know the path to the extensions directory, look at the phpinfo() page.

8) After placing "" into the extensions directory, next thing is editing the php.ini file. Open it and add an entry as follows in the appropriate place,

9) Now every things ok. Write a php file with the following content and place it in the "htdocs" directory of the apache server,

echo asanka_getValue();

Check whether your web browser displays the correct output. If you see number 12, then your C library works correctly with the php module.

Saturday, August 21, 2010

Fundamental issue in the integration of php-tsql module and tikirisql library.

I think we've faced with a serious problem in works. Yesterday night I was working on integration of the php-tsql module with the tikirisql library. I was faced with a situation where it's hard to compile the integrated php module since it's makefile is an auto generated one. I think our tikirisql library makes us troubles since it's coded for a general purpose. I directly called the tikirisql's functions inside the php-tsql module. Then I compiled and placed it in my php extensions directory. When I try to run a testing php script in apache server which uses our php modules functions, the php file's going to be downloaded without rendering on the browser.
I think most probably the reason should be the usage of tikirisql's C files and header files within the php module. There may be some restrictions by the creators of php about the way we create extensions to the php.
Sometimes the same problem may have been encountered by the MySQL community who use a very simple php module which does only the exchanging of the web client's queries to MySQL server and results back to clients browser. They doesn't do parsing stuff in php module. I looked at the mysql module in php. It's very simple with only the standard source files. Those standard files are in each and every module in php. As I understand everything the mysql people has changed is the content in those source files. They have written new functions and called them. Therefore I think there may be a big reason for not using external libraries inside php modules.
I think we have to study more about the php internals to understand the problem and to find a possible solution.

Tuesday, August 17, 2010

A php progress bar

From several days I was trying to add a progress bar to the FIT4D's acquiring disk image front end. Even though I couldn't finish it, I thought to write a note about the things I learned from it. I found a php progress bar from here Then I included the following code in a php file and opened it with browser.

require_once 'ProgressBar.class.php';
$bar = new ProgressBar();
$elements = 1000000; //total number of elements to process
$bar->initialize($elements); //print the empty bar
for($i=0;$i<$elements;$i++){ //do something here... $bar->increase(); //calls the bar with every processed element

Then it worked as the developer of it mentioned. Now the hard part. I wanted to include it in our front end. But even though I included the above code segment inside the create_img2Main.php file in the lib directory of the FIT4D source, it doesn't show the dynamic progress bar. Instead, it suddenly shows the final state of the progress bar which is 100% filled.
According to my understanding, I think this is because the file create_img2Main.php is loaded using an ajax request from create_imgMain.php through functions in global.js file. I hope to discuss about the issue with Yasantha akka tomorrow.

Monday, July 26, 2010

Installing Forensic Investigation Toolkit (FIT4D)

To install FIT4D forensic investigation toolkit in Linux we need some extra tools which are necessary for the proper operation of FIT4D. Therefore first you have to install the following tools,

sudo apt-get install sleuthkit
sudo apt-get install ddrescue
sudo apt-get install foremost

Then if you haven't installed apache2 server with php5 and the mysql database server, you have to install them also. To do them give the command,

sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server

When the installation proceeds it asks to set a password for the mysql root user. I set the password as "root" because in the FIT4D installation it asks for the root users password of the mysql database.
After setting this environment which is necessary to install FIT4D I have to check in the php.ini file whether,


is set to "off" as above. Then I copied the FIT4D source folder to the www directory of the apache2 server. In that source directory goto ~/www/FIT4D/config folder. If there is a install.lock file, delete it. Then start your apache2 server and mysql database server by issuing the commands,

sudo service mysql start
sudo service apache2 start

Now open your web browser(tested for firefox) and goto http://localhost/fit4d/.

Fill the information asked in the form, and click the button "configure". Now you can login to the system and go around.
However according to the source codes of FIT4D I've got, the database (named as "ptk") which is created by the installation process is not complete enough. Therefore I had to run an extra SQL script which is given to me in addition to FIT4D source. There's another thing to do. The tools we've install at the beginning are going to be used by the FIT4D system. Therefore the FIT4D system should be given permission to run those tools. To do it, I added an entry to the sudoers file in /etc/ directory. To change the sudoers file you should use the command,

sudo visudo

in terminal. When the file is opened, I entered the following text to the end of it.


ok, now according to the specification we've completed the installation.

Saturday, June 26, 2010

Prevent apache2 from starting at boot time.

Apache2 server in my Ubuntu machine was used to start at each time I boot the Ubuntu. I found it recently and realized the reason which made me feel that machine is slow than the past days. Therefore I removed apache2 from the starting up at boot time by giving this command.

sudo update-rc.d -f apache2 remove

Tuesday, June 15, 2010

Installing Contiki and Cooja Simulator in UBUNTU

About a week ago, I thought to install TikiriDB and tryout it. To use it I have to install Contiki operating system and the cooja simulator which are the platform to run TikiriDB. Started from reading the tikiriDB home page ( There's a link provided in that page which shows how to install contiki and cooja in Ubuntu 8.10 (installing contiki/cooja). However I'm running Ubuntu 10.04 Lucid and it works. The only issue is if your going to install netsim simulator provided with contiki, your in trouble because the required package (libgtk1.2-dev) is not supporting to Ubuntu 9.04 and 10.04 as I know. By the way, I forget netsim and advanced to all the other things.
Here we go,

1. I had to install CVS to get the CVS version of Contiki,

sudo apt-get install cvs

2. Got the contiki source,

cvs -z3 co contiki-2.x

3. There is an example directory in the Contiki source which contains some example codes. To compile the hello-world example,

cd contiki-2.2.2/examples/hello-world

make TARGET=native


4. After testing that hello world example I cleaned the temporary files during the compilation,

make clean

5. Now contiki is ok. Then I needed java, since the cooja is a java based simulator,

sudo apt-get install sun-java6-jdk

6. To compile cooja I needed ant which is a compile tool,

sudo apt-get install ant

7. To compile and start cooja I gave the commands,

cd tools/cooja

ant run

8. To remove all the temporary files created during the compilation,

ant clean

After these steps cooja was started and I was exited by the facilities given in cooja. Then I stopped working on it and hope to complete the further configuration steps of cooja later.

Saturday, May 1, 2010

How to use SVN (Subversion)

"Subversion" is the version control system used in the php-tsql project. To contribute to it we have to use the subversion(svn) client in our local machine. This article includes the basic usage of subversion.

To install subversion,

sudo apt-get install subversion

To download the project's source files, you should create a directory somewhere in your
machine and go into that directory from shell,
Now give the command,

sudo svn checkout http://path to the project

sudo svn checkout

Now you can do editing of your files. But when you add or delete files/folders to the source directory you have to do it also in the command line.

To add a new file or directory to the source directory,

sudo svn add path/fileOrFoldername

eg -
(you're in the directory which you created to get the source files)
sudo svn add trunk/newfile.c

sudo svn add trunk/newDirectory

sudo svn add trunk/newDirectory/newfile2.c

You can delete a file or folder in a similar way,

sudo svn delete trunk/newfile2.c

sudo svn delete trunk/newDirectory

After you're done with the editing of source code, you have to commit it back to the repository.

sudo svn commit trunk/

When we commit we can put a log message which may be useful to track the purpose of editing the source of previous committed revision. To add the log message,

sudo svn commit trunk/ --message "This is the log message."

There are lot's of svn command available, following links will be helpful.

Saturday, April 24, 2010

Initial installations before developing php extensions.

To develop php extensions we have to be installed php in our system. Since it takes time and involve lot of works we can easily forget the steps we have to follow. Therefore I decided to document the steps I followed when setting up my development environment. I use UBUNTU 9.04 as my platform for php-tsql research works. Before we do anything it's necessary to install some development tools which require in extension development life cycle. Therefore you first install the latest versions of following packages in to you system.

1. libxml2 (which is required to compile php source code)
2. libtool
3 make
4. automake
5. autoconf
6. m4
7. bison

But remember that some of the packages may require some other once to be installed previously. If the installation stop somewhere, look at the error and install the requesting package first. Then you can install the interrupted package again. These kind of installations require a huge patience because it may take lot of time in progress printing different things and finally give you an error saying, without a particular package it cannot continue. Then you have to install that package patiently. All you have to do to install each package is,

step 1: Decompress the the package file.
step 2: Go into the package directory.
step 4: Give the commands,

sudo make install

Now I assume you have installed those packages. Now It's time to install apache server and php. download the sources of apache2 and php. Decompress the package files and spend some time reading readme files in those. I think most important one is INSTALL file in php. Now we're installing apache2.

step 1: Decompress the the apache2 package file.
step 2: Go into the package directory.
step 3: To configure and install apache2 give the command,

./configure --enable-so
sudo make install

To check whether apache2 installed correctly start the apache2 server normally. eg:

sudo /usr/local/apache2/bin/apachectl start

Open your wed browser and go to localhost, it should show the message "It Works"
To stop the server,

sudo /usr/local/apache2/bin/apachectl stop

Now apache2 is ok. Its time for php installation.

step 1: Decompress the php package file.
step 2: Go into the package directory.
step 3: To configure and install php give the command,

./configure --with-apxs2=/usr/local/apache2/bin/apxs
sudo make install

If these steps completed without any error, php is installed. But you have to do some more before you start using php.

step 4: To setup your php.ini file, give the command

cp php.ini-development /usr/local/lib/php.ini

step 5: You have to make sure whether apache2 is aware of the installed php. Open the file httpd.conf (it should be in /usr/local/apache2/conf directory) and check whether this kind of an entry is there in the file,

LoadModule php5_module modules/

If not, put that line in the file.

step 5: In that httpd.conf file put this line also in the correct position,

AddType application/x-httpd-php .php .phtml

Now php also installed correctly. To check whether php is working, copy following code to a php files body named testinfo.php and put it in the htdocs directory of apache2.


Now start apache2 server and go to the URL http://localhost/testinfo.php. It should give you the phpinfo page. If so, it confirms that php also working.
Here's a good reference with more detailed description about compiling from the source,

All the best & Enjoy your extensions developing works with this new platform. There's an article on extension writing in this blog. Better to read it.

Friday, April 23, 2010

php-tsql Project : Now the tsql module talks.

Few weeks ago Mr. Laxman gave us a sample web server and a client to study and to embed the sample client in our tsql module. After huge effort now we're able to communicate with the sample web server though the tsql module. Now we can understand the way we have to implement the module one day to communicate with the tsql server. However still we couldn't implement the provided function in the module to accept parameters for the host name and port number. Those details are hard coded in the function yet. I'm still looking for the correct way to make php modules to accept parameters in functions.

Saturday, April 3, 2010

Creating a simple php extension

(This article assumes that you have installed apache2,php and all the other development tools in your machine. To do those things there's an article with all the instructions)

To make a php extension we can use the mechanism provided in the php source code which is the shell script named ext_skel. First download the latest php source code and find the ext_skel shell script in the ext directory in source code.

1. Give this command from the terminal in ext directory.

./ext_skel --extname=TikiriDB

Now a directory will be created in ext called TikiriDB. Then we can use that extension skeliton to build our module.

2. Go to the TikiriDB directory. Open the file TikiriDB.c file and add the line PHP_FE(tikiri_print, NULL) in appropriate location to see like,

const zend_function_entry TikiriDB_functions[] = {

PHP_FE(confirm_TikiriDB_compiled, NULL)

PHP_FE(tikiri_print, NULL)

{NULL, NULL, NULL} /* Must be the last line in TikiriDB_functions[] */


There's another thing which should be added to the same file. Add the code below at the end of the file.


char *text = NULL;

/* count the number of arguments passed */

int argc = ZEND_NUM_ARGS();

int text_len;

/* TSRMLS_CC boils down to ", tsrm_ls" where tsrm_ls is a resource handler.

You don't need to worry about this, it is used to make it thread safe */

if (zend_parse_parameters(argc TSRMLS_CC, "s", &text, &text_len) == FAILURE) {

php_error_doc_ref(NULL TSRMLS_CC, E_ERROR, "Invalid Parameters");


} /* Copy the value from the passed string, create a new one and return it */



3. Now open the file php_TikiriDB.h. Add the line PHP_FUNCTION(tikiri_print); to the appropriate location to be like this.


4. Open the file config.m4 and remove the comments remain the following part uncommented.

PHP_ARG_ENABLE(TikiriDB, whether to enable TikiriDB support,

[ --enable-TikiriDB Enable TikiriDB support])

5. Now give this command inside the TikiriDB directory,


./configure --enable-TikiriDB


6. Now in the TikiriDB directory open the file Makefile and in the EXTENSION_DIR attribute give the path to the extension directory of your installed php.

eg- If your extensions are in the directory /usr/local/include/php/ext set the path as,

EXTENSION_DIR = /usr/local/include/php/ext

7. Now give this command inside the TikiriDB directory,

make install

8. The extension is now installed. Open your php.ini file and make sure the extension_dir attribute is set to the same path.

Add an entry to it as,

9. Now in your apache servers htdocs directory put a file named testing.php and put the content below in that folder.

$string = tikiri_print("Hello World");
echo $string;

10. Start your apache server and access the file testing.php from the web browser. The function tikiri_print returns the string given to it.

If you want to change the functions defined in the module several time and test again and again, you have to repeat the steps,

./configure --enable-TikiriDB

Copy the new file in the modules folder of the TikiriDB folder to the extension directory of the installed php's extension directory overwriting the old file.