/* $ModDesc: SQL Service Provider module for all other m_sql* modules */
/* $CompileFlags: `mysql_config --include` */
-/* $LinkerFlags: `mysql_config --libs_r` `perl ../mysql_rpath.pl` */
+/* $LinkerFlags: `mysql_config --libs_r` `perl extra/mysql_rpath.pl` */
/* THE NONBLOCKING MYSQL API!
*
std::vector<std::string> colnames;
std::vector<SQLfieldList> fieldlists;
SQLfieldMap* fieldmap;
+ SQLfieldMap fieldmap2;
+ SQLfieldList emptyfieldlist;
int rows;
- int cols;
public:
MySQLresult(Module* self, Module* to, MYSQL_RES* res, int affected_rows, unsigned int id) : SQLresult(self, to, id), currentrow(0), fieldmap(NULL)
virtual int Rows()
{
- /* An INSERT can return 0 columns, but N rows. This is unsafe to
- * allow the user to 'see'. Go figure. I hate you, MySQL devs.
- */
- if (colnames.size())
- return rows;
- else
- return 0;
+ return rows;
}
virtual int Cols()
virtual SQLfieldList& GetRow()
{
- return fieldlists[currentrow];
+ if (currentrow < rows)
+ return fieldlists[currentrow];
+ else
+ return emptyfieldlist;
}
virtual SQLfieldMap& GetRowMap()
{
- fieldmap = new SQLfieldMap();
-
- for (int i = 0; i < cols; i++)
+ fieldmap2.clear();
+
+ if (currentrow < rows)
{
- fieldmap->insert(std::make_pair(colnames[cols],GetValue(currentrow, i)));
+ for (int i = 0; i < Cols(); i++)
+ {
+ fieldmap2.insert(std::make_pair(colnames[i],GetValue(currentrow, i)));
+ }
+ currentrow++;
}
- currentrow++;
- return *fieldmap;
+ return fieldmap2;
}
virtual SQLfieldList* GetRowPtr()
{
- return &fieldlists[currentrow++];
+ SQLfieldList* fieldlist = new SQLfieldList();
+
+ if (currentrow < rows)
+ {
+ for (int i = 0; i < Rows(); i++)
+ {
+ fieldlist->push_back(fieldlists[currentrow][i]);
+ }
+ currentrow++;
+ }
+ return fieldlist;
}
virtual SQLfieldMap* GetRowMapPtr()
{
fieldmap = new SQLfieldMap();
-
- for (int i = 0; i < cols; i++)
+
+ if (currentrow < rows)
{
- fieldmap->insert(std::make_pair(colnames[cols],GetValue(currentrow, i)));
+ for (int i = 0; i < Cols(); i++)
+ {
+ fieldmap->insert(std::make_pair(colnames[i],GetValue(currentrow, i)));
+ }
+ currentrow++;
}
- currentrow++;
return fieldmap;
}
virtual void Free(SQLfieldList* fl)
{
- /* XXX: Yes, this is SUPPOSED to do nothing, we
- * dont want to free our fieldlist until we
- * destruct the object. Unlike the pgsql module,
- * we only have the one.
- */
+ delete fl;
}
};
class Notifier : public InspSocket
{
- sockaddr_in sock_us;
+ insp_sockaddr sock_us;
socklen_t uslen;
Server* Srv;
public:
/* Create a socket on a random port. Let the tcp stack allocate us an available port */
+#ifdef IPV6
+ Notifier(Server* S) : InspSocket("::1", 0, true, 3000), Srv(S)
+#else
Notifier(Server* S) : InspSocket("127.0.0.1", 0, true, 3000), Srv(S)
+#endif
{
uslen = sizeof(sock_us);
if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen))
/* Using getsockname and ntohs, we can determine which port number we were allocated */
int GetPort()
{
+#ifdef IPV6
+ return ntohs(sock_us.sin6_port);
+#else
return ntohs(sock_us.sin_port);
+#endif
}
virtual int OnIncomingConnection(int newsock, char* ip)
char* OnRequest(Request* request)
{
- if(strcmp(SQLREQID, request->GetData()) == 0)
+ if(strcmp(SQLREQID, request->GetId()) == 0)
{
SQLrequest* req = (SQLrequest*)request;
return returnval;
}
- log(DEBUG, "Got unsupported API version string: %s", request->GetData());
+ log(DEBUG, "Got unsupported API version string: %s", request->GetId());
return NULL;
}
/* Connect back to the Notifier */
- if ((QueueFD = socket(AF_INET, SOCK_STREAM, 0)) == -1)
+ if ((QueueFD = socket(AF_FAMILY, SOCK_STREAM, 0)) == -1)
{
/* crap, we're out of sockets... */
log(DEBUG,"QueueFD cant be created");
log(DEBUG,"Initialize QueueFD to %d",QueueFD);
- sockaddr_in addr;
- in_addr ia;
- inet_aton("127.0.0.1", &ia);
- addr.sin_family = AF_INET;
+ insp_sockaddr addr;
+
+#ifdef IPV6
+ insp_aton("::1", &addr.sin6_addr);
+ addr.sin6_family = AF_FAMILY;
+ addr.sin6_port = htons(MessagePipe->GetPort());
+#else
+ insp_inaddr ia;
+ insp_aton("127.0.0.1", &ia);
+ addr.sin_family = AF_FAMILY;
addr.sin_addr = ia;
addr.sin_port = htons(MessagePipe->GetPort());
+#endif
if (connect(QueueFD, (sockaddr*)&addr,sizeof(addr)) == -1)
{
{
return new ModuleSQLFactory;
}
-