Ticket #750: zeroconfig_patch.patch
File zeroconfig_patch.patch, 14.1 KB (added by , 18 years ago) |
---|
-
libs/libmyth/libmyth.pro
22 22 HEADERS += langsettings.h audiooutputnull.h 23 23 HEADERS += DisplayResScreen.h util-x11.h mythdeque.h qmdcodec.h 24 24 HEADERS += exitcodes.h virtualkeyboard.h 25 HEADERS += zeroconfigclient.h 25 26 26 27 SOURCES += dialogbox.cpp lcddevice.cpp mythcontext.cpp mythwidgets.cpp 27 28 SOURCES += oldsettings.cpp remotefile.cpp settings.cpp themedmenu.cpp … … 32 33 SOURCES += volumecontrol.cpp volumebase.cpp audiooutputbase.cpp 33 34 SOURCES += dbsettings.cpp screensaver.cpp screensaver-null.cpp output.cpp 34 35 SOURCES += langsettings.cpp mythdbcon.cpp audiooutputnull.cpp 35 SOURCES += DisplayResScreen.cpp util-x11.cpp qmdcodec.cpp 36 SOURCES += DisplayResScreen.cpp util-x11.cpp qmdcodec.cpp zeroconfigclient.cpp 36 37 SOURCES += virtualkeyboard.cpp 37 38 38 39 INCLUDEPATH += ../libmythsamplerate ../libmythsoundtouch ../.. -
libs/libmyth/mythcontext.cpp
19 19 20 20 #include "config.h" 21 21 #include "mythcontext.h" 22 #include "zeroconfigclient.h" 22 23 #include "exitcodes.h" 23 24 #include "oldsettings.h" 24 25 #include "themedmenu.h" … … 550 551 551 552 bool MythContextPrivate::FixSettingsFile(void) 552 553 { 554 DatabaseParams defaultParams; 555 556 /* Zero Configuration attempt */ 557 VERBOSE(VB_IMPORTANT, "Trying to find a backend on the network"); 558 559 /* Try to connect to the backend */ 560 ZeroConfigClient *zeroconfigclient = new ZeroConfigClient(true); 561 defaultParams = zeroconfigclient->GetDBInfo(); 562 563 /* Lets give zeroconfig 2 seconds to find the backend */ 564 sleep(2); 565 566 /* We got some data from the backend */ 567 if(zeroconfigclient->FoundBackend()) 568 { 569 VERBOSE(VB_IMPORTANT, "Found Mythtv Backend via zeroconfig"); 570 return WriteSettingsFile(defaultParams); 571 } 572 573 /* Standard attempt, Zero Configuration failed */ 574 VERBOSE(VB_IMPORTANT, "ZeroConfig failed, unable to find a master backend" 575 " to get database details from"); 553 576 VERBOSE(VB_IMPORTANT, "Trying to create a basic mysql.txt file"); 554 DatabaseParamsdefaultParams = parent->GetDatabaseParams();577 defaultParams = parent->GetDatabaseParams(); 555 578 556 579 return WriteSettingsFile(defaultParams); 557 580 } -
libs/libmyth/zeroconfigclient.cpp
1 #include <unistd.h> 2 #include <qsqldatabase.h> 3 #include <qsqlquery.h> 4 #include <qregexp.h> 5 #include <qstring.h> 6 #include <qdatetime.h> 7 8 #include <sys/socket.h> 9 #include <netinet/in.h> 10 #include <arpa/inet.h> 11 #include <stdio.h> 12 13 #include <stdlib.h> 14 #include <string.h> 15 #include <strings.h> 16 17 using namespace std; 18 19 #include <sys/stat.h> 20 #include <sys/time.h> 21 #include <sys/types.h> 22 #include <sys/wait.h> 23 24 #include "mythcontext.h" 25 #include "zeroconfigclient.h" 26 27 ZeroConfigClient::ZeroConfigClient(bool runthread) 28 { 29 foundBackend = false; 30 31 threadrunning = runthread; 32 33 if (runthread) 34 { 35 pthread_create(&zeroconfigclientthread, NULL, ZeroConfigClientThread, this); 36 } 37 } 38 39 ZeroConfigClient::~ZeroConfigClient() 40 { 41 pthread_cancel(zeroconfigclientthread); 42 } 43 44 void *ZeroConfigClient::ZeroConfigClientThread(void *param) 45 { 46 ZeroConfigClient *zeroconfigclient = (ZeroConfigClient *)param; 47 zeroconfigclient->GetDBInfo(); 48 49 return NULL; 50 } 51 52 DatabaseParams ZeroConfigClient::GetDBInfo(void) 53 { 54 // Parse the returned data and store it in the defaultParams structure 55 DatabaseParams dbParams; 56 57 int bytesRecieved; 58 struct sockaddr_in serveraddr; 59 char sendmsg[15] = "MYTHTVDISCOVER"; 60 char buffer[10000]; 61 QString recvmsg; 62 int x = 1; 63 64 // Clear the structure 65 bzero(&serveraddr,sizeof(serveraddr)); 66 67 // Create the UDP socket 68 socketfd = socket(AF_INET,SOCK_DGRAM,0); 69 70 // Set the socket so that we can broadcast to the entire network 71 setsockopt(socketfd, SOL_SOCKET, SO_BROADCAST, (char*) &x, sizeof(int)); 72 73 // Set the important information 74 serveraddr.sin_family = AF_INET; 75 serveraddr.sin_addr.s_addr = inet_addr("255.255.255.255"); 76 serveraddr.sin_port = htons(32000); 77 78 // Broadcast the message 79 sendto(socketfd, sendmsg, strlen(sendmsg), 0, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); 80 81 // Recieve the response from the server 82 // We have to get all the data in one "swoop" since UDP doesn't allow re-broadcasts, 83 // which means we have to have a large buffer for the largest possible response that 84 // can be expected 85 86 bytesRecieved = recvfrom(socketfd, buffer, sizeof(buffer), 0, NULL, NULL); 87 recvmsg.append(buffer); 88 89 #if DEBUG 90 printf("buffer: %s\n", buffer); 91 printf("recvmsg: %s\n", recvmsg.ascii()); 92 #endif 93 bzero(buffer, sizeof(buffer)); 94 95 foundBackend = true; 96 97 QString str(recvmsg); 98 99 #if DEBUG 100 printf("str: %s\n", str.ascii()); 101 #endif 102 QString parameter(" "); 103 QString value(" "); 104 105 int cnt = 0; 106 QString tmp(str.section(';', cnt, cnt)); 107 parameter = tmp.section(':', 0, 0); 108 value = tmp.section(':', 1, 1); 109 110 while( (!parameter.isNull() && !parameter.isEmpty()) && (!value.isNull() && !value.isEmpty()) ) 111 { 112 #if DEBUG 113 // Print out each parameter and value 114 printf(">>>>>parameter: [%s]\n", parameter.ascii()); 115 printf(">>>>>value: [%s]\n", value.ascii()); 116 #endif 117 118 if(parameter.compare("dbHostName") == 0) 119 { 120 dbParams.dbHostName = value; 121 } 122 else if(parameter.compare("dbUserName") == 0) 123 { 124 dbParams.dbUserName = value; 125 } 126 else if(parameter.compare("dbPassword") == 0) 127 { 128 dbParams.dbPassword = value; 129 } 130 else if(parameter.compare("dbName") == 0) 131 { 132 dbParams.dbName = value; 133 } 134 else if(parameter.compare("dbType") == 0) 135 { 136 dbParams.dbType = value; 137 } 138 139 cnt++; 140 141 QString tmp(str.section(';', cnt, cnt)); 142 parameter = tmp.section(':', 0, 0); 143 value = tmp.section(':', 1, 1); 144 } 145 146 #if DEBUG 147 // Print out the values we were able to parse out 148 printf("-----------------------------\n"); 149 printf("dbHostName: %s\n",dbParams.dbHostName.ascii()); 150 printf("dbUserName: %s\n",dbParams.dbUserName.ascii()); 151 printf("dbPassword: %s\n",dbParams.dbPassword.ascii()); 152 printf("dbName: %s\n",dbParams.dbName.ascii()); 153 printf("dbType: %s\n",dbParams.dbType.ascii()); 154 printf("-----------------------------\n"); 155 #endif 156 157 return dbParams; 158 } 159 160 bool ZeroConfigClient::FoundBackend() 161 { 162 return foundBackend; 163 } -
libs/libmyth/zeroconfigclient.h
1 #include <qobject.h> 2 #include <sys/socket.h> 3 #include <netinet/in.h> 4 #include <stdio.h> 5 6 #include <stdlib.h> 7 #include <string.h> 8 #include <strings.h> 9 10 #include "mythcontext.h" 11 12 using namespace std; 13 14 class ZeroConfigClient : public QObject 15 { 16 public: 17 ZeroConfigClient(bool runthread); 18 ~ZeroConfigClient(); 19 bool FoundBackend(); 20 DatabaseParams GetDBInfo(void); 21 22 protected: 23 static void *ZeroConfigClientThread(void *param); 24 25 private: 26 pthread_t zeroconfigclientthread; 27 bool threadrunning; 28 bool foundBackend; 29 int socketfd; 30 }; -
programs/mythbackend/main.cpp
22 22 #include "tv.h" 23 23 #include "autoexpire.h" 24 24 #include "scheduler.h" 25 #include "zeroconfigserver.h" 25 26 #include "mainserver.h" 26 27 #include "encoderlink.h" 27 28 #include "remoteutil.h" … … 38 39 AutoExpire *expirer = NULL; 39 40 Scheduler *sched = NULL; 40 41 JobQueue *jobqueue = NULL; 42 ZeroConfigServer *zeroconfigserver = NULL; 41 43 QString pidfile; 42 44 QString lockfile_location; 43 45 HouseKeeper *housekeeping = NULL; … … 233 235 bool nosched = false; 234 236 bool nojobqueue = false; 235 237 bool noexpirer = false; 238 bool usezeroconfig = false; 236 239 bool printexpire = false; 237 240 for (int argpos = 1; argpos < a.argc(); ++argpos) 238 241 { … … 317 320 { 318 321 noexpirer = true; 319 322 } 323 else if (!strcmp(a.argv()[argpos],"--usezeroconfig")) 324 { 325 usezeroconfig = true; 326 } 320 327 else if (!strcmp(a.argv()[argpos],"--printexpire")) 321 328 { 322 329 printexpire = true; … … 349 356 "--nosched Do not perform any scheduling" << endl << 350 357 "--nojobqueue Do not start the JobQueue" << endl << 351 358 "--noautoexpire Do not start the AutoExpire thread" << endl << 359 "--usezeroconfig Enable the Zero Configuration thread" << endl << 352 360 "--version Version information" << endl; 353 361 return BACKEND_EXIT_INVALID_CMDLINE; 354 362 } … … 517 525 else 518 526 jobqueue = new JobQueue(ismaster); 519 527 528 if(usezeroconfig) 529 { 530 cerr << "********* Using Zero Config *********\n"; 531 zeroconfigserver = new ZeroConfigServer(true); 532 } 533 else 534 { 535 cerr << "********* The Zero Config has been DISABLED by default*********\n"; 536 } 520 537 VERBOSE(VB_ALL, QString("%1 version: %2 www.mythtv.org") 521 538 .arg(binname).arg(MYTH_BINARY_VERSION)); 522 539 -
programs/mythbackend/mythbackend.pro
12 12 13 13 # Input 14 14 HEADERS += autoexpire.h encoderlink.h filetransfer.h httpstatus.h mainserver.h 15 HEADERS += playbacksock.h scheduler.h server.h housekeeper.h 15 HEADERS += playbacksock.h scheduler.h server.h housekeeper.h zeroconfigserver.h 16 16 17 17 SOURCES += autoexpire.cpp encoderlink.cpp filetransfer.cpp httpstatus.cpp 18 18 SOURCES += main.cpp mainserver.cpp playbacksock.cpp scheduler.cpp server.cpp 19 SOURCES += housekeeper.cpp 19 SOURCES += housekeeper.cpp zeroconfigserver.cpp 20 20 21 21 using_oss:DEFINES += USING_OSS 22 22 -
programs/mythbackend/zeroconfigserver.cpp
1 #include <unistd.h> 2 #include <qsqldatabase.h> 3 #include <qsqlquery.h> 4 #include <qregexp.h> 5 #include <qstring.h> 6 #include <qdatetime.h> 7 8 using namespace std; 9 10 #include <sys/stat.h> 11 #include <sys/time.h> 12 #include <sys/types.h> 13 #include <sys/wait.h> 14 15 #include <sys/socket.h> 16 #include <netinet/in.h> 17 #include <stdio.h> 18 19 #include "libmyth/exitcodes.h" 20 #include "libmyth/mythcontext.h" 21 #include "libmyth/mythdbcon.h" 22 #include "zeroconfigserver.h" 23 24 ZeroConfigServer::ZeroConfigServer(bool runthread) 25 { 26 threadrunning = runthread; 27 28 if (runthread) 29 { 30 pthread_t zeroconfigserverthread; 31 pthread_create(&zeroconfigserverthread, NULL, ZeroConfigServerThread, this); 32 } 33 } 34 35 ZeroConfigServer::~ZeroConfigServer() 36 { 37 38 } 39 40 void *ZeroConfigServer::ZeroConfigServerThread(void *param) 41 { 42 ZeroConfigServer *zeroconfigserver = (ZeroConfigServer *)param; 43 zeroconfigserver->RunZeroConfigServer(); 44 45 return NULL; 46 } 47 48 void ZeroConfigServer::RunZeroConfigServer(void) 49 { 50 int sockfd,n; 51 struct sockaddr_in servaddr,cliaddr; 52 socklen_t len; 53 char mesg[1000]; 54 55 sockfd=socket(AF_INET,SOCK_DGRAM,0); 56 57 bzero(&servaddr,sizeof(servaddr)); 58 servaddr.sin_family = AF_INET; 59 servaddr.sin_addr.s_addr=htonl(INADDR_ANY); 60 servaddr.sin_port=htons(32000); 61 bind(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr)); 62 63 while (1) 64 { 65 len = sizeof(cliaddr); 66 n = recvfrom(sockfd, mesg, 1000, 0, (struct sockaddr *)&cliaddr, &len); 67 mesg[n] = 0; 68 #if DEBUG 69 printf("-------------------------------------------------------\n"); 70 printf("Received the following:\n"); 71 printf("[%s]\n",mesg); 72 #endif 73 74 if(strcmp(mesg, "MYTHTVDISCOVER") == 0) { 75 DatabaseParams dbParams = gContext->GetDatabaseParams(); 76 QString msg; 77 78 msg.sprintf("dbHostName:%s;dbUserName:%s;dbPassword:%s;dbType:%s;dbName:%s", 79 dbParams.dbHostName.ascii(), 80 dbParams.dbUserName.ascii(), 81 dbParams.dbPassword.ascii(), 82 dbParams.dbType.ascii(), 83 dbParams.dbName.ascii()); 84 #if DEBUG 85 printf("Sending msg: %s\n", msg.ascii()); 86 #endif 87 sendto(sockfd,msg.ascii(),msg.length(),0,(struct sockaddr *)&cliaddr,sizeof(cliaddr)); 88 } 89 else { 90 QString msg; 91 msg.sprintf("ERROR: Unknown query\n"); 92 sendto(sockfd,msg.ascii(),msg.length(),0,(struct sockaddr *)&cliaddr,sizeof(cliaddr)); 93 } 94 #if DEBUG 95 printf("-------------------------------------------------------\n"); 96 #endif 97 } 98 } -
programs/mythbackend/zeroconfigserver.h
1 #include <qmutex.h> 2 #include <qobject.h> 3 4 using namespace std; 5 6 class ZeroConfigServer : public QObject 7 { 8 public: 9 ZeroConfigServer(bool runthread); 10 ~ZeroConfigServer(); 11 12 protected: 13 void RunZeroConfigServer(void); 14 static void *ZeroConfigServerThread(void *param); 15 16 private: 17 bool threadrunning; 18 };