23
Jul
10

vim/NERDTree/snippetsEmu in Windows

Text editors have been remarkably recognized for their intuitive support for the coders “developers”. There are two worth-mentioning features in vim in which you can, explore the filesystem and open files directly from a tree-view explorer. Also, the flexibility to assign a generic tab-triggers “Snippets” –provided originally by TextMate.

So, in this article, we will use both, NERTree and snippetsEmu plugins in vim.

NERDTree

  • Download NERDTree from vim website
  • Place NERD_tree.vim in “~/.vim/plugin”. In Windows, the exact path is “C:\Program Files\Vim\vimfiles\plugin”.
  • Restart vim and run :NERDTree in vim’s command mode “case-sensitive”. voila!

Now, we need to build the helptags in order to be able to read the help files from the command “:help NERDTree”.

  • Copy NERD_Tree.txt to “C:\Program Files\Vim\vimfiles\doc”. This path might differ from yours according to the installation directory. I am assuming the default installation folder in this context.
  • Run the command :helptag c:\program\ files\vim\vimfiles\doc\ Keep in mind the tab-auto-completion is tightly integrated here.
  • From vim’s command mode :help NERDTree

snippetsEmu

To cut this to the chase, download the complete bundle from vim website. The installation of the vimball can be done as the following:

  • Copy snippy_bundles.vba to “C:\Program Files\Vim\vimfiles\after\ftplugin”. Most probably, you will have to create the folder “after” and subfolder “ftplugin” manually. Remember, vba stands for VimBall-Archive and not ** for Application.
  • Open the bundle file using vim
  • In vim’s command mode, run the command :so % In more simple terms, :so opens the source file (:source) % means the current file.
  • Restart vim
  • In the command mode, run :Snippet or :help Snippet — Again, it’s case-sensitive

To do some test with it, create a new python file “.py” and type for as a keyword. You should get something like the below.

Now, you have both, NERDTree and snippetsEmu running in your vim. Enjoy hacking!

11
Mar
10

Python on FreeBSD

In this article, I will be installing the lovely python on FreeBSD system using FreeBSD Port Collection. The Port Collection is a PMS (Package Management System) for installing applications on FreeBSD. In the beginning, we want to obtain the Port Collection and make sure that it’s updated.

One of the easiest way to update the Port Collection is using portsnap command.

portsnap will connect to a remote site and download a snapshot of the Ports Collection into /var/db/portsnap.

#portsnap fetch

If this is the first time to use portsnap, you should extract the “compressed” snapshot into /user/ports. You can check this folder before if you are not sure about it.

#portsnap extract

In  case the snapshop is already populated, you need only to update it and no need for subsequent fetch:

#portsnap update

Tips: portsnap fetch, extract and update can run together (#portsnap fetch update).

Now, to install python we need to find the desired Python port. In our case, python port can be found in /usr/ports/lang/pythonX (where X is the python’s version).

# cd /usr/ports/lang/python26

#make install clean

At this stage, python26 should be installed and can be tested as the following:

#python -V

or

#pkg_info | grep -i python

Last thing I would like to shed some light on is the installation process of the port. The “make install clean” command makes the installation in three steps:

make: to compile the port code

make install: to install the port

make clean: to delete the compilation temporary directories

Happy pythoning!

26
Feb
10

SQL “Left Outer Join” can count NULL!

A friend of mine has recently consulted me on a common situation to calculate values “let’s say an employee salary” from different columns in different tables. The common way to do that is to use Left Outer Join, but the problem is that unmatched values will be returned as NULL. It makes sense that a NULL value will be returned in case of having any NULL value in the operation.

The scenario will be as the following:

mysql> select (1+2+3);
+———+
| (1+2+3) |
+———+
|       6 |
+———+
1 row in set (0.00 sec)

mysql> select (1+2+NULL);
+————+
| (1+2+NULL) |
+————+
|       NULL |
+————+
1 row in set (0.00 sec)

In MS SQL Server, this problem can be easily solved using ISNULL with replacement value. For instance,

ISNULL(salary, 0.00)

So, in case that the salary value was NULL, the returned value will be 0.00.

In mySQL, ISNULL is a little bit different than that. It simply tests if the provided value is NULL or not (yeah, 1 if it’s NULL and 0 if it did not match it).

However, another function can actually help in this case. IFNULL represents the same functionality provided by MSSQLSERVER’s ISNULL with replacement value.

mysql> select (ISNULL(NULL));
+—————-+
| (ISNULL(NULL)) |
+—————-+
|              1 |
+—————-+
1 row in set (0.00 sec)

mysql> select (ISNULL(10));
+————–+
| (ISNULL(10)) |
+————–+
|            0 |
+————–+
1 row in set (0.00 sec)

mysql> select (IFNULL(NULL,10));
+——————-+
| (IFNULL(NULL,10)) |
+——————-+
|                10 |
+——————-+
1 row in set (0.00 sec)

mysql> select (IFNULL(1,10));
+—————-+
| (IFNULL(1,10)) |
+—————-+
|              1 |
+—————-+
1 row in set (0.00 sec)

As a conclusion, these functions (ISNULL/IFNULL) can be very useful to enhance and optimize the quality of code that’s been written in many complex situations.

13
Apr
08

Virtual Network, no longer virtual!

Working in a virtual environment can be real and crucial sometimes. In addition to the simplicity and consolidation that can be offered by making things virtual, I love the networking part. It’s incredibly easy, a tasty little piece of cake… You don’t need to think about how many NICs you’ll need, or even how many IP addresses you could assign… Simply, it’s awesome!

Network Settings

In a real environment, we struggle to build a stable and effective network as we hopefully expect. Many factors and risks can ruin your project. A lot of legwork is involved plus a huge waste of time and money. Virtualization comes in to solve many issues alike. A sophisticated hosting environment can be built in a very simple and efficient way. It’s doesn’t really matter whether you’re using Xen, OpenVZ, Hyper-V or VMware, Virtual Network is fun with no regrets. Basically, I will demonstrate four different types of network settings which I usually encounter in many real “originally virtual!” scenarios.

  1. Not connected. Yea, exactly as you’ve already thought that the network adapter is disconnected “Cable Unplugged”. I guess that this option has been made to make things appear as real as possible 🙂
  2. Local “Host-only”. A virtual switch will be in place to communicate all guest machines within the same network segment. That means that those “guest” machines won’t be able to access any network resources on the host machine.
  3. Local

  4. Shared Networking (NAT – Network Address Translation). A simple NAT engine will manage all traffics between the host and guest machines. You don’t have to define any IP addressing scheme for that. Also, a virtual DHCP server will take care of assinging the IP addresses to all machines. In this case, the VDHCP server assigns 192.168.131.x internal addresses to all guest machines and the virtual gateway address 192.168.131.254. The point here is that this virtual gateway will be also responsible for answering DNS requests and thereby will only be able to answer queries from that virtual network segment. You can manually assign a different DNS to resolve this issue.
  5. NAT

  6. Network adapter on the physical computer “Bridged”. Each virtual network will appear as another network interface in the physical machine “host”. This will allow the guest machine to access any services in the external network and vice versa.
  7. bridged

  8. MS Loopback Adapter. For complexity purposes, definitely, this is your choice! If you’ve used VMware to create virtual machines, this is gonna be similar to “Custom” setting which allows you to choose the virtual network adapter. You can install a different Loopback “software-only” adapter in the host machine without the necessity to install any additional physical network adapters. In very common scenarios, you will need to manually set a static IP address for each Loopback adapter. Afterwards, you can connect to other virtual networks in a different network switch. Remember that this adapter is software only and no external network is involved.
    MS Loopback
    Here are very common steps to add a new Loopback adapter “Windows”:

    1. Control Panel >> Add Hardware “hdwwiz.cpl” >> Click Next
    2. Click Yes, I have already connected the hardware.
    3. In the Installed hardware list, click Add a new hardware device >> Next.
    4. Click Install the hardware that I manually select from a list (Advanced) >> Next.
    5. In the Common hardware types list, click Network adapters >> Next.
    6. In the Manufacturer box, click Microsoft, in the Network Adapter list, click Microsoft Loopback Adapter >> Next >> finish.
    7. Now, you can configure and use the new Loopback adapter that is listed in the Network Connections “ncpa.cpl“.

Conclusion

Virtual Networks are the most amazing thing in virtualization world. You don’t need to spend extra money or even efforts to communicate with different network segments. Surprisingly, NAT and DHCP services are already there and they need only to be enabled. The virtual machines are able communicate together in a private network, or to intranet, extranet, and the internet.

29
Mar
08

Adhoccing ICS…

In many occasions, I’ve been asked to compose an ad-hoc wireless network as a Host-computer and facilitate the Internet Connection through ICS. I thought it would be better off if I posted these information in my blog to be available for all people who are looking to share their internet connections and get some quick bucks! But before getting into this I would like to mention that this article isn’t a nitty-gritty config file that geeks would love to tweak.

The Scenario

Let’s assume that we have two laptops, the AHost “Adhoc Host” and the WClient “Wireless Client”. AHost is connected to the internet through whatever interface “LAN, 3G, Bluetooth, or even E1. Yah, I know, who needs to run ICS when he’s using E-Carrier!”.

adhocics-scenario.jpg

On the AHost “Adhoc Host Device”:

  1. Enable the Adhoc Wireless network.
  2. Enter a Network Name “SSID” and Security Key “WEP encryption key”.
  3. Enable ICS on the internet connection and disable all other ones “the dialog should prompt you for that”.

The WClient needs only to connect to the AHost Network…

AHost Part

Open the Control Panel » Network Connections » Wireless Network Connection properties » Advanced tab » Advanced button and choose Computer-to-Computer (ad hoc) networks only.

Adhoc 01

Now, you will be able to add the network SSID, let’s name the network “AHost Network” and enter all configurations as depicted in the figure below, the network key can be “12345” for demonstration and cracking purposes “Come on, It’s WEP!”..

Adhoc 02

Click OK and open the properties dialog of the Internet Connection. In our case “Mobily”, tick the ICS (Internet Connection Sharing) checkbox “allow other network users to…”. Finally, allow the home networking connection on the Wireless Network Connection and click OK.

Adhoc 03

On the Wireless Client (WCLient)

That was from the host side, in the client side we need to connect to “AHost network” as following:

Client01

Enter the network security key that has been set earlier “12345”.

Client2

Now, try to connect to the internet and remember that you don’t need to add any proxy configuration.

rule of thumb

  • The installed Wireless Network Adapters should have a built-in support for IEEE 802.11 Wireless LANs (WLANs).
  • For any connection failure, check the Windows Firewall mode and exceptions.
  • Check that the host and the clients have valid IP addresses.
  • To create an Adhoc Wireless Network in Windows Vista, try the following:
    • Start » Control Panel » Network and Internet » Network and Sharing Center » Select Manage wireless networks » Add » Create an ad hoc network » Next » Enter a network name » Enter a security key » Save & Next
  • As mentioned earlier, WEP has many security issues. I really recommend using WPA2/WPA.
  • Sometimes you will need to configure the IP Address manually in case the internet connection doesn’t provide dynamic IP Addressing. Furthermore, you may need to set the proxy address in the same manner if you don’t have direct connection to the internet or if the proxy-settings aren’t auto-detected. This could also be applied to the DNS settings.
20
Feb
08

BlackPearl Web Forms Workflow..

K2 (www.k2.com) is one of the pioneer companies in developing business process management (BPM) solutions. Microsoft products are by heart the foundation of K2 workflow platform. Including .NET 3.0, WWF, WPF, and MOSS 2007. Here, I will demonstrate a very basic walkthrough scenario on using K2BP workflow engine through ASPX pages.

The Scenario

Our walkthough scenario is an approval request for a general message generated by an employee. The employee will submit the form and the manager will either approve or reject it. Finally, the originator “employee” will get a copy of the submitted form.

The Solution

First, we need to build a new empty project from VS2005 File->New. Let’s name it “BasicApproval

Create New Project

From the Solution Explorer, add a new process from the New Item context menu.

Add K2 Process

Choose “process” and name it “BasicApprovalProcess.kprx“. Now, Let’s build and design our form that will represent the BasicApproval wrokflow. Basically, we will need three forms to fulfill the process requirements.

  1. BasicRequest.aspx: The first form that will initiate the process and the employee will create a new process instance from it.
  2. BasicApproval.aspx: The second form the will be passed to the originator’s manager. The manager will either approve or reject the request.
  3. BasicApprovalEnd.aspx: The last form that will notify the user of the request result.

Before getting into developing these forms, we need to configure two things. Adding new SourceCode reference and ASPX control. First, right click on the Web Project Icon -> Add Reference -> .NET -> “SourceCode.Workflow.Client”

k2bp6.jpg

The second thing is to add the ASPX Control form K2 BlackMarket (www.k2underground.com). Right click on the VS2005 toolbox -> Choose Items -> .NET Framework Components -> Browse -> Choose the downloaded DLL file “blackpearl.web.controls.dll” and then click OK. Here is the result:

k2bp7.jpg

It’s time to develop the ASPX forms, each page contains the following controls:

  • Subject Textbox: “subject”
  • Message Textbox: “message”

BasicRequest.aspx

We need only to add the submit button “K2Submit” to look like this:

BasicRequest.aspx

Afterwards, add the following code to the submit button’s click event “remember, the code attached is inlined within ASPX tags.”:

k2bp3.jpg

BasicApproval.aspx

Copy and paste the old web form and rename it to “BasicApproval.aspx“. Delete the submit button and replace it with the ASPX Control that we’ve added earlier. Rename the ASPX control to “submit” and check the control’s properties to meet the following:

k2bp8.jpg

Now, let’s us load the workflow data fields according to the workflow item’s serial key.

k2bp9.jpg

Add the following code to the “K2Submit_LoadFields” event:

k2bp11.jpg

BasicApprovalEnd.aspx

This form is identical to the “BasicApproval.aspx” form.

It’s show time now!

The earlier steps are very common for any .NET/ASPX developer. From now on, it’s gonna be nasty and really operative. We’ll publish those forms to a web server through FTP “Even that FTP is not secure, I still love it! since you are not concerned about having Front Page Extensions on the target machine”. Then, we are going to design the BasicApprovalProcess in K2 Designer. Afterwards, we will deploy the process and initiate the process as per our plan.

Before you deploy the web forms, you should enable the “identity impersonate” in the web.config as follows:

k2bp12.jpg

Don’t forget to deploy/copy the “blackpearl.web.controls.dll” to the bin folder in the target website directory path.

Designing the Process

Let’s get back to our K2 Project. Drop two “Default Client Events” into the designer workspace. Here’s the result:

k2bp13.jpg

Activity Configuration

BasicApproval .aspx

Web Form Name: http://ServerName/BasicApproval.aspx

Configure Actions: Add new action, name it “Approval Request”

k2bp14.jpg

Configure Outcomes as following and click Finish.

k2bp15.jpg

BasicApprovalEnd.aspx

Let’s do the same with this activity according to the following:

Connecting the activities

Now, connect the Start Activity to BasicApproval.aspx Activity (Hold the Ctrl + drag the Start Activity to the BasicApproval.aspx Activity). Also, do the same to the BasicApproval.aspx and BasicApprovalEnd.aspx activities.

k2bp16.jpg

Defining the Data Fields

To map our fields in our web forms, we have to define them first in the K2 Data Fields. From the project workspace (I know that sometimes I use Java terminologies in .NET environment..), view -> K2 Object Browser -> Data Fields -> BasicApprovalProcess -> right click and “Add” -> create the two fields as string “subject” and “message“.

k2bp17.jpg

I guess that we’re ready now to deploy and test the process. Right click on the Solution’s Name “BasicApproval” and choose Deploy. As I always do, click Finish directly in the deployment wizard…

Testing the process

The testing process will start by creating a new instance using the first web form “BasicRequest.aspx”. After that, a work item should be created for the destination user, K2 Workspace can view and operate all these information. The second step is to proceed the process and approve the work item “BasicApproval.aspx“, last thing is to check the returned result “BasicApprovalEnd.aspx“.

k2bp18.jpg

After you submit the form, check the work item flow from the “View Flow” option in Work Item Context Menu in the K2 Workspace

k2bp23.jpg

k2bp21.jpg

Now, let’s Submit and Approve the “BasicApproval.aspx” form.

k2bp20.jpg

The worklist should be updated to reflect the latest activity in the process.
k2bp22.jpg

Last Form to submit is “BasicApprovalEnd.aspx

k2bp24.jpg

Let’s check the process flow after completing all activities.

k2bp25.jpg

Conclusion

K2BP is a helluva BPM solution!. I’ve only scratched the basics of developing, deploying and testing a very simplified workflow process. K2BP can extend these capabilities to integrate with Microsoft Exchange, Office, InfoPath, BizTalk, LCS, Visio and SharePoint.

17
Feb
08

You wanna make a memory!

Aha, I guess it’s kinda nice coincidence! Me and Bon Jovi, one of my favorite songs “(You want to) Make A Memory”. And from my perspective, I really want to make such a thing!

Before diving into memory mysteries, here are few things that need to be clarified. I will start out stating the basic terms in memory management. In MM world, we care most about the Virtual Memory. VM is a virtual and contagious range of memory addresses. In turn, it simplifies working with the Real or Physical Memory. It also extends the PR “Physical RAM” space by using the existing disk space “Paging”. So, the program will deal with a very simplified, optimized, and more importantly addressable version of the Physical RAM. I really should be thanking the MMU “Memory Management Unit” for making this possible.

The demand paging is usually the process of swapping the data “as pages” from disk to the RAM. This process could raise a Page Fault exception, luckily this exception is handled by the OS which will try to find an available physical page to place the faulted data. Sometimes, the OS takes long time to swap data which described as thrashing. It looks obvious that to overcome those bottlenecks you mostly need to add RAM. Have a look at the Windows Task Manager “taskmgr.exe” and add the Page Faults option from the processes tab, view menu, Select Set Columns, check the Page Faults.

Task Manager

Memory Tracing

Most likely, to trace what is going on behind the scene is pretty much tough. Though, it is interesting. The first tool that we are going to use is as previously mentioned, Windows Task Manager. The two misleading columns in the task manager are the Mem Usage and Virtual Memory Size. So, what’s the deal? Mainly, it’s not as it sounds… Mem Usage demonstrates the Working Set “Resident Set”, which means the pages that are currently in main memory and can be shared by other processes. On the other hand, VM Size is the private memory that committed by the process and can’t be shared by other processes.
A very similar but advanced tool to the WTM is the Perfmon “perfmon.msc” which resides in the Administrative Tools. Huge number of counters is adapted in this tool to provide a graphical chart of the counters’ performance. Basically, we can map the WTM attributes to this one as following:

  • Mem Usage -> Process/Working Set
  • VM Size -> Process/Private Bytes
  • Page Faults -> Process/Page Faults

The “Performance” tool can show you (the explanations were taken from the “Performance” tool):

  • Private Bytes -(Corresponds to the “VM Size” from Task Manager). A not-shareable amount of memory “in bytes ” with other processes.
  • Virtual Bytes – (Not shown in Task Manager) Virtual Bytes is the current size in bytes of the virtual address space that the process is using.
  • Working Set “Resident set” – (Corresponds to the “Mem Usage” from Task Manager) – Number of pages that are reside in physical RAM memory. These pages are available for application use without triggering a page fault. The default working set amount is 50 pages for each process, the maximum size can not exceed the system wide maximum. In 32-bit machines, the system can reach up to 2GB memory application. It can also reach up to 3GB using 3-GB user space (precisely 00000000~BFFFFFFF). Above 4GB can be mapped up using PAE (Physical Address Extension) using 36-bit physical address.

Before closing this part, I’m really eager to demystify the difference between Paged and non-paged pool. As mentioned earlier, Paging is the process of writing objects to disk. So Pool Paged is the size of bytes of writing objects to disk when those objects are not currently used. Pool non-paged is the opposite, this means that those objects can not be written to the disk and should remain in the physical memory.

Memory segmentation or linear address decomposition can be described into two parts, the segment and the offset “segment:offset form”. For example, 0AFE:0100 is a segmented address in my debug session. One of the main ideas here is to emphasize the Segment Registers in IA-32 (CS, DS, SS, ES, FS, and GS). Basically, there are three types of storage. Code “text”, data and stack segment. Code segment contains the executable instructions. Data Segment as its name suggests is a portion of memory that deals with variables “data”. Stack segment which stores the procedure stack for the program. x86 processors can operate in two execution modes. Real and protection mode. Real mode execution is limited to map up to 1MB memory space, in this way, the processor needs 20 bits of the address bus for that (2^20 = 1048576 = 1024 * 1024). In this mode, there is no address translation for the memory. And the memory interpretation is processed directly into physical memory. Protected mode execution is what we’re here about. Without this mode, there is no multitasking, memory protection, paging, V86 mode.

VAS

Reading Memory Dump

I always consider debugging one of the most challenging tasks. Especially, when it comes to memory debugging “mini-assemblers”. Sometimes I stuck in boring training labs, I don’t have a tool to give me some challenge and excitement. The best thing to do in this situation is to use the little debug.exe tool that is included in windows.
Start a Windows prompt session using debug command “debug”. And have fun!

DOS Debug

  • “r” command is used to display the contents of the register.
  • “d” can display the memory contents in both hexadecimal and ASCII.
  • “0BB3:0100” is the memory address which includes the segment “0BB3” and the offset “0100”
  • The next 16 bytes are the hexadecial content of each byte.
  • In the right, the ASCII representation of each byte.

Conclusion

That was a complete startup for memory management. The next parts will go deeper in how the developer or the administrator can trace and optimize memory management using debuggers and tracing tools. Stay tuned!

12
Sep
07

xargs.. Life can be much easier!

Any Linux admin has a special love story with xargs, It’s like a true friend. It doesn’t always appear to be handy until you stuck looking for a quick and nifty solution. One of these situations is when you need to filter a certain directory that contains a lot of files and you need also to manipulate those files.

xargs is an execution command, you pass your arguments and it will take care of the execution based on the given commands. For instance, I need to get the number of lines in each file within the current path.

ls | xargs wc -l

ls0.png

Simple, Isn’t it?

The first part of this command is very basic, you list the contents of the directory. Which apparently shows the following output:

basicxargs0.png

The second part is the real crux! Here, each line of the ls output will be piped as a standard stream to the xargs which will be process each line accordingly. This means the wc -l will be executed for each line, as if you would write it this way:

wc -l hello.c hello.ko hello.mod.c hello.mod.o hello.o
.
..

And so on!

Internally, xargs command tears up its Stdin input to separate lines based on a delimited character. Most likely, It’s a whitespaces, tabs, new lines and EOF.

xargs-internals.png

A very useful way to check and debug the execution pipeline within xargs is to add the option -t:

ls | xargs -t wc -l

The result of adding the -t option would be:

wc -l 1 anaconda-ks.cfg apache_1.3.37 apache_1.3.37.tar.gz Desktop hello.c hello.ko hello.mod.c hello.mod.o hello.o index.html install.log install.log.syslog InstallShield JavaApplication1 jdk1.5.0_09 jdk-1_5_0_09-nb-5_5-linux.bin lighttpd-1.4.16 lighttpd-1.4.16.tar.gz lynx-2.8.3-1.i386-cygwin.rpm lynx-debuginfo-2.8.5-18.0.2.i386.rpm Makefile mysql-5.0.41.tar.gz php-4.4.6.tar.gz rpm temp temp.c

I guess it’s pretty much meaningful now, Isn’t it?

Let’s heat this up a little bit:

You can use the blackslah “\” to write commands in multiple lines, the same example can be written as follows:

lsbackslash.png

“Don’t worry about .serverauth.XXXX files, just an XServer thing. It’s OK!” 

A powerful aspect of xargs is the ability to control the input data “stdin” from the pipe per invocation. As an example, we can limit the number of delimited strings to accept only two arguments “Again, per invocation”:

xargs-n.png

In shell world, you’re the king! xargs can ask for you permission for any execution “y = affirmative response, others are negative!. How easy!!”. The option “-p” takes care of this:

xargs-p2.png

If you feel playful a little bit, I guess it’s your time to enjoy. Manipulation moments are pretty much exciting! As you have formerly seen, xargs depends largely on the stdin “Standard Input” and if you don’t have enough control over that, xargs would be vain. Luckily, the option “-I” is a drastic option to pass the pipe’s output to the execution command within xargs. To make things more comprehensible, suppose that we need to copy all files within a certain directory to a different directory as a backup files “.bak”.

xargs-icp.png

Let’s break down that command, the “-I” option will determine the replacement string “‘%'”. A neat and tricky question can be raised right here:

Does the “-I” option include the single quote in the replacement string as a variable or is it considered as a escaping character?

The answer can simply be: YES! anything after “-I” and before a single/double unquoted whitespace is considered a replacement string. So, we may have the following valid strings:
‘%’
“‘%'”
%

But please don’t try this one:
HI!

At work I use “Linux~GNU”, but at home I use “*BSD~BSD”… In anyway, take care and note that GNU xargs uses “-i” and BSD version uses “-I”.

06
Sep
07

ISAPI in a nutshell

ISAPI stands for Internet Server Application Programming Interface, In simple words it’s a way to gain the highest performance that you’d ever dream from IIS. ISAPI is “up to a certain level” similar to CGI but also overcomes many of CGI’s problems. One of the biggest differences between ISAPI and CGI is the process handling. In CGI, a new process is created “spawned” for each request. ISAPI uses threads to solve this issue “I wish to know a problem that hasn’t been solved by threading!”.

ISAPI extensions, the heart and soul!

ISAPI has two major types. ISAP extension applications and ISAPI Filters. ISAPI extensions are the heart of IIS. For instance, ASP.dll is an ISAPI extension that processes ASP pages, perlis.dll is another ISAPI extension works as a Perl script engine that runs .pl and .plx file extensions “You can obtain it from ActiveState“. Don’t conflict between the Perl ISAPI extension “perlis.dll and Perl CGI “Perl.exe”.

appconf.png

If you’re using IIS 6.0 or above, you will notice a different Application Configuration form. Have a look:
ISAPI Configuration in IIS 6.0+

Wildcard Application Maps

Wildcard Application Maps contain a list of ISAPI Applications (ISAPIA) that will be processed before any HTTPS request, will make these applications available for all file extensions “regardless of whatever the file extension is”.

ISAPI filters

On the other side, ISAPI filters can be used to enhance an existing functionality provided by IIS. Any incoming/outgoing request can be processed and modified by those filters. As an example, you can provide your own custom operations (authentication, logging, etc…)

isap-filters.png

You may conclude now that ISAPI filters (ISAPIF) are kinda similar to the Wildcard Application Maps (WAM). I also agree with you, except that the WAM has many advantages over using ISAPIF. One of the chief differences is that WAM performs the customization operations “remember: encryption, logging, etc.” using the ISAPI extensions (ISAPIE) through IIS 6. And thereby you can overcome many limitations in ISAPIF, such as:

  • ISAPIF are limited to parse the HTTP headers and cannot be used to process information contained in the body of an HTTP request “forget about processing HTTP Post”.
  • ISAPIF can only configured per website, not per virtual directory.
  • ISAPIF are synchronous.

ISAPIF are synchronous. “I know, that was informative!”

That last point is a very interesting one! Generally, a synchronous call blocks a process till the operation completes “Blocking Call”. In contrary, an asynchronous call is non-blocking and can only initiate the process “Send-And-Pray”. ISAPIF executes synchronously because of it’s execution on a core IIS thread. For example, If you’re involved in a network latency scenario “multiple agents”, ISAPIF are not of your choice. Most likely, It will cause serious problems. In ISAPIE “Again, ISAPIA -> WAM”, the concept is totally different, it has its own thread and thereby it executes asynchronously.

05
Sep
07

netstat: the indispensable tool!

One of my best ever troubleshooting tool, sometimes I stuck in many difficult situations that are related to remote access or internal services/daemons healthiness. You can easily figure out what the problem is from this straightforward command.

netstat-an.png

As you can see, If you have many connections on you PC it will be very difficult to maintain all the result. Fortunately, you can paginate the results using “more” command.

netstat -an | more

In the preceding example, the FTP service runs on a TCP port 21. This means that the service is waiting for a connection request from any remote TCP.

You can also filter the given results using either find or findstr. By the way, findstr is much better than find since you can provide a regular expression for your search.

Checking a certain port number

So, let’s start with a simple scenario. I need to check the MS SQL Server default TCP port (1433):

netstat -an | find “1433”

Find command will filter the results from the netstat command and grabs only the specified string.

PID Concatenation

A serious problem arises from unknown ports, sometimes you modify a port number for a certain service “SSH for example” and after awhile you forgot what that port is, though you can open the *.conf file and snatch the actual values, I really prefer techie and neat solutions. In this case, I usually display the associated process ID with each connection.

netstat-ano.png

Now, you can easily seize that process and figure out where that hidden process is. Simply, by matching the same PID in the Windows Task Manager “taskmgr.exe”. Another good-looking idea is to use the tasklist in the command prompt:

tasklist /svc | find “3306”

This is not all about netstat, there are many other ideas. Grouping the statistics per-protocol, or listing for the new requests.




Design a site like this with WordPress.com
Get started