$ git clone http://tcclient.ion.nu/tc_client.git
commit ee607609918f9ad860e4832ec923fe53f8896c30
Author: Alicia <...>
Date: Tue Apr 7 06:49:00 2015 +0200
Version 0.4
diff --git a/ChangeLog b/ChangeLog
index 79cf358..f9308a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+0.4:
+Adjustments for portability: nested functions are a GCC extension and should not be used, include headers needed on other systems.
+Use memcpy in some places instead of *x=y and x=*y to avoid alignment issues.
0.3:
Handle 'joins', 'join', 'nick' and 'quit' messages from the server (contributed by Jade)
Moved the AMF message writing functions into a separate source file.
diff --git a/Makefile b/Makefile
index cc34c31..269d2d2 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION=0.3
+VERSION=0.4
CFLAGS=-g3 -Wall $(shell curl-config --cflags)
LIBS=-g3 $(shell curl-config --libs)
diff --git a/amfparser.c b/amfparser.c
index b71dc81..77bf617 100644
--- a/amfparser.c
+++ b/amfparser.c
@@ -94,7 +94,7 @@ struct amf* amf_parse(const unsigned char* buf, int len)
else
item=amf_newitem(amf);
item->type=AMF_NUMBER;
- item->number=*(double*)buf;
+ memcpy(&item->number, buf, sizeof(double));
buf=&buf[sizeof(double)];
break;
case 1:
diff --git a/amfwriter.c b/amfwriter.c
index 38845f3..23d2ffb 100644
--- a/amfwriter.c
+++ b/amfwriter.c
@@ -69,8 +69,7 @@ void amfnum(struct amfmsg* msg, double v)
msg->buf=realloc(msg->buf, sizeof(struct rtmph)+msg->len);
unsigned char* type=msg->buf+offset;
type[0]='\x00';
- double* value=(double*)(msg->buf+offset+1);
- *value=v;
+ memcpy(msg->buf+offset+1, &v, sizeof(v));
}
void amfbool(struct amfmsg* msg, char v)
diff --git a/client.c b/client.c
index 8497b16..7b8978f 100644
--- a/client.c
+++ b/client.c
@@ -20,6 +20,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
+#include <netinet/in.h>
#include <netdb.h>
#include <poll.h>
#include <locale.h>
@@ -29,6 +30,12 @@
#include "numlist.h"
#include "amfwriter.h"
+struct writebuf
+{
+ char* buf;
+ int len;
+};
+
unsigned int flip(unsigned int bits, int bytecount)
{
unsigned int ret=0;
@@ -52,28 +59,30 @@ void b_read(int sock, void* buf, size_t len)
}
}
+size_t writehttp(char* ptr, size_t size, size_t nmemb, void* x)
+{
+ struct writebuf* data=x;
+ size*=nmemb;
+ data->buf=realloc(data->buf, data->len+size+1);
+ memcpy(&data->buf[data->len], ptr, size);
+ data->len+=size;
+ data->buf[data->len]=0;
+ return size;
+}
+
char* http_get(char* url)
{
CURL* curl=curl_easy_init();
if(!curl){return 0;}
curl_easy_setopt(curl, CURLOPT_URL, url);
- char* buf=0;
- int len=0;
- size_t writehttp(char* ptr, size_t size, size_t nmemb, void* x)
- {
- size*=nmemb;
- buf=realloc(buf, len+size+1);
- memcpy(&buf[len], ptr, size);
- len+=size;
- buf[len]=0;
- return size;
- }
+ struct writebuf writebuf={0, 0};
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writehttp);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, &writebuf);
char err[CURL_ERROR_SIZE];
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err);
if(curl_easy_perform(curl)){curl_easy_cleanup(curl); printf(err); return 0;}
curl_easy_cleanup(curl);
- return buf; // should be free()d when no longer needed
+ return writebuf.buf; // should be free()d when no longer needed
}
char* gethost(char *channel, char *password)
diff --git a/irchack.c b/irchack.c
index b3ab620..389ebb9 100644
--- a/irchack.c
+++ b/irchack.c
@@ -20,6 +20,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <sys/socket.h>
int main()
{