rendered paste body#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <string.h>#include <sys/types.h>#include <unistd.h>#include <assert.h>#include <curl/curl.h>#include <curl/easy.h>const char * username = "";const char * password = "";CURL * handle;char * reply=NULL;size_t reply_size=0;FILE * out;char auth_key[32];size_t write_function(void * ptr, size_t size, size_t nmemb, void * stream){ if(!reply) reply = (char*)malloc(size*nmemb); else reply = (char*)realloc(reply, size*nmemb+reply_size); /*out=fopen("D:\\out.html", "a"); fwrite(ptr,size,nmemb,out); fclose(out);*/ memcpy(&reply[reply_size], ptr, size*nmemb); reply_size+=size*nmemb; return nmemb;}int login(){ long http_result; int result; char buffer[500]; snprintf(buffer, 500, "referer=http%%3A%%2F%%2Fwww.ascentemu.com%%2Fforums%%2Findex.php%%3F&UserName=%s&PassWord=%s&CookieDate=1", username, password); curl_easy_setopt(handle, CURLOPT_COOKIEFILE, "cookies.txt"); curl_easy_setopt(handle, CURLOPT_URL, "http://www.ascentemu.com/forums/index.php?act=Login&CODE=01"); curl_easy_setopt(handle, CURLOPT_POSTFIELDS, buffer); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_function); curl_easy_setopt(handle, CURLOPT_VERBOSE, 1); result = curl_easy_perform(handle); if(result != 0) return 0; curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_result); if(http_result != 302) // FOUND return 1; return 0;}int make_post(const char * subject, const char * post){ char *p, *q; char buffer[10000] = {0}; int result; long http_result; reply_size=0; if(reply) free(reply); reply=NULL; sprintf(buffer,"http://www.ascentemu.com/forums/index.php?act=post&do=new_post&f=22"); curl_easy_setopt(handle, CURLOPT_URL, buffer); curl_easy_setopt(handle, CURLOPT_POSTFIELDS, NULL); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_function); curl_easy_setopt(handle, CURLOPT_VERBOSE, 1); result = curl_easy_perform(handle); if(result != 0) return 1; p = strstr(reply, "name='auth_key'"); if(p == 0) return 2; q = strstr(p, "' />"); if(q == 0) return 3; p = strstr(p, "value"); p += 7; *q = 0; strncpy(auth_key, p, 32); reply_size=0; free(reply); reply=NULL; ////////////////////////////////Forum id buffer[0]=0; strcat(buffer, "st=0&act=Post&f=22&CODE=01&TopicTitle="); strcat(buffer, subject); strcat(buffer, "&Post="); strcat(buffer, post); strcat(buffer, "&enableemo=yes&enablesig=yes&auth_key="); strcat(buffer, auth_key); curl_easy_setopt(handle, CURLOPT_URL, "http://www.ascentemu.com/forums/index.php?"); curl_easy_setopt(handle, CURLOPT_POSTFIELDS, buffer); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_function); curl_easy_setopt(handle, CURLOPT_VERBOSE, 1); result = curl_easy_perform(handle); if(result != 0) return 4; curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_result); if(http_result != 302) // FOUND return 5; return 0;}int line_count=10;int line_counter=0;struct revision{ int rev; char author[50]; char date[100]; char ** changed_files; char subject[100]; char * body;};int main(int argc, char * argv[]){ /* grab some info, TODO */ char buffer[50000]; char out_buffer[50000]; char temp_buffer[250]; char sub[200]; int bcount=0; struct revision thisrev; const char * repos = "svn://emupedia.com/svn/ascent"; int rev = 1000; int old_stdout; int pipe_fds[2]; int err; int i; char * p,*q,*r; pipe(pipe_fds); if(!fork()) { /* we are the child, redirect our stdout */ close(1); dup(pipe_fds[1]); close(pipe_fds[0]); execlp("svn", "svn", "log","-r1002","-v", "svn://emupedia.com/svn/ascent", NULL); exit(0); } close(0); dup(pipe_fds[0]); close(pipe_fds[1]); for(;;) { err = read(pipe_fds[0], temp_buffer, 200); //printf("read returned %u\n", err); if(err < 0) { if(errno != EAGAIN) { perror("reading pipe error"); return 1; } } else if(err==0) break; memcpy(&buffer[bcount],temp_buffer,err); bcount += err; } /* hoookay. lets process the buffer. */ p = strstr(buffer, "-\n"); assert(p); p+=2; if(sscanf(p, "r%d | %s", &thisrev.rev, thisrev.author) != 2) { printf("internal processing error\n"); return 2; } /* this is kinda hardcoded to 2007 :/ */ p += 5; p = strstr(buffer, "2007"); q = strstr(p, "|"); memcpy(thisrev.date, p, (q-p)); thisrev.date[q-p] = 0; //printf("revision: %d\n", thisrev.rev); //printf("author: %s\n", thisrev.author); //printf("date: %s\n", thisrev.date); p = strstr(q, "Changed paths:"); p = strchr(p, '\n'); ++p; thisrev.changed_files = (char**)malloc(sizeof(char*) * line_count); for(;;) { if(*p == '\n') break; q = strchr(p, '\n'); *q = 0; ++q; thisrev.changed_files[line_counter++] = p; if((line_counter+1) == line_count) { line_count += 10; thisrev.changed_files = (char**)realloc(thisrev.changed_files, sizeof(char*) * line_count); } p = q; } //printf("%u changes.\n", line_counter); //for(i = 0; i < line_counter; ++i) // printf("==%s\n", thisrev.changed_files[i]); p++; q = strstr(p, "------------------------------------------------------------------------"); --q; *q = 0; thisrev.body = p; p = strstr(thisrev.body, "\n"); if(!p) p = strchr(thisrev.body, '\0'); assert(p); i = (p-thisrev.body); if(i >= 100) i = 99; memcpy(thisrev.subject, thisrev.body, i); //printf("Subject: %s\n", thisrev.subject); //printf("Body: \n==%s==", thisrev.body); /* whee, lets format the body */ /*snprintf(out_buffer, 50000,"[size=4][b]Revision %u[/b] [i](author: %s)[/i][/size]\n" "[size=3][b]Timestamp: [/b] %s[/size]\n\n" "[code]%s[/code]\n" "[b]Changed files: [/b]%u\n", "[code]", thisrev.rev, thisrev.author, thisrev.date, thisrev.body, line_counter);*/ strcat(out_buffer, "[size=4][b]Revision "); sprintf(temp_buffer,"%u", thisrev.rev); strcat(out_buffer, temp_buffer); strcat(out_buffer, "[/b] [i](author: "); strcat(out_buffer, thisrev.author); strcat(out_buffer, ")[/i][/size]\n\n[size=3][b]Timestamp: [/b] "); strcat(out_buffer, thisrev.date); strcat(out_buffer, "[/size]\n\n"); strcat(out_buffer, "[code]"); strcat(out_buffer, thisrev.body); strcat(out_buffer, "[/code]\n[b]Changed files: [/b]"); sprintf(temp_buffer,"%u", line_counter); strcat(out_buffer, temp_buffer); strcat(out_buffer, "\n[code]"); for(i = 0; i < line_counter; ++i) { strcat(out_buffer, thisrev.changed_files[i]); strcat(out_buffer, "\n"); } strcat(out_buffer, "[/code]"); //printf("Post:\n\n%s", out_buffer); sprintf(sub, "[revision %u / %s] %s", thisrev.rev, thisrev.author, thisrev.subject); printf("Post generated.\n"); handle = curl_easy_init(); if(login()) { printf("Login failed. Maybe your details are incorrect?\n"); return 1; } printf("Logged in.\n"); printf("Posting...\n"); if(make_post(sub, out_buffer)) { printf("Making the post failed. Maybe something went wrong?\n"); return 1; } if(reply) free(reply); curl_easy_cleanup(handle); return 0; }