libsmooth: Make it its own package.

This commit is contained in:
Michael Tremer
2014-07-30 22:02:35 +02:00
parent fa6c8fdcd0
commit 765b17bc52
14 changed files with 583 additions and 979 deletions

View File

@@ -1,4 +1,3 @@
#!/usr/bin/perl
###############################################################################
# #
# IPFire.org - A linux based firewall #
@@ -19,9 +18,42 @@
# #
###############################################################################
while (<>)
{
if (/\/\* (TR_[A-Z0-9_]*)/) {
print "\t$1,\n"; }
}
print "};\n";
###############################################################################
# Definitions
###############################################################################
include Config
VER = ipfire
THISAPP = libsmooth
DIR_APP = $(DIR_SRC)/$(THISAPP)
TARGET = $(DIR_INFO)/$(THISAPP)
###############################################################################
# Top-level Rules
###############################################################################
install : $(TARGET)
check :
download :
md5 :
###############################################################################
# Installation Details
###############################################################################
$(TARGET) :
@$(PREBUILD)
@rm -rf $(DIR_APP) && mkdir $(DIR_APP) && cp -R $(DIR_SRC)/src/libsmooth/* $(DIR_APP)
cd $(DIR_APP) && ./autogen.sh
cd $(DIR_APP) && ./configure --prefix=/usr
cd $(DIR_APP) && make $(MAKETUNING)
cd $(DIR_APP) && make install
@rm -rf $(DIR_APP)
@$(POSTBUILD)

View File

@@ -383,6 +383,7 @@ buildipfire() {
LOGFILE="$BASEDIR/log/_build.ipfire.log"
export LOGFILE
ipfiremake configroot
ipfiremake libsmooth
ipfiremake backup
ipfiremake bind
ipfiremake dhcp

View File

@@ -1,15 +0,0 @@
/* SmoothWall libsmooth.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* This is a template (basically just a header). langs.h is generated via
* the Makefile, from lang_en.c.
*
* $Id: langs.h.temp,v 1.4 2003/12/11 11:25:53 riddles Exp $
*
*/
enum trstrings
{

View File

@@ -1,119 +0,0 @@
/* SmoothWall libsmooth.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Contains prototypes for library functions.
*
*/
#ifndef ___LIBSMOOTH_H
#define ___LIBSMOOTH_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <wchar.h>
#include <locale.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <newt.h>
#include <dirent.h>
#include <sys/mount.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>
#include "langs.h"
#define STRING_SIZE 1024
#define ADDRESS 0
#define NETADDRESS 1
#define NETMASK 2
#define DHCP 3
#define NETCHANGE_TOTAL 4
#define SCANNED_NICS "/var/ipfire/ethernet/scanned_nics"
#define SYSDIR "/sys/class/net"
#define _GREEN_CARD_ 0
#define _RED_CARD_ 1
#define _ORANGE_CARD_ 2
#define _BLUE_CARD_ 3
struct keyvalue
{
char key[STRING_SIZE];
char value[STRING_SIZE];
struct keyvalue *next;
};
struct nic
{
char driver[80];
char description[256];
char macaddr[20];
char nic[20];
};
struct knic
{
char driver[80];
char description[256];
char macaddr[20];
char colour[20];
};
/* libsmooth.c */
void reboot(void);
void stripnl(char *s);
int mysystem(char *command);
void errorbox(char *message);
int statuswindowscroll(int width, int height, char *title, char *text, ...);
int disclaimerbox(char *message);
void statuswindow(int width, int height, char *title, char *text, ...);
int runcommandwithprogress(int width, int height, char *title, char *command,
int lines, char *text, ...);
int runcommandwithstatus(char *command, char *message);
int runhiddencommandwithstatus(char *command, char *message);
int checkformodule(char *module);
int replace(char filename1[], char *from, char *to);
char* get_version(void);
/* netstuff.c */
int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
char *defaultdhcphostname);
int gettype(char *type);
int setnetaddress(struct keyvalue *kv, char *colour);
void networkdialogcallbacktype(newtComponent cm, void *data);
int interfacecheck(struct keyvalue *kv, char *colour);
int rename_nics(void);
int init_knics(void);
int create_udev(void);
int scan_network_cards(void);
int nicmenu(int colour);
int clear_card_entry(int cards);
int ask_clear_card_entry(int cards);
int manualdriver(char *driver, char *driveroptions);
/* varval.c */
struct keyvalue *initkeyvalues(void);
void freekeyvalues(struct keyvalue *head);
int readkeyvalues(struct keyvalue *head, char *filename);
int writekeyvalues(struct keyvalue *head, char *filename);
int findkey(struct keyvalue *head, char *key, char *value);
void appendkeyvalue(struct keyvalue *head, char *key, char *value);
void replacekeyvalue(struct keyvalue *head, char *key, char *value);
#endif

View File

@@ -1,776 +0,0 @@
/* SmoothWall libsmooth.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Contains network library functions.
*
*/
#include "libsmooth.h"
#include <signal.h>
extern FILE *flog;
extern char *mylog;
extern char **ctr;
extern struct nic nics[];
extern struct knic knics[];
char *ucolourcard[] = { "GREEN", "RED", "ORANGE", "BLUE", NULL };
char *lcolourcard[] = { "green", "red", "orange", "blue", NULL };
int scanned_nics_read_done = 0;
newtComponent networkform;
newtComponent addressentry;
newtComponent netmaskentry;
newtComponent statictyperadio;
newtComponent dhcptyperadio;
newtComponent pppoetyperadio;
newtComponent dhcphostnameentry;
newtComponent dhcpforcemtuentry;
/* acceptable character filter for IP and netmaks entry boxes */
static int ip_input_filter(newtComponent entry, void * data, int ch, int cursor)
{
if ((ch >= '0' && ch <= '9') || ch == '.' || ch == '\r' || ch >= NEWT_KEY_EXTRA_BASE)
return ch;
return 0;
}
/* This is a groovie dialog for showing network info. Takes a keyvalue list,
* a colour and a dhcp flag. Shows the current settings, and rewrites them
* if necessary. DHCP flag sets wether to show the dhcp checkbox. */
int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
char *defaultdhcphostname)
{
char *addressresult;
char *netmaskresult;
char *dhcphostnameresult;
char *dhcpforcemturesult;
struct newtExitStruct es;
newtComponent header;
newtComponent addresslabel;
newtComponent netmasklabel;
newtComponent dhcphostnamelabel;
newtComponent dhcpforcemtulabel;
newtComponent ok, cancel;
char message[1000];
char temp[STRING_SIZE];
char addressfield[STRING_SIZE];
char netmaskfield[STRING_SIZE];
char typefield[STRING_SIZE];
char dhcphostnamefield[STRING_SIZE];
char dhcpforcemtufield[STRING_SIZE];
int error;
int result = 0;
char type[STRING_SIZE];
int startstatictype = 0;
int startdhcptype = 0;
int startpppoetype = 0;
/* Build some key strings. */
sprintf(addressfield, "%s_ADDRESS", colour);
sprintf(netmaskfield, "%s_NETMASK", colour);
sprintf(typefield, "%s_TYPE", colour);
sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour);
sprintf(dhcpforcemtufield, "%s_DHCP_FORCE_MTU", colour);
sprintf(message, ctr[TR_INTERFACE], colour);
newtCenteredWindow(44, (typeflag ? 18 : 12), message);
networkform = newtForm(NULL, NULL, 0);
sprintf(message, ctr[TR_ENTER_THE_IP_ADDRESS_INFORMATION], colour);
header = newtTextboxReflowed(1, 1, message, 42, 0, 0, 0);
newtFormAddComponent(networkform, header);
/* See if we need a dhcp checkbox. If we do, then we shift the contents
* of the window down two rows to make room. */
if (typeflag)
{
strcpy(temp, "STATIC"); findkey(kv, typefield, temp);
if (strcmp(temp, "STATIC") == 0) startstatictype = 1;
if (strcmp(temp, "DHCP") == 0) startdhcptype = 1;
if (strcmp(temp, "PPPOE") == 0) startpppoetype = 1;
statictyperadio = newtRadiobutton(2, 4, ctr[TR_STATIC], startstatictype, NULL);
dhcptyperadio = newtRadiobutton(2, 5, ctr[TR_DHCP], startdhcptype, statictyperadio);
pppoetyperadio = newtRadiobutton(2, 6, ctr[TR_PPP_DIALUP], startpppoetype, dhcptyperadio);
newtFormAddComponents(networkform, statictyperadio, dhcptyperadio,
pppoetyperadio, NULL);
newtComponentAddCallback(statictyperadio, networkdialogcallbacktype, NULL);
newtComponentAddCallback(dhcptyperadio, networkdialogcallbacktype, NULL);
newtComponentAddCallback(pppoetyperadio, networkdialogcallbacktype, NULL);
dhcphostnamelabel = newtTextbox(2, 8, 18, 1, 0);
newtTextboxSetText(dhcphostnamelabel, ctr[TR_DHCP_HOSTNAME]);
dhcpforcemtulabel = newtTextbox(2, 9, 18, 1, 0);
newtTextboxSetText(dhcpforcemtulabel, ctr[TR_DHCP_FORCE_MTU]);
strcpy(temp, defaultdhcphostname);
findkey(kv, dhcphostnamefield, temp);
dhcphostnameentry = newtEntry(20, 8, temp, 20, &dhcphostnameresult, 0);
strcpy(temp, "");
findkey(kv, dhcpforcemtufield, temp);
dhcpforcemtuentry = newtEntry(20, 9, temp, 20, &dhcpforcemturesult, 0);
newtFormAddComponent(networkform, dhcphostnamelabel);
newtFormAddComponent(networkform, dhcphostnameentry);
newtFormAddComponent(networkform, dhcpforcemtulabel);
newtFormAddComponent(networkform, dhcpforcemtuentry);
if (startdhcptype == 0)
{
newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
}
}
/* Address */
addresslabel = newtTextbox(2, (typeflag ? 11 : 4) + 0, 18, 1, 0);
newtTextboxSetText(addresslabel, ctr[TR_IP_ADDRESS_PROMPT]);
strcpy(temp, "");
findkey(kv, addressfield, temp);
addressentry = newtEntry(20, (typeflag ? 11 : 4) + 0, temp, 20, &addressresult, 0);
newtEntrySetFilter(addressentry, ip_input_filter, NULL);
if (typeflag == 1 && startstatictype == 0)
newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtFormAddComponent(networkform, addresslabel);
newtFormAddComponent(networkform, addressentry);
/* Netmask */
netmasklabel = newtTextbox(2, (typeflag ? 11 : 4) + 1, 18, 1, 0);
newtTextboxSetText(netmasklabel, ctr[TR_NETMASK_PROMPT]);
strcpy(temp, "255.255.255.0"); findkey(kv, netmaskfield, temp);
netmaskentry = newtEntry(20, (typeflag ? 11 : 4) + 1, temp, 20, &netmaskresult, 0);
newtEntrySetFilter(netmaskentry, ip_input_filter, NULL);
if (typeflag == 1 && startstatictype == 0)
newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtFormAddComponent(networkform, netmasklabel);
newtFormAddComponent(networkform, netmaskentry);
/* Buttons. */
ok = newtButton(8, (typeflag ? 14 : 7), ctr[TR_OK]);
cancel = newtButton(26, (typeflag ? 14 : 7), ctr[TR_CANCEL]);
newtFormAddComponents(networkform, ok, cancel, NULL);
newtRefresh();
newtDrawForm(networkform);
do
{
error = 0;
newtFormRun(networkform, &es);
if (es.u.co == ok)
{
/* OK was pressed; verify the contents of each entry. */
strcpy(message, ctr[TR_INVALID_FIELDS]);
strcpy(type, "STATIC");
if (typeflag)
gettype(type);
if (strcmp(type, "STATIC") == 0)
{
if (inet_addr(addressresult) == INADDR_NONE)
{
strcat(message, ctr[TR_IP_ADDRESS_CR]);
error = 1;
}
if (inet_addr(netmaskresult) == INADDR_NONE)
{
strcat(message, ctr[TR_NETWORK_MASK_CR]);
error = 1;
}
}
if (strcmp(type, "DHCP") == 0)
{
if (!strlen(dhcphostnameresult))
{
strcat(message, ctr[TR_DHCP_HOSTNAME_CR]);
error = 1;
}
}
if (error)
errorbox(message);
else
{
/* No errors! Set new values, depending on dhcp flag etc. */
if (typeflag)
{
replacekeyvalue(kv, dhcphostnamefield, dhcphostnameresult);
replacekeyvalue(kv, dhcpforcemtufield, dhcpforcemturesult);
if (strcmp(type, "STATIC") != 0)
{
replacekeyvalue(kv, addressfield, "0.0.0.0");
replacekeyvalue(kv, netmaskfield, "0.0.0.0");
}
else
{
replacekeyvalue(kv, addressfield, addressresult);
replacekeyvalue(kv, netmaskfield, netmaskresult);
}
replacekeyvalue(kv, typefield, type);
}
else
{
replacekeyvalue(kv, addressfield, addressresult);
replacekeyvalue(kv, netmaskfield, netmaskresult);
}
setnetaddress(kv, colour);
result = 1;
}
}
/* Workaround for a bug that dhcp radiobutton also end the dialog at arm
*/
else {
if (es.u.co != cancel) {
error = 1;
}
}
}
while (error);
newtFormDestroy(networkform);
newtPopWindow();
return result;
}
/* for pppoe: return string thats type STATIC, DHCP or PPPOE */
int gettype(char *type)
{
newtComponent selected = newtRadioGetCurrent(statictyperadio);
if (selected == statictyperadio)
strcpy(type, "STATIC");
else if (selected == dhcptyperadio)
strcpy(type, "DHCP");
else if (selected == pppoetyperadio)
strcpy(type, "PPPOE");
else
strcpy(type, "ERROR");
return 0;
}
/* 0.9.9: calculates broadcast too. */
int setnetaddress(struct keyvalue *kv, char *colour)
{
char addressfield[STRING_SIZE];
char netaddressfield[STRING_SIZE];
char netmaskfield[STRING_SIZE];
char broadcastfield[STRING_SIZE];
char address[STRING_SIZE];
char netmask[STRING_SIZE];
unsigned long int intaddress;
unsigned long int intnetaddress;
unsigned long int intnetmask;
unsigned long int intbroadcast;
struct in_addr temp;
char *netaddress;
char *broadcast;
/* Build some key strings. */
sprintf(addressfield, "%s_ADDRESS", colour);
sprintf(netaddressfield, "%s_NETADDRESS", colour);
sprintf(netmaskfield, "%s_NETMASK", colour);
sprintf(broadcastfield, "%s_BROADCAST", colour);
strcpy(address, ""); findkey(kv, addressfield, address);
strcpy(netmask, ""); findkey(kv, netmaskfield, netmask);
/* Calculate netaddress. Messy.. */
intaddress = inet_addr(address);
intnetmask = inet_addr(netmask);
intnetaddress = intaddress & intnetmask;
temp.s_addr = intnetaddress;
netaddress = inet_ntoa(temp);
replacekeyvalue(kv, netaddressfield, netaddress);
intbroadcast = intnetaddress | ~intnetmask;
temp.s_addr = intbroadcast;
broadcast = inet_ntoa(temp);
replacekeyvalue(kv, broadcastfield, broadcast);
return 1;
}
/* Called when dhcp flag is toggled. Toggle disabled state of other 3
* controls. */
void networkdialogcallbacktype(newtComponent cm, void *data)
{
char type[STRING_SIZE];
gettype(type);
if (strcmp(type, "STATIC") != 0)
{
newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
}
else
{
newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
}
if (strcmp(type, "DHCP") == 0)
{
newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
}
else
{
newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
}
newtRefresh();
newtDrawForm(networkform);
}
int interfacecheck(struct keyvalue *kv, char *colour)
{
char temp[STRING_SIZE];
char colourfields[NETCHANGE_TOTAL][STRING_SIZE];
int c;
sprintf(colourfields[ADDRESS], "%s_ADDRESS", colour);
sprintf(colourfields[NETADDRESS], "%s_NETADDRESS", colour);
sprintf(colourfields[NETMASK], "%s_NETMASK", colour);
for (c = 0; c < 3; c++)
{
strcpy(temp, ""); findkey(kv, colourfields[c], temp);
if (!(strlen(temp))) return 0;
}
return 1;
}
/* Funky routine for loading all drivers (cept those are already loaded.). */
int probecards(char *driver, char *driveroptions )
{
return 0;
}
int get_knic(int card) //returns "0" for zero cards or error and "1" card is found.
{
struct keyvalue *kv = initkeyvalues();
char temp[STRING_SIZE], searchstr[STRING_SIZE];
int ret_value;
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
sprintf(searchstr, "%s_MACADDR", ucolourcard[card]);
strcpy(temp, ""); findkey(kv, searchstr, temp);
if (strlen(temp)) {
strcpy(knics[ card ].macaddr, temp);
strcpy(knics[ card ].colour, ucolourcard[card]);
sprintf(searchstr, "%s_DESCRIPTION", ucolourcard[card]);
findkey(kv, searchstr, temp);
strcpy(knics[ card ].description, temp);
sprintf(searchstr, "%s_DRIVER", ucolourcard[card]);
findkey(kv, searchstr, temp);
strcpy(knics[ card ].driver, temp);
ret_value = 1;
} else {
strcpy(knics[ card ].description, ctr[TR_UNSET]);
ret_value = 0;
}
freekeyvalues(kv);
return ret_value;
}
int init_knics(void)
{
int found = 0;
found += get_knic(_GREEN_CARD_);
found += get_knic(_RED_CARD_);
found += get_knic(_ORANGE_CARD_);
found += get_knic(_BLUE_CARD_);
return found;
}
int fmt_exists(const char *fname) { /* Check if it is any file or directory */
struct stat st;
if (stat(fname, &st) == -1) return 0;
else return 1;
}
int is_interface_up(char *card) { /* Check if the interface is UP */
char temp[STRING_SIZE];
sprintf(temp,"ip link show dev %s | grep -q UP", card);
if (mysystem(temp)) return 0; else return 1;
}
int rename_device(char *old_name, char *new_name) {
char temp[STRING_SIZE];
sprintf(temp,SYSDIR "/%s", old_name);
if (!(fmt_exists(temp))) {
fprintf(flog,"Device not found: %s\n",old_name);
return 0;
}
sprintf(temp,"/sbin/ip link set dev %s name %s",old_name ,new_name );
mysystem(temp);
return 1;
}
char g_temp[STRING_SIZE]="";
char* readmac(char *card) {
FILE *fp;
char temp[STRING_SIZE], mac[20];
sprintf(temp,"/sys/class/net/%s/address",card);
if( (fp = fopen(temp, "r")) == NULL ) {
fprintf(flog,"Couldn't open: %s\n",temp);
return NULL;
}
fgets(mac, 18, fp);
strtok(mac,"\n");
fclose(fp);
strcpy(g_temp, mac);
return g_temp;
}
char* find_nic4mac(char *findmac) {
DIR *dir;
struct dirent *dirzeiger;
char temp[STRING_SIZE], temp2[STRING_SIZE];
if((dir=opendir(SYSDIR)) == NULL) {
fprintf(flog,"Fehler bei opendir (find_name4nic) ...\n");
return NULL;
}
sprintf(temp, "");
while((dirzeiger=readdir(dir)) != NULL) {
if(*((*dirzeiger).d_name) != '.' & strcmp(((*dirzeiger).d_name), "lo") != 0) {
sprintf(temp2, "%s", readmac((*dirzeiger).d_name) );
if (strcmp(findmac, temp2) == 0) {
sprintf(temp,"%s", (*dirzeiger).d_name);
break;
}
}
}
if(closedir(dir) == -1) fprintf(flog,"Fehler beim schliessen von %s\n", SYSDIR);
strcpy(g_temp, temp);
return g_temp;
}
int nic_shutdown(char *nic) {
char temp[STRING_SIZE];
sprintf(temp,"ip link set %s down", nic);
mysystem(temp);
}
int nic_startup(char *nic) {
char temp[STRING_SIZE];
sprintf(temp,"ip link set %s up", nic);
mysystem(temp);
}
int rename_nics(void) {
int i, j, k;
int fnics = scan_network_cards();
char nic2find[STRING_SIZE], temp[STRING_SIZE];
for(i=0; i<4; i++)
if (strcmp(knics[i].macaddr, ""))
for(j=0; j<fnics; j++)
if(strcmp(knics[i].macaddr, nics[j].macaddr) == 0) {
sprintf(nic2find,"%s0",lcolourcard[i]);
if(strcmp(nic2find, nics[j].nic)) {
if(is_interface_up(nics[j].nic)) {
nic_shutdown(nics[j].nic);
}
sprintf(temp,SYSDIR "/%s", nic2find);
if(fmt_exists(temp)) {
for(k=0; k<fnics; k++)
if (strcmp(nics[k].nic, nic2find) == 0 ) {
if(is_interface_up(nics[k].nic)) {
nic_shutdown(nics[k].nic);
}
sprintf(temp,"dummy%i",k);
if (rename_device(nics[k].nic, temp)) strcpy(nics[k].nic, temp);
}
}
if (rename_device(nics[j].nic, nic2find)) strcpy(nics[j].nic, nic2find);
}
}
}
int create_udev(void)
{
#define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules"
FILE *fp;
int i;
if ( (fp = fopen(UDEV_NET_CONF, "w")) == NULL ) {
fprintf(stderr,"Couldn't open" UDEV_NET_CONF);
return 1;
}
for (i = 0 ; i < 4 ; i++)
{
if (strcmp(knics[i].macaddr, "")) {
fprintf(fp,"\n# %s\nACTION==\"add\", SUBSYSTEM==\"net\", ATTR{type}==\"1\", ATTR{address}==\"%s\", NAME=\"%s0\"\n", knics[i].description, knics[i].macaddr, lcolourcard[i]);
}
}
fclose(fp);
return 0;
}
int write_configs_netudev(int card , int colour)
{
char commandstring[STRING_SIZE];
struct keyvalue *kv = initkeyvalues();
char temp1[STRING_SIZE], temp2[STRING_SIZE], temp3[STRING_SIZE];
char ucolour[STRING_SIZE];
sprintf(ucolour, ucolourcard[colour]);
strcpy(knics[colour].driver, nics[card].driver);
strcpy(knics[colour].description, nics[card].description);
strcpy(knics[colour].macaddr, nics[card].macaddr);
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
sprintf(temp1, "%s_DEV", ucolour);
sprintf(temp2, "%s_MACADDR", ucolour);
sprintf(temp3, "%s0", lcolourcard[colour]);
replacekeyvalue(kv, temp1, temp3);
replacekeyvalue(kv, temp2, nics[card].macaddr);
sprintf(temp1, "%s_DESCRIPTION", ucolour);
replacekeyvalue(kv, temp1, nics[card].description);
sprintf(temp1, "%s_DRIVER", ucolour);
replacekeyvalue(kv, temp1, nics[card].driver);
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
freekeyvalues(kv);
return 0;
}
int scan_network_cards(void)
{
FILE *fp;
char driver[STRING_SIZE], description[STRING_SIZE], macaddr[STRING_SIZE], temp_line[STRING_SIZE];
int count = 0;
const char _driver[]="driver: ";
const char _desc[]="desc: ";
const char _network_hwaddr[]="network.hwaddr: ";
if (!(scanned_nics_read_done))
{
mysystem("/bin/probenic.sh");
if( (fp = fopen(SCANNED_NICS, "r")) == NULL )
{
fprintf(stderr,"Couldn't open "SCANNED_NICS);
return 1;
}
while (fgets(temp_line, STRING_SIZE, fp) != NULL)
{
temp_line[strlen(temp_line) -1] = 0;
if ( strncmp(temp_line, _driver, strlen(_driver)) == 0 ) sprintf(nics[count].driver, "%s", temp_line+strlen(_driver));
if ( strncmp(temp_line, _desc, strlen(_desc)) == 0 ) sprintf(nics[count].description, "%s", temp_line+strlen(_desc));
if ( strncmp(temp_line, _network_hwaddr, strlen(_network_hwaddr)) == 0 ) sprintf(nics[count].macaddr, "%s", temp_line+strlen(_network_hwaddr));
if (strlen(nics[count].macaddr) > 15 ) {
sprintf(nics[count].nic, "%s", find_nic4mac(nics[count].macaddr));
count++;
}
}
fclose(fp);
scanned_nics_read_done = count;
} else fprintf(flog,"Scan Networkcards does read.\n");
return scanned_nics_read_done;
}
int nicmenu(int colour)
{
int rc, choise = 0, count = 0, kcount = 0, mcount = 0, i, j, nic_in_use;
int found_NIC_as_Card[4];
char message[STRING_SIZE];
char temp[STRING_SIZE];
char cMenuInhalt[STRING_SIZE];
char MenuInhalt[20][180];
char *pMenuInhalt[20];
while (strcmp(nics[count].macaddr, "")) count++; // 2 find how many nics in system
for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++; // loop to find all knowing nics
// If new nics are found...
if (count > kcount) {
for (i=0 ; i < count ; i++)
{
nic_in_use = 0;
for (j=0 ; j <= kcount ; j++) {
if (strcmp(nics[ i ].macaddr, knics[ j ].macaddr) == 0 ) {
nic_in_use = 1;
break;
}
}
if (!(nic_in_use)) {
if ( strlen(nics[i].description) < 55 )
sprintf(MenuInhalt[mcount], "%.*s", strlen(nics[i].description)-2, nics[i].description+1);
else {
sprintf(cMenuInhalt, "%.50s", nics[i].description + 1);
sprintf(MenuInhalt[mcount], cMenuInhalt);
strcat (MenuInhalt[mcount], "...");
}
while ( strlen(MenuInhalt[mcount]) < 53) strcat(MenuInhalt[mcount], " "); // Fill with space.
strcat(MenuInhalt[mcount], " (");
strcat(MenuInhalt[mcount], nics[i].macaddr);
strcat(MenuInhalt[mcount], ")");
pMenuInhalt[mcount] = MenuInhalt[mcount];
found_NIC_as_Card[mcount]=i;
mcount++;
}
}
pMenuInhalt[mcount] = NULL;
sprintf(message, ctr[TR_CHOOSE_NETCARD], ucolourcard[colour]);
rc=2;
while ( rc == 2 ) {
rc = newtWinMenu( ctr[TR_NETCARDMENU2], message, 50, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_SELECT], ctr[TR_IDENTIFY], ctr[TR_CANCEL], NULL);
if ( rc == 2 ) {
sprintf(temp, "/sbin/ip link set %s up", nics[found_NIC_as_Card[choise]].nic);
mysystem(temp);
sprintf(temp, "/usr/sbin/ethtool -p %s 10", nics[found_NIC_as_Card[choise]].nic);
if (runcommandwithstatus(temp,ctr[TR_IDENTIFY_SHOULD_BLINK]) != 0) {
errorbox(ctr[TR_IDENTIFY_NOT_SUPPORTED]);
sprintf(temp, "/sbin/ip link set %s down", nics[found_NIC_as_Card[choise]].nic);
mysystem(temp);
}
}
}
if ( rc == 0 || rc == 1) {
write_configs_netudev(found_NIC_as_Card[choise], colour);
}
return 0;
} else {
// We have to add here that you can manually add a device
errorbox( ctr[TR_ERROR_INTERFACES]);
return 1;
}
}
int clear_card_entry(int card)
{
struct keyvalue *kv = initkeyvalues();
char temp[STRING_SIZE];
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
strcpy(knics[card].driver, "");
strcpy(knics[card].description, ctr[TR_UNSET]);
strcpy(knics[card].macaddr, "");
strcpy(knics[card].colour, "");
sprintf(temp, "%s_DRIVER", ucolourcard[card]);
replacekeyvalue(kv, temp, "");
sprintf(temp, "%s_DEV", ucolourcard[card]);
replacekeyvalue(kv, temp, "");
sprintf(temp, "%s_MACADDR", ucolourcard[card]);
replacekeyvalue(kv, temp, "");
sprintf(temp, "%s_DESCRIPTION", ucolourcard[card]);
replacekeyvalue(kv, temp, "");
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
freekeyvalues(kv);
return 0;
}
int ask_clear_card_entry(int card)
{
char message[STRING_SIZE];
int rc;
sprintf(message, ctr[TR_REMOVE_CARD], ucolourcard[card]);
rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message);
if ( rc = 0 || rc == 1) {
clear_card_entry(card);
} else return 1;
return 0;
}
/* Manual entry for gurus. */
int manualdriver(char *driver, char *driveroptions)
{
char *values[] = { NULL, NULL }; /* pointers for the values. */
struct newtWinEntry entries[] =
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
int rc;
char commandstring[STRING_SIZE];
char *driverend;
strcpy(driver, "");
strcpy(driveroptions, "");
rc = newtWinEntries(ctr[TR_SELECT_NETWORK_DRIVER],
ctr[TR_MODULE_PARAMETERS], 50, 5, 5, 40, entries,
ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 0 || rc == 1)
{
if (strlen(values[0]))
{
sprintf(commandstring, "/sbin/modprobe %s", values[0]);
if (runcommandwithstatus(commandstring, ctr[TR_LOADING_MODULE]) == 0)
{
if ((driverend = strchr(values[0], ' ')))
{
*driverend = '\0';
strcpy(driver, values[0]);
strcpy(driveroptions, driverend + 1);
}
else
{
strcpy(driver, values[0]);
strcpy(driveroptions, "");
}
}
else
errorbox(ctr[TR_UNABLE_TO_LOAD_DRIVER_MODULE]);
}
else
errorbox(ctr[TR_MODULE_NAME_CANNOT_BE_BLANK]);
}
free(values[0]);
return 1;
}

81
src/libsmooth/Makefile.am Normal file
View File

@@ -0,0 +1,81 @@
# This file is part of the libsmooth library.
#
# libsmooth is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
AM_MAKEFLAGS = --no-print-directory
AUTOMAKE_OPTIONS = color-tests parallel-tests
SUBDIRS = .
# remove targets if the command fails
.DELETE_ON_ERROR:
# keep intermediate files
.SECONDARY:
LIBSMOOTH_CURRENT=1
LIBSMOOTH_REVISION=0
LIBSMOOTH_AGE=0
pkgconfiglibdir=$(libdir)/pkgconfig
CLEANFILES =
EXTRA_DIST =
AM_CPPFLAGS = \
-include $(top_builddir)/config.h \
-I $(top_srcdir)/include \
$(OUR_CPPFLAGS)
AM_CFLAGS = $(OUR_CFLAGS)
AM_CXXFLAGS = $(OUR_CXXFLAGS)
AM_LDFLAGS = $(OUR_LDFLAGS)
lib_LTLIBRARIES =
include_HEADERS =
#- libsmooth -------------------------------------------------------------------
lib_LTLIBRARIES += \
libsmooth.la
libsmooth_la_SOURCES = \
main.c \
varval.c
libsmooth_la_LDFLAGS = \
$(AM_LDFLAGS) \
-version-info $(LIBSMOOTH_CURRENT):$(LIBSMOOTH_REVISION):$(LIBSMOOTH_AGE)
include_HEADERS += \
libsmooth.h
pkgconfiglib_DATA = \
libsmooth.pc
CLEANFILES += \
libsmooth.pc
EXTRA_DIST += \
libsmooth.pc.in
#-------------------------------------------------------------------------------
substitutions = \
'|PACKAGE_NAME=$(PACKAGE_NAME)|' \
'|PACKAGE_VERSION=$(PACKAGE_VERSION)|' \
'|prefix=$(prefix)|' \
'|exec_prefix=$(exec_prefix)|' \
'|libdir=$(libdir)|' \
'|includedir=$(includedir)|'
SED_PROCESS = \
$(AM_V_GEN)$(MKDIR_P) $(dir $@) && \
$(SED) $(subst '|,-e 's|@,$(subst =,\@|,$(subst |',|g',$(substitutions)))) < $< > $@
%.pc: %.pc.in Makefile
$(SED_PROCESS)

3
src/libsmooth/autogen.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
autoreconf --force --install -I m4

View File

@@ -0,0 +1,58 @@
# This file is part of libsmooth.
#
# libsmooth is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
AC_PREREQ([2.64])
AC_INIT([libsmooth],
[001],
[],
[libsmooth],
[http://git.ipfire.org/?p=ipfire-2.x.git;a=summary])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([
foreign
1.11
-Wall
-Wno-portability
silent-rules
tar-pax
no-dist-gzip
dist-xz
subdir-objects
])
AM_SILENT_RULES([yes])
LT_PREREQ(2.2)
LT_INIT([disable-static])
AC_PROG_SED
AC_PROG_CC
AC_PROG_CC_C99
AC_PROG_CC_C_O
AC_PATH_PROG([M4], [m4])
# This makes sure pkg.m4 is available.
m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config])
AC_CONFIG_FILES([
Makefile
])
AC_OUTPUT
AC_MSG_RESULT([
$PACKAGE_NAME $VERSION
CFLAGS: ${OUR_CFLAGS} ${CFLAGS}
CPPFLAGS: ${OUR_CPPFLAGS} ${CPPFLAGS}
LDFLAGS: ${OUR_LDFLAGS} ${LDFLAGS}
])

68
src/libsmooth/libsmooth.h Normal file
View File

@@ -0,0 +1,68 @@
/* SmoothWall libsmooth.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Contains prototypes for library functions.
*
*/
#ifndef ___LIBSMOOTH_H
#define ___LIBSMOOTH_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <wchar.h>
#include <locale.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <newt.h>
#include <dirent.h>
#include <sys/mount.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>
#define STRING_SIZE 1024
struct keyvalue {
char key[STRING_SIZE];
char value[STRING_SIZE];
struct keyvalue *next;
};
/* libsmooth.c */
void stripnl(char *s);
int mysystem(const char *command);
void errorbox(char *message);
int statuswindowscroll(int width, int height, const char *title, const char *text, ...);
int disclaimerbox(char *message);
void statuswindow(int width, int height, const char *title, const char *text, ...);
int runcommandwithprogress(int width, int height, const char *title, const char *command,
int lines, char *text, ...);
int runcommandwithstatus(const char *command, const char* title, const char *message);
int runhiddencommandwithstatus(const char *command, const char* title, const char *message);
int checkformodule(const char *module);
int replace(char filename1[], char *from, char *to);
char* get_version(void);
/* varval.c */
struct keyvalue *initkeyvalues(void);
void freekeyvalues(struct keyvalue *head);
int readkeyvalues(struct keyvalue *head, char *filename);
int writekeyvalues(struct keyvalue *head, char *filename);
int findkey(struct keyvalue *head, char *key, char *value);
void appendkeyvalue(struct keyvalue *head, char *key, char *value);
void replacekeyvalue(struct keyvalue *head, char *key, char *value);
#endif

View File

@@ -0,0 +1,18 @@
# This file is part of the libsmooth library.
#
# libsmooth is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libsmooth
Description: libsmooth library
URL: @PACKAGE_URL@
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lsmooth
Cflags: -I${includedir}

View File

@@ -0,0 +1,288 @@
dnl Macros to check the presence of generic (non-typed) symbols.
dnl Copyright (c) 2006-2008 Diego Pettenò <flameeyes@gmail.com>
dnl Copyright (c) 2006-2008 xine project
dnl Copyright (c) 2012 Lucas De Marchi <lucas.de.marchi@gmail.com>
dnl
dnl This program is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2, or (at your option)
dnl any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
dnl 02110-1301, USA.
dnl
dnl As a special exception, the copyright owners of the
dnl macro gives unlimited permission to copy, distribute and modify the
dnl configure scripts that are the output of Autoconf when processing the
dnl Macro. You need not follow the terms of the GNU General Public
dnl License when using or distributing such scripts, even though portions
dnl of the text of the Macro appear in them. The GNU General Public
dnl License (GPL) does govern all other use of the material that
dnl constitutes the Autoconf Macro.
dnl
dnl This special exception to the GPL applies to versions of the
dnl Autoconf Macro released by this project. When you make and
dnl distribute a modified version of the Autoconf Macro, you may extend
dnl this special exception to the GPL to apply to your modified version as
dnl well.
dnl Check if FLAG in ENV-VAR is supported by compiler and append it
dnl to WHERE-TO-APPEND variable
dnl CC_CHECK_FLAG_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG])
AC_DEFUN([CC_CHECK_FLAG_APPEND], [
AC_CACHE_CHECK([if $CC supports flag $3 in envvar $2],
AS_TR_SH([cc_cv_$2_$3]),
[eval "AS_TR_SH([cc_save_$2])='${$2}'"
eval "AS_TR_SH([$2])='-Werror $3'"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([int a = 0; int main(void) { return a; } ])],
[eval "AS_TR_SH([cc_cv_$2_$3])='yes'"],
[eval "AS_TR_SH([cc_cv_$2_$3])='no'"])
eval "AS_TR_SH([$2])='$cc_save_$2'"])
AS_IF([eval test x$]AS_TR_SH([cc_cv_$2_$3])[ = xyes],
[eval "$1='${$1} $3'"])
])
dnl CC_CHECK_FLAGS_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG1 FLAG2])
AC_DEFUN([CC_CHECK_FLAGS_APPEND], [
for flag in $3; do
CC_CHECK_FLAG_APPEND($1, $2, $flag)
done
])
dnl Check if the flag is supported by linker (cacheable)
dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
AC_DEFUN([CC_CHECK_LDFLAGS], [
AC_CACHE_CHECK([if $CC supports $1 flag],
AS_TR_SH([cc_cv_ldflags_$1]),
[ac_save_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS $1"
AC_LINK_IFELSE([int main() { return 1; }],
[eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"],
[eval "AS_TR_SH([cc_cv_ldflags_$1])="])
LDFLAGS="$ac_save_LDFLAGS"
])
AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
[$2], [$3])
])
dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for
dnl the current linker to avoid undefined references in a shared object.
AC_DEFUN([CC_NOUNDEFINED], [
dnl We check $host for which systems to enable this for.
AC_REQUIRE([AC_CANONICAL_HOST])
case $host in
dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads
dnl are requested, as different implementations are present; to avoid problems
dnl use -Wl,-z,defs only for those platform not behaving this way.
*-freebsd* | *-openbsd*) ;;
*)
dnl First of all check for the --no-undefined variant of GNU ld. This allows
dnl for a much more readable commandline, so that people can understand what
dnl it does without going to look for what the heck -z defs does.
for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do
CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"])
break
done
;;
esac
AC_SUBST([LDFLAGS_NOUNDEFINED])
])
dnl Check for a -Werror flag or equivalent. -Werror is the GCC
dnl and ICC flag that tells the compiler to treat all the warnings
dnl as fatal. We usually need this option to make sure that some
dnl constructs (like attributes) are not simply ignored.
dnl
dnl Other compilers don't support -Werror per se, but they support
dnl an equivalent flag:
dnl - Sun Studio compiler supports -errwarn=%all
AC_DEFUN([CC_CHECK_WERROR], [
AC_CACHE_CHECK(
[for $CC way to treat warnings as errors],
[cc_cv_werror],
[CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror],
[CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])])
])
])
AC_DEFUN([CC_CHECK_ATTRIBUTE], [
AC_REQUIRE([CC_CHECK_WERROR])
AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))],
AS_TR_SH([cc_cv_attribute_$1]),
[ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $cc_cv_werror"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])],
[eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"],
[eval "AS_TR_SH([cc_cv_attribute_$1])='no'"])
CFLAGS="$ac_save_CFLAGS"
])
AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes],
[AC_DEFINE(
AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1,
[Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))]
)
$4],
[$5])
])
AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [
CC_CHECK_ATTRIBUTE(
[constructor],,
[void __attribute__((constructor)) ctor() { int a; }],
[$1], [$2])
])
AC_DEFUN([CC_ATTRIBUTE_FORMAT], [
CC_CHECK_ATTRIBUTE(
[format], [format(printf, n, n)],
[void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }],
[$1], [$2])
])
AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [
CC_CHECK_ATTRIBUTE(
[format_arg], [format_arg(printf)],
[char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }],
[$1], [$2])
])
AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [
CC_CHECK_ATTRIBUTE(
[visibility_$1], [visibility("$1")],
[void __attribute__((visibility("$1"))) $1_function() { }],
[$2], [$3])
])
AC_DEFUN([CC_ATTRIBUTE_NONNULL], [
CC_CHECK_ATTRIBUTE(
[nonnull], [nonnull()],
[void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }],
[$1], [$2])
])
AC_DEFUN([CC_ATTRIBUTE_UNUSED], [
CC_CHECK_ATTRIBUTE(
[unused], ,
[void some_function(void *foo, __attribute__((unused)) void *bar);],
[$1], [$2])
])
AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [
CC_CHECK_ATTRIBUTE(
[sentinel], ,
[void some_function(void *foo, ...) __attribute__((sentinel));],
[$1], [$2])
])
AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [
CC_CHECK_ATTRIBUTE(
[deprecated], ,
[void some_function(void *foo, ...) __attribute__((deprecated));],
[$1], [$2])
])
AC_DEFUN([CC_ATTRIBUTE_ALIAS], [
CC_CHECK_ATTRIBUTE(
[alias], [weak, alias],
[void other_function(void *foo) { }
void some_function(void *foo) __attribute__((weak, alias("other_function")));],
[$1], [$2])
])
AC_DEFUN([CC_ATTRIBUTE_MALLOC], [
CC_CHECK_ATTRIBUTE(
[malloc], ,
[void * __attribute__((malloc)) my_alloc(int n);],
[$1], [$2])
])
AC_DEFUN([CC_ATTRIBUTE_PACKED], [
CC_CHECK_ATTRIBUTE(
[packed], ,
[struct astructure { char a; int b; long c; void *d; } __attribute__((packed));],
[$1], [$2])
])
AC_DEFUN([CC_ATTRIBUTE_CONST], [
CC_CHECK_ATTRIBUTE(
[const], ,
[int __attribute__((const)) twopow(int n) { return 1 << n; } ],
[$1], [$2])
])
AC_DEFUN([CC_FLAG_VISIBILITY], [
AC_REQUIRE([CC_CHECK_WERROR])
AC_CACHE_CHECK([if $CC supports -fvisibility=hidden],
[cc_cv_flag_visibility],
[cc_flag_visibility_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $cc_cv_werror"
CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden],
cc_cv_flag_visibility='yes',
cc_cv_flag_visibility='no')
CFLAGS="$cc_flag_visibility_save_CFLAGS"])
AS_IF([test "x$cc_cv_flag_visibility" = "xyes"],
[AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1,
[Define this if the compiler supports the -fvisibility flag])
$1],
[$2])
])
AC_DEFUN([CC_FUNC_EXPECT], [
AC_REQUIRE([CC_CHECK_WERROR])
AC_CACHE_CHECK([if compiler has __builtin_expect function],
[cc_cv_func_expect],
[ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $cc_cv_werror"
AC_COMPILE_IFELSE([AC_LANG_SOURCE(
[int some_function() {
int a = 3;
return (int)__builtin_expect(a, 3);
}])],
[cc_cv_func_expect=yes],
[cc_cv_func_expect=no])
CFLAGS="$ac_save_CFLAGS"
])
AS_IF([test "x$cc_cv_func_expect" = "xyes"],
[AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1,
[Define this if the compiler supports __builtin_expect() function])
$1],
[$2])
])
AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [
AC_REQUIRE([CC_CHECK_WERROR])
AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported],
[cc_cv_attribute_aligned],
[ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $cc_cv_werror"
for cc_attribute_align_try in 64 32 16 8 4 2; do
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
int main() {
static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0;
return c;
}])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break])
done
CFLAGS="$ac_save_CFLAGS"
])
if test "x$cc_cv_attribute_aligned" != "x"; then
AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned],
[Define the highest alignment supported])
fi
])

View File

@@ -5,48 +5,40 @@
*
* (c) Lawrence Manning, 2001
* Contains library functions.
*
* $Id: main.c,v 1.6.2.9 2005/12/09 22:31:41 franck78 Exp $
*
*/
#include "libsmooth.h"
#include <libintl.h>
#define _(x) dgettext("libsmooth", x)
extern FILE *flog;
extern char *mylog;
extern char **ctr;
/* reboot(). reboots. */
void reboot(void)
{
mysystem("/etc/halt");
}
/* stripnl(). Replaces \n with \0 */
void stripnl(char *s)
{
void stripnl(char *s) {
char *t = strchr(s, '\n');
if (t) *t = '\0';
if (t)
*t = '\0';
}
/* Little wrapper. */
int mysystem(char *command)
{
int mysystem(const char *command) {
char mycommand[STRING_SIZE];
snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog);
fprintf(flog, "Running command: %s\n", command);
return system(mycommand);
}
void errorbox(char *message)
{
newtWinMessage(ctr[TR_ERROR], ctr[TR_OK], message);
void errorbox(char *message) {
newtWinMessage(_("Error"), _("OK"), message);
}
void statuswindow(int width, int height, char *title, char *text, ...)
{
void statuswindow(int width, int height, const char *title, const char *text, ...) {
newtComponent t, f;
char *buf = NULL;
int size = 0;
@@ -79,39 +71,31 @@ void statuswindow(int width, int height, char *title, char *text, ...)
newtFormDestroy(f);
}
int runcommandwithstatus(char *command, char *message)
{
int rc;
char title[STRING_SIZE];
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
int runcommandwithstatus(const char *command, const char* title, const char *message) {
statuswindow(60, 4, title, message);
rc = mysystem(command);
int rc = mysystem(command);
newtPopWindow();
return rc;
}
int runhiddencommandwithstatus(char *command, char *message)
{
int rc;
char title[STRING_SIZE];
char mycommand[STRING_SIZE];
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
int runhiddencommandwithstatus(const char *command, const char* title, const char *message) {
statuswindow(60, 4, title, message);
char mycommand[STRING_SIZE];
snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog);
fprintf(flog, "Running command: ***** HIDDEN *****\n");
rc = system(mycommand);
int rc = system(mycommand);
newtPopWindow();
return rc;
}
/* This one borrowed from redhat installer. */
int runcommandwithprogress(int width, int height, char *title, char *command,
int lines, char *text, ...)
{
int runcommandwithprogress(int width, int height, const char *title, const char *command,
int lines, char *text, ...) {
newtComponent t, f, s;
char *buf = NULL;
int size = 0;
@@ -178,12 +162,11 @@ EXIT:
return rc;
}
int checkformodule(char *module)
{
int checkformodule(const char *module) {
FILE *file;
char buffer[STRING_SIZE];
int result = 0;
if (!(file = fopen("/proc/modules", "r")))
{
fprintf(flog, "Unable to open /proc/modules in checkformodule()\n");
@@ -239,8 +222,7 @@ int _replace_string(char string[], char *from, char *to)
return 0;
}
int replace(char filename1[], char *from, char *to)
{
int replace(char filename1[], char *from, char *to) {
FILE *file1, *file2;
char filename2[1000];
char temp[1000];
@@ -257,7 +239,6 @@ int replace(char filename1[], char *from, char *to)
/* Start reading in lines */
while (fgets (temp, 1000, file1) != NULL) {
if (strlen(to) > 0) {
/* Replace string */
ret = _replace_string (temp, from, to);
@@ -281,20 +262,6 @@ int replace(char filename1[], char *from, char *to)
return (ret);
}
/* Include enabled languages */
#ifdef LANG_EN_ONLY
#include "lang_en.c"
#else
#include "lang_de.c"
#include "lang_en.c"
#include "lang_es.c"
#include "lang_fr.c"
#include "lang_pl.c"
#include "lang_ru.c"
#include "lang_nl.c"
#include "lang_tr.c"
#endif
// returns a pointer to the actual running version number of IPFire.
// Successive updates increase effective version but not VERSION !
char g_title[STRING_SIZE] = "";
@@ -304,8 +271,6 @@ char* get_version(void) {
fgets (g_title, STRING_SIZE, f_title);
fclose (f_title);
if (g_title[strlen(g_title) - 1] == '\n') g_title[strlen(g_title) - 1] = '\0';
} else {
sprintf (g_title, "%s %s - %s", NAME, VERSION, SLOGAN);
}
return g_title;
}