Wednesday, January 21, 2009
Tuesday, December 2, 2008
Overlaying windows over GTK Window
While doing my research to build a vncviewer similar to the drop down disconnect box we see in vmplayer, I realised that there are a couple of techniques to do this, namely as follows:
1.) Modifying vncdisplay.c to emmit signals to the program.
2.) Inserting a one pixel high button on top to catch events.
Both methods has its pros and cons. By using method 1, we will be able to see the entire screen. But by using method 1 also, we will be required to modify the source of the original code (the codebase i was using is gtk-vnc-0.3.7).
In order to stear clear from modifying the author's code, the best way round this is to use method 2, which is to insert a single pixel button on top of the vnc viewer so that we can catch events instead of catching signals. The codes are fairly simple. But this is rather tricky to do because what happens when the mouse leaves the button? The button will close immediately. So, there needs to be a sleep event right?
No, GTK doesn't like sleeping.. somehow.. there will be an error, but I managed to overcome this stupid problem (look at the earlier post for details). But actually the best way to do this is to use an alarm signals.
The idea is as follows:
1.) If the cursor is above the single pixel button, show the disconnect button.
2.) Once the cursor leaves, it, create a signal alarm of 2.
3.) In the event of the signal 'rings' after 2 seconds, we hide the disconnect button.
With that said, the codes are:
// create another window above an existing window
popWindow = gtk_window_new(GTK_WINDOW_POPUP);
// show and hide windows in GTK
void showMenu (GtkWidget *vncdisplay, GdkEventMotion *event) {
gtk_widget_show(popWindow);
}
void choseMenu (GtkWidget *vncdisplay, GdkEventMotion *event) {
signal(SIGALRM, catch_alarm);
alarm(2);
}
// alarm function
void catch_alarm() {
gtk_widget_hide(popWindow);
alarm(0);
}
// signals
gtk_signal_connect(GTK_OBJECT(myButton), "enter", GTK_SIGNAL_FUNC(showMenu), window);
gtk_signal_connect(GTK_OBJECT(myButton), "leave", GTK_SIGNAL_FUNC(hideMenu), window);
1.) Modifying vncdisplay.c to emmit signals to the program.
2.) Inserting a one pixel high button on top to catch events.
Both methods has its pros and cons. By using method 1, we will be able to see the entire screen. But by using method 1 also, we will be required to modify the source of the original code (the codebase i was using is gtk-vnc-0.3.7).
In order to stear clear from modifying the author's code, the best way round this is to use method 2, which is to insert a single pixel button on top of the vnc viewer so that we can catch events instead of catching signals. The codes are fairly simple. But this is rather tricky to do because what happens when the mouse leaves the button? The button will close immediately. So, there needs to be a sleep event right?
No, GTK doesn't like sleeping.. somehow.. there will be an error, but I managed to overcome this stupid problem (look at the earlier post for details). But actually the best way to do this is to use an alarm signals.
The idea is as follows:
1.) If the cursor is above the single pixel button, show the disconnect button.
2.) Once the cursor leaves, it, create a signal alarm of 2.
3.) In the event of the signal 'rings' after 2 seconds, we hide the disconnect button.
With that said, the codes are:
// create another window above an existing window
popWindow = gtk_window_new(GTK_WINDOW_POPUP);
// show and hide windows in GTK
void showMenu (GtkWidget *vncdisplay, GdkEventMotion *event) {
gtk_widget_show(popWindow);
}
void choseMenu (GtkWidget *vncdisplay, GdkEventMotion *event) {
signal(SIGALRM, catch_alarm);
alarm(2);
}
// alarm function
void catch_alarm() {
gtk_widget_hide(popWindow);
alarm(0);
}
// signals
gtk_signal_connect(GTK_OBJECT(myButton), "enter", GTK_SIGNAL_FUNC(showMenu), window);
gtk_signal_connect(GTK_OBJECT(myButton), "leave", GTK_SIGNAL_FUNC(hideMenu), window);
Getting coordinates of cursor in GTK
The codes are simple, but we need to get the variables out of its static context.
gint x, y;
gdk_window_get_pointer(window->window, &x, &y, 0);
printf("My cords are: x %d and y: %d", x, y);
Viola!
gint x, y;
gdk_window_get_pointer(window->window, &x, &y, 0);
printf("My cords are: x %d and y: %d", x, y);
Viola!
GTK Error When forking
When you get an error such as a "Fatal IO error" when using GTK and forking a child process. you have just ran into a bug with GTK. GTK doesn't like the way the child exits when it is being forked.
To resolve this, make sure that we exit the child using: _exit (-1), instead of the normal exit function.
To resolve this, make sure that we exit the child using: _exit (-1), instead of the normal exit function.
Monday, November 24, 2008
Dumping output of a program
In perl, if you want to do a dump of a program, say SSH. You do the following
system ("SSH 192.168.1.102 1> /dev/null 2> /dev/null");
Basically 1> /dev/null means dump all the output of the program to /dev/null
and 2> /dev/null means dump all the error output to /dev/null
system ("SSH 192.168.1.102 1> /dev/null 2> /dev/null");
Basically 1> /dev/null means dump all the output of the program to /dev/null
and 2> /dev/null means dump all the error output to /dev/null
Monday, November 17, 2008
Research on Netstat
I am basically trying to check if there is a vncviewer connecting to a vncserver through SSH.
So my first stop was really to play around with netstat. And I found a very interesting behaviour when vncviewer is connecting to a vncserver through an SSH tunnel.
Setup:
I started port forwarding: SSH -L 10001:localhost:5900
Then. with the command: netstat -t grep
Observations:
1.) When RECV-Q is = 0, it means there is no user activity in SSH
2.) When RECV-Q is > 0, it means there is user activity
3.) When SEND-Q is = 0 or > 1504, it means SSH connection is active and host is alive.
4.) When SEND-Q is = 1504, it means SSH connection is active, but host is dead.
So my first stop was really to play around with netstat. And I found a very interesting behaviour when vncviewer is connecting to a vncserver through an SSH tunnel.
Setup:
I started port forwarding: SSH -L 10001:localhost:5900
Then. with the command: netstat -t grep
Observations:
1.) When RECV-Q is = 0, it means there is no user activity in SSH
2.) When RECV-Q is > 0, it means there is user activity
3.) When SEND-Q is = 0 or > 1504, it means SSH connection is active and host is alive.
4.) When SEND-Q is = 1504, it means SSH connection is active, but host is dead.
Sunday, November 16, 2008
PHP Session Manipulation
Today on linuxquestion somebody asked something about PHP's session variable. Which I thought was quite interesting. The question goes: "Can we actually manipulate the PHP session information on the server? If so how?"
Well this question actually brings two more questions in my mind instantly:
1.) Is PHP session information stored only on the server?
We can't actually manipulate PHP information that resides on the server, it is just not really possible security wise. But what we can do is manipulate it in such a way that we can resume it even after it dies when garbage collector destroys it.
2.) How is PHP Session stored on the server? On disk or in memory?
The first time you call session_start(), PHP basically generates a new session ID and creates an empty file to store session variables. PHP also sends a cookie back to the client that contains the session ID.
There are a couple of techniques to session resumption.
1.) Cookies - Store session information into cookie as it is being stored on the session variable. That way, when we resume our session after we close the browser window, we can first of all check if there was a cookie set, and if there is, read that cookie information to the session and start.
2.) Database - Store session information into database as it is being stored on the session variable. Similar to the cookie approach, but this is preferred because it is really permanent and it does not rely on the client's cookie function (some client disable cookies on their browser).
3.) Mixture of Cookies + Database. Cookies is faster than database but database is more persistent than a cookie. Therefore, a mixture of this techniques allows for a persistent and fast session resumption.
Well this question actually brings two more questions in my mind instantly:
1.) Is PHP session information stored only on the server?
We can't actually manipulate PHP information that resides on the server, it is just not really possible security wise. But what we can do is manipulate it in such a way that we can resume it even after it dies when garbage collector destroys it.
2.) How is PHP Session stored on the server? On disk or in memory?
The first time you call session_start(), PHP basically generates a new session ID and creates an empty file to store session variables. PHP also sends a cookie back to the client that contains the session ID.
There are a couple of techniques to session resumption.
1.) Cookies - Store session information into cookie as it is being stored on the session variable. That way, when we resume our session after we close the browser window, we can first of all check if there was a cookie set, and if there is, read that cookie information to the session and start.
2.) Database - Store session information into database as it is being stored on the session variable. Similar to the cookie approach, but this is preferred because it is really permanent and it does not rely on the client's cookie function (some client disable cookies on their browser).
3.) Mixture of Cookies + Database. Cookies is faster than database but database is more persistent than a cookie. Therefore, a mixture of this techniques allows for a persistent and fast session resumption.
Subscribe to:
Posts (Atom)