mirror of
				https://github.com/VCMP-SqMod/SqMod.git
				synced 2025-11-04 00:07:19 +01:00 
			
		
		
		
	Updated the MaxmindDB module to include the location for C++ exceptions in source code for debug builds.
This commit is contained in:
		@@ -395,7 +395,7 @@
 | 
				
			|||||||
		<Unit filename="../modules/mmdb/Module.cpp" />
 | 
							<Unit filename="../modules/mmdb/Module.cpp" />
 | 
				
			||||||
		<Unit filename="../modules/mmdb/Module.hpp" />
 | 
							<Unit filename="../modules/mmdb/Module.hpp" />
 | 
				
			||||||
		<Unit filename="../modules/mmdb/SockAddr.cpp" />
 | 
							<Unit filename="../modules/mmdb/SockAddr.cpp" />
 | 
				
			||||||
		<Unit filename="../modules/mmdb/SockAddr.hpp" />
 | 
							<Unit filename="../modules/mmdb/Sockaddr.hpp" />
 | 
				
			||||||
		<Unit filename="../shared/SqMod.cpp" />
 | 
							<Unit filename="../shared/SqMod.cpp" />
 | 
				
			||||||
		<Extensions>
 | 
							<Extensions>
 | 
				
			||||||
			<code_completion />
 | 
								<code_completion />
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ void Database::Validate() const
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    // Is the document handle valid?
 | 
					    // Is the document handle valid?
 | 
				
			||||||
    if (!m_Db)
 | 
					    if (!m_Db)
 | 
				
			||||||
        SqThrowF("Invalid Maxmind database reference");
 | 
					        STHROWF("Invalid Maxmind database reference");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ------------------------------------------------------------------------------------------------
 | 
					// ------------------------------------------------------------------------------------------------
 | 
				
			||||||
@@ -51,14 +51,14 @@ void Database::Open(CSStr filepath, Uint32 flags)
 | 
				
			|||||||
        m_Db = DbRef(true); // Create a database handle
 | 
					        m_Db = DbRef(true); // Create a database handle
 | 
				
			||||||
    // Check if the database handle could be allocated one more time
 | 
					    // Check if the database handle could be allocated one more time
 | 
				
			||||||
    if (!m_Db)
 | 
					    if (!m_Db)
 | 
				
			||||||
        SqThrowF("Unable to create a Maxmind database reference");
 | 
					        STHROWF("Unable to create a Maxmind database reference");
 | 
				
			||||||
    // Are there any other references?
 | 
					    // Are there any other references?
 | 
				
			||||||
    else if (m_Db.Count() > 1)
 | 
					    else if (m_Db.Count() > 1)
 | 
				
			||||||
        // To load new values now, would mean to cause undefined behavior in existing references
 | 
					        // To load new values now, would mean to cause undefined behavior in existing references
 | 
				
			||||||
        SqThrowF("Loading is disabled while database is referenced");
 | 
					        STHROWF("Loading is disabled while database is referenced");
 | 
				
			||||||
    // Validate the specified file path
 | 
					    // Validate the specified file path
 | 
				
			||||||
    else if (!filepath || strlen(filepath) <= 0)
 | 
					    else if (!filepath || strlen(filepath) <= 0)
 | 
				
			||||||
        SqThrowF("Invalid database file path");
 | 
					        STHROWF("Invalid database file path");
 | 
				
			||||||
    // Let's attempt to open the specified database
 | 
					    // Let's attempt to open the specified database
 | 
				
			||||||
    const Int32 status = MMDB_open(filepath, flags, m_Db.m_Ptr);
 | 
					    const Int32 status = MMDB_open(filepath, flags, m_Db.m_Ptr);
 | 
				
			||||||
    // Validate the result of the operation
 | 
					    // Validate the result of the operation
 | 
				
			||||||
@@ -67,7 +67,7 @@ void Database::Open(CSStr filepath, Uint32 flags)
 | 
				
			|||||||
        // Release the database reference
 | 
					        // Release the database reference
 | 
				
			||||||
        m_Db.Drop();
 | 
					        m_Db.Drop();
 | 
				
			||||||
        // Now it's safe to throw the error
 | 
					        // Now it's safe to throw the error
 | 
				
			||||||
        SqThrowF("Unable to open the specified database [%s]", MMDB_strerror(status));
 | 
					        STHROWF("Unable to open the specified database [%s]", MMDB_strerror(status));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -78,17 +78,17 @@ LookupResult Database::LookupString(CSStr addr)
 | 
				
			|||||||
    Validate();
 | 
					    Validate();
 | 
				
			||||||
    // Validate the specified string
 | 
					    // Validate the specified string
 | 
				
			||||||
    if (!addr || strlen(addr) <= 0)
 | 
					    if (!addr || strlen(addr) <= 0)
 | 
				
			||||||
        SqThrowF("Invalid address string");
 | 
					        STHROWF("Invalid address string");
 | 
				
			||||||
    // Dummy variables to obtain the status codes
 | 
					    // Dummy variables to obtain the status codes
 | 
				
			||||||
    int gai_error, mmdb_error;
 | 
					    int gai_error, mmdb_error;
 | 
				
			||||||
    // Attempt to perform the actual lookup
 | 
					    // Attempt to perform the actual lookup
 | 
				
			||||||
    MMDB_lookup_result_s result = MMDB_lookup_string(m_Db, addr, &gai_error, &mmdb_error);
 | 
					    MMDB_lookup_result_s result = MMDB_lookup_string(m_Db, addr, &gai_error, &mmdb_error);
 | 
				
			||||||
    // Validate the result of the getaddrinfo() function call
 | 
					    // Validate the result of the getaddrinfo() function call
 | 
				
			||||||
    if (gai_error != 0)
 | 
					    if (gai_error != 0)
 | 
				
			||||||
        SqThrowF("Unable to resolve address (%s) because [%s]", addr, gai_strerror(gai_error));
 | 
					        STHROWF("Unable to resolve address (%s) because [%s]", addr, gai_strerror(gai_error));
 | 
				
			||||||
    // Validate the lookup status code
 | 
					    // Validate the lookup status code
 | 
				
			||||||
    else if (mmdb_error != MMDB_SUCCESS)
 | 
					    else if (mmdb_error != MMDB_SUCCESS)
 | 
				
			||||||
        SqThrowF("Unable to lookup address (%s) because [%s]", addr, MMDB_strerror(mmdb_error));
 | 
					        STHROWF("Unable to lookup address (%s) because [%s]", addr, MMDB_strerror(mmdb_error));
 | 
				
			||||||
    // Now it's safe to return the lookup result
 | 
					    // Now it's safe to return the lookup result
 | 
				
			||||||
    return LookupResult(m_Db, result);
 | 
					    return LookupResult(m_Db, result);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -100,14 +100,14 @@ LookupResult Database::LookupSockAddr(SockAddr & addr)
 | 
				
			|||||||
    Validate();
 | 
					    Validate();
 | 
				
			||||||
    // Validate the specified socket address
 | 
					    // Validate the specified socket address
 | 
				
			||||||
    if (!addr.IsValid())
 | 
					    if (!addr.IsValid())
 | 
				
			||||||
        SqThrowF("Invalid address instance");
 | 
					        STHROWF("Invalid address instance");
 | 
				
			||||||
    // Dummy variable to obtain the status codes
 | 
					    // Dummy variable to obtain the status codes
 | 
				
			||||||
    int mmdb_error;
 | 
					    int mmdb_error;
 | 
				
			||||||
    // Attempt to perform the actual lookup
 | 
					    // Attempt to perform the actual lookup
 | 
				
			||||||
    MMDB_lookup_result_s result = MMDB_lookup_sockaddr(m_Db, addr.GetHandle()->ai_addr, &mmdb_error);
 | 
					    MMDB_lookup_result_s result = MMDB_lookup_sockaddr(m_Db, addr.GetHandle()->ai_addr, &mmdb_error);
 | 
				
			||||||
    // Validate the lookup status code
 | 
					    // Validate the lookup status code
 | 
				
			||||||
    if (mmdb_error != MMDB_SUCCESS)
 | 
					    if (mmdb_error != MMDB_SUCCESS)
 | 
				
			||||||
        SqThrowF("Unable to lookup address (%s) because [%s]",
 | 
					        STHROWF("Unable to lookup address (%s) because [%s]",
 | 
				
			||||||
                    addr.GetAddress(), MMDB_strerror(mmdb_error));
 | 
					                    addr.GetAddress(), MMDB_strerror(mmdb_error));
 | 
				
			||||||
    // Now it's safe to return the lookup result
 | 
					    // Now it's safe to return the lookup result
 | 
				
			||||||
    return LookupResult(m_Db, result);
 | 
					    return LookupResult(m_Db, result);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,10 +25,10 @@ void EntryDataList::Validate() const
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    // Is the document handle valid?
 | 
					    // Is the document handle valid?
 | 
				
			||||||
    if (!m_Db)
 | 
					    if (!m_Db)
 | 
				
			||||||
        SqThrowF("Invalid Maxmind database reference");
 | 
					        STHROWF("Invalid Maxmind database reference");
 | 
				
			||||||
    // Do we have a valid list?
 | 
					    // Do we have a valid list?
 | 
				
			||||||
    else if (!m_List)
 | 
					    else if (!m_List)
 | 
				
			||||||
        SqThrowF("Invalid entry data list");
 | 
					        STHROWF("Invalid entry data list");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ------------------------------------------------------------------------------------------------
 | 
					// ------------------------------------------------------------------------------------------------
 | 
				
			||||||
@@ -36,13 +36,13 @@ void EntryDataList::ValidateElem() const
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    // Is the document handle valid?
 | 
					    // Is the document handle valid?
 | 
				
			||||||
    if (!m_Db)
 | 
					    if (!m_Db)
 | 
				
			||||||
        SqThrowF("Invalid Maxmind database reference");
 | 
					        STHROWF("Invalid Maxmind database reference");
 | 
				
			||||||
    // Do we have a valid list?
 | 
					    // Do we have a valid list?
 | 
				
			||||||
    else if (!m_List)
 | 
					    else if (!m_List)
 | 
				
			||||||
        SqThrowF("Invalid entry data list");
 | 
					        STHROWF("Invalid entry data list");
 | 
				
			||||||
    // Do we have a valid element?
 | 
					    // Do we have a valid element?
 | 
				
			||||||
    else if (!m_Elem)
 | 
					    else if (!m_Elem)
 | 
				
			||||||
        SqThrowF("Invalid entry data element");
 | 
					        STHROWF("Invalid entry data element");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ------------------------------------------------------------------------------------------------
 | 
					// ------------------------------------------------------------------------------------------------
 | 
				
			||||||
@@ -50,16 +50,16 @@ void EntryDataList::ValidateData() const
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    // Is the document handle valid?
 | 
					    // Is the document handle valid?
 | 
				
			||||||
    if (!m_Db)
 | 
					    if (!m_Db)
 | 
				
			||||||
        SqThrowF("Invalid Maxmind database reference");
 | 
					        STHROWF("Invalid Maxmind database reference");
 | 
				
			||||||
    // Do we have a valid list?
 | 
					    // Do we have a valid list?
 | 
				
			||||||
    else if (!m_List)
 | 
					    else if (!m_List)
 | 
				
			||||||
        SqThrowF("Invalid entry data list");
 | 
					        STHROWF("Invalid entry data list");
 | 
				
			||||||
    // Do we have a valid element?
 | 
					    // Do we have a valid element?
 | 
				
			||||||
    else if (!m_Elem)
 | 
					    else if (!m_Elem)
 | 
				
			||||||
        SqThrowF("Invalid entry data element");
 | 
					        STHROWF("Invalid entry data element");
 | 
				
			||||||
    // Do we have some valid data?
 | 
					    // Do we have some valid data?
 | 
				
			||||||
    else if (!m_Elem->entry_data.has_data)
 | 
					    else if (!m_Elem->entry_data.has_data)
 | 
				
			||||||
        SqThrowF("Entry data element has no data");
 | 
					        STHROWF("Entry data element has no data");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ------------------------------------------------------------------------------------------------
 | 
					// ------------------------------------------------------------------------------------------------
 | 
				
			||||||
@@ -181,7 +181,7 @@ CSStr EntryDataList::GetString() const
 | 
				
			|||||||
        case MMDB_DATA_TYPE_FLOAT:
 | 
					        case MMDB_DATA_TYPE_FLOAT:
 | 
				
			||||||
            return FmtStr("%f", m_Elem->entry_data.float_value);
 | 
					            return FmtStr("%f", m_Elem->entry_data.float_value);
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            SqThrowF("Unsupported conversion from (%s) to (string)", AsTypeStr(m_Elem->entry_data.type));
 | 
					            STHROWF("Unsupported conversion from (%s) to (string)", AsTypeStr(m_Elem->entry_data.type));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // Shouldn't really reach this point
 | 
					    // Shouldn't really reach this point
 | 
				
			||||||
    return _SC("");
 | 
					    return _SC("");
 | 
				
			||||||
@@ -213,7 +213,7 @@ SQInteger EntryDataList::GetInteger() const
 | 
				
			|||||||
        case MMDB_DATA_TYPE_FLOAT:
 | 
					        case MMDB_DATA_TYPE_FLOAT:
 | 
				
			||||||
            return llround(m_Elem->entry_data.float_value);
 | 
					            return llround(m_Elem->entry_data.float_value);
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            SqThrowF("Unsupported conversion from (%s) to (int32)", AsTypeStr(m_Elem->entry_data.type));
 | 
					            STHROWF("Unsupported conversion from (%s) to (int32)", AsTypeStr(m_Elem->entry_data.type));
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
        case MMDB_DATA_TYPE_UTF8_STRING:
 | 
					        case MMDB_DATA_TYPE_UTF8_STRING:
 | 
				
			||||||
            return strtol(m_Elem->entry_data.utf8_string, NULL, 10);
 | 
					            return strtol(m_Elem->entry_data.utf8_string, NULL, 10);
 | 
				
			||||||
@@ -232,7 +232,7 @@ SQInteger EntryDataList::GetInteger() const
 | 
				
			|||||||
        case MMDB_DATA_TYPE_FLOAT:
 | 
					        case MMDB_DATA_TYPE_FLOAT:
 | 
				
			||||||
            return lround(m_Elem->entry_data.float_value);
 | 
					            return lround(m_Elem->entry_data.float_value);
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            SqThrowF("Unsupported conversion from (%s) to (int64)", AsTypeStr(m_Elem->entry_data.type));
 | 
					            STHROWF("Unsupported conversion from (%s) to (int64)", AsTypeStr(m_Elem->entry_data.type));
 | 
				
			||||||
#endif // _SQ64
 | 
					#endif // _SQ64
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // Shouldn't really reach this point
 | 
					    // Shouldn't really reach this point
 | 
				
			||||||
@@ -268,7 +268,7 @@ SQFloat EntryDataList::GetFloat() const
 | 
				
			|||||||
        case MMDB_DATA_TYPE_FLOAT:
 | 
					        case MMDB_DATA_TYPE_FLOAT:
 | 
				
			||||||
            return static_cast< SQFloat >(m_Elem->entry_data.float_value);
 | 
					            return static_cast< SQFloat >(m_Elem->entry_data.float_value);
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            SqThrowF("Unsupported conversion from (%s) to (float)", AsTypeStr(m_Elem->entry_data.type));
 | 
					            STHROWF("Unsupported conversion from (%s) to (float)", AsTypeStr(m_Elem->entry_data.type));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // Shouldn't really reach this point
 | 
					    // Shouldn't really reach this point
 | 
				
			||||||
    return 0.0;
 | 
					    return 0.0;
 | 
				
			||||||
@@ -315,7 +315,7 @@ Object EntryDataList::GetLong() const
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            SqThrowF("Unsupported conversion from (%s) to (uint64)", AsTypeStr(m_Elem->entry_data.type));
 | 
					            STHROWF("Unsupported conversion from (%s) to (uint64)", AsTypeStr(m_Elem->entry_data.type));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // Obtain the initial stack size
 | 
					    // Obtain the initial stack size
 | 
				
			||||||
    const StackGuard sg(_SqVM);
 | 
					    const StackGuard sg(_SqVM);
 | 
				
			||||||
@@ -350,7 +350,7 @@ bool EntryDataList::GetBool() const
 | 
				
			|||||||
        case MMDB_DATA_TYPE_FLOAT:
 | 
					        case MMDB_DATA_TYPE_FLOAT:
 | 
				
			||||||
            return EpsGt(m_Elem->entry_data.float_value, 0.0f);
 | 
					            return EpsGt(m_Elem->entry_data.float_value, 0.0f);
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            SqThrowF("Unsupported conversion from (%s) to (boolean)", AsTypeStr(m_Elem->entry_data.type));
 | 
					            STHROWF("Unsupported conversion from (%s) to (boolean)", AsTypeStr(m_Elem->entry_data.type));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // Shouldn't really reach this point
 | 
					    // Shouldn't really reach this point
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
@@ -363,12 +363,12 @@ void EntryDataList::DumpTo(CSStr filepath, Int32 indent) const
 | 
				
			|||||||
    Validate();
 | 
					    Validate();
 | 
				
			||||||
    // Validate the specified file path
 | 
					    // Validate the specified file path
 | 
				
			||||||
    if (!filepath || strlen(filepath) <= 0)
 | 
					    if (!filepath || strlen(filepath) <= 0)
 | 
				
			||||||
        SqThrowF("Invalid file path");
 | 
					        STHROWF("Invalid file path");
 | 
				
			||||||
    // Attempt to open the specified file
 | 
					    // Attempt to open the specified file
 | 
				
			||||||
    FILE * fp = fopen(filepath, "w");
 | 
					    FILE * fp = fopen(filepath, "w");
 | 
				
			||||||
    // Validate the file handle
 | 
					    // Validate the file handle
 | 
				
			||||||
    if (!fp)
 | 
					    if (!fp)
 | 
				
			||||||
        SqThrowF("Unable to open file %s", filepath);
 | 
					        STHROWF("Unable to open file %s", filepath);
 | 
				
			||||||
    // Attempt to dump the entry data list
 | 
					    // Attempt to dump the entry data list
 | 
				
			||||||
    Int32 status = MMDB_dump_entry_data_list(fp, m_List, indent);
 | 
					    Int32 status = MMDB_dump_entry_data_list(fp, m_List, indent);
 | 
				
			||||||
    // Close the file handle
 | 
					    // Close the file handle
 | 
				
			||||||
@@ -376,7 +376,7 @@ void EntryDataList::DumpTo(CSStr filepath, Int32 indent) const
 | 
				
			|||||||
    // Validate the result of the operation
 | 
					    // Validate the result of the operation
 | 
				
			||||||
    if (status != MMDB_SUCCESS)
 | 
					    if (status != MMDB_SUCCESS)
 | 
				
			||||||
        // Now it's safe to throw the error
 | 
					        // Now it's safe to throw the error
 | 
				
			||||||
        SqThrowF("Unable to dump the list [%s]", MMDB_strerror(status));
 | 
					        STHROWF("Unable to dump the list [%s]", MMDB_strerror(status));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // Namespace:: SqMod
 | 
					} // Namespace:: SqMod
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,7 @@ void LookupResult::Validate() const
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    // Is the document handle valid?
 | 
					    // Is the document handle valid?
 | 
				
			||||||
    if (!m_Db)
 | 
					    if (!m_Db)
 | 
				
			||||||
        SqThrowF("Invalid Maxmind database reference");
 | 
					        STHROWF("Invalid Maxmind database reference");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ------------------------------------------------------------------------------------------------
 | 
					// ------------------------------------------------------------------------------------------------
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,7 @@ void SockAddr::Validate() const
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    // Is the document handle valid?
 | 
					    // Is the document handle valid?
 | 
				
			||||||
    if (!m_Handle)
 | 
					    if (!m_Handle)
 | 
				
			||||||
        SqThrowF("Invalid sockaddr structure handle");
 | 
					        STHROWF("Invalid sockaddr structure handle");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ------------------------------------------------------------------------------------------------
 | 
					// ------------------------------------------------------------------------------------------------
 | 
				
			||||||
@@ -40,7 +40,7 @@ SockAddr::SockAddr(CSStr addr)
 | 
				
			|||||||
        if (m_Handle)
 | 
					        if (m_Handle)
 | 
				
			||||||
            freeaddrinfo(m_Handle);
 | 
					            freeaddrinfo(m_Handle);
 | 
				
			||||||
        // Now it's safe to throw the error
 | 
					        // Now it's safe to throw the error
 | 
				
			||||||
        SqThrowF("Unable to query the specified address for information [%s]", gai_strerror(status));
 | 
					        STHROWF("Unable to query the specified address for information [%s]", gai_strerror(status));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // Save the specified string address
 | 
					    // Save the specified string address
 | 
				
			||||||
    m_Addres.assign(addr ? addr : _SC(""));
 | 
					    m_Addres.assign(addr ? addr : _SC(""));
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user