00001 #include "phupdate.h"
00002 #include "common/log.h"
00003 #include <signal.h>
00004 #ifndef WIN32
00005 #include <arpa/inet.h>
00006 #include <netdb.h>
00007 #include <unistd.h>
00008
00009 static void create_pidfile()
00010 {
00011 FILE *pidfile;
00012 char pidfilename[128];
00013 sprintf(pidfilename, "%s", "/var/run/phddns.pid");
00014
00015 if ((pidfile = fopen(pidfilename, "w")) != NULL) {
00016 fprintf(pidfile, "%d\n", getpid());
00017 (void) fclose(pidfile);
00018 } else {
00019 printf("Failed to create pid file %s: %m", pidfilename);
00020 pidfilename[0] = 0;
00021 }
00022 }
00023 #endif
00024
00025 class CPhUpdater : public CUpdateBase
00026 {
00027 public:
00028 protected:
00029 virtual void OnStatusChanged(int status, long data)
00030 {
00031 printf("OnStatusChanged %s\n", convert_status_code(status));
00032 if (status == okKeepAliveRecved)
00033 {
00034 printf("IP: %d\n", data);
00035 }
00036 if (status == okDomainsRegistered)
00037 {
00038 printf("UserType: %d\n", data);
00039 }
00040 }
00041 virtual void OnDomainRegistered(std::string domain)
00042 {
00043 printf("OnDomainRegistered %s\n", domain.c_str());
00044 }
00045 virtual void OnUserInfo(std::string userInfo)
00046 {
00047 printf("OnUserInfo %s\n", userInfo.c_str());
00048 }
00049 virtual void OnAccountDomainInfo(std::string domainInfo)
00050 {
00051 printf("OnAccountDomainInfo %s\n", domainInfo.c_str());
00052 }
00053 private:
00054 };
00055 CPhUpdater phup;
00056
00057
00058 static void my_handleSIG (int sig)
00059 {
00060 if (sig == SIGINT)
00061 {
00062 #ifndef WIN32
00063 remove("/var/run/phddns.pid");
00064 #endif
00065 printf ("signal = SIGINT\n");
00066 phup.stop();
00067 exit(0);
00068 }
00069 if (sig == SIGTERM)
00070 {
00071 #ifndef WIN32
00072 remove("/var/run/phddns.pid");
00073 #endif
00074 printf ("signal = SIGTERM\n");
00075 phup.stop();
00076 }
00077 signal (sig, my_handleSIG);
00078 }
00079
00080
00081
00082 int main(int argc, char *argv[])
00083 {
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 #ifdef WIN32
00095 WORD VersionRequested;
00096 WSADATA WsaData;
00097 int error;
00098
00099 VersionRequested = MAKEWORD(2, 0);
00100
00101
00102 error = WSAStartup(VersionRequested, &WsaData);
00103 Log::open("c:\\phclientlog.log", 1);
00104 #else
00105
00106
00107 Log::open("/var/log/phddns.log", 1);
00108 create_pidfile();
00109 #endif
00110 void (*ohandler) (int);
00111 ohandler = signal (SIGINT, my_handleSIG);
00112 if (ohandler != SIG_DFL) {
00113 printf ("previous signal handler for SIGINT is not a default handler\n");
00114 signal (SIGINT, ohandler);
00115 }
00116
00117
00118 phup.phglobal.clientinfo = 0x267C9745;
00119 phup.phglobal.challengekey = 0x1E08065E;
00120 strcpy(phup.phglobal.szUserID, "skyvense");
00121 strcpy(phup.phglobal.szUserPWD, "CHECKIN8!@#4");
00122
00123 for (;;)
00124 {
00125 int next = phup.step();
00126 sleep(next);
00127 }
00128
00129 return 0;
00130 }