From: Pekka Riikonen Date: Mon, 1 Jan 2007 12:25:16 +0000 (+0000) Subject: Added preliminary Symbian support. X-Git-Tag: silc.client.1.1.beta1~79 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=9905799a86c606304fd7df2cd401de1740a272a1 Added preliminary Symbian support. Added silc_snprintf. Added SilcRng argument to silc_pkcs_encrypt API. --- diff --git a/CHANGES b/CHANGES index 96f924c4..20856172 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,12 @@ +Sat Dec 30 23:23:17 EET 2006 Pekka Riikonen + + * Added preliminary Symbian support. Changes around the source + tree. The symbian/ directory now includes Carbide.c++ project + files to compile the sources. + + * Added silc_snprintf. Affected files are + lib/silcutil/silcstrutil.[ch]. + Thu Dec 21 18:01:51 EET 2006 Pekka Riikonen * Changed SILC_FSM_[CONTINUE|YIELD|WAIT|FINISH] enums to diff --git a/TODO b/TODO index 9a8d4881..22cd60b3 100644 --- a/TODO +++ b/TODO @@ -161,6 +161,10 @@ lib/silccrypt ****PARTLY DONE**** lib/silcutil ****PARTLY DONE**** ============ + o The regex code from lib/contrib might compile fine on all platforms. + No need to make it silcutil/unix/ specific. Add them to generic + silcutil.c. + o silc_stringprep to non-allocating version. o Compression routines are missing. The protocol supports packet @@ -310,13 +314,11 @@ lib/silcmath o All utility functions should be made non-allocating ones. -lib/silcutil/epoc/* -=================== - - o lib/silcutil/epoc routines missing or not completed. +lib/silcutil/symbian/ ****PARTLY DONE**** +===================== - o The PKCS#1 also calls global RNG (even though it is not used - currently in SILC, the interface allows its use). + o lib/silcutil/symbian routines missing or not completed. + (****TESTING NEEDED) o Something needs to be thought to the logging globals as well, like silc_debug etc. They won't work on EPOC. Perhaps logging diff --git a/configure.ad b/configure.ad index 90c55578..5f014183 100644 --- a/configure.ad +++ b/configure.ad @@ -3,7 +3,7 @@ # # Author: Pekka Riikonen # -# Copyright (C) 2000 - 2006 Pekka Riikonen +# Copyright (C) 2000 - 2007 Pekka Riikonen # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -178,7 +178,7 @@ AC_CHECK_FUNCS(setrlimit time ctime utime gettimeofday getrusage) AC_CHECK_FUNCS(chmod fcntl stat fstat getenv putenv strerror) AC_CHECK_FUNCS(getpid getgid getsid getpgid getpgrp getuid) AC_CHECK_FUNCS(setgroups initgroups nl_langinfo epoll_wait) -AC_CHECK_FUNCS(strchr strstr strcpy strncpy memcpy memset memmove) +AC_CHECK_FUNCS(strchr snprintf strstr strcpy strncpy memcpy memset memmove) #ifdef SILC_DIST_SIM # SIM support checking @@ -1142,9 +1142,9 @@ AC_ARG_WITH(win32, ]) AM_CONDITIONAL(SILC_WIN32, test x$win32_support = xtrue) -# Native EPOC support (disabled by default) +# Native Symbian OS support (disabled by default) # -AM_CONDITIONAL(SILC_EPOC, test xfalse = xtrue) +AM_CONDITIONAL(SILC_SYMBIAN, test xfalse = xtrue) # Native BeOS support (disabled by default) # diff --git a/doc/draft-riikonen-silc-pp-09.nroff b/doc/draft-riikonen-silc-pp-09.nroff index 12730259..53c73e45 100644 --- a/doc/draft-riikonen-silc-pp-09.nroff +++ b/doc/draft-riikonen-silc-pp-09.nroff @@ -1838,6 +1838,10 @@ on channel. This means that channel uses channel private keys which are not server generated. For this reason server cannot send this packet as it does not know the key. +The destination ID in the packet SHOULD be the entity to whom the +packet is sent. Using Channel ID as destination ID is not +necessary as the Channel ID is included in the Channel Key Payload. + The payload may only be sent with SILC_PACKET_CHANNEL_KEY packet. It MUST NOT be sent in any other packet type. The following diagram represents the Channel Key Payload. @@ -2344,7 +2348,7 @@ types. The following diagram represents the Key Agreement Payload. ~ Hostname ~ | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Port | +| Protocol | Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ .in 3 @@ -2361,10 +2365,16 @@ o Hostname (variable length) - The hostname or IP address where MAY fill this field when sending the payload. If the receiver sends this payload as reply to the request it MUST fill this field. -o Port (4 bytes) - The port where the SKE protocol is bound. +o Protocol (2 bytes) - The internet protocol used for the key + agreement connection. Possible values are 0 for TCP and 1 for + UDP. Other values are unsupported. This is a 16 bit MSB first + order value. If Hostname field is not present, the value in + this field is ignored. + +o Port (2 bytes) - The port where the SKE protocol is bound. The sender MAY fill this field when sending the payload. If the receiver sends this payload as reply to the request it - MUST fill this field. This is a 32 bit MSB first order value. + MUST fill this field. This is a 16 bit MSB first order value. .in 3 diff --git a/doc/draft-riikonen-silc-spec-09.nroff b/doc/draft-riikonen-silc-spec-09.nroff index 6d7b93c6..f5c95784 100644 --- a/doc/draft-riikonen-silc-spec-09.nroff +++ b/doc/draft-riikonen-silc-spec-09.nroff @@ -1239,10 +1239,10 @@ debugging mode. .ti 0 3.10.1.1 CBC Mode -The "cbc" encryption mode is CBC mode with inter-packet chaining. This -means that the Initialization Vector (IV) for the next encryption block -is the previous ciphertext block. The very first IV MUST be random and -is generated as described in [SILC3]. +The "cbc" encryption mode is the standard cipher-block chaining mode. +The very first IV is derived from the SILC Key Exchange protocol. +Subsequent IVs for encryption is the previous ciphertext block. The very +first IV MUST be random and is generated as described in [SILC3]. .ti 0 @@ -1368,19 +1368,12 @@ stream to perform the decryption. The "rcbc" encryption mode is CBC mode with randomized IV. This means that each IV for each packet MUST be chosen randomly. When encrypting -more than one block the normal inter-packet chaining is used, but for -the first block new random IV is selected in each packet. In this mode -the IV is appended at the end of the last ciphertext block and thus -delivered to the recipient. This mode increases the ciphertext size by -one ciphertext block. Note also that some data payloads in SILC are -capable of delivering the IV to the recipient. When explicitly -encrypting these payloads with randomized CBC the IV MUST NOT be appended -at the end of the ciphertext, but is placed at the specified location -in the payload. However, Message Payload for example has the IV at -the location which is equivalent to placing it after the last ciphertext -block. When using CBC mode with such payloads it is actually equivalent -to using randomized CBC since the IV is selected in random and included -in the ciphertext. +more than one block the normal IV chaining is used, but for the first +block new random IV is selected in each packet. In this mode the IV +is appended to the ciphertext. If this mode is used to secure the SILC +session, the IV Included flag must be negotiated in SILC Key Exchange +protocol. It may also be used to secure Message Payloads which can +deliver the IV to the recipient. .ti 0 @@ -2403,7 +2396,9 @@ processing is equivalent to normal SKE negotiation. After both parties have regenerated the session key, both MUST send SILC_PACKET_REKEY_DONE packet to each other. These packets are still secured with the old key. After these packets, the subsequent packets -MUST be protected with the new key. +MUST be protected with the new key. Note that, in case SKE was performed +again the SILC_PACKET_SUCCESS is not sent. The SILC_PACKET_REKEY_DONE +is sent in its stead. .ti 0 diff --git a/includes/silc.h.in b/includes/silc.h.in index 5eaf86c8..fce93cb0 100644 --- a/includes/silc.h.in +++ b/includes/silc.h.in @@ -37,35 +37,19 @@ extern "C" { #endif #endif -#if defined(__EPOC32__) -#ifndef SILC_EPOC -#define SILC_EPOC -#undef SILC_UNIX -#endif -#endif - -#ifdef BEOS -#ifndef SILC_BEOS -#define SILC_BEOS -#undef SILC_UNIX -#endif -#elif defined(__BEOS__) -#ifndef SILC_BEOS -#define SILC_BEOS -#undef SILC_UNIX -#endif -#endif - -#if defined(OS2) -#ifndef SILC_OS2 -#define SILC_OS2 +#if defined(__EPOC32__) || defined(__SYMBIAN32__) +#ifndef SILC_SYMBIAN +#define SILC_SYMBIAN #undef SILC_UNIX +#undef SILC_WIN32 #endif #endif #if defined(__MACH__) && defined(__APPLE__) #ifndef SILC_MACOSX #define SILC_MACOSX +#undef SILC_WIN32 +#undef SILC_SYMBIAN #endif #endif @@ -84,8 +68,13 @@ extern "C" { #if defined(HAVE_SILCDEFS_H) /* Automatically generated configuration header */ +#ifndef SILC_SYMBIAN #include "silcdefs.h" #include "silcdistdefs.h" +#else +#include "../symbian/silcdefs.h" +#include "../symbian/silcdistdefs.h" +#endif /* SILC_SYMBIAN */ #endif /* HAVE_SILCDEFS_H */ /* Platform specific includes */ @@ -94,16 +83,8 @@ extern "C" { #include "silcwin32.h" #endif -#if defined(SILC_EPOC) -#include "silcepoc.h" -#endif - -#if defined(SILC_BEOS) -#include "silcbeos.h" -#endif - -#if defined(SILC_OS2) -#include "silcos2.h" +#if defined(SILC_SYMBIAN) +#include "silcsymbian.h" #endif #ifndef DLLAPI @@ -140,9 +121,12 @@ extern "C" { #include #include #include -#include #include +#ifdef HAVE_GRP_H +#include +#endif + #if defined(HAVE_GETOPT_H) && defined(HAVE_GETOPT) #include #else @@ -232,6 +216,7 @@ extern "C" { /* Include generic SILC type definitions */ #include "silctypes.h" +#include "silcmutex.h" #include "silcatomic.h" #include "silcversion.h" @@ -245,7 +230,6 @@ extern "C" { /* More SILC util library includes */ #include "silctime.h" -#include "silcmutex.h" #include "silccond.h" #include "silcthread.h" #include "silcschedule.h" diff --git a/includes/silcepoc.h b/includes/silcepoc.h deleted file mode 100644 index ab57922a..00000000 --- a/includes/silcepoc.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - - silcepoc.h - - Author: Pekka Riikonen - - Copyright (C) 2002 Pekka Riikonen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - -*/ -/* Native EPOC specific includes and definitions. */ - -#ifndef SILCEPOC_H -#define SILCEPOC_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/includes/silcsymbian.h b/includes/silcsymbian.h new file mode 100644 index 00000000..396a1210 --- /dev/null +++ b/includes/silcsymbian.h @@ -0,0 +1,43 @@ +/* + + silcsymbian.h + + Author: Pekka Riikonen + + Copyright (C) 2002 - 2006 Pekka Riikonen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ +/* Native Symbian specific includes and definitions. */ + +#ifndef SILCSYMBIAN_H +#define SILCSYMBIAN_H + +/* Various hacks follow */ + +/* Do not treat conversions from 'unsigned char *' to 'char *' as errors + with WINSCW */ +#ifdef __WINSCW__ +#pragma mpwc_relax on +#endif /* __WINSCW__ */ + +/* Define the need for wchar_t, otherwise the stddef.h may not define it, + as it is not guaranteed that the stddef.h used is from Symbian headers + (due to some include path ordering problem in some cases). */ +#ifndef __need_wchar_t +#define __need_wchar_t +#endif /* __need_wchar_t */ + +/* And just in case, include stddef.h here to get the Symbian one as + early as possible. */ +#include + +#endif /* SILCSYMBIAN_H */ diff --git a/lib/configure.ad b/lib/configure.ad index 889a74b1..5f13377f 100644 --- a/lib/configure.ad +++ b/lib/configure.ad @@ -4,7 +4,7 @@ # # Author: Pekka Riikonen # -# Copyright (C) 2005 Pekka Riikonen +# Copyright (C) 2005, 2007 Pekka Riikonen # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -209,7 +209,6 @@ lib/silcutil/unix/Makefile lib/silcutil/win32/Makefile lib/silcutil/beos/Makefile lib/silcutil/os2/Makefile -lib/silcutil/epoc/Makefile lib/silcapputil/Makefile #ifdef SILC_DIST_SFTP lib/silcsftp/Makefile diff --git a/lib/contrib/regexpr.c b/lib/contrib/regexpr.c index 1ddde56c..65917bc7 100644 --- a/lib/contrib/regexpr.c +++ b/lib/contrib/regexpr.c @@ -29,6 +29,7 @@ $Id$ */ +#include "silc.h" #include #include #include @@ -40,7 +41,6 @@ $Id$ #include #include -//#include "silc.h" #include "regexpr.h" #define MACRO_BEGIN do { diff --git a/lib/silcapputil/silcapputil.c b/lib/silcapputil/silcapputil.c index c8a9a35a..32018654 100644 --- a/lib/silcapputil/silcapputil.c +++ b/lib/silcapputil/silcapputil.c @@ -40,7 +40,7 @@ static char *silc_create_pk_identifier(void) return NULL; /* Create default email address, whether it is right or not */ - snprintf(email, sizeof(email), "%s@%s", username, hostname); + silc_snprintf(email, sizeof(email), "%s@%s", username, hostname); ident = silc_pkcs_silc_encode_identifier(username, hostname, realname, email, NULL, NULL); @@ -123,9 +123,9 @@ New pair of keys will be created. Please, answer to following questions.\n\ if (interactive) { memset(line, 0, sizeof(line)); if (def) - snprintf(line, sizeof(line), "Identifier [%s]: ", def); + silc_snprintf(line, sizeof(line), "Identifier [%s]: ", def); else - snprintf(line, sizeof(line), + silc_snprintf(line, sizeof(line), "Identifier (eg. UN=jon, HN=jon.dummy.com, " "RN=Jon Johnson, E=jon@dummy.com): "); @@ -153,7 +153,7 @@ New pair of keys will be created. Please, answer to following questions.\n\ if (!pkfile) { if (interactive) { memset(line, 0, sizeof(line)); - snprintf(line, sizeof(line), "Public key filename [public_key.pub]: "); + silc_snprintf(line, sizeof(line), "Public key filename [public_key.pub]: "); pkfile = silc_get_input(line, FALSE); } if (!pkfile) @@ -163,7 +163,7 @@ New pair of keys will be created. Please, answer to following questions.\n\ if (!prvfile) { if (interactive) { memset(line, 0, sizeof(line)); - snprintf(line, sizeof(line), "Private key filename [private_key.prv]: "); + silc_snprintf(line, sizeof(line), "Private key filename [private_key.prv]: "); prvfile = silc_get_input(line, FALSE); } if (!prvfile) @@ -753,11 +753,11 @@ SilcBool silc_parse_version_string(const char *version, min = atoi(cp); memset(buf, 0, sizeof(buf)); - snprintf(buf, sizeof(buf) - 1, "%d%d", maj, min); + silc_snprintf(buf, sizeof(buf) - 1, "%d%d", maj, min); if (protocol_version) *protocol_version = atoi(buf); memset(buf, 0, sizeof(buf)); - snprintf(buf, sizeof(buf) - 1, "%d.%d", maj, min); + silc_snprintf(buf, sizeof(buf) - 1, "%d.%d", maj, min); if (protocol_version_string) *protocol_version_string = strdup(buf); @@ -779,11 +779,11 @@ SilcBool silc_parse_version_string(const char *version, } memset(buf, 0, sizeof(buf)); - snprintf(buf, sizeof(buf) - 1, "%d%d", maj, min); + silc_snprintf(buf, sizeof(buf) - 1, "%d%d", maj, min); if (software_version) *software_version = atoi(buf); memset(buf, 0, sizeof(buf)); - snprintf(buf, sizeof(buf) - 1, "%d.%d", maj, min); + silc_snprintf(buf, sizeof(buf) - 1, "%d.%d", maj, min); if (software_version_string) *software_version_string = strdup(buf); @@ -815,7 +815,7 @@ SilcUInt32 silc_version_to_num(const char *version) min = atoi(cp + 1); memset(buf, 0, sizeof(buf)); - snprintf(buf, sizeof(buf) - 1, "%d%d", maj, min); + silc_snprintf(buf, sizeof(buf) - 1, "%d%d", maj, min); return (SilcUInt32)atoi(buf); } @@ -987,11 +987,11 @@ char *silc_id_render(void *id, SilcIdType id_type) } memset(tmp, 0, sizeof(tmp)); - snprintf(tmp, sizeof(tmp) - 1, ",%d,", ntohs(server_id->port)); + silc_snprintf(tmp, sizeof(tmp) - 1, ",%d,", ntohs(server_id->port)); _PUT_STRING(rid, tmp); SILC_PUT16_MSB(server_id->rnd, tmps); memset(tmp, 0, sizeof(tmp)); - snprintf(tmp, sizeof(tmp) - 1, "[%02x %02x]", tmps[0], tmps[1]); + silc_snprintf(tmp, sizeof(tmp) - 1, "[%02x %02x]", tmps[0], tmps[1]); _PUT_STRING(rid, tmp); } break; @@ -1017,10 +1017,10 @@ char *silc_id_render(void *id, SilcIdType id_type) } memset(tmp, 0, sizeof(tmp)); - snprintf(tmp, sizeof(tmp) - 1, ",%02x,", client_id->rnd); + silc_snprintf(tmp, sizeof(tmp) - 1, ",%02x,", client_id->rnd); _PUT_STRING(rid, tmp); memset(tmp, 0, sizeof(tmp)); - snprintf(tmp, sizeof(tmp) - 1, "[%02x %02x %02x %02x...]", + silc_snprintf(tmp, sizeof(tmp) - 1, "[%02x %02x %02x %02x...]", client_id->hash[0], client_id->hash[1], client_id->hash[2], client_id->hash[3]); _PUT_STRING(rid, tmp); @@ -1048,11 +1048,11 @@ char *silc_id_render(void *id, SilcIdType id_type) } memset(tmp, 0, sizeof(tmp)); - snprintf(tmp, sizeof(tmp) - 1, ",%d,", ntohs(channel_id->port)); + silc_snprintf(tmp, sizeof(tmp) - 1, ",%d,", ntohs(channel_id->port)); _PUT_STRING(rid, tmp); SILC_PUT16_MSB(channel_id->rnd, tmps); memset(tmp, 0, sizeof(tmp)); - snprintf(tmp, sizeof(tmp) - 1, "[%02x %02x]", tmps[0], tmps[1]); + silc_snprintf(tmp, sizeof(tmp) - 1, "[%02x %02x]", tmps[0], tmps[1]); _PUT_STRING(rid, tmp); } break; diff --git a/lib/silcasn1/silcasn1_decode.c b/lib/silcasn1/silcasn1_decode.c index fd162c7a..911515b2 100644 --- a/lib/silcasn1/silcasn1_decode.c +++ b/lib/silcasn1/silcasn1_decode.c @@ -528,7 +528,7 @@ silc_asn1_decoder(SilcAsn1 asn1, SilcStack stack1, SilcAsn1Tag type, /* Set two OID values */ memset(&tmpb, 0, sizeof(tmpb)); memset(tmpstr, 0, sizeof(tmpstr)); - snprintf(tmpstr, sizeof(tmpstr) - 1, "%lu.%lu", + silc_snprintf(tmpstr, sizeof(tmpstr) - 1, "%lu.%lu", (unsigned long)(rdata[0] & 0xff) / 40, (unsigned long)(rdata[0] & 0xff) % 40); silc_buffer_sstrformat(asn1->stack1, &tmpb, tmpstr, SILC_STR_END); @@ -550,7 +550,7 @@ silc_asn1_decoder(SilcAsn1 asn1, SilcStack stack1, SilcAsn1Tag type, oid |= rdata[i]; memset(tmpstr, 0, sizeof(tmpstr)); - snprintf(tmpstr, sizeof(tmpstr) - 1, ".%lu", (unsigned long)oid); + silc_snprintf(tmpstr, sizeof(tmpstr) - 1, ".%lu", (unsigned long)oid); silc_buffer_sstrformat(asn1->stack1, &tmpb, tmpstr, SILC_STR_END); } *oidstr = tmpb.head; diff --git a/lib/silcclient/client_entry.c b/lib/silcclient/client_entry.c index e3f2eafa..a58298fc 100644 --- a/lib/silcclient/client_entry.c +++ b/lib/silcclient/client_entry.c @@ -423,6 +423,7 @@ SilcUInt16 silc_client_get_clients_by_list(SilcClient client, SilcUInt32 *res_argv_lens = NULL, *res_argv_types = NULL, res_argc = 0; SilcUInt16 idp_len, cmd_ident; SilcID id; + va_list tmp; int i; SILC_LOG_DEBUG(("Resolve clients from Client ID list")); @@ -490,7 +491,7 @@ SilcUInt16 silc_client_get_clients_by_list(SilcClient client, /* We have the clients in cache, get them and call the completion */ silc_client_get_clients_list_cb(client, conn, SILC_COMMAND_WHOIS, - SILC_STATUS_OK, SILC_STATUS_OK, in, NULL); + SILC_STATUS_OK, SILC_STATUS_OK, in, tmp); return 0; err: @@ -1086,7 +1087,7 @@ SilcClientEntry silc_client_nickname_format(SilcClient client, } memset(tmp, 0, sizeof(tmp)); - snprintf(tmp, sizeof(tmp) - 1, "%d", ++max); + silc_snprintf(tmp, sizeof(tmp) - 1, "%d", ++max); len = strlen(tmp); memcpy(&newnick[off], tmp, len); off += len; diff --git a/lib/silcclient/client_ftp.c b/lib/silcclient/client_ftp.c index 9eec9740..09aac707 100644 --- a/lib/silcclient/client_ftp.c +++ b/lib/silcclient/client_ftp.c @@ -317,7 +317,7 @@ static void silc_client_ftp_open_handle(SilcSFTP sftp, /* Open the actual local file */ memset(path, 0, sizeof(path)); - snprintf(path, sizeof(path) - 1, "%s%s", session->path ? + silc_snprintf(path, sizeof(path) - 1, "%s%s", session->path ? session->path : "", session->filepath); session->fd = silc_file_open(path, O_RDWR | O_CREAT | O_EXCL); if (session->fd < 0) { diff --git a/lib/silcclient/client_keyagr.c b/lib/silcclient/client_keyagr.c index 34a160b9..a0c791d8 100644 --- a/lib/silcclient/client_keyagr.c +++ b/lib/silcclient/client_keyagr.c @@ -416,7 +416,7 @@ void silc_client_send_key_agreement(SilcClient client, port = params->local_port; if (!port) { /* Get listener port */ - int sock; + SilcSocket sock; silc_socket_stream_get_info(stream, &sock, NULL, NULL, NULL); port = silc_net_get_local_port(sock); } diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index afc3e27d..6de9eb08 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -325,7 +325,7 @@ static inline SilcBool silc_packet_stream_read(SilcPacketStream ps, } /* See if remote packet stream exist for this sender */ - snprintf(tuple, sizeof(tuple), "%d%s", remote_port, remote_ip); + silc_snprintf(tuple, sizeof(tuple), "%d%s", remote_port, remote_ip); silc_mutex_lock(ps->sc->engine->lock); if (silc_hash_table_find(ps->sc->engine->udp_remote, tuple, NULL, (void *)&remote)) { @@ -796,7 +796,7 @@ void silc_packet_stream_destroy(SilcPacketStream stream) } else { /* Delete from UDP remote hash table */ char tuple[64]; - snprintf(tuple, sizeof(tuple), "%d%s", stream->remote_udp->remote_port, + silc_snprintf(tuple, sizeof(tuple), "%d%s", stream->remote_udp->remote_port, stream->remote_udp->remote_ip); silc_mutex_lock(stream->sc->engine->lock); silc_hash_table_del(stream->sc->engine->udp_remote, tuple); diff --git a/lib/silccrypt/silcpk.c b/lib/silccrypt/silcpk.c index 7e7c234e..cb9ef422 100644 --- a/lib/silccrypt/silcpk.c +++ b/lib/silccrypt/silcpk.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2006 Pekka Riikonen + Copyright (C) 1997 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1529,7 +1529,8 @@ SilcBool silc_pkcs_silc_encrypt(void *public_key, SilcUInt32 src_len, unsigned char *dst, SilcUInt32 dst_size, - SilcUInt32 *ret_dst_len) + SilcUInt32 *ret_dst_len, + SilcRng rng) { SilcSILCPublicKey silc_pubkey = public_key; @@ -1538,7 +1539,7 @@ SilcBool silc_pkcs_silc_encrypt(void *public_key, return silc_pubkey->pkcs->encrypt(silc_pubkey->public_key, src, src_len, - dst, dst_size, ret_dst_len); + dst, dst_size, ret_dst_len, rng); } /* Decrypts as specified in SILC protocol specification */ diff --git a/lib/silccrypt/silcpk_i.h b/lib/silccrypt/silcpk_i.h index 38029658..06fe473a 100644 --- a/lib/silccrypt/silcpk_i.h +++ b/lib/silccrypt/silcpk_i.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2005 Pekka Riikonen + Copyright (C) 2005, 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -69,7 +69,8 @@ SilcBool silc_pkcs_silc_encrypt(void *public_key, SilcUInt32 src_len, unsigned char *dst, SilcUInt32 dst_size, - SilcUInt32 *ret_dst_len); + SilcUInt32 *ret_dst_len, + SilcRng rng); SilcBool silc_pkcs_silc_decrypt(void *private_key, unsigned char *src, SilcUInt32 src_len, diff --git a/lib/silccrypt/silcpkcs.c b/lib/silccrypt/silcpkcs.c index 4665c160..457deb80 100644 --- a/lib/silccrypt/silcpkcs.c +++ b/lib/silccrypt/silcpkcs.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2006 Pekka Riikonen + Copyright (C) 1997 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -571,10 +571,10 @@ void silc_pkcs_private_key_free(SilcPrivateKey private_key) SilcBool silc_pkcs_encrypt(SilcPublicKey public_key, unsigned char *src, SilcUInt32 src_len, unsigned char *dst, SilcUInt32 dst_size, - SilcUInt32 *dst_len) + SilcUInt32 *dst_len, SilcRng rng) { return public_key->pkcs->encrypt(public_key->public_key, src, src_len, - dst, dst_size, dst_len); + dst, dst_size, dst_len, rng); } /* Decrypts */ diff --git a/lib/silccrypt/silcpkcs.h b/lib/silccrypt/silcpkcs.h index f0dfca17..78812b0f 100644 --- a/lib/silccrypt/silcpkcs.h +++ b/lib/silccrypt/silcpkcs.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2006 Pekka Riikonen + Copyright (C) 1997 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -155,7 +155,8 @@ typedef struct { SilcUInt32 src_len, unsigned char *dst, SilcUInt32 dst_size, - SilcUInt32 *ret_dst_len); + SilcUInt32 *ret_dst_len, + SilcRng rng); SilcBool (*decrypt)(void *private_key, unsigned char *src, SilcUInt32 src_len, @@ -260,7 +261,8 @@ struct SilcPKCSObjectStruct { SilcUInt32 src_len, unsigned char *dst, SilcUInt32 dst_size, - SilcUInt32 *ret_dst_len); + SilcUInt32 *ret_dst_len, + SilcRng rng); SilcBool (*decrypt)(void *private_key, unsigned char *src, SilcUInt32 src_len, @@ -656,7 +658,7 @@ void silc_pkcs_private_key_free(SilcPrivateKey private_key); SilcBool silc_pkcs_encrypt(SilcPublicKey public_key, unsigned char *src, SilcUInt32 src_len, unsigned char *dst, SilcUInt32 dst_size, - SilcUInt32 *dst_len); + SilcUInt32 *dst_len, SilcRng rng); /****f* silccrypt/SilcPKCSAPI/silc_pkcs_decrypt * diff --git a/lib/silccrypt/silcpkcs1.c b/lib/silccrypt/silcpkcs1.c index 0094e130..e3c6b68f 100644 --- a/lib/silccrypt/silcpkcs1.c +++ b/lib/silccrypt/silcpkcs1.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2003 - 2006 Pekka Riikonen + Copyright (C) 2003 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -74,14 +74,15 @@ SilcBool silc_pkcs1_encode(SilcPkcs1BlockType bt, case SILC_PKCS1_BT_PUB: /* Encryption */ + if (!rng) { + SILC_LOG_ERROR(("Cannot encrypt: random number generator not provided")); + return FALSE; + } /* It is guaranteed this routine does not return zero byte. */ - if (rng) - for (i = 2; i < padlen; i++) - dest_data[i] = silc_rng_get_byte_fast(rng); - else - for (i = 2; i < padlen; i++) - dest_data[i] = silc_rng_global_get_byte_fast(); + for (i = 2; i < padlen; i++) + dest_data[i] = silc_rng_get_byte_fast(rng); + break; } @@ -473,7 +474,8 @@ SilcBool silc_pkcs1_encrypt(void *public_key, SilcUInt32 src_len, unsigned char *dst, SilcUInt32 dst_size, - SilcUInt32 *ret_dst_len) + SilcUInt32 *ret_dst_len, + SilcRng rng) { RsaPublicKey *key = public_key; SilcMPInt mp_tmp; @@ -488,7 +490,7 @@ SilcBool silc_pkcs1_encrypt(void *public_key, /* Pad data */ if (!silc_pkcs1_encode(SILC_PKCS1_BT_PUB, src, src_len, - padded, len, NULL)) + padded, len, rng)) return FALSE; silc_mp_init(&mp_tmp); diff --git a/lib/silchttp/silchttpphp.c b/lib/silchttp/silchttpphp.c index f70b2acd..6b699d94 100644 --- a/lib/silchttp/silchttpphp.c +++ b/lib/silchttp/silchttpphp.c @@ -34,7 +34,7 @@ SilcBuffer silc_http_php(char *php_data) return NULL; #else memset(tmp, 0, sizeof(tmp)); - snprintf(tmp, sizeof(tmp) - 1, "/tmp/silchttpphpXXXXXX"); + silc_snprintf(tmp, sizeof(tmp) - 1, "/tmp/silchttpphpXXXXXX"); if (mkstemp(tmp) == -1) return NULL; name = tmp; @@ -66,7 +66,7 @@ SilcBuffer silc_http_php_file(const char *filename) SILC_LOG_DEBUG(("Executing PHP")); memset(tmp, 0, sizeof(tmp)); - snprintf(tmp, sizeof(tmp) - 1, "php -f %s", filename); + silc_snprintf(tmp, sizeof(tmp) - 1, "php -f %s", filename); #ifdef SILC_WIN32 fd = _popen(tmp, "r"); diff --git a/lib/silchttp/silchttpserver.c b/lib/silchttp/silchttpserver.c index d2700ff2..ed01beae 100644 --- a/lib/silchttp/silchttpserver.c +++ b/lib/silchttp/silchttpserver.c @@ -547,11 +547,11 @@ SilcBool silc_http_server_send(SilcHttpServer httpd, silc_mime_add_field(conn->headers, "Last-Modified", silc_time_string(conn->touched)); - snprintf(tmp, sizeof(tmp), "%d", (int)silc_buffer_len(data)); + silc_snprintf(tmp, sizeof(tmp), "%d", (int)silc_buffer_len(data)); silc_mime_add_field(conn->headers, "Content-Length", tmp); if (conn->keepalive) { silc_mime_add_field(conn->headers, "Connection", "keep-alive"); - snprintf(tmp, sizeof(tmp), "%d", (int)SILC_HTTP_SERVER_TIMEOUT); + silc_snprintf(tmp, sizeof(tmp), "%d", (int)SILC_HTTP_SERVER_TIMEOUT); silc_mime_add_field(conn->headers, "Keep-alive", tmp); } diff --git a/lib/silcserver/server_send.c b/lib/silcserver/server_send.c index 5f9a61ab..4b585e0e 100644 --- a/lib/silcserver/server_send.c +++ b/lib/silcserver/server_send.c @@ -47,7 +47,7 @@ SilcBool silc_server_send_error(SilcPacketStream stream, const char *fmt, ...) memset(buf, 0, sizeof(buf)); va_start(ap, fmt); - vsnprintf(buf, sizeof(buf) - 1, fmt, ap); + vsilc_snprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); return silc_packet_send(stream, SILC_PACKET_ERROR, 0, buf, strlen(buf)); diff --git a/lib/silcserver/server_st_accept.c b/lib/silcserver/server_st_accept.c index cad6f55f..7ad789a9 100644 --- a/lib/silcserver/server_st_accept.c +++ b/lib/silcserver/server_st_accept.c @@ -555,8 +555,8 @@ SILC_FSM_STATE(silc_server_st_accept_client) ret = silc_parse_userfqdn(username, u, 128, h, sizeof(h)); if (ret < 2) { /* Hostname not present, add it */ - snprintf(n, sizeof(n), "%s", u); - snprintf(u, sizeof(u) - 1, "%s@%s", n, ac->hostname); + silc_snprintf(n, sizeof(n), "%s", u); + silc_snprintf(u, sizeof(u) - 1, "%s@%s", n, ac->hostname); } else { /* Verify that hostname is same than resolved hostname */ if (strcmp(ac->hostname, h)) { @@ -568,8 +568,8 @@ SILC_FSM_STATE(silc_server_st_accept_client) silc_fsm_next(fsm, silc_server_st_accept_error); SILC_FSM_CONTINUE; } - snprintf(n, sizeof(n), "%s", u); - snprintf(u, sizeof(u) - 1, "%s@%s", n, h); + silc_snprintf(n, sizeof(n), "%s", u); + silc_snprintf(u, sizeof(u) - 1, "%s@%s", n, h); } /* If configured as anonymous, scramble the username and hostname */ diff --git a/lib/silcsftp/sftp_fs_memory.c b/lib/silcsftp/sftp_fs_memory.c index dc055761..66d393ac 100644 --- a/lib/silcsftp/sftp_fs_memory.c +++ b/lib/silcsftp/sftp_fs_memory.c @@ -788,7 +788,7 @@ void mem_readdir(void *context, SilcSFTP sftp, /* Long name format is: drwx------ 1 324210 Apr 8 08:40 mail/ 1234567890 123 12345678 123456789012 */ - snprintf(long_name, sizeof(long_name) - 1, + silc_snprintf(long_name, sizeof(long_name) - 1, "%c%c%c%c------ %3d %8llu %12s %s%s", (entry->directory ? 'd' : '-'), ((entry->perm & SILC_SFTP_FS_PERM_READ) ? 'r' : '-'), diff --git a/lib/silcskr/silcskr.c b/lib/silcskr/silcskr.c index f2317c9e..1ed22beb 100644 --- a/lib/silcskr/silcskr.c +++ b/lib/silcskr/silcskr.c @@ -20,6 +20,8 @@ #include "silc.h" #include "silcskr.h" +/* XXX Locking, when removing keys */ + /************************** Types and definitions ***************************/ /* Search constraints */ @@ -77,16 +79,16 @@ static void silc_skr_type_string(SilcSKRFindType type, void *data, switch (type) { case SILC_SKR_FIND_PKCS_TYPE: case SILC_SKR_FIND_USAGE: - snprintf(retbuf, retbuf_size, "[%s] [%d]", find_name[type], + silc_snprintf(retbuf, retbuf_size, "[%s] [%d]", find_name[type], (int)SILC_PTR_TO_32(data)); break; case SILC_SKR_FIND_PUBLIC_KEY: - snprintf(retbuf, retbuf_size, "[%s] [%p]", find_name[type], data); + silc_snprintf(retbuf, retbuf_size, "[%s] [%p]", find_name[type], data); break; default: - snprintf(retbuf, retbuf_size, "[%s] [%s]", find_name[type], + silc_snprintf(retbuf, retbuf_size, "[%s] [%s]", find_name[type], (char *)data); } } diff --git a/lib/silcutil/Makefile.ad b/lib/silcutil/Makefile.ad index 76c73df8..cb837bd3 100644 --- a/lib/silcutil/Makefile.ad +++ b/lib/silcutil/Makefile.ad @@ -3,7 +3,7 @@ # # Author: Pekka Riikonen # -# Copyright (C) 2000 - 2005 Pekka Riikonen +# Copyright (C) 2000 - 2006 Pekka Riikonen # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,22 +20,14 @@ AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign if SILC_WIN32 SUBDIRS=win32 else -if SILC_EPOC -SUBDIRS=epoc -else -if SILC_BEOS -SUBDIRS=beos -else -if SILC_OS2 -SUBDIRS=os2 +if SILC_SYMBIAN +SUBDIRS=symbian else SUBDIRS=unix endif endif -endif -endif -DIST_SUBDIRS=win32 epoc beos os2 unix +DIST_SUBDIRS=win32 symbian unix #ifdef SILC_DIST_TOOLKIT SILC_DIST_SOURCE = stacktrace.c diff --git a/lib/silcutil/silclog.c b/lib/silcutil/silclog.c index 1c0116f2..9deff33a 100644 --- a/lib/silcutil/silclog.c +++ b/lib/silcutil/silclog.c @@ -112,7 +112,7 @@ static void silc_log_checksize(SilcLog log) fclose(log->fp); memset(newname, 0, sizeof(newname)); - snprintf(newname, sizeof(newname) - 1, "%s.old", log->filename); + silc_silc_snprintf(newname, sizeof(newname) - 1, "%s.old", log->filename); unlink(newname); rename(log->filename, newname); diff --git a/lib/silcutil/silcmime.c b/lib/silcutil/silcmime.c index aa138a51..14fde956 100644 --- a/lib/silcutil/silcmime.c +++ b/lib/silcutil/silcmime.c @@ -229,10 +229,10 @@ SilcMime silc_mime_decode(SilcMime mime, const unsigned char *data, line = strdup(value); if (strrchr(line, '"')) { *strrchr(line, '"') = '\0'; - snprintf(b, sizeof(b) - 1, "--%s", line + 1); + silc_silc_snprintf(b, sizeof(b) - 1, "--%s", line + 1); mime->boundary = strdup(line + 1); } else { - snprintf(b, sizeof(b) - 1, "--%s", line); + silc_silc_snprintf(b, sizeof(b) - 1, "--%s", line); mime->boundary = strdup(line); } silc_free(line); @@ -325,7 +325,7 @@ unsigned char *silc_mime_encode(SilcMime mime, SilcUInt32 *encoded_len) while (silc_hash_table_get(&htl, (void **)&field, (void **)&value)) { memset(tmp, 0, sizeof(tmp)); SILC_LOG_DEBUG(("Header %s: %s", field, value)); - snprintf(tmp, sizeof(tmp) - 1, "%s: %s\r\n", field, value); + silc_silc_snprintf(tmp, sizeof(tmp) - 1, "%s: %s\r\n", field, value); silc_buffer_strformat(&buf, tmp, SILC_STRFMT_END); i++; } @@ -370,8 +370,8 @@ unsigned char *silc_mime_encode(SilcMime mime, SilcUInt32 *encoded_len) /* If fields are not present, add extra CRLF */ if (!silc_hash_table_count(part->fields)) - snprintf(tmp2, sizeof(tmp2) - 1, "\r\n"); - snprintf(tmp, sizeof(tmp) - 1, "%s--%s\r\n%s", + silc_silc_snprintf(tmp2, sizeof(tmp2) - 1, "\r\n"); + silc_silc_snprintf(tmp, sizeof(tmp) - 1, "%s--%s\r\n%s", i != 0 ? "\r\n" : "", mime->boundary, tmp2); i = 1; @@ -387,7 +387,7 @@ unsigned char *silc_mime_encode(SilcMime mime, SilcUInt32 *encoded_len) } memset(tmp, 0, sizeof(tmp)); - snprintf(tmp, sizeof(tmp) - 1, "\r\n--%s--\r\n", mime->boundary); + silc_silc_snprintf(tmp, sizeof(tmp) - 1, "\r\n--%s--\r\n", mime->boundary); buffer = silc_buffer_realloc(buffer, silc_buffer_truelen(buffer) + strlen(tmp)); if (!buffer) @@ -578,7 +578,7 @@ SilcDList silc_mime_encode_partial(SilcMime mime, int max_size) memset(type, 0, sizeof(type)); gethostname(type, sizeof(type) - 1); srand((time(NULL) + buf_len) ^ rand()); - snprintf(id, sizeof(id) - 1, "%X%X%X%s", + silc_silc_snprintf(id, sizeof(id) - 1, "%X%X%X%s", (unsigned int)rand(), (unsigned int)time(NULL), (unsigned int)buf_len, type); @@ -590,7 +590,7 @@ SilcDList silc_mime_encode_partial(SilcMime mime, int max_size) silc_mime_add_field(partial, "MIME-Version", "1.0"); memset(type, 0, sizeof(type)); - snprintf(type, sizeof(type) - 1, + silc_silc_snprintf(type, sizeof(type) - 1, "message/partial; id=\"%s\"; number=1", id); silc_mime_add_field(partial, "Content-Type", type); silc_mime_add_data(partial, buf, max_size); @@ -620,14 +620,14 @@ SilcDList silc_mime_encode_partial(SilcMime mime, int max_size) silc_mime_add_field(partial, "MIME-Version", "1.0"); if (len > max_size) { - snprintf(type, sizeof(type) - 1, + silc_silc_snprintf(type, sizeof(type) - 1, "message/partial; id=\"%s\"; number=%d", id, num++); silc_mime_add_data(partial, buf + off, max_size); off += max_size; len -= max_size; } else { - snprintf(type, sizeof(type) - 1, + silc_silc_snprintf(type, sizeof(type) - 1, "message/partial; id=\"%s\"; number=%d; total=%d", id, num, num); silc_mime_add_data(partial, buf + off, len); @@ -777,7 +777,7 @@ void silc_mime_set_multipart(SilcMime mime, const char *type, return; memset(tmp, 0, sizeof(tmp)); - snprintf(tmp, sizeof(tmp) - 1, "multipart/%s; boundary=%s", type, boundary); + silc_silc_snprintf(tmp, sizeof(tmp) - 1, "multipart/%s; boundary=%s", type, boundary); silc_mime_add_field(mime, "Content-Type", tmp); silc_free(mime->boundary); mime->boundary = strdup(boundary); diff --git a/lib/silcutil/silcnet.c b/lib/silcutil/silcnet.c index 2a868d22..a6c0f927 100644 --- a/lib/silcutil/silcnet.c +++ b/lib/silcutil/silcnet.c @@ -248,7 +248,8 @@ void silc_net_gethostbyname_async(const char *name, /* Resolves hostname by IP address. */ -SilcBool silc_net_gethostbyaddr(const char *addr, char *name, SilcUInt32 name_len) +SilcBool silc_net_gethostbyaddr(const char *addr, char *name, + SilcUInt32 name_len) { #ifdef HAVE_IPV6 struct addrinfo req, *ai; @@ -300,10 +301,13 @@ void silc_net_gethostbyaddr_async(const char *addr, silc_thread_create(silc_net_gethostbyaddr_thread, r, FALSE); } +#ifndef SILC_SYMBIAN + /* Performs lookups for remote name and IP address. This peforms reverse lookup as well to verify that the IP has FQDN. */ -SilcBool silc_net_check_host_by_sock(int sock, char **hostname, char **ip) +SilcBool silc_net_check_host_by_sock(SilcSocket sock, char **hostname, + char **ip) { char host[1024]; int rval, len; @@ -381,7 +385,8 @@ SilcBool silc_net_check_host_by_sock(int sock, char **hostname, char **ip) /* Performs lookups for local name and IP address. This peforms reverse lookup as well to verify that the IP has FQDN. */ -SilcBool silc_net_check_local_by_sock(int sock, char **hostname, char **ip) +SilcBool silc_net_check_local_by_sock(SilcSocket sock, char **hostname, + char **ip) { char host[1024]; int rval, len; @@ -458,7 +463,7 @@ SilcBool silc_net_check_local_by_sock(int sock, char **hostname, char **ip) /* Return remote port by socket. */ -SilcUInt16 silc_net_get_remote_port(int sock) +SilcUInt16 silc_net_get_remote_port(SilcSocket sock) { #ifdef HAVE_IPV6 struct sockaddr_storage remote; @@ -490,7 +495,7 @@ SilcUInt16 silc_net_get_remote_port(int sock) /* Return local port by socket. */ -SilcUInt16 silc_net_get_local_port(int sock) +SilcUInt16 silc_net_get_local_port(SilcSocket sock) { #ifdef HAVE_IPV6 struct sockaddr_storage local; @@ -519,6 +524,7 @@ SilcUInt16 silc_net_get_local_port(int sock) return ntohs(local.sin_port); #endif } +#endif /* !SILC_SYMBIAN */ /* Return name of localhost. */ diff --git a/lib/silcutil/silcnet.h b/lib/silcutil/silcnet.h index 30edce4e..c4a1f045 100644 --- a/lib/silcutil/silcnet.h +++ b/lib/silcutil/silcnet.h @@ -313,7 +313,8 @@ int silc_net_udp_send(SilcStream stream, * * DESCRIPTION * - * Closes the connection by closing the socket connection. + * Closes the connection by closing the socket connection. This routine + * can only be used with POSIX compliant systems. * ***/ void silc_net_close_connection(int sock); @@ -326,24 +327,13 @@ void silc_net_close_connection(int sock); * * DESCRIPTION * - * Accepts a connection from a particular socket. + * Accepts a connection from a particular socket. This routine can only + * be used with POSIX compliant systems. This call is equivalent to + * accept(2). * ***/ int silc_net_accept_connection(int sock); -/****f* silcutil/SilcNetAPI/silc_net_set_socket_nonblock - * - * SYNOPSIS - * - * int silc_net_set_socket_nonblock(int sock); - * - * DESCRIPTION - * - * Sets the socket to non-blocking mode. - * - ***/ -int silc_net_set_socket_nonblock(int sock); - /****f* silcutil/SilcNetAPI/silc_net_set_socket_opt * * SYNOPSIS @@ -354,7 +344,8 @@ int silc_net_set_socket_nonblock(int sock); * * Sets a option for a socket. This function can be used to set * various options for the socket. Some of the options might be - * system specific. + * system specific. This routine can only be used with POSIX compliant + * systems. This call is equivalent to setsockopt(2); * ***/ int silc_net_set_socket_opt(int sock, int level, int option, int on); @@ -368,12 +359,27 @@ int silc_net_set_socket_opt(int sock, int level, int option, int on); * * DESCRIPTION * - * Return socket options to the `optval' and `opt_len'. + * Return socket options to the `optval' and `opt_len'. This routine + * can only be used with POSIX compliant systems. This call is + * equivalent to getsockopt(2). * ***/ int silc_net_get_socket_opt(int sock, int level, int option, void *optval, int *opt_len); +/****f* silcutil/SilcNetAPI/silc_net_set_socket_nonblock + * + * SYNOPSIS + * + * int silc_net_set_socket_nonblock(SilcSocket sock); + * + * DESCRIPTION + * + * Sets the socket `sock' to non-blocking mode. + * + ***/ +int silc_net_set_socket_nonblock(SilcSocket sock); + /****f* silcutil/SilcNetAPI/silc_net_is_ip4 * * SYNOPSIS @@ -539,7 +545,7 @@ void silc_net_gethostbyaddr_async(const char *addr, * * SYNOPSIS * - * SilcBool silc_net_check_host_by_sock(int sock, char **hostname, + * SilcBool silc_net_check_host_by_sock(SilcSocket sock, char **hostname, * char **ip); * * DESCRIPTION @@ -548,13 +554,14 @@ void silc_net_gethostbyaddr_async(const char *addr, * lookup as well to verify that the IP has FQDN. * ***/ -SilcBool silc_net_check_host_by_sock(int sock, char **hostname, char **ip); +SilcBool silc_net_check_host_by_sock(SilcSocket sock, char **hostname, + char **ip); /****f* silcutil/SilcNetAPI/silc_net_check_local_by_sock * * SYNOPSIS * - * SilcBool silc_net_check_local_by_sock(int sock, char **hostname, + * SilcBool silc_net_check_local_by_sock(SilcSocket sock, char **hostname, * char **ip); * * DESCRIPTION @@ -563,33 +570,34 @@ SilcBool silc_net_check_host_by_sock(int sock, char **hostname, char **ip); * lookup as well to verify that the IP has FQDN. * ***/ -SilcBool silc_net_check_local_by_sock(int sock, char **hostname, char **ip); +SilcBool silc_net_check_local_by_sock(SilcSocket sock, char **hostname, + char **ip); /****f* silcutil/SilcNetAPI/silc_net_get_remote_port * * SYNOPSIS * - * SilcUInt16 silc_net_get_remote_port(int sock); + * SilcUInt16 silc_net_get_remote_port(SilcSocket sock); * * DESCRIPTION * * Return remote port by socket. * ***/ -SilcUInt16 silc_net_get_remote_port(int sock); +SilcUInt16 silc_net_get_remote_port(SilcSocket sock); /****f* silcutil/SilcNetAPI/silc_net_get_local_port * * SYNOPSIS * - * SilcUInt16 silc_net_get_local_port(int sock); + * SilcUInt16 silc_net_get_local_port(SilcSocket sock); * * DESCRIPTION * * Return local port by socket. * ***/ -SilcUInt16 silc_net_get_local_port(int sock); +SilcUInt16 silc_net_get_local_port(SilcSocket sock); /****f* silcutil/SilcNetAPI/silc_net_localhost * diff --git a/lib/silcutil/silcnet_i.h b/lib/silcutil/silcnet_i.h index 7cc356e2..a5ec1038 100644 --- a/lib/silcutil/silcnet_i.h +++ b/lib/silcutil/silcnet_i.h @@ -24,12 +24,12 @@ #error "Do not include this header directly" #endif -/* Net listenrr context */ +/* Net listener context */ struct SilcNetListenerStruct { SilcSchedule schedule; SilcNetCallback callback; void *context; - int *socks; + SilcSocket *socks; unsigned int socks_count : 30; unsigned int require_fqdn : 1; unsigned int lookup : 1; diff --git a/lib/silcutil/silcsocketstream.c b/lib/silcutil/silcsocketstream.c index 1c4e952a..c3206447 100644 --- a/lib/silcutil/silcsocketstream.c +++ b/lib/silcutil/silcsocketstream.c @@ -21,13 +21,7 @@ /************************** Types and definitions ***************************/ -#define SILC_IS_SOCKET_STREAM(s) (s->ops == &silc_socket_stream_ops) -#define SILC_IS_SOCKET_STREAM_UDP(s) (s->ops == &silc_socket_udp_stream_ops) - -const SilcStreamOps silc_socket_stream_ops; -const SilcStreamOps silc_socket_udp_stream_ops; - -/* Platform specific functions */ +/* Stream operation functions (platform specific) */ int silc_socket_stream_read(SilcStream stream, unsigned char *buf, SilcUInt32 buf_len); int silc_socket_stream_write(SilcStream stream, const unsigned char *data, @@ -38,6 +32,13 @@ int silc_socket_udp_stream_read(SilcStream stream, unsigned char *buf, SilcUInt32 buf_len); int silc_socket_udp_stream_write(SilcStream stream, const unsigned char *data, SilcUInt32 data_len); +SilcBool silc_socket_stream_close(SilcStream stream); +void silc_socket_stream_destroy(SilcStream stream); +void silc_socket_stream_notifier(SilcStream stream, + SilcSchedule schedule, + SilcStreamNotifier callback, + void *context); +SilcSchedule silc_socket_stream_get_schedule(SilcStream stream); /* Internal async host lookup context. */ typedef struct { @@ -53,30 +54,6 @@ typedef struct { /************************ Static utility functions **************************/ -/* The IO process callback that calls the notifier callback to upper - layer. */ - -SILC_TASK_CALLBACK(silc_socket_stream_io) -{ - SilcSocketStream stream = context; - - if (silc_unlikely(!stream->notifier)) - return; - - switch (type) { - case SILC_TASK_READ: - stream->notifier(stream, SILC_STREAM_CAN_READ, stream->notifier_context); - break; - - case SILC_TASK_WRITE: - stream->notifier(stream, SILC_STREAM_CAN_WRITE, stream->notifier_context); - break; - - default: - break; - } -} - /* Finishing timeout callback that will actually call the user specified host lookup callback. This is executed back in the calling thread and not in the lookup thread. */ @@ -88,20 +65,16 @@ SILC_TASK_CALLBACK(silc_socket_host_lookup_finish) if (lookup->aborted) { SILC_LOG_DEBUG(("Socket stream creation was aborted")); - silc_net_close_connection(stream->sock); - silc_free(stream->ip); - silc_free(stream->hostname); - silc_free(stream); + stream->schedule = NULL; + silc_socket_stream_destroy(stream); silc_free(lookup); return; } if (lookup->status != SILC_SOCKET_OK) { SILC_LOG_DEBUG(("Socket stream failed")); - silc_net_close_connection(stream->sock); - silc_free(stream->ip); - silc_free(stream->hostname); - silc_free(stream); + stream->schedule = NULL; + silc_socket_stream_destroy(stream); stream = lookup->stream = NULL; } @@ -170,7 +143,7 @@ static void silc_socket_host_lookup_abort(SilcAsyncOperation op, /* Creates TCP socket stream */ SilcAsyncOperation -silc_socket_tcp_stream_create(int sock, SilcBool lookup, +silc_socket_tcp_stream_create(SilcSocket sock, SilcBool lookup, SilcBool require_fqdn, SilcSchedule schedule, SilcSocketStreamCallback callback, @@ -179,6 +152,12 @@ silc_socket_tcp_stream_create(int sock, SilcBool lookup, SilcSocketStream stream; SilcSocketHostLookup l; + if (!sock) { + if (callback) + callback(SILC_SOCKET_ERROR, NULL, context); + return NULL; + } + stream = silc_calloc(1, sizeof(*stream)); if (!stream) { if (callback) @@ -232,7 +211,7 @@ silc_socket_tcp_stream_create(int sock, SilcBool lookup, /* Creates UDP socket stream */ -SilcStream silc_socket_udp_stream_create(int sock, SilcBool ipv6, +SilcStream silc_socket_udp_stream_create(SilcSocket sock, SilcBool ipv6, SilcBool connected, SilcSchedule schedule) { @@ -271,7 +250,7 @@ SilcBool silc_socket_stream_is_udp(SilcStream stream, SilcBool *connected) /* Returns socket stream information */ SilcBool silc_socket_stream_get_info(SilcStream stream, - int *sock, const char **hostname, + SilcSocket *sock, const char **hostname, const char **ip, SilcUInt16 *port) { SilcSocketStream socket_stream = stream; @@ -396,91 +375,6 @@ SilcBool silc_socket_stream_set_qos(SilcStream stream, return TRUE; } -/* Closes socket */ - -SilcBool silc_socket_stream_close(SilcStream stream) -{ - SilcSocketStream socket_stream = stream; - - if (!SILC_IS_SOCKET_STREAM(socket_stream) && - !SILC_IS_SOCKET_STREAM_UDP(socket_stream)) - return FALSE; - - silc_schedule_unset_listen_fd(socket_stream->schedule, socket_stream->sock); - silc_net_close_connection(socket_stream->sock); - - return TRUE; -} - -/* Destroys the stream */ - -void silc_socket_stream_destroy(SilcStream stream) -{ - SilcSocketStream socket_stream = stream; - - if (!SILC_IS_SOCKET_STREAM(socket_stream) && - !SILC_IS_SOCKET_STREAM_UDP(socket_stream)) - return; - - silc_socket_stream_close(socket_stream); - silc_free(socket_stream->ip); - silc_free(socket_stream->hostname); - silc_schedule_task_del_by_fd(socket_stream->schedule, socket_stream->sock); - - if (socket_stream->qos) { - silc_schedule_task_del_by_context(socket_stream->schedule, - socket_stream->qos); - if (socket_stream->qos->buffer) { - memset(socket_stream->qos->buffer, 0, - socket_stream->qos->read_limit_bytes); - silc_free(socket_stream->qos->buffer); - } - silc_free(socket_stream->qos); - } - - silc_schedule_wakeup(socket_stream->schedule); - - silc_free(socket_stream); -} - -/* Sets stream notification callback for the stream */ - -void silc_socket_stream_notifier(SilcStream stream, - SilcSchedule schedule, - SilcStreamNotifier callback, - void *context) -{ - SilcSocketStream socket_stream = stream; - - if (!SILC_IS_SOCKET_STREAM(socket_stream) && - !SILC_IS_SOCKET_STREAM_UDP(socket_stream)) - return; - - SILC_LOG_DEBUG(("Setting stream notifier callback")); - - socket_stream->notifier = callback; - socket_stream->notifier_context = context; - socket_stream->schedule = schedule; - - if (socket_stream->notifier) { - /* Add the socket to scheduler. Safe to call if already added. */ - silc_schedule_task_add_fd(socket_stream->schedule, socket_stream->sock, - silc_socket_stream_io, socket_stream); - - /* Initially set socket for reading */ - silc_schedule_set_listen_fd(socket_stream->schedule, socket_stream->sock, - SILC_TASK_READ, FALSE); - silc_schedule_wakeup(socket_stream->schedule); - } else { - /* Unschedule the socket */ - silc_schedule_unset_listen_fd(socket_stream->schedule, - socket_stream->sock); - silc_schedule_task_del_by_fd(socket_stream->schedule, - socket_stream->sock); - silc_schedule_wakeup(socket_stream->schedule); - } -} - /* Return associated scheduler */ SilcSchedule silc_socket_stream_get_schedule(SilcStream stream) diff --git a/lib/silcutil/silcsocketstream.h b/lib/silcutil/silcsocketstream.h index e03c3255..560e7e0f 100644 --- a/lib/silcutil/silcsocketstream.h +++ b/lib/silcutil/silcsocketstream.h @@ -71,11 +71,12 @@ typedef enum { * Callback function of this type is called after the socket stream * creation is completed. If the `stream' is NULL the socket stream could * not be created or the socket connection is not otherwise allowed. The - * `status' will indicate the error status. The `stream' is socket stream - * representing the socket connection and silc_socket_stream_* functions - * can be used to access the stream. All other silc_stream_* functions - * can also be used to read data, send data, and otherwise handle the - * stream. + * `status' will indicate the error status. In case error ocurrs the + * associated socket has already been destroyed. The `stream' is socket + * stream representing the socket connection and silc_socket_stream_* + * functions can be used to access the stream. All other silc_stream_* + * functions can also be used to read data, send data, and otherwise + * handle the stream. * ***/ typedef void (*SilcSocketStreamCallback)(SilcSocketStreamStatus status, @@ -86,7 +87,7 @@ typedef void (*SilcSocketStreamCallback)(SilcSocketStreamStatus status, * SYNOPSIS * * SilcAsyncOperation - * silc_socket_tcp_stream_create(int sock, SilcBool lookup, + * silc_socket_tcp_stream_create(SilcSocket sock, SilcBool lookup, * SilcBool require_fqdn, * SilcSchedule schedule, * SilcSocketStreamCallback callback, @@ -113,7 +114,7 @@ typedef void (*SilcSocketStreamCallback)(SilcSocketStreamStatus status, * ***/ SilcAsyncOperation -silc_socket_tcp_stream_create(int sock, SilcBool lookup, +silc_socket_tcp_stream_create(SilcSocket sock, SilcBool lookup, SilcBool require_fqdn, SilcSchedule schedule, SilcSocketStreamCallback callback, @@ -123,7 +124,8 @@ silc_socket_tcp_stream_create(int sock, SilcBool lookup, * * SYNOPSIS * - * SilcStream silc_socket_udp_stream_create(int sock, SilcBool ipv6, + * SilcStream silc_socket_udp_stream_create(SilcSocket sock, + * SilcBool ipv6, * SilcBool connected, * SilcSchedule schedule); * @@ -151,7 +153,8 @@ silc_socket_tcp_stream_create(int sock, SilcBool lookup, * This function returns the created SilcStream or NULL on error. * ***/ -SilcStream silc_socket_udp_stream_create(int sock, SilcBool ipv6, +SilcStream silc_socket_udp_stream_create(SilcSocket sock, + SilcBool ipv6, SilcBool connected, SilcSchedule schedule); @@ -179,18 +182,18 @@ SilcBool silc_socket_stream_is_udp(SilcStream stream, SilcBool *connected); * * SilcBool * silc_socket_stream_get_info(SilcStream stream, - * int *sock, const char **hostname, + * SilcSocket *sock, const char **hostname, * const char **ip, SilcUInt16 *port); * * DESCRIPTION * - * Returns socket stream information such as the socket number, hostname, - * IP address and the port of the remote socket connection. Return FALSE - * if these informations are not available. + * Returns socket stream information such as the socket, remote hostname, + * remote IP address and the remote port of the remote socket connection. + * Return FALSE if these informations are not available. * ***/ SilcBool silc_socket_stream_get_info(SilcStream stream, - int *sock, const char **hostname, + SilcSocket *sock, const char **hostname, const char **ip, SilcUInt16 *port); /****f* silcutil/SilcSocketStreamAPI/silc_socket_stream_set_info diff --git a/lib/silcutil/silcsocketstream_i.h b/lib/silcutil/silcsocketstream_i.h index 73547ea2..50385df3 100644 --- a/lib/silcutil/silcsocketstream_i.h +++ b/lib/silcutil/silcsocketstream_i.h @@ -44,7 +44,7 @@ typedef struct SilcSocketQosStruct { struct SilcSocketStreamStruct { const SilcStreamOps *ops; SilcSchedule schedule; - int sock; + SilcSocket sock; char *hostname; char *ip; SilcUInt16 port; @@ -56,4 +56,10 @@ struct SilcSocketStreamStruct { unsigned int connected : 1; /* UDP connected state */ }; +#define SILC_IS_SOCKET_STREAM(s) (s->ops == &silc_socket_stream_ops) +#define SILC_IS_SOCKET_STREAM_UDP(s) (s->ops == &silc_socket_udp_stream_ops) + +extern const SilcStreamOps silc_socket_stream_ops; +extern const SilcStreamOps silc_socket_udp_stream_ops; + #endif /* SILCSOCKETSTREAM_I_H */ diff --git a/lib/silcutil/silcstrutil.c b/lib/silcutil/silcstrutil.c index db912fe3..5ba4c02e 100644 --- a/lib/silcutil/silcstrutil.c +++ b/lib/silcutil/silcstrutil.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2002 - 2006 Pekka Riikonen + Copyright (C) 2002 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -170,6 +170,15 @@ unsigned char *silc_pem_decode(unsigned char *pem, SilcUInt32 pem_len, return data; } +#ifndef HAVE_SNPRINTF +/* Outputs string according to the `format'. */ + +int silc_snprintf(char *str, SilcUInt32 size, const char *format, ...) +{ + +} +#endif /* HAVE_SNPRINTF */ + /* Concatenates the `src' into `dest'. If `src_len' is more than the size of the `dest' (minus NULL at the end) the `src' will be truncated to fit. */ diff --git a/lib/silcutil/silcstrutil.h b/lib/silcutil/silcstrutil.h index 0e20e98f..1fdc0fd1 100644 --- a/lib/silcutil/silcstrutil.h +++ b/lib/silcutil/silcstrutil.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2002 - 2006 Pekka Riikonen + Copyright (C) 2002 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -111,6 +111,26 @@ char *silc_pem_encode_file(unsigned char *data, SilcUInt32 data_len); unsigned char *silc_pem_decode(unsigned char *pem, SilcUInt32 pem_len, SilcUInt32 *ret_len); +/****f* silcutil/SilcStrStrUtilAPI/silc_snprintf + * + * SYNOPSIS + * + * int silc_snprintf(char *str, SilcUInt32 size, const char *format, ...); + * + * DESCRIPTION + * + * Produces output string according to the `format'. The formatting + * is equivalent to silc_snprintf(3) and sprintf(3). Returns the number of + * characters output into `str', at most `size' characters including the + * trailing '\0' character. Returns negative value on error. + * + ***/ +#ifndef SILC_SNPRINTF +int silc_snprintf(char *str, SilcUInt32 size, const char *format, ...); +#else +#define silc_snprintf snprintf +#endif /* SILC_SNPRINTF */ + /****f* silcutil/SilcStrStrUtilAPI/silc_strncat * * SYNOPSIS diff --git a/lib/silcutil/silctime.c b/lib/silcutil/silctime.c index 3f1abe7e..b2f84c3c 100644 --- a/lib/silcutil/silctime.c +++ b/lib/silcutil/silctime.c @@ -209,7 +209,7 @@ SilcBool silc_time_universal_string(SilcTime time_val, char *ret_string, { int ret, len = 0; memset(ret_string, 0, ret_string_size); - ret = snprintf(ret_string, ret_string_size - 1, + ret = silc_silc_snprintf(ret_string, ret_string_size - 1, "%02u%02u%02u%02u%02u%02u", time_val->year % 100, time_val->month, time_val->day, time_val->hour, time_val->minute, time_val->second); @@ -218,12 +218,12 @@ SilcBool silc_time_universal_string(SilcTime time_val, char *ret_string, len += ret; if (!time_val->utc_hour && !time_val->utc_minute) { - ret = snprintf(ret_string + len, ret_string_size - 1 - len, "Z"); + ret = silc_silc_snprintf(ret_string + len, ret_string_size - 1 - len, "Z"); if (ret < 0) return FALSE; len += ret; } else { - ret = snprintf(ret_string + len, ret_string_size - 1 - len, + ret = silc_silc_snprintf(ret_string + len, ret_string_size - 1 - len, "%c%02u%02u", time_val->utc_east ? '+' : '-', time_val->utc_hour, time_val->utc_minute); if (ret < 0) @@ -319,7 +319,7 @@ SilcBool silc_time_generalized_string(SilcTime time_val, char *ret_string, { int len = 0, ret; memset(ret_string, 0, ret_string_size); - ret = snprintf(ret_string, ret_string_size - 1, + ret = silc_silc_snprintf(ret_string, ret_string_size - 1, "%04u%02u%02u%02u%02u%02u", time_val->year, time_val->month, time_val->day, time_val->hour, time_val->minute, time_val->second); @@ -328,7 +328,7 @@ SilcBool silc_time_generalized_string(SilcTime time_val, char *ret_string, len += ret; if (time_val->msecond) { - ret = snprintf(ret_string + len, ret_string_size - 1 - len, + ret = silc_silc_snprintf(ret_string + len, ret_string_size - 1 - len, ".%lu", (unsigned long)time_val->msecond); if (ret < 0) return FALSE; @@ -336,12 +336,12 @@ SilcBool silc_time_generalized_string(SilcTime time_val, char *ret_string, } if (!time_val->utc_hour && !time_val->utc_minute) { - ret = snprintf(ret_string + len, ret_string_size - 1 - len, "Z"); + ret = silc_silc_snprintf(ret_string + len, ret_string_size - 1 - len, "Z"); if (ret < 0) return FALSE; len += ret; } else { - ret = snprintf(ret_string + len, ret_string_size - 1 - len, + ret = silc_silc_snprintf(ret_string + len, ret_string_size - 1 - len, "%c%02u%02u", time_val->utc_east ? '+' : '-', time_val->utc_hour, time_val->utc_minute); if (ret < 0) diff --git a/lib/silcutil/silctypes.h b/lib/silcutil/silctypes.h index 851bdd01..7500b1fb 100644 --- a/lib/silcutil/silctypes.h +++ b/lib/silcutil/silctypes.h @@ -275,6 +275,28 @@ typedef SilcInt32 SilcInt64; typedef SilcUInt32 * void *; #endif +/****d* silcutil/SILCTypes/SilcSocket + * + * NAME + * + * SilcSocket + * + * DESCRIPTION + * + * Platform specific socket. On POSIX compliant systems this is simply + * an integer, representing the socket. On other systems it is platform + * specific socket context. Access it only through routines that can + * handle SilcSocket types, unless you know what you are doing. + * + * SOURCE + */ +#if defined(SILC_UNIX) || defined(SILC_WIN32) +typedef int SilcSocket; +#elif defined(SILC_SYMBIAN) +typedef void * SilcSocket; +#endif +/***/ + /* Macros */ #define SILC_GET_WORD(cp) ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \ diff --git a/lib/silcutil/silcutf8.c b/lib/silcutil/silcutf8.c index 0ecc999c..29f74dc3 100644 --- a/lib/silcutil/silcutf8.c +++ b/lib/silcutil/silcutf8.c @@ -491,7 +491,7 @@ SilcUInt32 silc_utf8_decode(const unsigned char *utf8, SilcUInt32 utf8_len, if (enclen + 3 > bin_size) return 0; bin[enclen] = '\\'; - snprintf(bin + enclen + 1, 3, "%02X", cv); + silc_silc_snprintf(bin + enclen + 1, 3, "%02X", cv); } enclen += 3; continue; diff --git a/lib/silcutil/silcutil.c b/lib/silcutil/silcutil.c index c4122624..04b10363 100644 --- a/lib/silcutil/silcutil.c +++ b/lib/silcutil/silcutil.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2006 Pekka Riikonen + Copyright (C) 1997 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -236,7 +236,7 @@ char *silc_format(char *fmt, ...) memset(buf, 0, sizeof(buf)); va_start(args, fmt); - vsnprintf(buf, sizeof(buf) - 1, fmt, args); + vsilc_snprintf(buf, sizeof(buf) - 1, fmt, args); va_end(args); return strdup(buf); @@ -473,14 +473,14 @@ char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len) memset(fingerprint, 0, sizeof(fingerprint)); cp = fingerprint; for (i = 0; i < data_len; i++) { - snprintf(cp, sizeof(fingerprint), "%02X", data[i]); + silc_silc_snprintf(cp, sizeof(fingerprint), "%02X", data[i]); cp += 2; if ((i + 1) % 2 == 0) - snprintf(cp++, sizeof(fingerprint), " "); + silc_silc_snprintf(cp++, sizeof(fingerprint), " "); if ((i + 1) % 10 == 0) - snprintf(cp++, sizeof(fingerprint), " "); + silc_silc_snprintf(cp++, sizeof(fingerprint), " "); } i--; if ((i + 1) % 2 == 0) diff --git a/lib/silcutil/symbian/Makefile.am b/lib/silcutil/symbian/Makefile.am deleted file mode 100644 index 92e6b3ef..00000000 --- a/lib/silcutil/symbian/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ -# -# Makefile.am -# -# Author: Pekka Riikonen -# -# Copyright (C) 2002 Pekka Riikonen -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign - -include $(top_srcdir)/Makefile.defines.in diff --git a/lib/silcutil/symbian/silcepocsockconn.cpp b/lib/silcutil/symbian/silcepocsockconn.cpp deleted file mode 100644 index 7c71207e..00000000 --- a/lib/silcutil/symbian/silcepocsockconn.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - - silcepocsockconn.cpp - - Author: Pekka Riikonen - - Copyright (C) 2002 Pekka Riikonen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - -*/ -/* $Id$ */ - -#include "silcincludes.h" - -/* Writes data from encrypted buffer to the socket connection. If the - data cannot be written at once, it will be written later with a timeout. - The data is written from the data section of the buffer, not from head - or tail section. This automatically pulls the data section towards end - after writing the data. */ - -int silc_socket_write(SilcSocketConnection sock) -{ - /* XXX */ -} - -/* Reads data from the socket connection into the incoming data buffer. - It reads as much as possible from the socket connection. This returns - amount of bytes read or -1 on error or -2 on case where all of the - data could not be read at once. */ - -int silc_socket_read(SilcSocketConnection sock) -{ - /* XXX */ -} - -/* Returns human readable socket error message. These are copied from the - PuTTY. */ - -#define PUT_ERROR(s) -do { - if (strlen(s) > err_len) - return FALSE; - memset(error, 0, error_len); - memcpy(error, s, strlen(s)); - return TRUE; -} while(0) - -bool silc_socket_get_error(SilcSocketConnection sock, char *error, - SilcUInt32 error_len) -{ - if (sock->sock_error == KErrNone) - return FALSE; - - switch (sock->sock_error) { - case KErrNotFound: - PUT_ERROR("Item not found. (NotFound)"); - case KErrGeneral: - PUT_ERROR("Uncategorized error. (General)"); - case KErrCancel: - PUT_ERROR("Operation cancelled. (Cancel)"); - case KErrNoMemory: - PUT_ERROR("A memory allocation failed. (NoMemory)"); - case KErrNotSupported: - PUT_ERROR("A function is not supported in a given context. " - "(NotSupported)"); - case KErrArgument: - PUT_ERROR("An argument is out of range. (Argument)"); - case KErrBadHandle: - PUT_ERROR("Bad handle. (BadHandle)"); - case KErrOverflow: - PUT_ERROR("Overflow. (Overflow)"); - case KErrUnderflow: - PUT_ERROR("Underflow. (Underflow)"); - case KErrAlreadyExists: - PUT_ERROR("The resource already exists. (AlreadyExists)"); - case KErrPathNotFound: - PUT_ERROR("In the context of file operations, the path was " - "not found. (PathNotFound)"); - case KErrDied: - PUT_ERROR("A handle refers to a thread which has died (Died)"); - case KErrInUse: - PUT_ERROR("A requested resource is already in use. (InUse)"); - case KErrServerTerminated: - PUT_ERROR("A client/server operation cannot execute, because the " - "server has terminated. (ServerTerminated)"); - case KErrServerBusy: - PUT_ERROR("A client/server operation cannot execute, because the server " - "is busy. (ServerBusy)"); - case KErrNotReady: - PUT_ERROR("Resource not ready. Not initialized, or has no power. " - "(NotReady)"); - case KErrUnknown: - PUT_ERROR("A device is of unknown type. (Unknown)"); - case KErrCorrupt: - PUT_ERROR("Corrupted. (Corrupt)"); - case KErrAccessDenied: - PUT_ERROR("Access denied. (AccessDenied)"); - case KErrLocked: - PUT_ERROR("The operation cannot be performed, because the resource " - "is locked. (Locked)"); - case KErrWrite: - PUT_ERROR("During a file write operation, not all the data could " - "be written. (Write)"); - case KErrDisMounted: - PUT_ERROR("A volume which was to be used for a file system operation " - "has been dismounted. (DisMounted)"); - case KErrEof: - PUT_ERROR("End of file has been reached. (Eof)"); - case KErrDiskFull: - PUT_ERROR("A write operation could not complete, because the disk " - "was full. (DiskFull)"); - case KErrBadDriver: - PUT_ERROR("A driver DLL was of the wrong type. (BadDriver)"); - case KErrBadName: - PUT_ERROR("Name did not conform with the required syntax. (BadName)"); - case KErrCommsLineFail: - PUT_ERROR("The communication line failed. (CommsLineFail)"); - case KErrCommsFrame: - PUT_ERROR("A frame error occurred in a communications operation. " - "(CommsFrame)"); - case KErrCommsOverrun: - PUT_ERROR("An overrun was detected by a communications driver. " - "(CommsOverrun)"); - case KErrCommsParity: - PUT_ERROR("A parity error occurred in communications. (CommsParity)"); - case KErrTimedOut: - PUT_ERROR("An operation timed out. (TimedOut)"); - case KErrCouldNotConnect: - PUT_ERROR("A session could not connect. (CouldNotConnect)"); - case KErrCouldNotDisconnect: - PUT_ERROR("A session could not disconnect. (CouldNotDisconnect)"); - case KErrDisconnected: - PUT_ERROR("The required session was disconnected. (Disconnected)"); - case KErrBadLibraryEntryPoint: - PUT_ERROR("A library entry point was not of the required type. " - "(BadLibraryEntryPoint)"); - case KErrBadDescriptor: - PUT_ERROR("A non-descriptor parameter was passed. (BadDescriptor)"); - case KErrAbort: - PUT_ERROR("An operation was aborted (Abort)"); - case KErrTooBig: - PUT_ERROR("A number was too big (TooBig)"); - case KErrDivideByZero: - PUT_ERROR("A divide-by-zero operation was attempted. (DivideByZero)"); - case KErrBadPower: - PUT_ERROR("Insufficient power was available to complete an operation. " - "(BadPower)"); - case KErrWouldBlock: - PUT_ERROR("Network error: Resource temporarily unavailable (WouldBlock)"); - case KErrNetUnreach: - PUT_ERROR("Network unreachable. (NetUnreach)"); - case KErrHostUnreach: - PUT_ERROR("Host unreachable. (HostUnreach)"); - case KErrNoProtocolOpt: - PUT_ERROR("No such protocol option. (NoProtocolOpt)"); - case KErrUrgentData: - PUT_ERROR("Urgent data arrived. (UrgentData)"); - case KInvalSocket: - PUT_ERROR("Got NULL sokcet."); - } - - return FALSE; -} diff --git a/lib/silcutil/symbian/silcepocthread.cpp b/lib/silcutil/symbian/silcepocthread.cpp deleted file mode 100644 index 12ad59cf..00000000 --- a/lib/silcutil/symbian/silcepocthread.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - - silcepocthread.cpp - - Author: Pekka Riikonen - - Copyright (C) 2002 Pekka Riikonen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - -*/ -/* $Id$ */ - -#include "silcincludes.h" - -#ifdef SILC_THREADS - -/* Thread structure for EPOC */ -typedef struct { - RThread *thread; - SilcThreadStart start_func; - void *context; - bool waitable; -} *SilcEpocThread; - -/* The actual thread function */ - -TInt silc_thread_epoc_start(TAny *context) -{ - SilcEpocThread thread = (SilcEpocThread)context; - - thread->start_func(thread->context); - silc_thread_exit(NULL); - - return 0; -} - -SilcThread silc_thread_create(SilcThreadStart start_func, void *context, - bool waitable) -{ -#ifdef SILC_THREADS - SilcEpocThread thread; - TInt ret; - - SILC_LOG_DEBUG(("Creating new thread")); - - thread = silc_calloc(1, sizeof(*thread)); - thread->start_func = start_func; - thread->context = context; - thread->waitable = waitable; - - /* Create the thread */ - /* XXX Unique name should be given for the thread */ - thread->thread = new RThread(); - ret = thread->thread->Create(NULL, silc_thread_epoc_start, 0, 0, 0, - (TAny *)thread, EOwnerProcess); - if (ret != KErrNone) { - SILC_LOG_ERROR(("Could not create new thread")); - delete thread->thread; - silc_free(thread); - return NULL; - } - - return (SilcThread)thread; -#else - /* Call thread callback immediately */ - (*start_func)(context); - return NULL; -#endif -} - -void silc_thread_exit(void *exit_value) -{ -#ifdef SILC_THREADS - /* XXX */ -#endif -} - -SilcThread silc_thread_self(void) -{ -#ifdef SILC_THREADS - /* XXX */ - return NULL; -#else - return NULL; -#endif -} - -bool silc_thread_wait(SilcThread thread, void **exit_value) -{ -#ifdef SILC_THREADS - /* XXX */ - return TRUE; -#else - return FALSE; -#endif -} diff --git a/lib/silcutil/symbian/silcepocutil.cpp b/lib/silcutil/symbian/silcepocutil.cpp deleted file mode 100644 index b43eda90..00000000 --- a/lib/silcutil/symbian/silcepocutil.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - - silcepocutil.cpp - - Author: Pekka Riikonen - - Copyright (C) 2002 Pekka Riikonen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - -*/ -/* $Id$ */ - -#include "silcincludes.h" - -/* XXX TODO or use GNU regex if it compiles */ -char *silc_string_regexify(const char *string) -{ - return strdup(string); -} - -char *silc_string_regex_combine(const char *string1, const char *string2) -{ - return strdup(string1); -} - -int silc_string_regex_match(const char *regex, const char *string) -{ - return TRUE; -} - -int silc_string_match(const char *string1, const char *string2) -{ - return TRUE; -} - -/* Return current time to struct timeval. */ - -int silc_gettimeofday(struct timeval *p) -{ - return gettimeofday(p, NULL); -} diff --git a/lib/silcutil/symbian/silcsymbiannet.cpp b/lib/silcutil/symbian/silcsymbiannet.cpp new file mode 100644 index 00000000..f2ae993d --- /dev/null +++ b/lib/silcutil/symbian/silcsymbiannet.cpp @@ -0,0 +1,744 @@ +/* + + silcsymbiannet.cpp + + Author: Pekka Riikonen + + Copyright (C) 2006 Pekka Riikonen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +#include "silc.h" +#include "silcsymbiansocketstream.h" + +/****************************** TCP Listener ********************************/ + +class SilcSymbianTCPListener; + +/* Deliver new stream to upper layer */ + +static void silc_net_accept_stream(SilcSocketStreamStatus status, + SilcStream stream, void *context) +{ + SilcNetListener listener = (SilcNetListener)context; + + /* In case of error, the socket has been destroyed already */ + if (status != SILC_SOCKET_OK) + return; + + listener->callback(SILC_NET_OK, stream, listener->context); +} + +/* TCP Listener class */ + +class SilcSymbianTCPListener : public CActive { +public: + /* Constructor */ + SilcSymbianTCPListener() : CActive(CActive::EPriorityStandard) + { + CActiveScheduler::Add(this); + } + + /* Destructor */ + ~SilcSymbianTCPListener() + { + Cancel(); + } + + /* Listen for connection */ + void Listen() + { + new_conn = new RSocket; + if (!new_conn) + return; + User::LeaveIfError(new_conn->Open(ss)); + + /* Start listenning */ + sock.Accept(*new_conn, iStatus); + SetActive(); + } + + /* Listener callback */ + void RunL() + { + if (iStatus != KErrNone) { + if (new_conn) + delete new_conn; + new_conn = NULL; + Listen(); + return; + } + + /* Set socket options */ + new_conn->SetOpt(KSoReuseAddr, KSolInetIp, 1); + + /* Create socket stream */ + silc_socket_tcp_stream_create( + (SilcSocket)silc_create_symbian_socket(new_conn, NULL), + listener->lookup, listener->require_fqdn, + listener->schedule, silc_net_accept_stream, + (void *)listener); + + /* Continue listenning */ + Listen(); + } + + /* Cancel */ + void DoCancel() + { + sock.CancelAll(); + ss.Close(); + if (new_conn) + delete new_conn; + } + + RSocket *new_conn; + RSocket sock; + RSocketServ ss; + SilcNetListener listener; +}; + +/* Create TCP listener */ + +SilcNetListener +silc_net_tcp_create_listener(const char **local_ip_addr, + SilcUInt32 local_ip_count, int port, + SilcBool lookup, SilcBool require_fqdn, + SilcSchedule schedule, + SilcNetCallback callback, void *context) +{ + SilcNetListener listener = NULL; + SilcSymbianTCPListener *l = NULL; + TInetAddr server; + TInt ret; + TBuf<64> tmp; + int i; + + SILC_LOG_DEBUG(("Creating TCP listener")); + + if (port < 0 || !schedule || !callback) + goto err; + + listener = (SilcNetListener)silc_calloc(1, sizeof(*listener)); + if (!listener) { + callback(SILC_NET_NO_MEMORY, NULL, context); + return NULL; + } + listener->schedule = schedule; + listener->callback = callback; + listener->context = context; + listener->require_fqdn = require_fqdn; + listener->lookup = lookup; + + if (local_ip_count > 0) { + listener->socks = (SilcSocket *)silc_calloc(local_ip_count, + sizeof(*listener->socks)); + if (!listener->socks) { + callback(SILC_NET_NO_MEMORY, NULL, context); + return NULL; + } + } else { + listener->socks = (SilcSocket *)silc_calloc(1, sizeof(*listener->socks)); + if (!listener->socks) { + callback(SILC_NET_NO_MEMORY, NULL, context); + return NULL; + } + + local_ip_count = 1; + } + + /* Bind to local addresses */ + for (i = 0; i < local_ip_count; i++) { + SILC_LOG_DEBUG(("Binding to local address %s", + local_ip_addr ? local_ip_addr[i] : "0.0.0.0")); + + l = new SilcSymbianTCPListener; + if (!l) + goto err; + + /* Connect to socket server */ + ret = l->ss.Connect(); + if (ret != KErrNone) + goto err; + + /* Set listener address */ + if (local_ip_addr) { + server = TInetAddr(port); + tmp = (TText *)local_ip_addr[i]; + ret = server.Input(tmp); + if (ret != KErrNone) + goto err; + } else { + server = TInetAddr(KInetAddrAny, port); + } + + /* Create the socket */ + ret = l->sock.Open(l->ss, KAfInet, KSockStream, KProtocolInetTcp); + if (ret != KErrNone) { + SILC_LOG_ERROR(("Cannot create socket")); + goto err; + } + + /* Set the socket options */ + ret = l->sock.SetOpt(KSoReuseAddr, KSolInetIp, 1); + if (ret != KErrNone) { + SILC_LOG_ERROR(("Cannot set socket options")); + goto err; + } + + /* Bind the listener socket */ + ret = l->sock.Bind(server); + if (ret != KErrNone) { + SILC_LOG_DEBUG(("Cannot bind socket")); + goto err; + } + + /* Specify that we are listenning */ + ret = l->sock.Listen(5); + if (ret != KErrNone) { + SILC_LOG_ERROR(("Cannot set socket listenning")); + goto err; + } + l->Listen(); + + l->listener = listener; + listener->socks[i] = (SilcSocket)l; + listener->socks_count++; + } + + SILC_LOG_DEBUG(("TCP listener created")); + + return listener; + + err: + if (l) + delete l; + if (callback) + callback(SILC_NET_ERROR, NULL, context); + if (listener) + silc_net_close_listener(listener); + return NULL; +} + +/* Close network listener */ + +void silc_net_close_listener(SilcNetListener listener) +{ + int i; + + SILC_LOG_DEBUG(("Closing network listener")); + + for (i = 0; i < listener->socks_count; i++) { + SilcSymbianTCPListener *l = (SilcSymbianTCPListener *)listener->socks[i]; + l->sock.CancelAll(); + l->sock.Close(); + l->ss.Close(); + if (l->new_conn) + delete l->new_conn; + delete l; + } + + silc_free(listener->socks); + silc_free(listener); +} + +/**************************** TCP/IP connecting *****************************/ + +static void silc_net_connect_stream(SilcSocketStreamStatus status, + SilcStream stream, void *context); + +/* TCP connecting class */ + +class SilcSymbianTCPConnect : public CActive { +public: + /* Constructor */ + SilcSymbianTCPConnect() : CActive(CActive::EPriorityStandard) + { + CActiveScheduler::Add(this); + } + + /* Destructor */ + ~SilcSymbianTCPConnect() + { + silc_free(remote); + if (op) + silc_async_free(op); + Cancel(); + } + + /* Connect to remote host */ + void Connect(TSockAddr &addr) + { + sock->Connect(addr, iStatus); + SetActive(); + } + + /* Connection callback */ + void RunL() + { + if (iStatus != KErrNone) { + if (callback) + callback(SILC_NET_ERROR, NULL, context); + sock->CancelConnect(); + delete sock; + ss->Close(); + delete ss; + delete this; + } + + /* Create stream */ + if (callback) { + silc_socket_tcp_stream_create( + (SilcSocket)silc_create_symbian_socket(sock, ss), + FALSE, FALSE, schedule, silc_net_connect_stream, + (void *)this); + } else { + sock->Close(); + delete sock; + ss->Close(); + delete ss; + } + + delete this; + } + + /* Cancel */ + void DoCancel() + { + sock->CancelConnect(); + ss->Close(); + delete ss; + delete sock; + delete this; + } + + RSocket *sock; + RSocketServ *ss; + char *remote; + char remote_ip[64]; + int port; + SilcAsyncOperation op; + SilcSchedule schedule; + SilcNetCallback callback; + void *context; +}; + +/* Stream creation callback */ + +static void silc_net_connect_stream(SilcSocketStreamStatus status, + SilcStream stream, void *context) +{ + SilcSymbianTCPConnect *conn = (SilcSymbianTCPConnect *)context; + SilcNetStatus net_status = SILC_NET_OK; + + if (status != SILC_SOCKET_OK) { + /* In case of error, the socket has been destroyed already */ + if (status == SILC_SOCKET_UNKNOWN_IP) + net_status = SILC_NET_UNKNOWN_IP; + else if (status == SILC_SOCKET_UNKNOWN_HOST) + net_status = SILC_NET_UNKNOWN_HOST; + else + net_status = SILC_NET_ERROR; + } + + /* Set stream information */ + if (stream && conn->callback) + silc_socket_stream_set_info(stream, + !silc_net_is_ip(conn->remote) ? conn->remote : + conn->remote_ip, conn->remote_ip, conn->port); + + /* Call connection callback */ + if (conn->callback) + conn->callback(net_status, stream, conn->context); + else if (stream) + silc_stream_destroy(stream); + + delete conn; +} + +/* Connecting abort callback */ + +static void silc_net_connect_abort(SilcAsyncOperation op, void *context) +{ + SilcSymbianTCPConnect *conn = (SilcSymbianTCPConnect *)context; + + /* Abort */ + conn->callback = NULL; + conn->op = NULL; + conn->DoCancel(); +} + +/* Create TCP/IP connection */ + +SilcAsyncOperation silc_net_tcp_connect(const char *local_ip_addr, + const char *remote_ip_addr, + int remote_port, + SilcSchedule schedule, + SilcNetCallback callback, + void *context) +{ + SilcSymbianTCPConnect *conn; + TInetAddr local, remote; + SilcNetStatus status; + TBuf<64> tmp; + TInt ret; + + if (!remote_ip_addr || remote_port < 1 || !schedule || !callback) + return NULL; + + SILC_LOG_DEBUG(("Creating connection to host %s port %d", + remote_ip_addr, remote_port)); + + conn = new SilcSymbianTCPConnect; + if (!conn) { + callback(SILC_NET_NO_MEMORY, NULL, context); + return NULL; + } + conn->schedule = schedule; + conn->callback = callback; + conn->context = context; + conn->port = remote_port; + conn->remote = strdup(remote_ip_addr); + if (!conn->remote) { + status = SILC_NET_NO_MEMORY; + goto err; + } + + /* Allocate socket */ + conn->sock = new RSocket; + if (!conn->sock) { + status = SILC_NET_NO_MEMORY; + goto err; + } + + /* Allocate socket server */ + conn->ss = new RSocketServ; + if (!conn->ss) { + status = SILC_NET_NO_MEMORY; + goto err; + } + + /* Connect to socket server */ + ret = conn->ss->Connect(); + if (ret != KErrNone) { + status = SILC_NET_ERROR; + goto err; + } + + /* Start async operation */ + conn->op = silc_async_alloc(silc_net_connect_abort, NULL, (void *)conn); + if (!conn->op) { + status = SILC_NET_NO_MEMORY; + goto err; + } + + /* Do host lookup */ + if (!silc_net_is_ip(remote_ip_addr)) { + if (!silc_net_gethostbyname(remote_ip_addr, FALSE, conn->remote_ip, + sizeof(conn->remote_ip))) { + SILC_LOG_ERROR(("Network (%s) unreachable: could not resolve the " + "host", conn->remote)); + status = SILC_NET_HOST_UNREACHABLE; + goto err; + } + } else { + strcpy(conn->remote_ip, remote_ip_addr); + } + + /* Create the connection socket */ + ret = conn->sock->Open(*conn->ss, KAfInet, KSockStream, KProtocolInetTcp); + if (ret != KErrNone) { + SILC_LOG_ERROR(("Cannot create socket")); + status = SILC_NET_ERROR; + goto err; + } + + /* Set appropriate options */ + conn->sock->SetOpt(KSoTcpNoDelay, KSolInetTcp, 1); + conn->sock->SetOpt(KSoTcpKeepAlive, KSolInetTcp, 1); + + /* Bind to the local address if provided */ + if (local_ip_addr) { + local = TInetAddr(0); + tmp = (TText *)local_ip_addr; + ret = local.Input(tmp); + if (ret == KErrNone) + ret = conn->sock->Bind(local); + } + + /* Connect to the host */ + remote = TInetAddr(remote_port); + tmp = (TText *)conn->remote_ip; + ret = remote.Input(tmp); + if (ret != KErrNone) { + SILC_LOG_ERROR(("Cannot connect (cannot set address)")); + status = SILC_NET_ERROR; + goto err; + } + conn->Connect(remote); + + SILC_LOG_DEBUG(("Connection operation in progress")); + + return conn->op; + + err: + if (conn->ss) { + conn->ss->Close(); + delete conn->ss; + } + if (conn->sock) + delete conn->sock; + if (conn->remote) + silc_free(conn->remote); + if (conn->op) + silc_async_free(conn->op); + callback(status, NULL, context); + delete conn; + return NULL; +} + +/****************************** UDP routines ********************************/ + +/* Create UDP/IP connection */ + +SilcStream silc_net_udp_connect(const char *local_ip_addr, int local_port, + const char *remote_ip_addr, int remote_port, + SilcSchedule schedule) +{ + SilcSymbianSocket *s; + SilcStream stream; + TInetAddr local, remote; + TRequestStatus status; + RSocket *sock = NULL; + RSocketServ *ss = NULL; + TBuf<64> tmp; + TInt ret; + + SILC_LOG_DEBUG(("Creating UDP stream")); + + if (!schedule) + goto err; + + SILC_LOG_DEBUG(("Binding to local address %s", + local_ip_addr ? local_ip_addr : "0.0.0.0")); + + sock = new RSocket; + if (!sock) + goto err; + + ss = new RSocketServ; + if (!ss) + goto err; + + /* Open socket server */ + ret = ss->Connect(); + if (ret != KErrNone) + goto err; + + /* Get local bind address */ + if (local_ip_addr) { + local = TInetAddr(local_port); + tmp = (TText *)local_ip_addr; + ret = local.Input(tmp); + if (ret != KErrNone) + goto err; + } else { + local = TInetAddr(KInetAddrAny, local_port); + } + + /* Create the socket */ + ret = sock->Open(*ss, KAfInet, KSockDatagram, KProtocolInetUdp); + if (ret != KErrNone) { + SILC_LOG_ERROR(("Cannot create socket")); + goto err; + } + + /* Set the socket options */ + sock->SetOpt(KSoReuseAddr, KSolInetIp, 1); + + /* Bind the listener socket */ + ret = sock->Bind(local); + if (ret != KErrNone) { + SILC_LOG_DEBUG(("Cannot bind socket")); + goto err; + } + + /* Set to connected state if remote address is provided. */ + if (remote_ip_addr && remote_port) { + remote = TInetAddr(remote_port); + tmp = (TText *)remote_ip_addr; + ret = remote.Input(tmp); + if (ret != KErrNone) + goto err; + + sock->Connect(remote, status); + if (status != KErrNone) { + SILC_LOG_DEBUG(("Cannot connect UDP stream")); + goto err; + } + } + + /* Encapsulate into socket stream */ + s = silc_create_symbian_socket(sock, ss); + if (!s) + goto err; + stream = + silc_socket_udp_stream_create((SilcSocket)s, local_ip_addr ? + silc_net_is_ip6(local_ip_addr) : FALSE, + remote_ip_addr ? TRUE : FALSE, schedule); + if (!stream) + goto err; + + SILC_LOG_DEBUG(("UDP stream created, fd=%d", sock)); + return stream; + + err: + if (sock) + delete sock; + if (ss) { + ss->Close(); + delete ss; + } + return NULL; +} + +/* Sets socket to non-blocking mode */ + +int silc_net_set_socket_nonblock(SilcSocket sock) +{ + /* Nothing to do in Symbian where blocking socket mode is asynchronous + already (ie. non-blocking). */ + return 0; +} + +/* Converts the IP number string from numbers-and-dots notation to + binary form. */ + +SilcBool silc_net_addr2bin(const char *addr, void *bin, SilcUInt32 bin_len) +{ + int ret = 0; + + struct in_addr tmp; + ret = inet_aton(addr, &tmp); + if (bin_len < 4) + return FALSE; + + memcpy(bin, (unsigned char *)&tmp.s_addr, 4); + + return ret != 0; +} + +/* Get remote host and IP from socket */ + +SilcBool silc_net_check_host_by_sock(SilcSocket sock, char **hostname, + char **ip) +{ + SilcSymbianSocket *s = (SilcSymbianSocket *)sock; + TInetAddr addr; + char host[256]; + TBuf<64> tmp; + + if (hostname) + *hostname = NULL; + *ip = NULL; + + s->sock->RemoteName(addr); + addr.Output(tmp); + + *ip = (char *)silc_memdup(tmp.Ptr(), tmp.Length()); + if (*ip == NULL) + return FALSE; + + /* Do reverse lookup if we want hostname too. */ + if (hostname) { + /* Get host by address */ + if (!silc_net_gethostbyaddr(*ip, host, sizeof(host))) + return FALSE; + + *hostname = (char *)silc_memdup(host, strlen(host)); + SILC_LOG_DEBUG(("Resolved hostname `%s'", *hostname)); + + /* Reverse */ + if (!silc_net_gethostbyname(*hostname, TRUE, host, sizeof(host))) + return FALSE; + + if (strcmp(*ip, host)) + return FALSE; + } + + SILC_LOG_DEBUG(("Resolved IP address `%s'", *ip)); + return TRUE; +} + +/* Get local host and IP from socket */ + +SilcBool silc_net_check_local_by_sock(SilcSocket sock, char **hostname, + char **ip) +{ + SilcSymbianSocket *s = (SilcSymbianSocket *)sock; + TInetAddr addr; + char host[256]; + TBuf<64> tmp; + + if (hostname) + *hostname = NULL; + *ip = NULL; + + s->sock->LocalName(addr); + addr.Output(tmp); + + *ip = (char *)silc_memdup(tmp.Ptr(), tmp.Length()); + if (*ip == NULL) + return FALSE; + + /* Do reverse lookup if we want hostname too. */ + if (hostname) { + /* Get host by address */ + if (!silc_net_gethostbyaddr(*ip, host, sizeof(host))) + return FALSE; + + *hostname = (char *)silc_memdup(host, strlen(host)); + SILC_LOG_DEBUG(("Resolved hostname `%s'", *hostname)); + + /* Reverse */ + if (!silc_net_gethostbyname(*hostname, TRUE, host, sizeof(host))) + return FALSE; + + if (strcmp(*ip, host)) + return FALSE; + } + + SILC_LOG_DEBUG(("Resolved IP address `%s'", *ip)); + return TRUE; +} + +/* Get remote port from socket */ + +SilcUInt16 silc_net_get_remote_port(SilcSocket sock) +{ + SilcSymbianSocket *s = (SilcSymbianSocket *)sock; + TInetAddr addr; + + s->sock->RemoteName(addr); + return (SilcUInt16)addr.Port(); +} + +/* Get local port from socket */ + +SilcUInt16 silc_net_get_local_port(SilcSocket sock) +{ + SilcSymbianSocket *s = (SilcSymbianSocket *)sock; + TInetAddr addr; + + s->sock->LocalName(addr); + return (SilcUInt16)addr.Port(); +} diff --git a/lib/silcutil/symbian/silcsymbianscheduler.cpp b/lib/silcutil/symbian/silcsymbianscheduler.cpp new file mode 100644 index 00000000..bf3ee235 --- /dev/null +++ b/lib/silcutil/symbian/silcsymbianscheduler.cpp @@ -0,0 +1,109 @@ +/* + + silcsymbianschduler.cpp + + Author: Pekka Riikonen + + Copyright (C) 1998 - 2006 Pekka Riikonen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +/* On symbian the SILC Scheduler doesn't do anything. All timeout tasks + are dispatched by the generic scheduler implementation. Sockets and + file descriptors are dispatched automatically in their class + implementation, so adding FD Tasks on Symbian doesn't do anything. + + This also means that on Symbian the SILC Scheduler always returns + immediately. Because FD tasks use the Symbian scheduler the performance + is as good as it can be. For timeout tasks the performance is not an + issue. */ + +#include "silc.h" + +int silc_poll(SilcSchedule schedule, void *context) +{ + /* Return immediately, timeout. */ + return 0; +} + +SilcBool silc_schedule_internal_schedule_fd(SilcSchedule schedule, + void *context, + SilcTaskFd task, + SilcTaskEvent event_mask) +{ + /* Nothing to do */ + return TRUE; +} + +void *silc_schedule_internal_init(SilcSchedule schedule, + void *app_context) +{ + /* Nothing to do */ + return NULL; +} + + +void silc_schedule_internal_uninit(SilcSchedule schedule, void *context) +{ + /* Nothing to do */ +} + +void silc_schedule_internal_wakeup(SilcSchedule schedule, void *context) +{ + /* Nothing to do */ +} + +void silc_schedule_internal_signal_register(SilcSchedule schedule, + void *context, + SilcUInt32 sig, + SilcTaskCallback callback, + void *callback_context) +{ + /* Nothing to do */ +} + +void silc_schedule_internal_signal_unregister(SilcSchedule schedule, + void *context, + SilcUInt32 sig) +{ + /* Nothing to do */ +} + +void silc_schedule_internal_signals_call(SilcSchedule schedule, void *context) +{ + /* Nothing to do */ +} + +void silc_schedule_internal_signals_block(SilcSchedule schedule, void *context) +{ + /* Nothing to do */ +} + +void silc_schedule_internal_signals_unblock(SilcSchedule schedule, + void *context) +{ + /* Nothing to do */ +} + +const SilcScheduleOps schedule_ops = +{ + silc_schedule_internal_init, + silc_schedule_internal_uninit, + silc_poll, + silc_schedule_internal_schedule_fd, + silc_schedule_internal_wakeup, + silc_schedule_internal_signal_register, + silc_schedule_internal_signal_unregister, + silc_schedule_internal_signals_call, + silc_schedule_internal_signals_block, + silc_schedule_internal_signals_unblock, +}; diff --git a/lib/silcutil/symbian/silcsymbiansocketstream.cpp b/lib/silcutil/symbian/silcsymbiansocketstream.cpp new file mode 100644 index 00000000..fe9d57d6 --- /dev/null +++ b/lib/silcutil/symbian/silcsymbiansocketstream.cpp @@ -0,0 +1,421 @@ + +/* + + silcsymbiansocketstream.cpp + + Author: Pekka Riikonen + + Copyright (C) 2006 Pekka Riikonen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +/* In this implementation the sockets are in blocking mode, except that + on Symbian the blocking mode is actually asynchronous, which semantically + translates into non-blocking mode. The non-blocking mode just is not + explicitly set because it would require us also to explicitly poll for the + socket, which is done automatically by the Active Scheduler in blocking + mode. */ + +#include "silc.h" +#include "silcsymbiansocketstream.h" + +/***************************** Socket Classes *******************************/ + +/* Socket stream sender */ + +class SilcSymbianSocketSend : public CActive { +public: + /* Constructor */ + SilcSymbianSocketSend() : CActive(CActive::EPriorityStandard) + { + CActiveScheduler::Add(this); + } + + /* Destructor */ + ~SilcSymbianSocketSend() + { + Cancel(); + } + + /* Send data */ + void Send(const TDesC8& buf, TSockXfrLength& ret_len) + { + s->sock->Send(buf, 0, iStatus, ret_len); + SetActive(); + } + + /* Send data */ + void Send(const TDesC8& buf, TSockXfrLength& ret_len, + const char *remote_ip, int remote_port) + { + TInetAddr remote; + TBuf<64> tmp; + + remote = TInetAddr(remote_port); + tmp = (TText *)remote_ip; + if (remote.Input(tmp) == KErrNone) { + s->sock->SendTo(buf, remote, 0, iStatus, ret_len); + SetActive(); + } + } + + /* Sending callback */ + void RunL() + { + if (iStatus != KErrNone) { + if (iStatus == KErrEof) + s->eof = 1; + else + s->error = 1; + return; + } + + /* Call stream callback */ + if (s->stream && s->stream->notifier) + s->stream->notifier(s->stream, SILC_STREAM_CAN_WRITE, + s->stream->notifier_context); + } + + /* Cancel */ + void DoCancel() + { + s->sock->CancelWrite(); + } + + SilcSymbianSocket *s; +}; + +/* Socket stream receiver */ + +class SilcSymbianSocketReceive : public CActive { +public: + /* Constructor */ + SilcSymbianSocketReceive() : CActive(CActive::EPriorityStandard) + { + CActiveScheduler::Add(this); + } + + /* Destructor */ + ~SilcSymbianSocketReceive() + { + Cancel(); + } + + /* Read data */ + void Read() + { + if (!s->stream || s->stream->connected) + s->sock->RecvOneOrMore(inbuf, 0, iStatus, inbuf_len); + else + s->sock->RecvFrom(inbuf, remote, 0, iStatus); + SetActive(); + } + + /* Reading callback */ + void RunL() + { + if (iStatus != KErrNone) { + if (iStatus == KErrEof) + s->eof = 1; + else + s->error = 1; + return; + } + + if (!inbuf_ptr) + inbuf_ptr = inbuf.Ptr(); + inbuf_len = inbuf.Length(); + + /* Call stream callback */ + if (s->stream && s->stream->notifier) + s->stream->notifier(s->stream, SILC_STREAM_CAN_READ, + s->stream->notifier_context); + + /* Read more */ + Read(); + } + + /* Cancel */ + void DoCancel() + { + s->sock->CancelRecv(); + } + + TBuf8<8192> inbuf; + const unsigned char *inbuf_ptr; + TSockXfrLength inbuf_len; + SilcSymbianSocket *s; + TInetAddr remote; +}; + +/* Creates symbian socket stream context */ + +SilcSymbianSocket *silc_create_symbian_socket(RSocket *sock, + RSocketServ *ss) +{ + SilcSymbianSocket *stream; + + stream = (SilcSymbianSocket *)silc_calloc(1, sizeof(*stream)); + if (!stream) + return NULL; + stream->sock = sock; + stream->ss = ss; + + stream->send = new SilcSymbianSocketSend; + if (!stream->send) { + silc_free(stream); + return NULL; + } + + stream->receive = new SilcSymbianSocketReceive; + if (!stream->receive) { + delete stream->send; + silc_free(stream); + return NULL; + } + + return stream; +} + +/***************************** SILC Stream API ******************************/ + +/* Stream read operation */ + +int silc_socket_stream_read(SilcStream stream, unsigned char *buf, + SilcUInt32 buf_len) +{ + SilcSocketStream socket_stream = (SilcSocketStream)stream; + SilcSymbianSocket *s = (SilcSymbianSocket *)socket_stream->sock; + SilcSymbianSocketReceive *recv = s->receive; + int len; + + if (s->error || !s->stream) + return -2; + if (s->eof) + return 0; + if (!recv->inbuf_len() || !recv->inbuf_ptr) + return -1; + + len = recv->inbuf_len(); + if (buf_len < len) + len = buf_len; + + /* Copy the read data */ + memcpy(buf, recv->inbuf_ptr, len); + + recv->inbuf_ptr = NULL; + if (len < recv->inbuf_len()) + recv->inbuf_ptr += len; + + return len; +} + +/* Stream write operation */ + +int silc_socket_stream_write(SilcStream stream, const unsigned char *data, + SilcUInt32 data_len) +{ + SilcSocketStream socket_stream = (SilcSocketStream)stream; + SilcSymbianSocket *s = (SilcSymbianSocket *)socket_stream->sock; + SilcSymbianSocketSend *send = s->send; + TSockXfrLength ret_len; + TPtrC8 write_buf(data, data_len); + + if (s->would_block) + return -1; + if (s->error || !s->stream) + return -2; + if (s->eof) + return 0; + + /* Send data */ + send->Send(write_buf, ret_len); + if (send->iStatus.Int() != KErrNone) { + if (send->iStatus.Int() == KErrEof) + return 0; + return -2; + } + + if (!ret_len()) + return -1; + + s->would_block = 0; + if (ret_len() < data_len) + s->would_block = 1; + + return ret_len(); +} + +/* Receive UDP packet, connected socket. */ + +int silc_socket_udp_stream_read(SilcStream stream, unsigned char *buf, + SilcUInt32 buf_len) +{ + return silc_net_udp_receive(stream, NULL, 0, NULL, buf, buf_len); +} + +/* Send UDP packet, connected socket. */ + +int silc_socket_udp_stream_write(SilcStream stream, const unsigned char *data, + SilcUInt32 data_len) +{ + SilcSocketStream sock = (SilcSocketStream)stream; + + /* In connectionless state check if remote IP and port is provided */ + if (!sock->connected && sock->ip && sock->port) + return silc_net_udp_send(stream, sock->ip, sock->port, data, data_len); + + /* In connected state use normal writing to socket. */ + return silc_socket_stream_write(stream, data, data_len); +} + +/* Receive UDP packet, connectionless socket */ + +int silc_net_udp_receive(SilcStream stream, char *remote_ip_addr, + SilcUInt32 remote_ip_addr_size, int *remote_port, + unsigned char *buf, SilcUInt32 buf_len) +{ + SilcSocketStream socket_stream = (SilcSocketStream)stream; + SilcSymbianSocket *s = (SilcSymbianSocket *)socket_stream->sock; + SilcSymbianSocketReceive *recv = s->receive; + int len; + + if (s->eof) + return 0; + if (!recv->inbuf_len() || !recv->inbuf_ptr) + return -1; + + len = recv->inbuf_len(); + if (buf_len < len) + len = buf_len; + + /* Copy the read data */ + memcpy(buf, recv->inbuf_ptr, len); + + recv->inbuf_ptr = NULL; + if (len < recv->inbuf_len()) + recv->inbuf_ptr += len; + + if (remote_ip_addr && remote_ip_addr_size && remote_port) { + TBuf<64> ip; + recv->remote.Output(ip); + silc_strncat(remote_ip_addr, remote_ip_addr_size, (const char *)ip.Ptr(), + ip.Length()); + *remote_port = recv->remote.Port(); + } + + return len; +} + +/* Send UDP packet, connectionless socket */ + +int silc_net_udp_send(SilcStream stream, + const char *remote_ip_addr, int remote_port, + const unsigned char *data, SilcUInt32 data_len) +{ + SilcSocketStream socket_stream = (SilcSocketStream)stream; + SilcSymbianSocket *s = (SilcSymbianSocket *)socket_stream->sock; + SilcSymbianSocketSend *send = s->send; + TSockXfrLength ret_len; + TPtrC8 write_buf(data, data_len); + + if (s->would_block) + return -1; + if (s->eof) + return 0; + + /* Send data */ + send->Send(write_buf, ret_len, remote_ip_addr, remote_port); + if (send->iStatus.Int() != KErrNone) { + if (send->iStatus.Int() == KErrEof) + return 0; + return -2; + } + + if (!ret_len()) + return -1; + + s->would_block = 0; + if (ret_len() < data_len) + s->would_block = 1; + + return ret_len(); +} + +/* Closes socket */ + +SilcBool silc_socket_stream_close(SilcStream stream) +{ + SilcSocketStream socket_stream = (SilcSocketStream)stream; + SilcSymbianSocket *s; + + if (!SILC_IS_SOCKET_STREAM(socket_stream) && + !SILC_IS_SOCKET_STREAM_UDP(socket_stream)) + return FALSE; + + s = (SilcSymbianSocket *)socket_stream->sock; + s->sock->Close(); + + return TRUE; +} + +/* Destroys the stream */ + +void silc_socket_stream_destroy(SilcStream stream) +{ + SilcSocketStream socket_stream = (SilcSocketStream)stream; + SilcSymbianSocket *s; + + if (!SILC_IS_SOCKET_STREAM(socket_stream) && + !SILC_IS_SOCKET_STREAM_UDP(socket_stream)) + return; + + s = (SilcSymbianSocket *)socket_stream->sock; + + silc_socket_stream_close(stream); + silc_free(socket_stream->ip); + silc_free(socket_stream->hostname); + silc_free(socket_stream); + delete s->send; + delete s->receive; + delete s->sock; + if (s->ss) { + s->ss->Close(); + delete s->ss; + } + delete s; +} + +/* Sets stream notification callback for the stream */ + +void silc_socket_stream_notifier(SilcStream stream, + SilcSchedule schedule, + SilcStreamNotifier callback, + void *context) +{ + SilcSocketStream socket_stream = (SilcSocketStream)stream; + SilcSymbianSocket *s; + + if (!SILC_IS_SOCKET_STREAM(socket_stream) && + !SILC_IS_SOCKET_STREAM_UDP(socket_stream)) + return; + + s = (SilcSymbianSocket *)socket_stream->sock; + if (callback) + s->stream = socket_stream; + else + s->stream = NULL; + + socket_stream->notifier = callback; + socket_stream->notifier_context = context; + socket_stream->schedule = schedule; +} diff --git a/lib/silcutil/symbian/silcsymbiansocketstream.h b/lib/silcutil/symbian/silcsymbiansocketstream.h new file mode 100644 index 00000000..c0ff2a4b --- /dev/null +++ b/lib/silcutil/symbian/silcsymbiansocketstream.h @@ -0,0 +1,46 @@ +/* + + silcsymbiansocketstream.h + + Author: Pekka Riikonen + + Copyright (C) 2006 Pekka Riikonen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +#ifndef SILCSYMBIANSOCKETSTREAM_H +#define SILCSYMBIANSOCKETSTREAM_H + +#include +#include +#include + +class SilcSymbianSocketSend; +class SilcSymbianSocketReceive; + +/* Symbian Socket context */ +typedef struct { + SilcSymbianSocketSend *send; + SilcSymbianSocketReceive *receive; + RSocket *sock; + RSocketServ *ss; + SilcSocketStream stream; + unsigned int eof : 1; + unsigned int error : 1; + unsigned int would_block : 1; +} SilcSymbianSocket; + +/* Creates symbian socket context. This will steal the `sock' and `ss'. */ +SilcSymbianSocket *silc_create_symbian_socket(RSocket *sock, + RSocketServ *ss); + +#endif /* SILCSYMBIANSOCKETSTREAM_H */ diff --git a/lib/silcutil/symbian/silcsymbianthread.cpp b/lib/silcutil/symbian/silcsymbianthread.cpp new file mode 100644 index 00000000..5d637b42 --- /dev/null +++ b/lib/silcutil/symbian/silcsymbianthread.cpp @@ -0,0 +1,270 @@ +/* + + silcsymbianthread.cpp + + Author: Pekka Riikonen + + Copyright (C) 2006 Pekka Riikonen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +#include "silc.h" +#include + +/**************************** SILC Thread API *******************************/ + +/* Thread structure for Symbian */ +typedef struct { +#ifdef SILC_THREADS + RThread *thread; + SilcThreadStart start_func; + void *context; + bool waitable; +#else + void *tmp; +#endif +} *SilcSymbianThread; + +/* The actual thread function */ + +TInt silc_thread_epoc_start(TAny *context) +{ +#ifdef SILC_THREADS + SilcSymbianThread thread = (SilcSymbianThread)context; + void *ret; + + ret = thread->start_func(thread->context); + silc_thread_exit(ret); + +#endif + return 0; +} + +SilcThread silc_thread_create(SilcThreadStart start_func, void *context, + bool waitable) +{ +#ifdef SILC_THREADS + SilcSymbianThread thread; + TInt ret; + TBuf<32> name; + + SILC_LOG_DEBUG(("Creating new thread")); + + thread = (SilcSymbianThread)silc_calloc(1, sizeof(*thread)); + if (!thread) + return NULL; + thread->start_func = start_func; + thread->context = context; + thread->waitable = waitable; + + /* Create the thread */ + /* XXX Unique name should be given for the thread */ + thread->thread = new RThread(); + if (!thread->thread) { + silc_free(thread); + return NULL; + } + + name = (TText *)"silc" + time(NULL); + ret = thread->thread->Create(name, silc_thread_epoc_start, + 8192, 4096, 1024 * 1024, (TAny *)thread); + if (ret != KErrNone) { + SILC_LOG_ERROR(("Could not create new thread")); + delete thread->thread; + silc_free(thread); + return NULL; + } + thread->thread->Resume(); + + return (SilcThread)thread; +#else + /* Call thread callback immediately */ + (*start_func)(context); + return NULL; +#endif +} + +void silc_thread_exit(void *exit_value) +{ +#ifdef SILC_THREADS + /* XXX */ +#endif +} + +SilcThread silc_thread_self(void) +{ +#ifdef SILC_THREADS + /* XXX */ + return NULL; +#else + return NULL; +#endif +} + +SilcBool silc_thread_wait(SilcThread thread, void **exit_value) +{ +#ifdef SILC_THREADS + /* XXX */ + return TRUE; +#else + return FALSE; +#endif +} + +/***************************** SILC Mutex API *******************************/ + +/* SILC Mutex structure */ +struct SilcMutexStruct { +#ifdef SILC_THREADS + RMutex *mutex; +#endif /* SILC_THREADS */ + unsigned int locked : 1; +}; + +SilcBool silc_mutex_alloc(SilcMutex *mutex) +{ +#ifdef SILC_THREADS + *mutex = (SilcMutex)silc_calloc(1, sizeof(**mutex)); + if (*mutex == NULL) + return FALSE; + (*mutex)->mutex = new RMutex(); + if (!(*mutex)->mutex) { + silc_free(*mutex); + return FALSE; + } + if ((*mutex)->mutex->CreateLocal() != KErrNone) { + delete (*mutex)->mutex; + silc_free(*mutex); + return FALSE; + } + (*mutex)->locked = FALSE; + return TRUE; +#else + return FALSE; +#endif /* SILC_THREADS */ +} + +void silc_mutex_free(SilcMutex mutex) +{ +#ifdef SILC_THREADS + if (mutex) { + mutex->mutex->Close(); + delete mutex->mutex; + silc_free(mutex); + } +#endif /* SILC_THREADS */ +} + +void silc_mutex_lock(SilcMutex mutex) +{ +#ifdef SILC_THREADS + if (mutex) { + mutex->mutex->Wait(); + mutex->locked = TRUE; + } +#endif /* SILC_THREADS */ +} + +void silc_mutex_unlock(SilcMutex mutex) +{ +#ifdef SILC_THREADS + if (mutex) { + mutex->mutex->Signal(); + mutex->locked = FALSE; + } +#endif /* SILC_THREADS */ +} + +void silc_mutex_assert_locked(SilcMutex mutex) +{ +#ifdef SILC_THREADS + if (mutex) + SILC_ASSERT(mutex->locked); +#endif /* SILC_THREADS */ +} + + +/****************************** SILC Cond API *******************************/ + +/* SILC Conditional Variable context */ +struct SilcCondStruct { +#ifdef SILC_THREADS + RCondVar *cond; +#else + void *tmp; +#endif /* SILC_THREADS*/ +}; + +SilcBool silc_cond_alloc(SilcCond *cond) +{ +#ifdef SILC_THREADS + *cond = (SilcCond)silc_calloc(1, sizeof(**cond)); + if (*cond == NULL) + return FALSE; + (*cond)->cond = new RCondVar(); + if (!(*cond)->cond) { + silc_free(*cond); + return FALSE; + } + if ((*cond)->cond->CreateLocal() != KErrNone) { + delete (*cond)->cond; + silc_free(*cond); + return FALSE; + } + return TRUE; +#else + return FALSE; +#endif /* SILC_THREADS*/ +} + +void silc_cond_free(SilcCond cond) +{ +#ifdef SILC_THREADS + cond->cond->Close(); + delete cond->cond; + silc_free(cond); +#endif /* SILC_THREADS*/ +} + +void silc_cond_signal(SilcCond cond) +{ +#ifdef SILC_THREADS + cond->cond->Signal(); +#endif /* SILC_THREADS*/ +} + +void silc_cond_broadcast(SilcCond cond) +{ +#ifdef SILC_THREADS + cond->cond->Broadcast(); +#endif /* SILC_THREADS*/ +} + +void silc_cond_wait(SilcCond cond, SilcMutex mutex) +{ +#ifdef SILC_THREADS + cond->cond->Wait(*mutex->mutex); +#endif /* SILC_THREADS*/ +} + +SilcBool silc_cond_timedwait(SilcCond cond, SilcMutex mutex, + int timeout) +{ +#ifdef SILC_THREADS + if (timeout) + return (cond->cond->TimedWait(*mutex->mutex, (TInt)timeout * 1000) == + KErrNone); + return (cond->cond->Wait(*mutex->mutex) == KErrNone); +#else + return FALSE; +#endif /* SILC_THREADS*/ +} diff --git a/lib/silcutil/symbian/silcsymbianutil.cpp b/lib/silcutil/symbian/silcsymbianutil.cpp new file mode 100644 index 00000000..93ae79ab --- /dev/null +++ b/lib/silcutil/symbian/silcsymbianutil.cpp @@ -0,0 +1,74 @@ +/* + + silcsymbianutil.cpp + + Author: Pekka Riikonen + + Copyright (C) 2006 Pekka Riikonen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +#include "silc.h" + +/* Returns the username of the user. */ + +char *silc_get_username() +{ + char *logname = NULL; + + logname = getlogin(); + if (!logname) { + struct passwd *pw; + + pw = getpwuid(getuid()); + if (!pw) + return strdup("User"); + + logname = pw->pw_name; + } + + return strdup(logname); +} + +/* Returns the real name of ther user. */ + +char *silc_get_real_name() +{ + char *realname = NULL; + struct passwd *pw; + + pw = getpwuid(getuid()); + if (!pw) + return strdup("No Name"); + + if (strchr(pw->pw_gecos, ',')) + *strchr(pw->pw_gecos, ',') = 0; + + if (!strlen(pw->pw_gecos)) + return strdup("No Name"); + + realname = strdup(pw->pw_gecos); + + return realname; +} + +/* Return current time to struct timeval. */ + +int silc_gettimeofday(struct timeval *p) +{ + return gettimeofday(p, NULL); +} + +int silc_file_set_nonblock(int fd) +{ + return 0; +} diff --git a/lib/silcutil/tests/test_silchashtable.c b/lib/silcutil/tests/test_silchashtable.c index 21b3fca3..622fc453 100644 --- a/lib/silcutil/tests/test_silchashtable.c +++ b/lib/silcutil/tests/test_silchashtable.c @@ -49,7 +49,7 @@ SilcBool add_entries() e = silc_calloc(1, sizeof(*e)); if (!e) return FALSE; - snprintf(e->name, sizeof(e->name), "%d", i); + silc_snprintf(e->name, sizeof(e->name), "%d", i); e->val = i; silc_hash_table_add(t, (void *)e, (void *)e->name); @@ -99,7 +99,7 @@ SilcBool del_n_entries_foreach() for (i = 0; i < count; i++) { memset(&f, 0, sizeof(f)); - snprintf(f.name, sizeof(f.name), "%d", i); + silc_snprintf(f.name, sizeof(f.name), "%d", i); f.val = i; silc_hash_table_find_foreach(t, &f, del_foreach, NULL); @@ -169,7 +169,7 @@ SilcBool find_entries() for (i = 0; i < count; i++) { memset(&f, 0, sizeof(f)); - snprintf(f.name, sizeof(f.name), "%d", i); + silc_snprintf(f.name, sizeof(f.name), "%d", i); f.val = i; /* Find */ diff --git a/lib/silcutil/unix/silcunixnet.c b/lib/silcutil/unix/silcunixnet.c index bc138cd9..1ce20381 100644 --- a/lib/silcutil/unix/silcunixnet.c +++ b/lib/silcutil/unix/silcunixnet.c @@ -196,7 +196,7 @@ silc_net_tcp_create_listener(const char **local_ip_addr, } /* Specify that we are listenning */ - rval = listen(sock, 5); + rval = listen(sock, 64); if (rval < 0) { SILC_LOG_ERROR(("Cannot set socket listenning: %s", strerror(errno))); goto err; @@ -453,7 +453,7 @@ typedef struct { SilcSocketStreamStatus stream_status; SilcStream stream; SilcFSMStruct fsm; - SilcFSMEventStruct sema; + SilcFSMEventStruct event; SilcAsyncOperation op; SilcAsyncOperation sop; char *local_ip; @@ -475,7 +475,7 @@ SILC_FSM_STATE(silc_net_connect_st_finish); SILC_TASK_CALLBACK(silc_net_connect_wait) { SilcNetConnect conn = context; - SILC_FSM_EVENT_SIGNAL(&conn->sema); + SILC_FSM_EVENT_SIGNAL(&conn->event); silc_schedule_task_del_by_fd(schedule, conn->sock); } @@ -575,12 +575,12 @@ SILC_FSM_STATE(silc_net_connect_st_start) /** Wait for connection */ silc_fsm_next(fsm, silc_net_connect_st_connected); - silc_fsm_event_init(&conn->sema, fsm); + silc_fsm_event_init(&conn->event, fsm); silc_schedule_task_add_fd(silc_fsm_get_schedule(fsm), sock, silc_net_connect_wait, conn); silc_schedule_set_listen_fd(silc_fsm_get_schedule(fsm), sock, SILC_TASK_WRITE, FALSE); - SILC_FSM_EVENT_WAIT(&conn->sema); + SILC_FSM_EVENT_WAIT(&conn->event); SILC_FSM_CONTINUE; } @@ -743,6 +743,7 @@ SilcAsyncOperation silc_net_tcp_connect(const char *local_ip_addr, /* Start async operation */ conn->op = silc_async_alloc(silc_net_connect_abort, NULL, conn); if (!conn->op) { + silc_free(conn); callback(SILC_NET_NO_MEMORY, NULL, context); return NULL; } @@ -751,6 +752,9 @@ SilcAsyncOperation silc_net_tcp_connect(const char *local_ip_addr, conn->local_ip = strdup(local_ip_addr); conn->remote = strdup(remote_ip_addr); if (!conn->remote) { + silc_async_free(conn->op); + silc_free(conn->local_ip); + silc_free(conn); callback(SILC_NET_NO_MEMORY, NULL, context); return NULL; } @@ -775,9 +779,9 @@ void silc_net_close_connection(int sock) /* Set's the socket to non-blocking mode. */ -int silc_net_set_socket_nonblock(int sock) +int silc_net_set_socket_nonblock(SilcSocket sock) { - return fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK); + return fcntl((int)sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK); } /* Converts the IP number string from numbers-and-dots notation to diff --git a/lib/silcutil/unix/silcunixsocketstream.c b/lib/silcutil/unix/silcunixsocketstream.c index e171369b..1b9d6629 100644 --- a/lib/silcutil/unix/silcunixsocketstream.c +++ b/lib/silcutil/unix/silcunixsocketstream.c @@ -20,6 +20,33 @@ #include "silc.h" +/************************ Static utility functions **************************/ + +/* The IO process callback that calls the notifier callback to upper layer. */ + +SILC_TASK_CALLBACK(silc_socket_stream_io) +{ + SilcSocketStream stream = context; + + if (silc_unlikely(!stream->notifier)) + return; + + switch (type) { + case SILC_TASK_READ: + stream->notifier(stream, SILC_STREAM_CAN_READ, stream->notifier_context); + break; + + case SILC_TASK_WRITE: + stream->notifier(stream, SILC_STREAM_CAN_WRITE, stream->notifier_context); + break; + + default: + break; + } +} + +/**************************** Stream Operations *****************************/ + /* QoS read handler, this will call the read and write events to indicate that data is available again after a timeout. */ @@ -219,3 +246,90 @@ SilcBool silc_socket_get_error(SilcStream sock, char *error, return TRUE; } #endif /* 0 */ + +/* Closes socket */ + +SilcBool silc_socket_stream_close(SilcStream stream) +{ + SilcSocketStream socket_stream = stream; + + if (!SILC_IS_SOCKET_STREAM(socket_stream) && + !SILC_IS_SOCKET_STREAM_UDP(socket_stream)) + return FALSE; + + silc_schedule_unset_listen_fd(socket_stream->schedule, socket_stream->sock); + silc_net_close_connection(socket_stream->sock); + + return TRUE; +} + +/* Destroys the stream */ + +void silc_socket_stream_destroy(SilcStream stream) +{ + SilcSocketStream socket_stream = stream; + + if (!SILC_IS_SOCKET_STREAM(socket_stream) && + !SILC_IS_SOCKET_STREAM_UDP(socket_stream)) + return; + + silc_socket_stream_close(socket_stream); + silc_free(socket_stream->ip); + silc_free(socket_stream->hostname); + if (socket_stream->schedule) + silc_schedule_task_del_by_fd(socket_stream->schedule, socket_stream->sock); + + if (socket_stream->qos) { + silc_schedule_task_del_by_context(socket_stream->schedule, + socket_stream->qos); + if (socket_stream->qos->buffer) { + memset(socket_stream->qos->buffer, 0, + socket_stream->qos->read_limit_bytes); + silc_free(socket_stream->qos->buffer); + } + silc_free(socket_stream->qos); + } + + if (socket_stream->schedule) + silc_schedule_wakeup(socket_stream->schedule); + + silc_free(socket_stream); +} + +/* Sets stream notification callback for the stream */ + +void silc_socket_stream_notifier(SilcStream stream, + SilcSchedule schedule, + SilcStreamNotifier callback, + void *context) +{ + SilcSocketStream socket_stream = stream; + + if (!SILC_IS_SOCKET_STREAM(socket_stream) && + !SILC_IS_SOCKET_STREAM_UDP(socket_stream)) + return; + + SILC_LOG_DEBUG(("Setting stream notifier callback")); + + socket_stream->notifier = callback; + socket_stream->notifier_context = context; + socket_stream->schedule = schedule; + + if (socket_stream->notifier) { + /* Add the socket to scheduler. Safe to call if already added. */ + silc_schedule_task_add_fd(socket_stream->schedule, socket_stream->sock, + silc_socket_stream_io, socket_stream); + + /* Initially set socket for reading */ + silc_schedule_set_listen_fd(socket_stream->schedule, socket_stream->sock, + SILC_TASK_READ, FALSE); + silc_schedule_wakeup(socket_stream->schedule); + } else { + /* Unschedule the socket */ + silc_schedule_unset_listen_fd(socket_stream->schedule, + socket_stream->sock); + silc_schedule_task_del_by_fd(socket_stream->schedule, + socket_stream->sock); + silc_schedule_wakeup(socket_stream->schedule); + } +} diff --git a/lib/silcutil/unix/silcunixthread.c b/lib/silcutil/unix/silcunixthread.c index 3985a617..7f52de90 100644 --- a/lib/silcutil/unix/silcunixthread.c +++ b/lib/silcutil/unix/silcunixthread.c @@ -163,7 +163,7 @@ void silc_mutex_assert_locked(SilcMutex mutex) } -/**************************** SILC Cond API ******************************/ +/****************************** SILC Cond API *******************************/ /* SILC Conditional Variable context */ struct SilcCondStruct { diff --git a/symbian/silcdefs.h b/symbian/silcdefs.h new file mode 100644 index 00000000..30d40b0f --- /dev/null +++ b/symbian/silcdefs.h @@ -0,0 +1,289 @@ +/* silcdefs.h. Generated from silcdefs.h.in by configure. */ +/* silcdefs.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the `bind' function. */ +#define HAVE_BIND 1 + +/* Define to 1 if you have the `chmod' function. */ +#define HAVE_CHMOD 1 + +/* Define to 1 if you have the `close' function. */ +#define HAVE_CLOSE 1 + +/* Define to 1 if you have the `connect' function. */ +#define HAVE_CONNECT 1 + +/* Define to 1 if you have the `ctime' function. */ +#define HAVE_CTIME 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_CTYPE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the `fcntl' function. */ +#define HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `fstat' function. */ +#define HAVE_FSTAT 1 + +/* Define to 1 if you have the `getenv' function. */ +#define HAVE_GETENV 1 + +/* Define to 1 if you have the `getgid' function. */ +#define HAVE_GETGID 1 + +/* Define to 1 if you have the `gethostbyaddr' function. */ +#define HAVE_GETHOSTBYADDR 1 + +/* Define to 1 if you have the `gethostname' function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have the `getpgid' function. */ +#define HAVE_GETPGID 1 + +/* Define to 1 if you have the `getpgrp' function. */ +#define HAVE_GETPGRP 1 + +/* Define to 1 if you have the `getpid' function. */ +#define HAVE_GETPID 1 + +/* Define to 1 if you have the `getservbyname' function. */ +#define HAVE_GETSERVBYNAME 1 + +/* Define to 1 if you have the `getservbyport' function. */ +#define HAVE_GETSERVBYPORT 1 + +/* Define to 1 if you have the `getsid' function. */ +#define HAVE_GETSID 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the `getuid' function. */ +#define HAVE_GETUID 1 + +/* Define to 1 if you have the `initgroups' function. */ +#define HAVE_INITGROUPS 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* Define to 1 if you have the `listen' function. */ +#define HAVE_LISTEN 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LOCALE_H 1 + +/* Define to 1 if you have the `memcpy' function. */ +#define HAVE_MEMCPY 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the `nl_langinfo' function. */ +#define HAVE_NL_LANGINFO 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_PATHS_H 1 + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Define to 1 if you have the `putenv' function. */ +#define HAVE_PUTENV 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_PWD_H 1 + +/* Define to 1 if you have the `select' function. */ +#define HAVE_SELECT 1 + +/* Define to 1 if you have the `setgroups' function. */ +#define HAVE_SETGROUPS 1 + +/* Define to 1 if you have the `setrlimit' function. */ +#define HAVE_SETRLIMIT 1 + +/* Define to 1 if you have the `setsockopt' function. */ +#define HAVE_SETSOCKOPT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if you have the `stat' function. */ +#define HAVE_STAT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strchr' function. */ +#define HAVE_STRCHR 1 + +/* Define to 1 if you have the `strcpy' function. */ +#define HAVE_STRCPY 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strncpy' function. */ +#define HAVE_STRNCPY 1 + +/* Define to 1 if you have the `strstr' function. */ +#define HAVE_STRSTR 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the `time' function. */ +#define HAVE_TIME 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* HAVE_VA_COPY */ +//#define HAVE_VA_COPY +#define HAVE_VA_COPY_AARRAY + +/* Name of package */ +#define PACKAGE "silc-toolkit" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "Toolkit" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "Toolkit 1.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "toolkit" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.1" + +/* Define as the return type of signal handlers (`int' or `void'). */ +#define RETSIGTYPE void + +/* SILC_DOCDIR */ +#define SILC_DOCDIR "/usr/local/silc/doc" + +/* SILC_ETCDIR */ +#define SILC_ETCDIR "/usr/local/silc/etc" + +/* SILC_HELPDIR */ +#define SILC_HELPDIR "/usr/local/silc/help" + +/* SILC_I386 */ +/* #undef SILC_I386 */ + +/* SILC_I486 */ +/* #undef SILC_I486 */ + +/* SILC_IA64 */ +/* #undef SILC_IA64 */ + +/* SILC_MODULESDIR */ +#define SILC_MODULESDIR "/usr/local/silc/modules" + +/* GMP */ +/* #undef SILC_MP_GMP */ + +/* SILCMATH */ +#define SILC_MP_SILCMATH + +/* SILC_NO_ASM */ +/* #undef SILC_NO_ASM */ + +/* SILC_POWERPC */ +/* #undef SILC_POWERPC */ + +/* SILC_STACKTRACE */ +/* #undef SILC_STACKTRACE */ + +/* HAVE_THREAD */ +#define SILC_THREADS + +/* SILC_VA_COPY_ARRAY */ +/* #undef SILC_VA_COPY_ARRAY */ + +/* SILC_WIN32 */ +/* #undef SILC_WIN32 */ + +/* SILC_X86_64 */ +/* #undef SILC_X86_64 */ + +/* The size of `char', as computed by sizeof. */ +#define SIZEOF_CHAR 1 + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `long long', as computed by sizeof. */ +#define SIZEOF_LONG_LONG 8 + +/* The size of `short', as computed by sizeof. */ +#define SIZEOF_SHORT 2 + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 4 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Version number of package */ +#define VERSION "1.1" + +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +/* #undef WORDS_BIGENDIAN */ diff --git a/symbian/silcdistdefs.h b/symbian/silcdistdefs.h new file mode 100644 index 00000000..fd186f29 --- /dev/null +++ b/symbian/silcdistdefs.h @@ -0,0 +1,25 @@ +/* + Automatically generated by Autodist 1.3. Do not edit. + + Generated: Fri Dec 22 21:56:55 EET 2006 by priikone + Distribution: default + License: +*/ + +#ifndef _SILC_DISTDEFS_H +#define _SILC_DISTDEFS_H + +#define SILC_DIST_TOOLKIT 1 +#define SILC_DIST_ASN1 1 +#define SILC_DIST_COMPILER 1 +#define SILC_DIST_DOC 1 +#define SILC_DIST_IDCACHE 1 +#define SILC_DIST_INCLUDES 1 +#define SILC_DIST_LIB 1 +#define SILC_DIST_MATH 1 +#define SILC_DIST_SILC 1 +#define SILC_DIST_SKR 1 +#define SILC_DIST_TMA 1 +#define SILC_DIST_VCARD 1 + +#endif /* _SILC_DISTDEFS_H */ diff --git a/tutorial/mybot/mybot.c b/tutorial/mybot/mybot.c index f4ced5f1..6e689d06 100644 --- a/tutorial/mybot/mybot.c +++ b/tutorial/mybot/mybot.c @@ -39,7 +39,7 @@ */ -#include "silcincludes.h" /* Mandatory include for SILC applications */ +#include "silc.h" /* Mandatory include for SILC applications */ #include "silcclient.h" /* SILC Client Library API */ SilcClientOperations ops;