473,811 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

easy CGI w/ C

I'm here to promote my C library project for writing CGI progs in C.
The project is called Stutter and can be found at
http://freshmeat.net/projects/stutter

I'm horrible, I know. =)

-Matt
Nov 14 '05 #1
1 1740

On Sat, 17 Apr 2004, Matt Mayers wrote:

I'm here to promote my C library project for writing CGI progs in C.
The project is called Stutter and can be found at
http://freshmeat.net/projects/stutter

I'm horrible, I know. =)


Not at all! We all love topical discussion of real-world standard C
programming! :)

% gcc -W -Wall -ansi -pedantic -O2 -c stutter.c
stutter.c: In function `getParam':
stutter.c:49: warning: implicit declaration of function `strcasecmp'
stutter.c:74: warning: char format, different type arg (arg 3)
% gcc -W -Wall -ansi -pedantic -O2 -c stutter_ex.c
stutter_ex.c:5: initializer element is not constant
stutter_ex.c:6: initializer element is not constant
stutter_ex.c:7: initializer element is not constant

All of gcc's criticisms are right on.
'strcasecmp' needs to be declared before you can call it, and defined
somewhere. More importantly, *you* can't define 'strcasecmp' *anywhere*,
because names beginning with 'str' and another letter are reserved for
the implementation' s use only.
You have in "stutter.c" the line
sscanf(__pQuery String, "%s", &__qs);
That's wrong, because 'sscanf' is expecting a pointer to 'char' as its
third argument, and the value of the expression '&__qs' is a pointer
to array[MAX_QS_SIZE] of 'char'. More importantly, you can't use the
name '__qs' either, because the implementation *also* reserves names
beginning with two underscores for its own use. I presume you're worried
that if you use just plain old 'qs' as the identifier, the client code
will come up with naming conflicts. You should read [one of] the
section[s] on the 'static' keyword in a good book; 'static' will help
you make sure "package-local" variables like 'qs' don't escape.
In 'stutter_ex.c', you have some global variables you're trying to
initialize with the results of function calls. A little thought will
show you that you can't do that: when would those functions be called?
Before 'main'? *Nothing* in standard C happens before 'main'! So you
need to move their initializations --- in fact, their entire definitions
--- inside the body of 'main'.

Logic bug: Inside 'getParam', you're assigning the result of 'getenv'
to '__pQueryString ', and then immediately calling 'getenv' again. This
will, on many systems, *overwrite* the old string's data, effectively
trashing the value of the string pointed to by '__pQueryString '. This
is a major bug, and needs fixing badly!

Silliness: That 'while' loop with the increment inside it is just a
silly way of writing '__qscount += strlen(__pQSDum my);'

Silliness: Your "check for overflow" inside 'getParam' is kind of
silly. It's really checking whether the user (the web interface)
entered an extra-long line; no "buffer overflow" in the usual sense of
the term will ever occur. Wouldn't it be better to go ahead and handle
long lines, since machine-generated queries often end up really long
anyway? Your users might thank you, and it's a great way to get
introduced to non-trivial uses for 'realloc'. (Also, your line length
is WAAAAY too long in those comments. 80 characters, /please!/)

Slight silliness: 'IntFromHex' is ASCII-specific. This might be
perfectly fine; I wouldn't be surprised if the relevant Internet
standards for CGI specified that all URL-thingies were supposed to
be encoded in ASCII. But you could have replaced the whole thing
with

unsigned hex;
sscanf(__pChars , "%2x", hex);
return hex;

and saved yourself some time and disk space.
I see that you used 'static' correctly on 'IntFromHex', so you should
have known better with all those other variables and functions.

The comment on 'printBasicHead er' shows that you're a little shaky
on what exactly the difference is between arrays and pointers. Google
"'Chris Torek' 'The Rule'".
Also, I've recently converted to the practice of using 'puts' instead
of 'printf' whenever possible. It's a religious issue, I think, but
I'll mention it anyway. One rationale is that 'puts' might shave a few
nanoseconds off your execution time, by bypassing all of 'printf''s
format-specifier interpreter code.

3 is not a portable argument to 'exit', and 'theSize' is never used
in file "stutter_ex .c".

Finally, an ease-of-use suggestion: You might consider adding a
function to the library that would make HTML forms output easier
on the eye. For example, the client could replace

printf("<form action=\"/cgi-bin/stutter_ex\" method=\"GET\"> ");

with something like

HTMLdump("<form action='/cgi-bin/stutter_ex' method='GET'>") ;

and then the 'HTMLdump' function would take care of replacing all
's with "s. You could even reuse some of your existing code! ;-)

HTH, and thanks for sharing,
-Arthur
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
6515
by: Russ Perry Jr | last post by:
I'm using "ID" and "Value" in the generic sense here... Let's say one page I had a <html:select> with a collection like this: <html:options collection="items" property="key" labelProperty="value"/> In this case "key" is what I mean by "ID", and "value" is what I mean by "Value" -- the "Value" is shown to the user, but the "ID" is what I plan to keep, to be saved to a database (as a reference in a table to a common table as a part of...
0
1744
by: PatchFactory Support | last post by:
Description: Professional and easy-to-use patch building environment that can help you to create instant patch packages for software and file updating. Generated patch packages are small size self-extracting executable update programs in a famous installer style with adjustable user-friendly interface and multilingual support. Enhanced with features like easy-to-use interface including a Wizard mode, powerful patch engine, integrated...
4
3626
by: NBURGAN | last post by:
We are currently searching for a reporting tool with graphics for our end users who are using Oracle's standard edition. We are not using the Oracle's AS. The tool needs to be easy to use and easy to learn. We currently use Crystal Reports. Thanks. NBurgan
19
1532
by: Canon EOS | last post by:
Hi, I am really new in .net and pocket PC development. My background are purely C/C++/VC++. Have developed on Mobile Java for a year and felt completely insecure with it because all codes can easily uncompiled. And it is why I am trying on .net for smartphone and PocketPC devices.
8
1940
by: Adam Clauss | last post by:
I have a folder containing many subfolders (and subfolders and....) all containing various .cs files. Is there any "easy" way to get them all added to the solution. Preferable would be that the folders are actually created in the Solution Explorer so that I can find things easily. Its easy to select multiple files out of a single folder, but not recursively into subfolders. Any ideas? -- Adam Clauss
2
1185
by: Thomas | last post by:
Hi, I there anybody here that are designing applications with asp.net without html in aspx files? The problem is that aspx files is a dependency, and I would like to avoid having that dependency for easy deployment. Ideally - I would like a single binary or two to contain all resources - graphics etc - is that possible? - Thomas
5
1535
by: LedZep | last post by:
What up, All I need to do is enter a last name in a text box, query a MSAccess database and display the name with the corresponding columns. This is no problem, but when there are more than one records with the same last name, I need to click a command button to display the next record with that name. I cant find it in any of my books and it sounds like an easy enough question. Any help is definately appreciated. TIA,
1
4978
by: Mad Scientist Jr | last post by:
can someone explain how to simply populate a grid in .net ? the way i understand it, there is no more msflexgrid, and instead is this new control that has to be tied to a dataset, and it is a real pain to work with if you just want to throw some values in a grid and edit them with a textbox. i don't want to persist anything in a database, i just need a fast cheap and easy grid in memory that i can work with! i had functions in vb6 that...
13
1484
by: Ghislain Tanguay | last post by:
I have a compiled vb.net app and I want to give the user a choice to launch it from the start line command and pass it a parameter or not. How can I do that in my code? Is it possible? Ex. : MyApp.exe "Go"
409
11209
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are objects that are more than 4GB long. The problem is, when you have in thousands of places
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.