package.xml 0000664 0001750 0001750 00000704001 13210321137 013026 0 ustar jmikola jmikola
mongodb
pecl.php.net
MongoDB driver for PHP
The purpose of this driver is to provide exceptionally thin glue between MongoDB
and PHP, implementing only fundamental and performance-critical components
necessary to build a fully-functional MongoDB driver.
Jeremy Mikola
jmikola
jmikola@php.net
yes
Derick Rethans
derick
derick@php.net
yes
Hannes Magnusson
bjori
bjori@php.net
no
2017-12-01
1.3.4
1.3.4
stable
stable
Apache License
** Bug
* [PHPC-1053] - UTCDateTime constructor reports that its single argument is required
5.5.0
7.99.99
1.4.8
mongodb
mongodb-1.3.4/scripts/centos/ldap/Domain.ldif 0000664 0001750 0001750 00000000127 13210321137 020746 0 ustar jmikola jmikola dn: dc=10gen,dc=me
objectClass: dcObject
objectClass: organization
dc: 10gen
o : 10gen
mongodb-1.3.4/scripts/centos/ldap/Users.ldif 0000664 0001750 0001750 00000000106 13210321137 020635 0 ustar jmikola jmikola dn: ou=Users,dc=10gen,dc=me
ou: Users
objectClass: organizationalUnit
mongodb-1.3.4/scripts/centos/ldap/basics.ldif 0000664 0001750 0001750 00000000244 13210321137 021003 0 ustar jmikola jmikola dn: dc=10gen,dc=me
objectclass: dcObject
objectclass: organization
o: MongoDB
dc: 10gen
dn: cn=Manager,dc=10gen,dc=me
objectclass: organizationalRole
cn: Manager
mongodb-1.3.4/scripts/centos/ldap/install.sh 0000664 0001750 0001750 00000001141 13210321137 020676 0 ustar jmikola jmikola yum -y update
yum -y install openldap-servers openldap-clients openldap-devel python-devel gcc cyrus-sasl-plain xfsprogs net-snmp ps-misc wget python-ldap
service slapd stop
service slapd start
#just in case
sleep 10
ldapadd -Y EXTERNAL -H ldapi:/// -f /phongo/scripts/centos/ldap/pw.ldif
# Add our specifics
ldapadd -x -D "cn=Manager,dc=10gen,dc=me" -w password -f /phongo/scripts/centos/ldap/Domain.ldif
ldapadd -x -D "cn=Manager,dc=10gen,dc=me" -w password -f /phongo/scripts/centos/ldap/Users.ldif
# Add the users
python /phongo/scripts/centos/ldap/ldapconfig.py -f /phongo/scripts/centos/ldap/users
mongodb-1.3.4/scripts/centos/ldap/ldapconfig.py 0000664 0001750 0001750 00000003750 13210321137 021364 0 ustar jmikola jmikola #!/usr/bin/python
import optparse
import ldap
import ldap.modlist as modlist
def main():
parser = optparse.OptionParser(usage="""\
%prog [options]
Add users to LDAP """)
# add in command line options. Add mongo host/port combo later
parser.add_option("-f", "--filename", dest="fname",
help="name of file with user names",
default=None)
(options, args) = parser.parse_args()
if options.fname is None:
print "\nERROR: Must specify name of file to import\n"
sys.exit(-1)
# Open a connection
l = ldap.initialize("ldap://localhost")
# Bind/authenticate with a user with apropriate rights to add objects
l.simple_bind_s("cn=Manager,dc=10gen,dc=me","password")
for uname in open(options.fname, 'r'):
try:
# The dn of our new entry/object
print "adding ", uname
dn= 'uid=' + uname.lower() + ',ou=Users,dc=10gen,dc=me'
ldif = configUser(uname.rstrip('\r\n'))
# Do the actual synchronous add-operation to the ldapserver
l.add_s(dn,ldif)
except ldap.LDAPError, e:
print e.message['info']
# Its nice to the server to disconnect and free resources when done
l.unbind_s()
# Do the tld configuration for the ldap tree
def configDC():
# A dict to help build the "body" of the object
attrs = {}
attrs['objectclass'] = ['organization','dcObject']
attrs['dn'] = 'dc=10gen,dc=me'
attrs['dc'] = '10gen'
attrs['o'] = '10gen'
# Convert our dict to nice syntax for the add-function using modlist
ldif = modlist.addModlist(attrs)
def configOU():
# A dict to help build the "body" of the object
attrs = {}
attrs['dn'] = 'dc=10gen,dc=me'
attrs['objectclass'] = ['organiationalUnit']
attrs['ou'] = 'Users'
ldif = modlist.addModlist(attrs)
def configUser( uname ):
attrs = {}
# attrs['dn'] = ['cn=' + uname + 'ou=Users,dc=10gen,dc=me']
attrs['cn'] = [uname]
# attrs['uid'] = [uname]
attrs['sn'] = 'TestUser'
attrs['objectclass'] = ['inetOrgPerson']
attrs['userPassword'] = 'password'
return modlist.addModlist(attrs)
if __name__ == "__main__":
main()
mongodb-1.3.4/scripts/centos/ldap/mongod.ldif 0000664 0001750 0001750 00000010272 13210321137 021024 0 ustar jmikola jmikola #
# See slapd-config(5) for details on configuration options.
# This file should NOT be world readable.
#
dn: cn=config
objectClass: olcGlobal
cn: config
olcArgsFile: /var/run/openldap/slapd.args
olcPidFile: /var/run/openldap/slapd.pid
#
# TLS settings
#
olcTLSCACertificatePath: /etc/openldap/certs
olcTLSCertificateFile: "OpenLDAP Server"
olcTLSCertificateKeyFile: /etc/openldap/certs/password
#
# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#
#olcReferral: ldap://root.openldap.org
#
# Sample security restrictions
# Require integrity protection (prevent hijacking)
# Require 112-bit (3DES or better) encryption for updates
# Require 64-bit encryption for simple bind
#
#olcSecurity: ssf=1 update_ssf=112 simple_bind=64
#
# Load dynamic backend modules:
# - modulepath is architecture dependent value (32/64-bit system)
# - back_sql.la backend requires openldap-servers-sql package
# - dyngroup.la and dynlist.la cannot be used at the same time
#
#dn: cn=module,cn=config
#objectClass: olcModuleList
#cn: module
#olcModulepath: /usr/lib/openldap
#olcModulepath: /usr/lib64/openldap
#olcModuleload: accesslog.la
#olcModuleload: auditlog.la
#olcModuleload: back_dnssrv.la
#olcModuleload: back_ldap.la
#olcModuleload: back_mdb.la
#olcModuleload: back_meta.la
#olcModuleload: back_null.la
#olcModuleload: back_passwd.la
#olcModuleload: back_relay.la
#olcModuleload: back_shell.la
#olcModuleload: back_sock.la
#olcModuleload: collect.la
#olcModuleload: constraint.la
#olcModuleload: dds.la
#olcModuleload: deref.la
#olcModuleload: dyngroup.la
#olcModuleload: dynlist.la
#olcModuleload: memberof.la
#olcModuleload: pcache.la
#olcModuleload: ppolicy.la
#olcModuleload: refint.la
#olcModuleload: retcode.la
#olcModuleload: rwm.la
#olcModuleload: seqmod.la
#olcModuleload: smbk5pwd.la
#olcModuleload: sssvlv.la
#olcModuleload: syncprov.la
#olcModuleload: translucent.la
#olcModuleload: unique.la
#olcModuleload: valsort.la
#
# Schema settings
#
dn: cn=schema,cn=config
objectClass: olcSchemaConfig
cn: schema
include: file:///etc/openldap/schema/core.ldif
include: file:///etc/openldap/schema/corba.schema
include: file:///etc/openldap/schema/cosine.ldif
include: file:///etc/openldap/schema/duaconf.schema
include: file:///etc/openldap/schema/dyngroup.schema
include: file:///etc/openldap/schema/inetorgperson.ldif
include: file:///etc/openldap/schema/java.schema
include: file:///etc/openldap/schema/misc.schema
include: file:///etc/openldap/schema/nis.ldif
include: file:///etc/openldap/schema/openldap.ldif
include: file:///etc/openldap/schema/ppolicy.schema
include: file:///etc/openldap/schema/collective.schema
#
# Frontend settings
#
dn: olcDatabase=frontend,cn=config
objectClass: olcDatabaseConfig
olcDatabase: frontend
#
# Sample global access control policy:
# Root DSE: allow anyone to read it
# Subschema (sub)entry DSE: allow anyone to read it
# Other DSEs:
# Allow self write access
# Allow authenticated users read access
# Allow anonymous users to authenticate
#
#olcAccess: to dn.base="" by * read
#olcAccess: to dn.base="cn=Subschema" by * read
#olcAccess: to *
# by self write
# by users read
# by anonymous auth
#
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn. (e.g., "access to * by * read")
#
# rootdn can always read and write EVERYTHING!
#
#
# Configuration database
#
dn: olcDatabase=config,cn=config
objectClass: olcDatabaseConfig
olcDatabase: config
olcAccess: to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,c
n=auth" manage by * none
#
# Server status monitoring
#
dn: olcDatabase=monitor,cn=config
objectClass: olcDatabaseConfig
olcDatabase: monitor
olcAccess: to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,c
n=auth" read by dn.base="cn=Manager,dc=10gen,dc=me" read by * none
#
# Backend database definitions
#
dn: olcDatabase=hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: hdb
olcSuffix: dc=10gen,dc=me
olcRootDN: cn=Manager,dc=10gen,dc=me
olcRootPW: {SSHA}t3hTZGC4FTOS6AnTa76aX7HRtt1IDqFM
olcDbDirectory: /var/lib/ldap
olcDbIndex: objectClass eq,pres
olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub
mongodb-1.3.4/scripts/centos/ldap/pw.ldif 0000664 0001750 0001750 00000001173 13210321137 020167 0 ustar jmikola jmikola dn: olcDatabase={0}config,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {SSHA}t3hTZGC4FTOS6AnTa76aX7HRtt1IDqFM
-
replace: olcRootDN
olcRootDN: cn=Manager,dc=10gen,dc=me
dn: olcDatabase={2}bdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {SSHA}t3hTZGC4FTOS6AnTa76aX7HRtt1IDqFM
-
replace: olcSuffix
olcSuffix: dc=10gen,dc=me
-
replace: olcRootDN
olcRootDN: cn=Manager,dc=10gen,dc=me
dn: olcDatabase={1}monitor,cn=config
changetype: modify
replace: olcAccess
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read by dn.base="cn=Manager,dc=10gen,dc=me" read by * none
mongodb-1.3.4/scripts/centos/ldap/saslauthd.conf 0000664 0001750 0001750 00000000143 13210321137 021534 0 ustar jmikola jmikola ldap_servers: ldap://localhost:389
ldap_search_base: ou=Users,dc=10gen,dc=me
ldap_filter: (uid=%u)
mongodb-1.3.4/scripts/centos/ldap/users 0000664 0001750 0001750 00000000026 13210321137 017761 0 ustar jmikola jmikola bugs
features
dbadmin
mongodb-1.3.4/scripts/centos/essentials.sh 0000664 0001750 0001750 00000000362 13210321137 020466 0 ustar jmikola jmikola # Tools you can't live without
sudo yum install -y git vim
# I can't stand emacs
echo 'set -o vi' | sudo tee /etc/profile.d/vishell.sh
# Who knows how to configure RHEL at all anyway?
sudo service iptables stop
sudo chkconfig iptables off
mongodb-1.3.4/scripts/freebsd/essentials.sh 0000664 0001750 0001750 00000000575 13210321137 020613 0 ustar jmikola jmikola # Update ports
sudo portsnap fetch extract update
# Minimum required PHP install + pecl
sudo pkg install -y pcre php56 php56-openssl php56-json php56-zlib pear autoconf pkgconf cyrus-sasl
# We need vim. git requires curl. mongoc requires libtool and automake
sudo pkg install -y vim git curl libtool automake
# I can't stand emacs
echo 'set -o vi' | sudo tee -a /etc/profile
mongodb-1.3.4/scripts/freebsd/phongo.sh 0000664 0001750 0001750 00000000473 13210321137 017730 0 ustar jmikola jmikola ls -1 /phongo/mongodb*.tgz | sort -n -r | xargs sudo pecl install -f 2>&1 > /phongo/.build
if test $? -eq 0; then
php -m | grep -q mongodb || echo "extension=mongodb.so" | sudo tee -a /usr/local/etc/php/extensions.ini
pecl run-tests -q -p mongodb 2>&1 > /phongo/.tests
else
tail -n50 /phongo/.build
exit 3
fi
mongodb-1.3.4/scripts/presets/replicaset-30.json 0000664 0001750 0001750 00000002665 13210321137 021430 0 ustar jmikola jmikola {
"id": "REPLICASET_30",
"name": "mongod",
"members": [
{
"procParams": {
"dbpath": "/tmp/REPLICASET/3100/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/REPLICASET/3100/mongod.log",
"nohttpinterface": true,
"journal": true,
"noprealloc": true,
"nssize": 1,
"port": 3100,
"smallfiles": true,
"setParameter": {"enableTestCommands": 1}
},
"rsParams": {
"priority": 99,
"tags": {
"ordinal": "one",
"dc": "pa"
}
},
"server_id": "RS-30-one"
},
{
"procParams": {
"dbpath": "/tmp/REPLICASET/3101/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/REPLICASET/3101/mongod.log",
"nohttpinterface": true,
"journal": true,
"noprealloc": true,
"nssize": 1,
"port": 3101,
"smallfiles": true,
"setParameter": {"enableTestCommands": 1}
},
"rsParams": {
"priority": 1.1,
"tags": {
"ordinal": "two",
"dc": "nyc"
}
},
"server_id": "RS-30-two"
},
{
"procParams": {
"dbpath": "/tmp/REPLICASET/3102/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/REPLICASET/3002/mongod.log",
"nohttpinterface": true,
"journal": true,
"noprealloc": true,
"nssize": 1,
"port": 3102,
"smallfiles": true,
"setParameter": {"enableTestCommands": 1}
},
"rsParams": {
"arbiterOnly": true
},
"server_id": "RS-30-arbiter"
}
],
"version": "30-release"
}
mongodb-1.3.4/scripts/presets/replicaset.json 0000664 0001750 0001750 00000002617 13210321137 021205 0 ustar jmikola jmikola {
"id": "REPLICASET",
"name": "mongod",
"members": [
{
"procParams": {
"dbpath": "/tmp/REPLICASET/3000/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/REPLICASET/3000/mongod.log",
"nohttpinterface": true,
"journal": true,
"noprealloc": true,
"nssize": 1,
"port": 3000,
"smallfiles": true,
"setParameter": {"enableTestCommands": 1}
},
"rsParams": {
"priority": 99,
"tags": {
"ordinal": "one",
"dc": "pa"
}
},
"server_id": "RS-one"
},
{
"procParams": {
"dbpath": "/tmp/REPLICASET/3001/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/REPLICASET/3001/mongod.log",
"nohttpinterface": true,
"journal": true,
"noprealloc": true,
"nssize": 1,
"port": 3001,
"smallfiles": true,
"setParameter": {"enableTestCommands": 1}
},
"rsParams": {
"priority": 1.1,
"tags": {
"ordinal": "two",
"dc": "nyc"
}
},
"server_id": "RS-two"
},
{
"procParams": {
"dbpath": "/tmp/REPLICASET/3002/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/REPLICASET/3002/mongod.log",
"nohttpinterface": true,
"journal": true,
"noprealloc": true,
"nssize": 1,
"port": 3002,
"smallfiles": true,
"setParameter": {"enableTestCommands": 1}
},
"rsParams": {
"arbiterOnly": true
},
"server_id": "RS-arbiter"
}
]
}
mongodb-1.3.4/scripts/presets/standalone-24.json 0000664 0001750 0001750 00000000535 13210321137 021422 0 ustar jmikola jmikola {
"name": "mongod",
"id" : "STANDALONE_24",
"procParams": {
"dbpath": "/tmp/standalone-24/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/standalone-24/mongod.log",
"journal": true,
"port": 2500,
"setParameter": {"enableTestCommands": 1}
},
"version": "24-release"
}
mongodb-1.3.4/scripts/presets/standalone-26.json 0000664 0001750 0001750 00000000535 13210321137 021424 0 ustar jmikola jmikola {
"name": "mongod",
"id" : "STANDALONE_26",
"procParams": {
"dbpath": "/tmp/standalone-26/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/standalone-26/mongod.log",
"journal": true,
"port": 2600,
"setParameter": {"enableTestCommands": 1}
},
"version": "26-release"
}
mongodb-1.3.4/scripts/presets/standalone-30.json 0000664 0001750 0001750 00000000535 13210321137 021417 0 ustar jmikola jmikola {
"name": "mongod",
"id" : "STANDALONE_30",
"procParams": {
"dbpath": "/tmp/standalone-30/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/standalone-30/mongod.log",
"journal": true,
"port": 2700,
"setParameter": {"enableTestCommands": 1}
},
"version": "30-release"
}
mongodb-1.3.4/scripts/presets/standalone-auth.json 0000664 0001750 0001750 00000000610 13210321137 022130 0 ustar jmikola jmikola {
"name": "mongod",
"id" : "STANDALONE_AUTH",
"auth_key": "secret",
"login": "root",
"password": "toor",
"procParams": {
"dbpath": "/tmp/standalone-auth/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/standalone-auth/m.log",
"journal": true,
"port": 2200,
"setParameter": {"enableTestCommands": 1}
}
}
mongodb-1.3.4/scripts/presets/standalone-plain.json 0000664 0001750 0001750 00000000746 13210321137 022304 0 ustar jmikola jmikola {
"name": "mongod",
"id" : "STANDALONE_PLAIN",
"auth_key": "secret",
"login": "root",
"password": "toor",
"procParams": {
"dbpath": "/tmp/standalone-plain/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/standalone-plain/m.log",
"journal": true,
"port": 2400,
"setParameter": {"enableTestCommands": 1, "saslauthdPath": "/var/run/saslauthd/mux", "authenticationMechanisms": "MONGODB-CR,PLAIN"}
}
}
mongodb-1.3.4/scripts/presets/standalone-ssl.json 0000664 0001750 0001750 00000001015 13210321137 021770 0 ustar jmikola jmikola {
"name": "mongod",
"id" : "STANDALONE_SSL",
"procParams": {
"dbpath": "/tmp/standalone-ssl/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/standalone-ssl/m.log",
"journal": true,
"port": 2100,
"setParameter": {"enableTestCommands": 1}
},
"sslParams": {
"sslMode": "requireSSL",
"sslCAFile": "/phongo/scripts/ssl/ca.pem",
"sslPEMKeyFile": "/phongo/scripts/ssl/server.pem",
"sslWeakCertificateValidation": true
}
}
mongodb-1.3.4/scripts/presets/standalone-x509.json 0000664 0001750 0001750 00000001256 13210321137 021703 0 ustar jmikola jmikola {
"name": "mongod",
"id" : "STANDALONE_X509",
"authSource": "$external",
"login": "C=US,ST=New York,L=New York City,O=MongoDB,OU=KernelUser,CN=client",
"procParams": {
"dbpath": "/tmp/standalone-x509/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/standalone-x509/m.log",
"journal": true,
"port": 2300,
"setParameter": {"enableTestCommands": 1, "authenticationMechanisms": "MONGODB-X509"}
},
"sslParams": {
"sslMode": "requireSSL",
"sslCAFile": "/phongo/scripts/ssl/ca.pem",
"sslPEMKeyFile": "/phongo/scripts/ssl/server.pem",
"sslWeakCertificateValidation": true
}
}
mongodb-1.3.4/scripts/presets/standalone.json 0000664 0001750 0001750 00000000467 13210321137 021203 0 ustar jmikola jmikola {
"name": "mongod",
"id" : "STANDALONE",
"procParams": {
"dbpath": "/tmp/standalone/",
"ipv6": true,
"logappend": true,
"logpath": "/tmp/standalone/mongod.log",
"journal": true,
"port": 2000,
"setParameter": {"enableTestCommands": 1}
}
}
mongodb-1.3.4/scripts/ssl/ca.pem 0000664 0001750 0001750 00000005641 13210321137 016361 0 ustar jmikola jmikola -----BEGIN CERTIFICATE-----
MIIDczCCAlugAwIBAgIBATANBgkqhkiG9w0BAQUFADB0MRcwFQYDVQQDEw5LZXJu
ZWwgVGVzdCBDQTEPMA0GA1UECxMGS2VybmVsMRAwDgYDVQQKEwdNb25nb0RCMRYw
FAYDVQQHEw1OZXcgWW9yayBDaXR5MREwDwYDVQQIEwhOZXcgWW9yazELMAkGA1UE
BhMCVVMwHhcNMTQwNzE3MTYwMDAwWhcNMjAwNzE3MTYwMDAwWjB0MRcwFQYDVQQD
Ew5LZXJuZWwgVGVzdCBDQTEPMA0GA1UECxMGS2VybmVsMRAwDgYDVQQKEwdNb25n
b0RCMRYwFAYDVQQHEw1OZXcgWW9yayBDaXR5MREwDwYDVQQIEwhOZXcgWW9yazEL
MAkGA1UEBhMCVVMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCBxSXj
qA5y2EMQkcmvLDNikE88Og3+spJ3ex60HWVPk8EeXN68jyfbKLYsoCcBE2rBAE/N
shVBJa8irh0o/UTh1XNW4iGCsfMvYamXiHnaOjmGVKjfBoj6pzQH0uK0X5olm3Sa
zZPkLLCR81yxsK6woJZMFTvrlEjxj/SmDZ9tVXW692bC4i6nGvOCSpgv9kms85xO
Ed2xbuCLXFDXKafXZd5AK+iegkDs3ah7VXMEE8sbqGnlqC1nsy5bpCnb7aC+3af7
SV2XEFlSQT5kwTmk9CvTDzM9O78SO8nNhEOFBLQEdGDGd3BShE8dCdh2JTy3zKsb
WeE+mxy0mEwxNfGfAgMBAAGjEDAOMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEF
BQADggEBAANwbvhM5K/Jcl6yzUSqAawvyAypT5aWBob7rt9KFq/aemjMN0gY2nsS
8WTGd9jiXlxGc/TzrK6MOsJ904UAFE1L9uR//G1gIBa9dNbYoiii2Fc8b1xDVJEP
b23rl/+GAT6UTSY+YgEjeA4Jk6H9zotO07lSw06rbCQam5SdA5UiMvuLHWCo3BHY
8WzqLiW/uHlb4K5prF9yuTUBEIgkRvvvyOKXlRvm1Ed5UopT2hmwA86mffAfgJc2
vSbm9/8Q00fYwO7mluB6mbEcnbquaqRLoB83k+WbwUAZ2yjWHXuXVMPwyaysazcp
nOjaLwQJQgKejY62PiNcw7xC/nIxBeI=
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAgcUl46gOcthDEJHJrywzYpBPPDoN/rKSd3setB1lT5PBHlze
vI8n2yi2LKAnARNqwQBPzbIVQSWvIq4dKP1E4dVzVuIhgrHzL2Gpl4h52jo5hlSo
3waI+qc0B9LitF+aJZt0ms2T5CywkfNcsbCusKCWTBU765RI8Y/0pg2fbVV1uvdm
wuIupxrzgkqYL/ZJrPOcThHdsW7gi1xQ1ymn12XeQCvonoJA7N2oe1VzBBPLG6hp
5agtZ7MuW6Qp2+2gvt2n+0ldlxBZUkE+ZME5pPQr0w8zPTu/EjvJzYRDhQS0BHRg
xndwUoRPHQnYdiU8t8yrG1nhPpsctJhMMTXxnwIDAQABAoIBAD5iGOnM800wO2Uu
wGbOd9FNEFoiinHDRHfdnw/1BavwmqjO+mBo7T8E3jarsrRosiwfyz1V+7O6uuuQ
CgKXZlKuOuksgfGDPCWt7EolWHaZAOhbsGaujJD6ah/MuCD/yGmFxtNYOl05QpSX
Cht9lSzhtf7TQl/og/xkOLbO27JB540ck/OCSOczXg9Z/O8AmIUyDn7AKb6G1Zhk
2IN//HQoAvDUMZLWrzy+L7YGbA8pBR3yiPsYBH0rX2Oc9INpiGA+B9Nf1HDDsxeZ
/o+5xLbRDDfIDtlYO0cekJ053W0zUQLrMEIn9991EpG2O/fPgs10NlKJtaFH8CmT
ExgVA9ECgYEA+6AjtUdxZ0BL3Wk773nmhesNH5/5unWFaGgWpMEaEM7Ou7i6QApL
KAbzOYItV3NNCbkcrejq7jsDGEmiwUOdXeQx6XN7/Gb2Byc/wezy5ALi0kcUwaur
6s9+Ah+T4vcU2AjfuCWXIpe46KLEbwORmCRQGwkCBCwRhHGt5sGGxTkCgYEAhAaw
voHI6Cb+4z3PNAKRnf2rExBYRyCz1KF16ksuwJyQSLzFleXRyRWFUEwLuVRL0+EZ
JXhMbtrILrc23dJGEsB8kOCFehSH/IuL5eB0QfKpDFA+e6pimsbVeggx/rZhcERB
WkcV3jN4O82gSL3EnIgvAT1/nwhmbmjvDhFJhZcCgYBaW4E3IbaZaz9S/O0m69Fa
GbQWvS3CRV1oxqgK9cTUcE9Qnd9UC949O3GwHw0FMERjz3N7B/8FGW/dEuQ9Hniu
NLmvqWbGlnqWywNcMihutJKbDCdp/Km5olUPkiNbB3sWsOkViXoiU/V0pK6BZvir
d67EZpGwydpogyH9kVVCEQKBgGHXc3Q7SmCBRbOyQrQQk0m6i+V8328W1S5m2bPg
M62aWXMOMn976ZRT1pBDSwz1Y5yJ3NDf7gTZLjEwpgCNrFCJRcc4HLL0NDL8V5js
VjvpUU5GyYdsJdb+M4ZUPHi/QEaqzqPQumwJSLlJEdfWirZWVj9dDA8XcpGwQjjy
psHRAoGBAJUTgeJYhjK7k5sgfh+PRqiRJP0msIH8FK7SenBGRUkelWrW6td2Riey
EcOCMFkRWBeDgnZN5xDyWLBgrzpw9iHQQIUyyBaFknQcRUYKHkCx+k+fr0KHHCUb
X2Kvf0rbeMucb4y/h7950HkBBq83AYKMAoI8Ql3cx7pKmyOLXRov
-----END RSA PRIVATE KEY----- mongodb-1.3.4/scripts/ssl/client.pem 0000600 0001750 0001750 00000005611 13210321137 017237 0 ustar jmikola jmikola -----BEGIN CERTIFICATE-----
MIIDXTCCAkWgAwIBAgIBAzANBgkqhkiG9w0BAQUFADB0MRcwFQYDVQQDEw5LZXJu
ZWwgVGVzdCBDQTEPMA0GA1UECxMGS2VybmVsMRAwDgYDVQQKEwdNb25nb0RCMRYw
FAYDVQQHEw1OZXcgWW9yayBDaXR5MREwDwYDVQQIEwhOZXcgWW9yazELMAkGA1UE
BhMCVVMwHhcNMTQwNzE3MTYwMDAwWhcNMjAwNzE3MTYwMDAwWjBwMQ8wDQYDVQQD
EwZjbGllbnQxEzARBgNVBAsTCktlcm5lbFVzZXIxEDAOBgNVBAoTB01vbmdvREIx
FjAUBgNVBAcTDU5ldyBZb3JrIENpdHkxETAPBgNVBAgTCE5ldyBZb3JrMQswCQYD
VQQGEwJVUzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJIFboAk9Fdi
DY5Xld2iw36vB3IpHEfgWIimd+l1HX4jyp35i6xoqkZZHJUL/NMbUFJ6+44EfFJ5
biB1y1Twr6GqpYp/3R30jKQU4PowO7DSal38MR34yiRFYPG4ZPPXXfwPSuwKrSNo
bjqa0/DRJRVQlnGwzJkPsWxIgCjc8KNO/dSHv/CGymc9TjiFAI0VVOhMok1CBNvc
ifwWjGBg5V1s3ItMw9x5qk+b9ff5hiOAGxPiCrr8R0C7RoeXg7ZG8K/TqXbsOZEG
AOQPRGcrmqG3t4RNBJpZugarPWW6lr11zMpiPLFTrbq3ZNYB9akdsps4R43TKI4J
AOtGMJmK430CAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAA+nPgVT4addi13yB6mjW
+UhdUkFwtb1Wcg0sLtnNucopHZLlCj5FfDdp1RQxe3CyMonxyHTKkrWtQmVtUyvf
C/fjpIKt9A9kAmveMHBiu9FTNTc0sbiXcrEBeHF5cD7N+Uwfoc/4rJm0WjEGNkAd
pYLCCLVZXPVr3bnc3ZLY1dFZPsJrdH3nJGMjLgUmoNsKnaGozcjiKiXqm6doFzkg
0Le5yD4C/QTaie2ycFa1X5bJfrgoMP7NqKko05h4l0B0+DnjpoTJN+zRreNTMKvE
ETGvpUu0IYGxe8ZVAFnlEO/lUeMrPFvH+nDmJYsxO1Sjpds2hi1M1JoeyrTQPwXj
2Q==
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAkgVugCT0V2INjleV3aLDfq8HcikcR+BYiKZ36XUdfiPKnfmL
rGiqRlkclQv80xtQUnr7jgR8UnluIHXLVPCvoaqlin/dHfSMpBTg+jA7sNJqXfwx
HfjKJEVg8bhk89dd/A9K7AqtI2huOprT8NElFVCWcbDMmQ+xbEiAKNzwo0791Ie/
8IbKZz1OOIUAjRVU6EyiTUIE29yJ/BaMYGDlXWzci0zD3HmqT5v19/mGI4AbE+IK
uvxHQLtGh5eDtkbwr9Opduw5kQYA5A9EZyuaobe3hE0Emlm6Bqs9ZbqWvXXMymI8
sVOturdk1gH1qR2ymzhHjdMojgkA60YwmYrjfQIDAQABAoIBAB249VEoNIRE9TVw
JpVCuEBlKELYk2UeCWdnWykuKZ6vcmLNlNy3QVGoeeTs172w5ZykY+f4icXP6da5
o3XauCVUMvYKKNwcFzSe+1xxzPSlH/mZh/Xt2left6f8PLBVuk/AXSPG2I9Ihodv
VIzERaQdD0J9FmhhhV/hMhUfQ+w5rTCaDpq1KVGU61ks+JAtlQ46g+cvPF9c80cI
TEC875n2LqWKmLRN43JUnctV3uGTmolIqCRMHPAs/egl+lG2RXJjqXSQ2uFLOvC/
PXtBb597yadSs2BWPnTu/r7LbLGBAExzlQK1uFsTvuKsBPb3qrvUux0L68qwPuiv
W24N8BECgYEAydtAvVB7OymQEX3mck2j7ixDN01wc1ZaCLBDvYPYS/Pvzq4MBiAD
lHRtbIa6HPGA5jskbccPqQn8WGnJWCaYvCQryvgaA+BBgo1UTLfQJUo/7N5517vv
KvbUa6NF0nj3VwfDV1vvy+amoWi9NOVn6qOh0K84PF4gwagb1EVy9MsCgYEAuTAt
KCWdZ/aNcKgJc4NCUqBpLPF7EQypX14teixrbF/IRNS1YC9S20hpkG25HMBXjpBe
tVg/MJe8R8CKzYjCt3z5Ff1bUQ2bzivbAtgjcaO0Groo8WWjnamQlrIQcvWM7vBf
dnIflQ0slxbHfCi3XEe8tj2T69R7wJZ8L7PxR9cCgYEACgwNtt6Qo6s37obzt3DB
3hL57YC/Ph5oMNKFLKOpWm5z2zeyhYOGahc5cxNppBMpNUxwTb6AuwsyMjxhty+E
nqi2PU4IDXVWDWd3cLIdfB2r/OA99Ez4ZI0QmaLw0L8QoJZUVL7QurdqR9JsyHs6
puUqIrb195s/yiPR7sjeJe0CgYEAuJviKEd3JxCN52RcJ58OGrh2oKsJ9/EbV0rX
Ixfs7th9GMDDHuOOQbNqKOR4yMSlhCU/hKA4PgTFWPIEbOiM08XtuZIb2i0qyNjH
N4qnqr166bny3tJnzOAgl1ljNHa8y+UsBTO3cCr17Jh0vL0KLSAGa9XvBAWKaG6b
1iIXwXkCgYAVz+DA1yy0qfXdS1pgPiCJGlGZXpbBcFnqvbpGSclKWyUG4obYCbrb
p5VKVfoK7uU0ly60w9+PNIRsX/VN/6SVcoOzKx40qQBMuYfJ72DQrsPjPYvNg/Nb
4SK94Qhp9TlAyXbqKJ02DjtuDim44sGZ8g7b+k3FfoK4OtzNsqdVdQ==
-----END RSA PRIVATE KEY----- mongodb-1.3.4/scripts/ssl/crl.pem 0000664 0001750 0001750 00000003765 13210321137 016563 0 ustar jmikola jmikola Certificate Revocation List (CRL):
Version 2 (0x1)
Signature Algorithm: sha256WithRSAEncryption
Issuer: /CN=Kernel Test CA/OU=Kernel/O=MongoDB/L=New York City/ST=New York/C=US
Last Update: Aug 21 13:56:28 2014 GMT
Next Update: Aug 18 13:56:28 2024 GMT
CRL extensions:
X509v3 CRL Number:
4096
No Revoked Certificates.
Signature Algorithm: sha256WithRSAEncryption
48:1b:0b:b1:89:f5:6f:af:3c:dd:2a:a0:e5:55:04:80:16:b4:
23:98:39:bb:9f:16:c9:25:73:72:c6:a6:73:21:1d:1a:b6:99:
fc:47:5e:bc:af:64:29:02:9c:a5:db:15:8a:65:48:3c:4f:a6:
cd:35:47:aa:c6:c0:39:f5:a6:88:8f:1b:6c:26:61:4e:10:d7:
e2:b0:20:3a:64:92:c1:d3:2a:11:3e:03:e2:50:fd:4e:3c:de:
e2:e5:78:dc:8e:07:a5:69:55:13:2b:8f:ae:21:00:42:85:ff:
b6:b1:2b:69:08:40:5a:25:8c:fe:57:7f:b1:06:b0:72:ff:61:
de:21:59:05:a8:1b:9e:c7:8a:08:ab:f5:bc:51:b3:36:68:0f:
54:65:3c:8d:b7:80:d0:27:01:3e:43:97:89:19:89:0e:c5:01:
2c:55:9f:b6:e4:c8:0b:35:f8:52:45:d3:b4:09:ce:df:73:98:
f5:4c:e4:5a:06:ac:63:4c:f8:4d:9c:af:88:fc:19:f7:77:ea:
ee:56:18:49:16:ce:62:66:d1:1b:8d:66:33:b5:dc:b1:25:b3:
6c:81:e9:d0:8a:1d:83:61:49:0e:d9:94:6a:46:80:41:d6:b6:
59:a9:30:55:3d:5b:d3:5b:f1:37:ec:2b:76:d0:3a:ac:b2:c8:
7c:77:04:78
-----BEGIN X509 CRL-----
MIIBzjCBtwIBATANBgkqhkiG9w0BAQsFADB0MRcwFQYDVQQDEw5LZXJuZWwgVGVz
dCBDQTEPMA0GA1UECxMGS2VybmVsMRAwDgYDVQQKEwdNb25nb0RCMRYwFAYDVQQH
Ew1OZXcgWW9yayBDaXR5MREwDwYDVQQIEwhOZXcgWW9yazELMAkGA1UEBhMCVVMX
DTE0MDgyMTEzNTYyOFoXDTI0MDgxODEzNTYyOFqgDzANMAsGA1UdFAQEAgIQADAN
BgkqhkiG9w0BAQsFAAOCAQEASBsLsYn1b6883Sqg5VUEgBa0I5g5u58WySVzcsam
cyEdGraZ/EdevK9kKQKcpdsVimVIPE+mzTVHqsbAOfWmiI8bbCZhThDX4rAgOmSS
wdMqET4D4lD9Tjze4uV43I4HpWlVEyuPriEAQoX/trEraQhAWiWM/ld/sQawcv9h
3iFZBagbnseKCKv1vFGzNmgPVGU8jbeA0CcBPkOXiRmJDsUBLFWftuTICzX4UkXT
tAnO33OY9UzkWgasY0z4TZyviPwZ93fq7lYYSRbOYmbRG41mM7XcsSWzbIHp0Iod
g2FJDtmUakaAQda2WakwVT1b01vxN+wrdtA6rLLIfHcEeA==
-----END X509 CRL-----
mongodb-1.3.4/scripts/ssl/server.pem 0000664 0001750 0001750 00000005665 13210321137 017312 0 ustar jmikola jmikola -----BEGIN CERTIFICATE-----
MIIDfjCCAmagAwIBAgIBBzANBgkqhkiG9w0BAQUFADB0MRcwFQYDVQQDEw5LZXJu
ZWwgVGVzdCBDQTEPMA0GA1UECxMGS2VybmVsMRAwDgYDVQQKEwdNb25nb0RCMRYw
FAYDVQQHEw1OZXcgWW9yayBDaXR5MREwDwYDVQQIEwhOZXcgWW9yazELMAkGA1UE
BhMCVVMwHhcNMTQwNzE3MTYwMDAwWhcNMjAwNzE3MTYwMDAwWjBsMQ8wDQYDVQQD
EwZzZXJ2ZXIxDzANBgNVBAsTBktlcm5lbDEQMA4GA1UEChMHTW9uZ29EQjEWMBQG
A1UEBxMNTmV3IFlvcmsgQ2l0eTERMA8GA1UECBMITmV3IFlvcmsxCzAJBgNVBAYT
AlVTMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp76KJeDczBqjSPJj
5f8DHdtrWpQDK9AWNDlslWpi6+pL8hMqwbX0D7hC2r3kAgccMyFoNIudPqIXfXVd
1LOh6vyY+jveRvqjKW/UZVzZeiL4Gy4bhke6R8JRC3O5aMKIAbaiQUAI1Nd8LxIt
LGvH+ia/DFza1whgB8ym/uzVQB6igOifJ1qHWJbTtIhDKaW8gvjOhv5R3jzjfLEb
R9r5Q0ZyE0lrO27kTkqgBnHKPmu54GSzU/r0HM3B+Sc/6UN+xNhNbuR+LZ+EvJHm
r4de8jhW8wivmjTIvte33jlLibQ5nYIHrlpDLEwlzvDGaIio+OfWcgs2WuPk98MU
tht0IQIDAQABoyMwITAfBgNVHREEGDAWgglsb2NhbGhvc3SCCTEyNy4wLjAuMTAN
BgkqhkiG9w0BAQUFAAOCAQEANoYxvVFsIol09BQA0fwryAye/Z4dYItvKhmwB9VS
t99DsmJcyx0P5meB3Ed8SnwkD0NGCm5TkUY/YLacPP9uJ4SkbPkNZ1fRISyShCCn
SGgQUJWHbCbcIEj+vssFb91c5RFJbvnenDkQokRvD2VJWspwioeLzuwtARUoMH3Y
qg0k0Mn7Bx1bW1Y6xQJHeVlnZtzxfeueoFO55ZRkZ0ceAD/q7q1ohTXi0vMydYgu
1CB6VkDuibGlv56NdjbttPJm2iQoPaez8tZGpBo76N/Z1ydan0ow2pVjDXVOR84Y
2HSZgbHOGBiycNw2W3vfw7uK0OmiPRTFpJCmewDjYwZ/6w==
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAp76KJeDczBqjSPJj5f8DHdtrWpQDK9AWNDlslWpi6+pL8hMq
wbX0D7hC2r3kAgccMyFoNIudPqIXfXVd1LOh6vyY+jveRvqjKW/UZVzZeiL4Gy4b
hke6R8JRC3O5aMKIAbaiQUAI1Nd8LxItLGvH+ia/DFza1whgB8ym/uzVQB6igOif
J1qHWJbTtIhDKaW8gvjOhv5R3jzjfLEbR9r5Q0ZyE0lrO27kTkqgBnHKPmu54GSz
U/r0HM3B+Sc/6UN+xNhNbuR+LZ+EvJHmr4de8jhW8wivmjTIvte33jlLibQ5nYIH
rlpDLEwlzvDGaIio+OfWcgs2WuPk98MUtht0IQIDAQABAoIBACgi1ilECXCouwMc
RDzm7Jb7Rk+Q9MVJ79YlG08Q+oRaNjvAzE03PSN5wj1WjDTUALJXPvi7oy82V4qE
R6Q6Kvbv46aUJpYzKFEk2dw7ACpSLa1LNfjGNtMusnecA/QF/8bxLReRu8s5mBQn
NDnZvCqllLbfjNlAvsF+/UIn5sqFZpAZPMtPwkTAeh5ge8H9JvrG8y8aXsiFGAhV
Z7tMZyn8wPCUrRi14NLvVB4hxM66G/tuTp8r9AmeTU+PV+qbCnKXd+v0IS52hvX9
z75OPfAc66nm4bbPCapb6Yx7WaewPXXU0HDxeaT0BeQ/YfoNa5OT+ZOX1KndSfHa
VhtmEsECgYEA3m86yYMsNOo+dkhqctNVRw2N+8gTO28GmWxNV9AC+fy1epW9+FNR
yTQXpBkRrR7qrd5mF7WBc7vAIiSfVs021RMofzn5B1x7jzkH34VZtlviNdE3TZhx
lPinqo0Yy3UEksgsCBJFIofuCmeTLk4ZtqoiZnXr35RYibaZoQdUT4kCgYEAwQ6Y
xsKFYFks1+HYl29kR0qUkXFlVbKOhQIlj/dPm0JjZ0xYkUxmzoXD68HrOWgz7hc2
hZaQTgWf+8cRaZNfh7oL+Iglczc2UXuwuUYguYssD/G6/ZPY15PhItgCghaU5Ewy
hMwIJ81NENY2EQTgk/Z1KZitXdVJfHl/IPMQgdkCgYASdqkqkPjaa5dDuj8byO8L
NtTSUYlHJbAmjBbfcyTMG230/vkF4+SmDuznci1FcYuJYyyWSzqzoKISM3gGfIJQ
rYZvCSDiu4qGGPXOWANaX8YnMXalukGzW/CO96dXPB9lD7iX8uxKMX5Q3sgYz+LS
hszUNHWf2XB//ehCtZkKAQKBgQCxL2luepeZHx82H9T+38BkYgHLHw0HQzLkxlyd
LjlE4QCEjSB4cmukvkZbuYXfEVEgAvQKVW6p/SWhGkpT4Gt8EXftKV9dyF21GVXQ
JZnhUOcm1xBsrWYGLXYi2agrpvgONBTlprERfq5tdnz2z8giZL+RZswu45Nnh8bz
AcKzuQKBgQCGOQvKvNL5XKKmws/KRkfJbXgsyRT2ubO6pVL9jGQG5wntkeIRaEpT
oxFtWMdPx3b3cxtgSP2ojllEiISk87SFIN1zEhHZy/JpTF0GlU1qg3VIaA78M1p2
ZdpUsuqJzYmc3dDbQMepIaqdW4xMoTtZFyenUJyoezz6eWy/NlZ/XQ==
-----END RSA PRIVATE KEY----- mongodb-1.3.4/scripts/ubuntu/ldap/install.sh 0000664 0001750 0001750 00000001006 13210321137 020725 0 ustar jmikola jmikola sudo apt-get -y install ldap-utils libsasl2-modules-ldap sasl2-bin
# setup saslauthd
sudo sed -i 's/MECHANISMS="pam"/MECHANISMS="ldap"/' /etc/default/saslauthd
sudo sed -i 's/START=no/START="yes"/' /etc/default/saslauthd
sudo cp /phongo/scripts/ubuntu/ldap/saslauthd.conf /etc/
sudo service saslauthd restart
testsaslauthd -u bugs -p password -s mongod -f /var/run/saslauthd/mux
#ldapsearch -x -LLL -b dc=10gen,dc=me -h 192.168.112.20
#ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts -h 192.168.112.20
mongodb-1.3.4/scripts/ubuntu/ldap/saslauthd.conf 0000664 0001750 0001750 00000000150 13210321137 021561 0 ustar jmikola jmikola ldap_servers: ldap://192.168.112.20:389
ldap_search_base: ou=Users,dc=10gen,dc=me
ldap_filter: (uid=%u)
mongodb-1.3.4/scripts/ubuntu/essentials.sh 0000664 0001750 0001750 00000000365 13210321137 020520 0 ustar jmikola jmikola if [ ! -e ".provisioned" ]; then
# Tools you can't live without
apt-get update
apt-get install -y build-essential git vim libtool autoconf
# I can't stand emacs
echo 'set -o vi' | sudo tee /etc/profile.d/vishell.sh
touch .provisioned
fi
mongodb-1.3.4/scripts/ubuntu/mongo-orchestration.sh 0000664 0001750 0001750 00000003277 13210321137 022354 0 ustar jmikola jmikola # Enable MongoDB Enterprise repo
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
# 3.2 key
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo 'deb http://repo.mongodb.com/apt/ubuntu precise/mongodb-enterprise/3.2 multiverse' | sudo tee /etc/apt/sources.list.d/mongodb-enterprise-3.2.list
echo 'deb http://repo.mongodb.com/apt/ubuntu precise/mongodb-enterprise/3.0 multiverse' | sudo tee /etc/apt/sources.list.d/mongodb-enterprise-3.0.list
echo 'deb http://repo.mongodb.com/apt/ubuntu precise/mongodb-enterprise/2.6 multiverse' | sudo tee /etc/apt/sources.list.d/mongodb-enterprise-2.6.list
echo 'deb http://repo.mongodb.com/apt/ubuntu precise/mongodb-enterprise/2.4 multiverse' | sudo tee /etc/apt/sources.list.d/mongodb-enterprise-2.4.list
apt-get update
apt-get install -y libsnmp15 libgsasl7
sudo apt-get download mongodb-enterprise-server=3.2.0
sudo apt-get download mongodb-enterprise-mongos=3.2.0
sudo apt-get download mongodb-enterprise-server=3.0.3
sudo apt-get download mongodb-enterprise-server=2.6.9
sudo apt-get download mongodb-10gen-enterprise=2.4.13
dpkg -x mongodb-10gen-enterprise_2.4.13_amd64.deb 2.4.13
dpkg -x mongodb-enterprise-server_2.6.9_amd64.deb 2.6.9
dpkg -x mongodb-enterprise-server_3.0.3_amd64.deb 3.0.3
dpkg -x mongodb-enterprise-server_3.2.0_amd64.deb 3.2.0
dpkg -x mongodb-enterprise-mongos_3.2.0_amd64.deb 3.2.0
# Python stuff for mongo-orchestration
apt-get install -y python python-dev python-pip
pip install --upgrade 'git+https://github.com/10gen/mongo-orchestration.git#egg=mongo_orchestration'
# Launch mongo-orchestration
mongo-orchestration -f mongo-orchestration-config.json -b 192.168.112.10 --enable-majority-read-concern start
mongodb-1.3.4/scripts/ubuntu/phongo.sh 0000664 0001750 0001750 00000000566 13210321137 017643 0 ustar jmikola jmikola apt-get install -y php-pear php5-dbg gdb
apt-get install -y libssl-dev libsasl2-dev libpcre3-dev pkg-config
ls -1 /phongo/mongodb*.tgz | sort -n -r | xargs sudo pecl install -f 2>&1 > /phongo/.build
php -m | grep -q mongodb || echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
pecl run-tests -q -p mongodb 2>&1 > /phongo/.tests
mongodb-1.3.4/scripts/vmware/kernel.sh 0000664 0001750 0001750 00000000466 13210321137 017607 0 ustar jmikola jmikola # Ensure that VMWare Tools recompiles kernel modules
# when we update the linux images
sed -i.bak 's/answer AUTO_KMODS_ENABLED_ANSWER no/answer AUTO_KMODS_ENABLED_ANSWER yes/g' /etc/vmware-tools/locations
sed -i.bak 's/answer AUTO_KMODS_ENABLED no/answer AUTO_KMODS_ENABLED yes/g' /etc/vmware-tools/locations
mongodb-1.3.4/scripts/convert-bson-corpus-tests.php 0000664 0001750 0001750 00000026676 13210321137 022306 0 ustar jmikola jmikola 'Variation in double\'s string representation (SPEC-850)',
'Double type: -1.23456789012345677E+18' => 'Variation in double\'s string representation (SPEC-850)',
'Int64 type: -1' => 'PHP encodes integers as 32-bit if range allows',
'Int64 type: 0' => 'PHP encodes integers as 32-bit if range allows',
'Int64 type: 1' => 'PHP encodes integers as 32-bit if range allows',
'Javascript Code with Scope: bad scope doc (field has bad string length)' => 'Depends on PHPC-889',
'Javascript Code with Scope: Unicode and embedded null in code string, empty scope' => 'Embedded null in code string is not supported in libbson (CDRIVER-1879)',
'Multiple types within the same document: All BSON types' => 'PHP encodes integers as 32-bit if range allows',
'Top-level document validity: Bad $date (number, not string or hash)' => 'Legacy extended JSON $date syntax uses numbers (CDRIVER-2223)',
];
$outputPath = realpath(__DIR__ . '/../tests') . '/bson-corpus/';
if ( ! is_dir($outputPath) && ! mkdir($outputPath, 0755, true)) {
printf("Error creating output path: %s\n", $outputPath);
}
foreach (array_slice($argv, 1) as $inputFile) {
if ( ! is_readable($inputFile) || ! is_file($inputFile)) {
printf("Error reading %s\n", $inputFile);
continue;
}
$test = json_decode(file_get_contents($inputFile), true);
if (json_last_error() !== JSON_ERROR_NONE) {
printf("Error decoding %s: %s\n", $inputFile, json_last_error_msg());
continue;
}
if ( ! isset($test['description'])) {
printf("Skipping test file without \"description\" field: %s\n", $inputFile);
continue;
}
if ( ! empty($test['deprecated'])) {
printf("Skipping deprecated test file: %s\n", $inputFile);
continue;
}
if ( ! empty($test['valid'])) {
foreach ($test['valid'] as $i => $case) {
$outputFile = sprintf('%s-valid-%03d.phpt', pathinfo($inputFile, PATHINFO_FILENAME), $i + 1);
try {
$output = renderPhpt(getParamsForValid($test, $case), $expectedFailures);
} catch (Exception $e) {
printf("Error processing valid[%d] in %s: %s\n", $i, $inputFile, $e->getMessage());
continue;
}
if (false === file_put_contents($outputPath . '/' . $outputFile, $output)) {
printf("Error writing valid[%d] in %s\n", $i, $inputFile);
continue;
}
}
}
if ( ! empty($test['decodeErrors'])) {
foreach ($test['decodeErrors'] as $i => $case) {
$outputFile = sprintf('%s-decodeError-%03d.phpt', pathinfo($inputFile, PATHINFO_FILENAME), $i + 1);
try {
$output = renderPhpt(getParamsForDecodeError($test, $case), $expectedFailures);
} catch (Exception $e) {
printf("Error processing decodeErrors[%d] in %s: %s\n", $i, $inputFile, $e->getMessage());
continue;
}
if (false === file_put_contents($outputPath . '/' . $outputFile, $output)) {
printf("Error writing decodeErrors[%d] in %s\n", $i, $inputFile);
continue;
}
}
}
if ( ! empty($test['parseErrors'])) {
foreach ($test['parseErrors'] as $i => $case) {
$outputFile = sprintf('%s-parseError-%03d.phpt', pathinfo($inputFile, PATHINFO_FILENAME), $i + 1);
try {
$output = renderPhpt(getParamsForParseError($test, $case), $expectedFailures);
} catch (Exception $e) {
printf("Error processing parseErrors[%d] in %s: %s\n", $i, $inputFile, $e->getMessage());
continue;
}
if (false === file_put_contents($outputPath . '/' . $outputFile, $output)) {
printf("Error writing parseErrors[%d] in %s\n", $i, $inputFile);
continue;
}
}
}
}
function getParamsForValid(array $test, array $case)
{
foreach (['description', 'canonical_bson', 'canonical_extjson'] as $field) {
if (!isset($case[$field])) {
throw new InvalidArgumentException(sprintf('Missing "%s" field', $field));
}
}
$code = '';
$expect = '';
$lossy = isset($case['lossy']) ? (boolean) $case['lossy'] : false;
$canonicalBson = $case['canonical_bson'];
$expectedCanonicalBson = strtolower($canonicalBson);
$code .= sprintf('$canonicalBson = hex2bin(%s);', var_export($canonicalBson, true)) . "\n";
if (isset($case['degenerate_bson'])) {
$degenerateBson = $case['degenerate_bson'];
$expectedDegenerateBson = strtolower($degenerateBson);
$code .= sprintf('$degenerateBson = hex2bin(%s);', var_export($degenerateBson, true)) . "\n";
}
if (isset($case['converted_bson'])) {
$convertedBson = $case['converted_bson'];
$expectedConvertedBson = strtolower($convertedBson);
$code .= sprintf('$convertedBson = hex2bin(%s);', var_export($convertedBson, true)) . "\n";
}
$canonicalExtJson = $case['canonical_extjson'];
$expectedCanonicalExtJson = json_canonicalize($canonicalExtJson);
$code .= sprintf('$canonicalExtJson = %s;', var_export($canonicalExtJson, true)) . "\n";
if (isset($case['relaxed_extjson'])) {
$relaxedExtJson = $case['relaxed_extjson'];
$expectedRelaxedExtJson = json_canonicalize($relaxedExtJson);
$code .= sprintf('$relaxedExtJson = %s;', var_export($relaxedExtJson, true)) . "\n";
}
if (isset($case['degenerate_extjson'])) {
$degenerateExtJson = $case['degenerate_extjson'];
$expectedDegenerateExtJson = json_canonicalize($degenerateExtJson);
$code .= sprintf('$degenerateExtJson = %s;', var_export($degenerateExtJson, true)) . "\n";
}
if (isset($case['converted_extjson'])) {
$convertedExtJson = $case['converted_extjson'];
$expectedConvertedExtJson = json_canonicalize($convertedExtJson);
$code .= sprintf('$convertedExtJson = %s;', var_export($convertedExtJson, true)) . "\n";
}
$code .= "\n// Canonical BSON -> Native -> Canonical BSON \n";
$code .= 'echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";' . "\n";
$expect .= $expectedCanonicalBson . "\n";
$code .= "\n// Canonical BSON -> Canonical extJSON \n";
$code .= 'echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";' . "\n";;
$expect .= $expectedCanonicalExtJson . "\n";
if (isset($relaxedExtJson)) {
$code .= "\n// Canonical BSON -> Relaxed extJSON \n";
$code .= 'echo json_canonicalize(toRelaxedExtendedJSON($canonicalBson)), "\n";' . "\n";;
$expect .= $expectedRelaxedExtJson . "\n";
}
if (!$lossy) {
$code .= "\n// Canonical extJSON -> Canonical BSON \n";
$code .= 'echo bin2hex(fromJSON($canonicalExtJson)), "\n";' . "\n";
$expect .= $expectedCanonicalBson . "\n";
}
if (isset($degenerateBson)) {
$code .= "\n// Degenerate BSON -> Native -> Canonical BSON \n";
$code .= 'echo bin2hex(fromPHP(toPHP($degenerateBson))), "\n";' . "\n";
$expect .= $expectedCanonicalBson . "\n";
$code .= "\n// Degenerate BSON -> Canonical extJSON \n";
$code .= 'echo json_canonicalize(toCanonicalExtendedJSON($degenerateBson)), "\n";' . "\n";;
$expect .= $expectedCanonicalExtJson . "\n";
if (isset($relaxedExtJson)) {
$code .= "\n// Degenerate BSON -> Relaxed extJSON \n";
$code .= 'echo json_canonicalize(toRelaxedExtendedJSON($degenerateBson)), "\n";' . "\n";;
$expect .= $expectedRelaxedExtJson . "\n";
}
}
if (isset($degenerateExtJson) && !$lossy) {
$code .= "\n// Degenerate extJSON -> Canonical BSON \n";
$code .= 'echo bin2hex(fromJSON($degenerateExtJson)), "\n";' . "\n";
$expect .= $expectedCanonicalBson . "\n";
}
if (isset($relaxedExtJson)) {
$code .= "\n// Relaxed extJSON -> BSON -> Relaxed extJSON \n";
$code .= 'echo json_canonicalize(toRelaxedExtendedJSON(fromJSON($relaxedExtJson))), "\n";' . "\n";
$expect .= $expectedRelaxedExtJson . "\n";
}
return [
'%NAME%' => sprintf('%s: %s', trim($test['description']), trim($case['description'])),
'%CODE%' => trim($code),
'%EXPECT%' => trim($expect),
];
}
function getParamsForDecodeError(array $test, array $case)
{
foreach (['description', 'bson'] as $field) {
if (!isset($case[$field])) {
throw new InvalidArgumentException(sprintf('Missing "%s" field', $field));
}
}
$code = sprintf('$bson = hex2bin(%s);', var_export($case['bson'], true)) . "\n\n";
$code .= "throws(function() use (\$bson) {\n";
$code .= " var_dump(toPHP(\$bson));\n";
$code .= "}, 'MongoDB\Driver\Exception\UnexpectedValueException');";
/* We do not test for the exception message, since that may differ based on
* the nature of the decoding error. */
$expect = "OK: Got MongoDB\Driver\Exception\UnexpectedValueException";
return [
'%NAME%' => sprintf('%s: %s', trim($test['description']), trim($case['description'])),
'%CODE%' => trim($code),
'%EXPECT%' => trim($expect),
];
}
function getParamsForParseError(array $test, array $case)
{
foreach (['description', 'string'] as $field) {
if (!isset($case[$field])) {
throw new InvalidArgumentException(sprintf('Missing "%s" field', $field));
}
}
$code = '';
$expect = '';
switch ($test['bson_type']) {
case '0x00': // Top-level document
$code = "throws(function() {\n";
$code .= sprintf(" fromJSON(%s);\n", var_export($case['string'], true));
$code .= "}, 'MongoDB\Driver\Exception\UnexpectedValueException');";
/* We do not test for the exception message, since that may differ
* based on the nature of the parse error. */
$expect = "OK: Got MongoDB\Driver\Exception\UnexpectedValueException";
break;
case '0x13': // Decimal128
$code = "throws(function() {\n";
$code .= sprintf(" new MongoDB\BSON\Decimal128(%s);\n", var_export($case['string'], true));
$code .= "}, 'MongoDB\Driver\Exception\InvalidArgumentException');";
/* We do not test for the exception message, since that may differ
* based on the nature of the parse error. */
$expect = "OK: Got MongoDB\Driver\Exception\InvalidArgumentException";
break;
default:
throw new UnexpectedValueException(sprintf("Parse errors not supported for BSON type: %s", $test['bson_type']));
}
return [
'%NAME%' => sprintf('%s: %s', trim($test['description']), trim($case['description'])),
'%CODE%' => trim($code),
'%EXPECT%' => trim($expect),
];
}
function renderPhpt(array $params, array $expectedFailures)
{
$params['%XFAIL%'] = isset($expectedFailures[$params['%NAME%']])
? "--XFAIL--\n" . $expectedFailures[$params['%NAME%']] . "\n"
: '';
$template = <<< 'TEMPLATE'
--TEST--
%NAME%
%XFAIL%--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php
DO NOT EDIT THIS FILE
--FILE--
===DONE===
--EXPECT--
%EXPECT%
===DONE===
TEMPLATE;
return str_replace(array_keys($params), array_values($params), $template);
}
mongodb-1.3.4/scripts/convert-mo-tests.php 0000664 0001750 0001750 00000021305 13210321137 020427 0 ustar jmikola jmikola
--FILE--
array(
"method" => "DELETE",
"timeout" => 60,
"header" => "Accept: application/json\r\n" .
"Content-type: application/x-www-form-urlencoded",
"ignore_errors" => true,
),
);
$context = stream_context_create($opts);
$out = file_get_contents($url, false, $context);
}
function mo_post($url, $body) {
global $KILLLIST;
$url = getMOUri() . $url;
$opts = array("http" =>
array(
"method" => "POST",
"timeout" => 60,
"header" => "Accept: application/json\r\n" .
"Content-type: application/x-www-form-urlencoded",
"content" => json_encode($body),
"ignore_errors" => true,
),
);
$context = stream_context_create($opts);
$out = file_get_contents($url, false, $context);
$array = json_decode($out, true);
if ($array && !empty($array["mongodb_uri"])) {
$KILLLIST[] = $array["id"];
return $array["mongodb_uri"];
}
}
$KILLLIST = array();
$INITCONFIG = %INITCONFIG%;
$dsn = "%DSN%";
if ($INITCONFIG) {
$dsn = mo_post("/%URLTYPE%", $INITCONFIG);
}
$manager = new MongoDB\Driver\Manager($dsn);
%TESTPLAN%;
foreach($KILLLIST as $id) {
mo_delete("/%URLTYPE%/$id");
}
?>
===DONE===
--EXPECTF--
%OUTPUT%
===DONE===
TEMPLATE;
?>getMessage() . "\n";
}
file_put_contents($phptfile, $phpt);
}
function convert($test, $template) {
$TESTPLAN = array();
$OUTPUT = "";
$test["phases"] = isset($test["phases"]) ? $test["phases"] : array();
foreach($test["phases"] as $phase) {
$TESTPLAN[] = phase($phase, $output);
if ($output) {
ob_start();
var_dump($output);
$OUTPUT .= ob_get_contents();
ob_end_clean();
$OUTPUT = str_replace('2) "%s"', '%d) "%s"', $OUTPUT);
}
}
foreach($test["tests"] as $phase) {
$TESTPLAN[] = phase($phase, $output);
if ($output) {
ob_start();
var_dump($output);
$OUTPUT .= ob_get_contents();
ob_end_clean();
$OUTPUT = str_replace('2) "%s"', '%d) "%s"', $OUTPUT);
}
}
$replacements = array(
"%DSN%" => clientSetup($test),
"%DESCRIPTION%" => description($test),
"%INITCONFIG%" => initConfig($test),
"%URLTYPE%" => $test["type"],
"%TESTPLAN%" => join("\n\n", $TESTPLAN),
"%OUTPUT%" => rtrim($OUTPUT),
);
return makeTest($replacements, $template);
}
function phase($phase, &$output) {
$output = null;
if (isset($phase["MOOperation"])) {
return MOOperation($phase["MOOperation"], $output);
}
if (isset($phase["clientHosts"])) {
return clientHosts($phase["clientHosts"], $output);
}
if (isset($phase["clientOperation"])) {
return clientOperation($phase["clientOperation"], $output);
}
if (isset($phase["wait"])) {
return 'sleep(' . $phase["wait"] . ');';
}
throw new UnexpectedValueException("Don't know how to deal with " . json_encode($phase));
}
function MOOperation($phase, &$output) {
$method = strtolower($phase["method"]);
switch($method) {
case "post":
return 'mo_post("' . $phase["uri"] . '", ' . var_export($phase["payload"], true) . ');';
case "delete":
return 'mo_delete("' . $phase["uri"] . '");';
default:
throw new UnexpectedValueException("Don't know the method $method");
}
}
function clientHosts($hosts, &$output) {
$output = array();
$retval = <<< CODE
\$clientHosts = array();
CODE;
if (!empty($hosts['primary'])) {
$primary = var_export($hosts['primary'], true);
$retval .= <<< CODE
\$found = array_filter(\$manager->getServers(), function(\$server) {
return \$server->getHost() == $primary && \$server->getType() == MongoDB\\Driver\\SERVERTYPE_RS_PRIMARY;
});
if (count(\$found) == 1) {
\$clientHosts['primary'] = $primary;
}
CODE;
$output['primary'] = $hosts['primary'];
}
if (!empty($hosts['secondaries'])) {
foreach ($hosts['secondaries'] as $secondaryHost) {
$secondary = var_export($secondaryHost, true);
$retval .= <<< CODE
\$found = array_filter(\$manager->getServers(), function(\$server) {
return \$server->getHost() == $secondary && \$server->getType() == MongoDB\\Driver\\SERVERTYPE_RS_SECONDARY;
});
if (count(\$found) == 1) {
\$clientHosts['secondaries'][] = $secondary;
}
CODE;
$output['secondaries'][] = $secondaryHost;
}
}
$retval .= <<< CODE
var_dump(\$clientHosts);
CODE;
return $retval;
}
function clientOperation($phase, &$output) {
switch($phase["operation"]) {
case "insertOne":
$output = !isset($phase["outcome"]) ? array("ok" => 1) : $phase["outcome"];
if (!$output["ok"]) {
$output["errmsg"] = "%s";
}
$wc = !isset($phase["writeConcern"]) ? 1 : $phase["writeConcern"]["w"];
$doc = var_export($phase["doc"], true);;
$doc = str_replace("\n", "\n ", $doc);
$retval = <<< CODE
try {
\$wc = new MongoDB\\Driver\\WriteConcern($wc);
\$bulk = new MongoDB\Driver\BulkWrite();
\$bulk->insert($doc);
\$result = \$manager->executeBulkWrite("databaseName.collectionName", \$bulk, \$wc);
if (\$result->getInsertedCount() == 1) {
var_dump(array("ok" => 1));
} else {
var_dump(array("ok" => 0, "errmsg" => "getInsertedCount => " . \$result->getInsertedCount()));
}
} catch(Exception \$e) {
var_dump(array("ok" => 0, "errmsg" => get_class(\$e) . ": " . \$e->getMessage()));
}
CODE;
return $retval;
break;
case "find":
$output = $phase["outcome"];
if (!$output["ok"]) {
$output["errmsg"] = "%s";
}
$retval = <<< CODE
try {
\$query = new MongoDB\\Driver\\Query(array());
\$result = \$manager->executeQuery("databaseName.collectionName", \$query)->toArray();
var_dump(array("ok" => 1));
} catch(Exception \$e) {
var_dump(array("ok" => 0, "errmsg" => get_class(\$e) . ": " . \$e->getMessage()));
}
CODE;
return $retval;
break;
default:
throw new UnexpectedValueException("IDK what to do about {$phase["operation"]}");
}
}
function clientSetUp($test) {
$setup = $test["clientSetUp"];
if (!$setup) {
throw new UnexpectedValueException("No 'clientSetUp' key provided");
}
$seedlist = join(",", $setup["hosts"]);
$options = array();
if (!empty($setup["options"])) {
$entries = array();
foreach($setup["options"] as $k => $v) {
switch($k) {
case "readPreference":
$entries[] = "$k={$v["mode"]}";
break;
case "heartbeatFrequency":
$entries[] = "$k=$v";
break;
default:
throw new Exception("Don't know how to handle '$k'");
}
}
$options = join("&", $entries);
}
if ($options) {
return sprintf("mongodb://%s/?%s", $seedlist, $options);
} else {
return sprintf("mongodb://%s", $seedlist);
}
}
function makeTest($replacements, $template) {
return str_replace(array_keys($replacements), array_values($replacements), $template);
}
function description($test) {
static $count = 0;
$desc = $test["description"];
return sprintf("Cluster Integration Test#%03d: %s", ++$count, $desc);
}
function initConfig($test) {
// The initConfig entry alone isn't valid MO post
$config = $test["initConfig"];
$config["name"] = "mongod";
return var_export($config, true);
}
mongodb-1.3.4/scripts/list-servers.php 0000664 0001750 0001750 00000000340 13210321137 017634 0 ustar jmikola jmikola $uri) {
printf("%-20s \t %s\n", $serverid, $uri);
}
mongodb-1.3.4/scripts/run-tests-on.sh 0000664 0001750 0001750 00000000461 13210321137 017377 0 ustar jmikola jmikola #!/bin/sh
VMNAME=$1
vagrant status $VMNAME | grep -q "$VMNAME.*running"
if test $? -eq 0; then
vagrant provision $VMNAME > .$VMNAME
else
vagrant up $VMNAME > .$VMNAME
fi
cat .tests | grep -q -E "FAIL|WARN"
if test $? -eq 0; then
echo "$VMNAME FAILED"
cat .tests
exit 2
else
echo "$VMNAME OK"
fi
mongodb-1.3.4/scripts/start-servers.php 0000664 0001750 0001750 00000020370 13210321137 020023 0 ustar jmikola jmikola [
"scripts/presets/standalone.json",
"scripts/presets/standalone-24.json",
"scripts/presets/standalone-26.json",
"scripts/presets/standalone-30.json",
"scripts/presets/standalone-ssl.json",
"scripts/presets/standalone-auth.json",
"scripts/presets/standalone-x509.json",
"scripts/presets/standalone-plain.json",
],
"replicasets" => [
"scripts/presets/replicaset.json",
"scripts/presets/replicaset-30.json",
],
];
function make_ctx($preset, $method = "POST") {
$opts = [
"http" => [
"timeout" => 60,
"method" => $method,
"header" => "Accept: application/json\r\n" .
"Content-type: application/x-www-form-urlencoded",
"content" => json_encode(array("preset" => $preset)),
"ignore_errors" => true,
],
];
$ctx = stream_context_create($opts);
return $ctx;
}
function failed($result) {
echo "\n\n";
echo join("\n", $result);
printf("Last operation took: %.2f secs\n", lap());
exit();
}
function mo_http_request($uri, $context) {
global $http_response_header;
$result = file_get_contents($uri, false, $context);
if ($result === false) {
failed($http_response_header);
}
return $result;
}
printf("Cleaning out previous processes, if any ");
lap();
/* Remove all pre-existing ReplicaSets */
$replicasets = mo_http_request(getMOUri() . "/replica_sets", make_ctx(getMOPresetBase(), "GET"));
$replicasets = json_decode($replicasets, true);
foreach($replicasets["replica_sets"] as $replicaset) {
$uri = getMOUri() . "/replica_sets/" . $replicaset["id"];
mo_http_request($uri, make_ctx(getMOPresetBase(), "DELETE"));
echo ".";
}
echo " ";
/* Remove all pre-existing servers */
$servers = mo_http_request(getMOUri() . "/servers", make_ctx(getMOPresetBase(), "GET"));
$servers = json_decode($servers, true);
foreach($servers["servers"] as $server) {
$uri = getMOUri() . "/servers/" . $server["id"];
mo_http_request($uri, make_ctx(getMOPresetBase(), "DELETE"));
echo ".";
}
printf("\t(took: %.2f secs)\n", lap());
foreach($PRESETS["standalone"] as $preset) {
lap();
$json = json_decode(file_get_contents($preset), true);
printf("Starting %-20s ... ", $json["id"]);
$result = mo_http_request(getMOUri() . "/servers", make_ctx(getMOPresetBase() . $preset));
$decode = json_decode($result, true);
if (!isset($decode["id"])) {
failed($decode);
}
$SERVERS[$decode["id"]] = isset($decode["mongodb_auth_uri"]) ? $decode["mongodb_auth_uri"] : $decode["mongodb_uri"];
printf("'%s'\t(took: %.2f secs)\n", $SERVERS[$decode["id"]], lap());
}
echo "---\n";
foreach($PRESETS["replicasets"] as $preset) {
lap();
$json = json_decode(file_get_contents($preset), true);
printf("Starting %-20s ... ", $json["id"]);
$result = mo_http_request(getMOUri() . "/replica_sets", make_ctx(getMOPresetBase() . $preset));
$decode = json_decode($result, true);
if (!isset($decode["id"])) {
failed($decode);
}
$SERVERS[$decode["id"]] = isset($decode["mongodb_auth_uri"]) ? $decode["mongodb_auth_uri"] : $decode["mongodb_uri"];
printf("'%s'\t(took: %.2f secs)\n", $SERVERS[$decode["id"]], lap());
}
file_put_contents($FILENAME, json_encode($SERVERS, JSON_PRETTY_PRINT));
/*
wget --body-data='' --method='GET' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE-AUTH
wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE
wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE-24
wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE-26
wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/RS-two
wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/RS-arbiter
wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE-PLAIN
wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE-X509
wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/RS-one
wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE-SSL
wget --body-data='' --method='GET' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/replica_sets
wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/replica_sets/REPLICASET
wget --body-data='' --method='GET' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/
wget --body-data='' --method='GET' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
wget --body-data='' --method='GET' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/replica_sets
wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone-24.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone-26.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone-ssl.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone-auth.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone-x509.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone-plain.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/replicaset.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/replica_sets
*/
mongodb-1.3.4/src/BSON/Binary.c 0000664 0001750 0001750 00000036331 13210321137 015723 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#include
#include
#if PHP_VERSION_ID >= 70000
# include
#else
# include
#endif
#include "phongo_compat.h"
#include "php_phongo.h"
#define PHONGO_BINARY_UUID_SIZE 16
zend_class_entry *php_phongo_binary_ce;
/* Initialize the object and return whether it was successful. An exception will
* be thrown on error. */
static bool php_phongo_binary_init(php_phongo_binary_t *intern, const char *data, phongo_zpp_char_len data_len, phongo_long type TSRMLS_DC) /* {{{ */
{
if (type < 0 || type > UINT8_MAX) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected type to be an unsigned 8-bit integer, %" PHONGO_LONG_FORMAT " given", type);
return false;
}
if ((type == BSON_SUBTYPE_UUID_DEPRECATED || type == BSON_SUBTYPE_UUID) && data_len != PHONGO_BINARY_UUID_SIZE) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected UUID length to be %d bytes, %d given", PHONGO_BINARY_UUID_SIZE, data_len);
return false;
}
intern->data = estrndup(data, data_len);
intern->data_len = data_len;
intern->type = (uint8_t) type;
return true;
} /* }}} */
/* Initialize the object from a HashTable and return whether it was successful.
* An exception will be thrown on error. */
static bool php_phongo_binary_init_from_hash(php_phongo_binary_t *intern, HashTable *props TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval *data, *type;
if ((data = zend_hash_str_find(props, "data", sizeof("data")-1)) && Z_TYPE_P(data) == IS_STRING &&
(type = zend_hash_str_find(props, "type", sizeof("type")-1)) && Z_TYPE_P(type) == IS_LONG) {
return php_phongo_binary_init(intern, Z_STRVAL_P(data), Z_STRLEN_P(data), Z_LVAL_P(type) TSRMLS_CC);
}
#else
zval **data, **type;
if (zend_hash_find(props, "data", sizeof("data"), (void**) &data) == SUCCESS && Z_TYPE_PP(data) == IS_STRING &&
zend_hash_find(props, "type", sizeof("type"), (void**) &type) == SUCCESS && Z_TYPE_PP(type) == IS_LONG) {
return php_phongo_binary_init(intern, Z_STRVAL_PP(data), Z_STRLEN_PP(data), Z_LVAL_PP(type) TSRMLS_CC);
}
#endif
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"data\" string and \"type\" integer fields", ZSTR_VAL(php_phongo_binary_ce->name));
return false;
} /* }}} */
/* {{{ proto void MongoDB\BSON\Binary::__construct(string $data, int $type)
Construct a new BSON binary type */
static PHP_METHOD(Binary, __construct)
{
php_phongo_binary_t *intern;
zend_error_handling error_handling;
char *data;
phongo_zpp_char_len data_len;
phongo_long type;
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_BINARY_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &type) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
php_phongo_binary_init(intern, data, data_len, type TSRMLS_CC);
} /* }}} */
/* {{{ proto void MongoDB\BSON\Binary::__set_state(array $properties)
*/
static PHP_METHOD(Binary, __set_state)
{
php_phongo_binary_t *intern;
HashTable *props;
zval *array;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
RETURN_FALSE;
}
object_init_ex(return_value, php_phongo_binary_ce);
intern = Z_BINARY_OBJ_P(return_value);
props = Z_ARRVAL_P(array);
php_phongo_binary_init_from_hash(intern, props TSRMLS_CC);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Binary::__toString()
Return the Binary's data string. */
static PHP_METHOD(Binary, __toString)
{
php_phongo_binary_t *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_BINARY_OBJ_P(getThis());
PHONGO_RETURN_STRINGL(intern->data, intern->data_len);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Binary::getData()
*/
static PHP_METHOD(Binary, getData)
{
php_phongo_binary_t *intern;
intern = Z_BINARY_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_RETURN_STRINGL(intern->data, intern->data_len);
} /* }}} */
/* {{{ proto integer MongoDB\BSON\Binary::getType()
*/
static PHP_METHOD(Binary, getType)
{
php_phongo_binary_t *intern;
intern = Z_BINARY_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(intern->type);
} /* }}} */
/* {{{ proto array MongoDB\BSON\Binary::jsonSerialize()
*/
static PHP_METHOD(Binary, jsonSerialize)
{
php_phongo_binary_t *intern;
char type[3];
int type_len;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_BINARY_OBJ_P(getThis());
array_init_size(return_value, 2);
#if PHP_VERSION_ID >= 70000
{
zend_string *data = php_base64_encode((unsigned char *)intern->data, intern->data_len);
ADD_ASSOC_STRINGL(return_value, "$binary", ZSTR_VAL(data), ZSTR_LEN(data));
zend_string_free(data);
}
#else
{
int data_len = 0;
unsigned char *data = php_base64_encode((unsigned char *)intern->data, intern->data_len, &data_len);
ADD_ASSOC_STRINGL(return_value, "$binary", (char *)data, data_len);
efree(data);
}
#endif
type_len = snprintf(type, sizeof(type), "%02x", intern->type);
ADD_ASSOC_STRINGL(return_value, "$type", type, type_len);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Binary::serialize()
*/
static PHP_METHOD(Binary, serialize)
{
php_phongo_binary_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval *retval;
#endif
php_serialize_data_t var_hash;
smart_str buf = { 0 };
intern = Z_BINARY_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
#if PHP_VERSION_ID >= 70000
array_init_size(&retval, 2);
ADD_ASSOC_STRINGL(&retval, "data", intern->data, intern->data_len);
ADD_ASSOC_LONG_EX(&retval, "type", intern->type);
#else
ALLOC_INIT_ZVAL(retval);
array_init_size(retval, 2);
ADD_ASSOC_STRINGL(retval, "data", intern->data, intern->data_len);
ADD_ASSOC_LONG_EX(retval, "type", intern->type);
#endif
PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&buf, &retval, &var_hash TSRMLS_CC);
smart_str_0(&buf);
PHP_VAR_SERIALIZE_DESTROY(var_hash);
PHONGO_RETVAL_SMART_STR(buf);
smart_str_free(&buf);
zval_ptr_dtor(&retval);
} /* }}} */
/* {{{ proto void MongoDB\BSON\Binary::unserialize(string $serialized)
*/
static PHP_METHOD(Binary, unserialize)
{
php_phongo_binary_t *intern;
zend_error_handling error_handling;
char *serialized;
phongo_zpp_char_len serialized_len;
#if PHP_VERSION_ID >= 70000
zval props;
#else
zval *props;
#endif
php_unserialize_data_t var_hash;
intern = Z_BINARY_OBJ_P(getThis());
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &serialized_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
#if PHP_VERSION_ID < 70000
ALLOC_INIT_ZVAL(props);
#endif
PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char *) serialized + serialized_len, &var_hash TSRMLS_CC)) {
zval_ptr_dtor(&props);
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "%s unserialization failed", ZSTR_VAL(php_phongo_binary_ce->name));
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
#if PHP_VERSION_ID >= 70000
php_phongo_binary_init_from_hash(intern, HASH_OF(&props) TSRMLS_CC);
#else
php_phongo_binary_init_from_hash(intern, HASH_OF(props) TSRMLS_CC);
#endif
zval_ptr_dtor(&props);
} /* }}} */
/* {{{ MongoDB\BSON\Binary function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Binary___construct, 0, 0, 2)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Binary___set_state, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, properties, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Binary_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Binary_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_binary_me[] = {
PHP_ME(Binary, __construct, ai_Binary___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Binary, __set_state, ai_Binary___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Binary, __toString, ai_Binary_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Binary, jsonSerialize, ai_Binary_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Binary, serialize, ai_Binary_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Binary, unserialize, ai_Binary_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Binary, getData, ai_Binary_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Binary, getType, ai_Binary_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\BSON\Binary object handlers */
static zend_object_handlers php_phongo_handler_binary;
static void php_phongo_binary_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_binary_t *intern = Z_OBJ_BINARY(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->data) {
efree(intern->data);
}
if (intern->properties) {
zend_hash_destroy(intern->properties);
FREE_HASHTABLE(intern->properties);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_binary_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_binary_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_binary_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_binary;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_binary_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_binary;
return retval;
}
#endif
} /* }}} */
static int php_phongo_binary_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
{
php_phongo_binary_t *intern1, *intern2;
intern1 = Z_BINARY_OBJ_P(o1);
intern2 = Z_BINARY_OBJ_P(o2);
/* MongoDB compares binary types first by the data length, then by the type
* byte, and finally by the binary data itself. */
if (intern1->data_len != intern2->data_len) {
return intern1->data_len < intern2->data_len ? -1 : 1;
}
if (intern1->type != intern2->type) {
return intern1->type < intern2->type ? -1 : 1;
}
return zend_binary_strcmp(intern1->data, intern1->data_len, intern2->data, intern2->data_len);
} /* }}} */
static HashTable *php_phongo_binary_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
{
*table = NULL;
*n = 0;
return Z_BINARY_OBJ_P(object)->properties;
} /* }}} */
static HashTable *php_phongo_binary_get_properties_hash(zval *object, bool is_debug TSRMLS_DC) /* {{{ */
{
php_phongo_binary_t *intern;
HashTable *props;
intern = Z_BINARY_OBJ_P(object);
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2);
if (!intern->data) {
return props;
}
#if PHP_VERSION_ID >= 70000
{
zval data, type;
ZVAL_STRINGL(&data, intern->data, intern->data_len);
zend_hash_str_update(props, "data", sizeof("data")-1, &data);
ZVAL_LONG(&type, intern->type);
zend_hash_str_update(props, "type", sizeof("type")-1, &type);
}
#else
{
zval *data, *type;
MAKE_STD_ZVAL(data);
ZVAL_STRINGL(data, intern->data, intern->data_len, 1);
zend_hash_update(props, "data", sizeof("data"), &data, sizeof(data), NULL);
MAKE_STD_ZVAL(type);
ZVAL_LONG(type, intern->type);
zend_hash_update(props, "type", sizeof("type"), &type, sizeof(type), NULL);
}
#endif
return props;
} /* }}} */
static HashTable *php_phongo_binary_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
*is_temp = 1;
return php_phongo_binary_get_properties_hash(object, true TSRMLS_CC);
} /* }}} */
static HashTable *php_phongo_binary_get_properties(zval *object TSRMLS_DC) /* {{{ */
{
return php_phongo_binary_get_properties_hash(object, false TSRMLS_CC);
} /* }}} */
/* }}} */
void php_phongo_binary_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Binary", php_phongo_binary_me);
php_phongo_binary_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_binary_ce->create_object = php_phongo_binary_create_object;
PHONGO_CE_FINAL(php_phongo_binary_ce);
zend_class_implements(php_phongo_binary_ce TSRMLS_CC, 1, php_phongo_binary_interface_ce);
zend_class_implements(php_phongo_binary_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
zend_class_implements(php_phongo_binary_ce TSRMLS_CC, 1, php_phongo_type_ce);
zend_class_implements(php_phongo_binary_ce TSRMLS_CC, 1, zend_ce_serializable);
memcpy(&php_phongo_handler_binary, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_binary.compare_objects = php_phongo_binary_compare_objects;
php_phongo_handler_binary.get_debug_info = php_phongo_binary_get_debug_info;
php_phongo_handler_binary.get_gc = php_phongo_binary_get_gc;
php_phongo_handler_binary.get_properties = php_phongo_binary_get_properties;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_binary.free_obj = php_phongo_binary_free_object;
php_phongo_handler_binary.offset = XtOffsetOf(php_phongo_binary_t, std);
#endif
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_GENERIC"), BSON_SUBTYPE_BINARY TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_FUNCTION"), BSON_SUBTYPE_FUNCTION TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_OLD_BINARY"), BSON_SUBTYPE_BINARY_DEPRECATED TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_OLD_UUID"), BSON_SUBTYPE_UUID_DEPRECATED TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_UUID"), BSON_SUBTYPE_UUID TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_MD5"), BSON_SUBTYPE_MD5 TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_USER_DEFINED"), BSON_SUBTYPE_USER TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/BinaryInterface.c 0000664 0001750 0001750 00000003124 13210321137 017536 0 ustar jmikola jmikola /*
* Copyright 2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_binary_interface_ce;
/* {{{ MongoDB\BSON\BinaryInterface function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_BinaryInterface_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_binary_interface_me[] = {
ZEND_ABSTRACT_ME(BinaryInterface, getData, ai_BinaryInterface_void)
ZEND_ABSTRACT_ME(BinaryInterface, getType, ai_BinaryInterface_void)
ZEND_ABSTRACT_ME(BinaryInterface, __toString, ai_BinaryInterface_void)
PHP_FE_END
};
/* }}} */
void php_phongo_binary_interface_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "BinaryInterface", php_phongo_binary_interface_me);
php_phongo_binary_interface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/Decimal128.c 0000664 0001750 0001750 00000027525 13210321137 016275 0 ustar jmikola jmikola /*
* Copyright 2015-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#if PHP_VERSION_ID >= 70000
# include
#else
# include
#endif
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_decimal128_ce;
/* Initialize the object and return whether it was successful. An exception will
* be thrown on error. */
static bool php_phongo_decimal128_init(php_phongo_decimal128_t *intern, const char *value TSRMLS_DC) /* {{{ */
{
if (!bson_decimal128_from_string(value, &intern->decimal)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error parsing Decimal128 string: %s", value);
return false;
}
intern->initialized = true;
return true;
} /* }}} */
/* Initialize the object from a HashTable and return whether it was successful.
* An exception will be thrown on error. */
static bool php_phongo_decimal128_init_from_hash(php_phongo_decimal128_t *intern, HashTable *props TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval *dec;
if ((dec = zend_hash_str_find(props, "dec", sizeof("dec")-1)) && Z_TYPE_P(dec) == IS_STRING) {
return php_phongo_decimal128_init(intern, Z_STRVAL_P(dec) TSRMLS_CC);
}
#else
zval **dec;
if (zend_hash_find(props, "dec", sizeof("dec"), (void**) &dec) == SUCCESS && Z_TYPE_PP(dec) == IS_STRING) {
return php_phongo_decimal128_init(intern, Z_STRVAL_PP(dec) TSRMLS_CC);
}
#endif
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"dec\" string field", ZSTR_VAL(php_phongo_decimal128_ce->name));
return false;
} /* }}} */
/* {{{ proto void MongoDB\BSON\Decimal128::__construct(string $value)
Construct a new BSON Decimal128 type */
static PHP_METHOD(Decimal128, __construct)
{
php_phongo_decimal128_t *intern;
zend_error_handling error_handling;
char *value;
phongo_zpp_char_len value_len;
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_DECIMAL128_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
php_phongo_decimal128_init(intern, value TSRMLS_CC);
} /* }}} */
/* {{{ proto void MongoDB\BSON\Decimal128::__set_state(array $properties)
*/
static PHP_METHOD(Decimal128, __set_state)
{
php_phongo_decimal128_t *intern;
HashTable *props;
zval *array;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
RETURN_FALSE;
}
object_init_ex(return_value, php_phongo_decimal128_ce);
intern = Z_DECIMAL128_OBJ_P(return_value);
props = Z_ARRVAL_P(array);
php_phongo_decimal128_init_from_hash(intern, props TSRMLS_CC);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Decimal128::__toString()
*/
static PHP_METHOD(Decimal128, __toString)
{
php_phongo_decimal128_t *intern;
char outbuf[BSON_DECIMAL128_STRING];
intern = Z_DECIMAL128_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
bson_decimal128_to_string(&intern->decimal, outbuf);
PHONGO_RETURN_STRING(outbuf);
} /* }}} */
/* {{{ proto array MongoDB\BSON\Decimal128::jsonSerialize()
*/
static PHP_METHOD(Decimal128, jsonSerialize)
{
php_phongo_decimal128_t *intern;
char outbuf[BSON_DECIMAL128_STRING] = "";
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_DECIMAL128_OBJ_P(getThis());
array_init_size(return_value, 1);
bson_decimal128_to_string(&intern->decimal, outbuf);
ADD_ASSOC_STRING(return_value, "$numberDecimal", outbuf);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Decimal128::serialize()
*/
static PHP_METHOD(Decimal128, serialize)
{
php_phongo_decimal128_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval *retval;
#endif
php_serialize_data_t var_hash;
smart_str buf = { 0 };
char outbuf[BSON_DECIMAL128_STRING];
intern = Z_DECIMAL128_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
bson_decimal128_to_string(&intern->decimal, outbuf);
#if PHP_VERSION_ID >= 70000
array_init_size(&retval, 1);
ADD_ASSOC_STRING(&retval, "dec", outbuf);
#else
ALLOC_INIT_ZVAL(retval);
array_init_size(retval, 1);
ADD_ASSOC_STRING(retval, "dec", outbuf);
#endif
PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&buf, &retval, &var_hash TSRMLS_CC);
smart_str_0(&buf);
PHP_VAR_SERIALIZE_DESTROY(var_hash);
PHONGO_RETVAL_SMART_STR(buf);
smart_str_free(&buf);
zval_ptr_dtor(&retval);
} /* }}} */
/* {{{ proto void MongoDB\BSON\Decimal128::unserialize(string $serialized)
*/
static PHP_METHOD(Decimal128, unserialize)
{
php_phongo_decimal128_t *intern;
zend_error_handling error_handling;
char *serialized;
phongo_zpp_char_len serialized_len;
#if PHP_VERSION_ID >= 70000
zval props;
#else
zval *props;
#endif
php_unserialize_data_t var_hash;
intern = Z_DECIMAL128_OBJ_P(getThis());
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &serialized_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
#if PHP_VERSION_ID < 70000
ALLOC_INIT_ZVAL(props);
#endif
PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char *) serialized + serialized_len, &var_hash TSRMLS_CC)) {
zval_ptr_dtor(&props);
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "%s unserialization failed", ZSTR_VAL(php_phongo_decimal128_ce->name));
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
#if PHP_VERSION_ID >= 70000
php_phongo_decimal128_init_from_hash(intern, HASH_OF(&props) TSRMLS_CC);
#else
php_phongo_decimal128_init_from_hash(intern, HASH_OF(props) TSRMLS_CC);
#endif
zval_ptr_dtor(&props);
} /* }}} */
/* {{{ MongoDB\BSON\Decimal128 function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Decimal128___construct, 0, 0, 1)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Decimal128___set_state, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, properties, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Decimal128_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Decimal128_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_decimal128_me[] = {
PHP_ME(Decimal128, __construct, ai_Decimal128___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Decimal128, __set_state, ai_Decimal128___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Decimal128, __toString, ai_Decimal128_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Decimal128, jsonSerialize, ai_Decimal128_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Decimal128, serialize, ai_Decimal128_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Decimal128, unserialize, ai_Decimal128_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\BSON\Decimal128 object handlers */
static zend_object_handlers php_phongo_handler_decimal128;
static void php_phongo_decimal128_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_decimal128_t *intern = Z_OBJ_DECIMAL128(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->properties) {
zend_hash_destroy(intern->properties);
FREE_HASHTABLE(intern->properties);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_decimal128_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_decimal128_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_decimal128_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_decimal128;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_decimal128_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_decimal128;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_decimal128_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
{
*table = NULL;
*n = 0;
return Z_DECIMAL128_OBJ_P(object)->properties;
} /* }}} */
static HashTable *php_phongo_decimal128_get_properties_hash(zval *object, bool is_debug TSRMLS_DC) /* {{{ */
{
php_phongo_decimal128_t *intern;
HashTable *props;
char outbuf[BSON_DECIMAL128_STRING] = "";
intern = Z_DECIMAL128_OBJ_P(object);
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 1);
if (!intern->initialized) {
return props;
}
bson_decimal128_to_string(&intern->decimal, outbuf);
#if PHP_VERSION_ID >= 70000
{
zval dec;
ZVAL_STRING(&dec, outbuf);
zend_hash_str_update(props, "dec", sizeof("dec")-1, &dec);
}
#else
{
zval *dec;
MAKE_STD_ZVAL(dec);
ZVAL_STRING(dec, outbuf, 1);
zend_hash_update(props, "dec", sizeof("dec"), &dec, sizeof(dec), NULL);
}
#endif
return props;
} /* }}} */
static HashTable *php_phongo_decimal128_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
*is_temp = 1;
return php_phongo_decimal128_get_properties_hash(object, true TSRMLS_CC);
} /* }}} */
static HashTable *php_phongo_decimal128_get_properties(zval *object TSRMLS_DC) /* {{{ */
{
return php_phongo_decimal128_get_properties_hash(object, false TSRMLS_CC);
} /* }}} */
/* }}} */
void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Decimal128", php_phongo_decimal128_me);
php_phongo_decimal128_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_decimal128_ce->create_object = php_phongo_decimal128_create_object;
PHONGO_CE_FINAL(php_phongo_decimal128_ce);
zend_class_implements(php_phongo_decimal128_ce TSRMLS_CC, 1, php_phongo_decimal128_interface_ce);
zend_class_implements(php_phongo_decimal128_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
zend_class_implements(php_phongo_decimal128_ce TSRMLS_CC, 1, php_phongo_type_ce);
zend_class_implements(php_phongo_decimal128_ce TSRMLS_CC, 1, zend_ce_serializable);
memcpy(&php_phongo_handler_decimal128, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_decimal128.get_debug_info = php_phongo_decimal128_get_debug_info;
php_phongo_handler_decimal128.get_gc = php_phongo_decimal128_get_gc;
php_phongo_handler_decimal128.get_properties = php_phongo_decimal128_get_properties;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_decimal128.free_obj = php_phongo_decimal128_free_object;
php_phongo_handler_decimal128.offset = XtOffsetOf(php_phongo_decimal128_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/Decimal128Interface.c 0000664 0001750 0001750 00000002762 13210321137 020112 0 ustar jmikola jmikola /*
* Copyright 2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_decimal128_interface_ce;
/* {{{ MongoDB\BSON\Decimal128Interface function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Decimal128Interface_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_decimal128_interface_me[] = {
ZEND_ABSTRACT_ME(Decimal128Interface, __toString, ai_Decimal128Interface_void)
PHP_FE_END
};
/* }}} */
void php_phongo_decimal128_interface_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Decimal128Interface", php_phongo_decimal128_interface_me);
php_phongo_decimal128_interface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/Javascript.c 0000664 0001750 0001750 00000041166 13210321137 016607 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#if PHP_VERSION_ID >= 70000
# include
#else
# include
#endif
#include "phongo_compat.h"
#include "php_phongo.h"
#include "php_bson.h"
zend_class_entry *php_phongo_javascript_ce;
/* Initialize the object and return whether it was successful. An exception will
* be thrown on error. */
static bool php_phongo_javascript_init(php_phongo_javascript_t *intern, const char *code, phongo_zpp_char_len code_len, zval *scope TSRMLS_DC) /* {{{ */
{
if (scope && Z_TYPE_P(scope) != IS_OBJECT && Z_TYPE_P(scope) != IS_ARRAY && Z_TYPE_P(scope) != IS_NULL) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected scope to be array or object, %s given", zend_get_type_by_const(Z_TYPE_P(scope)));
return false;
}
if (strlen(code) != code_len) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Code cannot contain null bytes");
return false;
}
intern->code = estrndup(code, code_len);
intern->code_len = code_len;
if (scope && (Z_TYPE_P(scope) == IS_OBJECT || Z_TYPE_P(scope) == IS_ARRAY)) {
intern->scope = bson_new();
php_phongo_zval_to_bson(scope, PHONGO_BSON_NONE, intern->scope, NULL TSRMLS_CC);
} else {
intern->scope = NULL;
}
return true;
} /* }}} */
/* Initialize the object from a HashTable and return whether it was successful.
* An exception will be thrown on error. */
static bool php_phongo_javascript_init_from_hash(php_phongo_javascript_t *intern, HashTable *props TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval *code, *scope;
if ((code = zend_hash_str_find(props, "code", sizeof("code")-1)) && Z_TYPE_P(code) == IS_STRING) {
scope = zend_hash_str_find(props, "scope", sizeof("scope")-1);
return php_phongo_javascript_init(intern, Z_STRVAL_P(code), Z_STRLEN_P(code), scope TSRMLS_CC);
}
#else
zval **code, **scope;
if (zend_hash_find(props, "code", sizeof("code"), (void**) &code) == SUCCESS && Z_TYPE_PP(code) == IS_STRING) {
zval *tmp = zend_hash_find(props, "scope", sizeof("scope"), (void**) &scope) == SUCCESS ? *scope : NULL;
return php_phongo_javascript_init(intern, Z_STRVAL_PP(code), Z_STRLEN_PP(code), tmp TSRMLS_CC);
}
#endif
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"code\" string field", ZSTR_VAL(php_phongo_javascript_ce->name));
return false;
} /* }}} */
/* {{{ proto void MongoDB\BSON\Javascript::__construct(string $code[, array|object $scope])
Construct a new BSON Javascript type. The scope is a document mapping
identifiers and values, representing the scope in which the code string will
be evaluated. Note that this type cannot be represented as Extended JSON. */
static PHP_METHOD(Javascript, __construct)
{
php_phongo_javascript_t *intern;
zend_error_handling error_handling;
char *code;
phongo_zpp_char_len code_len;
zval *scope = NULL;
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_JAVASCRIPT_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|A!", &code, &code_len, &scope) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
php_phongo_javascript_init(intern, code, code_len, scope TSRMLS_CC);
} /* }}} */
/* {{{ proto void MongoDB\BSON\Javascript::__set_state(array $properties)
*/
static PHP_METHOD(Javascript, __set_state)
{
php_phongo_javascript_t *intern;
HashTable *props;
zval *array;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
RETURN_FALSE;
}
object_init_ex(return_value, php_phongo_javascript_ce);
intern = Z_JAVASCRIPT_OBJ_P(return_value);
props = Z_ARRVAL_P(array);
php_phongo_javascript_init_from_hash(intern, props TSRMLS_CC);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Javascript::__toString()
Return the Javascript's code string. */
static PHP_METHOD(Javascript, __toString)
{
php_phongo_javascript_t *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_JAVASCRIPT_OBJ_P(getThis());
PHONGO_RETURN_STRINGL(intern->code, intern->code_len);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Javascript::getCode()
*/
static PHP_METHOD(Javascript, getCode)
{
php_phongo_javascript_t *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_JAVASCRIPT_OBJ_P(getThis());
PHONGO_RETURN_STRINGL(intern->code, intern->code_len);
} /* }}} */
/* {{{ proto object|null MongoDB\BSON\Javascript::getScope()
*/
static PHP_METHOD(Javascript, getScope)
{
php_phongo_javascript_t *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_JAVASCRIPT_OBJ_P(getThis());
if (!intern->scope) {
RETURN_NULL();
}
if (intern->scope->len) {
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state);
#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
RETURN_ZVAL(state.zchild, 0, 1);
#endif
} else {
RETURN_NULL();
}
} /* }}} */
/* {{{ proto array MongoDB\BSON\Javascript::jsonSerialize()
*/
static PHP_METHOD(Javascript, jsonSerialize)
{
php_phongo_javascript_t *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_JAVASCRIPT_OBJ_P(getThis());
array_init_size(return_value, 2);
ADD_ASSOC_STRINGL(return_value, "$code", intern->code, intern->code_len);
if (intern->scope && intern->scope->len) {
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
if (php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) {
#if PHP_VERSION_ID >= 70000
Z_ADDREF(state.zchild);
ADD_ASSOC_ZVAL_EX(return_value, "$scope", &state.zchild);
#else
Z_ADDREF_P(state.zchild);
ADD_ASSOC_ZVAL_EX(return_value, "$scope", state.zchild);
#endif
}
zval_ptr_dtor(&state.zchild);
}
} /* }}} */
/* {{{ proto string MongoDB\BSON\Javascript::serialize()
*/
static PHP_METHOD(Javascript, serialize)
{
php_phongo_javascript_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval *retval;
#endif
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
php_serialize_data_t var_hash;
smart_str buf = { 0 };
intern = Z_JAVASCRIPT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
#if PHP_VERSION_ID >= 70000
if (intern->scope && intern->scope->len) {
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) {
return;
}
Z_ADDREF(state.zchild);
} else {
ZVAL_NULL(&state.zchild);
}
#else
if (intern->scope && intern->scope->len) {
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) {
return;
}
Z_ADDREF_P(state.zchild);
} else {
MAKE_STD_ZVAL(state.zchild);
ZVAL_NULL(state.zchild);
Z_ADDREF_P(state.zchild);
}
#endif
#if PHP_VERSION_ID >= 70000
array_init_size(&retval, 2);
ADD_ASSOC_STRINGL(&retval, "code", intern->code, intern->code_len);
ADD_ASSOC_ZVAL(&retval, "scope", &state.zchild);
#else
ALLOC_INIT_ZVAL(retval);
array_init_size(retval, 2);
ADD_ASSOC_STRINGL(retval, "code", intern->code, intern->code_len);
ADD_ASSOC_ZVAL(retval, "scope", state.zchild);
#endif
PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&buf, &retval, &var_hash TSRMLS_CC);
smart_str_0(&buf);
PHP_VAR_SERIALIZE_DESTROY(var_hash);
PHONGO_RETVAL_SMART_STR(buf);
smart_str_free(&buf);
zval_ptr_dtor(&retval);
zval_ptr_dtor(&state.zchild);
} /* }}} */
/* {{{ proto void MongoDB\BSON\Javascript::unserialize(string $serialized)
*/
static PHP_METHOD(Javascript, unserialize)
{
php_phongo_javascript_t *intern;
zend_error_handling error_handling;
char *serialized;
phongo_zpp_char_len serialized_len;
#if PHP_VERSION_ID >= 70000
zval props;
#else
zval *props;
#endif
php_unserialize_data_t var_hash;
intern = Z_JAVASCRIPT_OBJ_P(getThis());
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &serialized_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
#if PHP_VERSION_ID < 70000
ALLOC_INIT_ZVAL(props);
#endif
PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char *) serialized + serialized_len, &var_hash TSRMLS_CC)) {
zval_ptr_dtor(&props);
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "%s unserialization failed", ZSTR_VAL(php_phongo_javascript_ce->name));
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
#if PHP_VERSION_ID >= 70000
php_phongo_javascript_init_from_hash(intern, HASH_OF(&props) TSRMLS_CC);
#else
php_phongo_javascript_init_from_hash(intern, HASH_OF(props) TSRMLS_CC);
#endif
zval_ptr_dtor(&props);
} /* }}} */
/* {{{ MongoDB\BSON\Javascript function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Javascript___construct, 0, 0, 1)
ZEND_ARG_INFO(0, javascript)
ZEND_ARG_INFO(0, scope)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Javascript___set_state, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, properties, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Javascript_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Javascript_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_javascript_me[] = {
PHP_ME(Javascript, __construct, ai_Javascript___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Javascript, __set_state, ai_Javascript___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Javascript, __toString, ai_Javascript_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Javascript, jsonSerialize, ai_Javascript_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Javascript, serialize, ai_Javascript_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Javascript, unserialize, ai_Javascript_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Javascript, getCode, ai_Javascript_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Javascript, getScope, ai_Javascript_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\BSON\Javascript object handlers */
static zend_object_handlers php_phongo_handler_javascript;
static void php_phongo_javascript_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_javascript_t *intern = Z_OBJ_JAVASCRIPT(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->code) {
efree(intern->code);
}
if (intern->scope) {
bson_destroy(intern->scope);
intern->scope = NULL;
}
if (intern->properties) {
zend_hash_destroy(intern->properties);
FREE_HASHTABLE(intern->properties);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
phongo_create_object_retval php_phongo_javascript_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_javascript_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_javascript_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_javascript;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_javascript_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_javascript;
return retval;
}
#endif
} /* }}} */
static int php_phongo_javascript_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
{
php_phongo_javascript_t *intern1, *intern2;
intern1 = Z_JAVASCRIPT_OBJ_P(o1);
intern2 = Z_JAVASCRIPT_OBJ_P(o2);
/* Do not consider the scope document for comparisons */
return strcmp(intern1->code, intern2->code);
} /* }}} */
static HashTable *php_phongo_javascript_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
{
*table = NULL;
*n = 0;
return Z_JAVASCRIPT_OBJ_P(object)->properties;
} /* }}} */
HashTable *php_phongo_javascript_get_properties_hash(zval *object, bool is_debug TSRMLS_DC) /* {{{ */
{
php_phongo_javascript_t *intern;
HashTable *props;
intern = Z_JAVASCRIPT_OBJ_P(object);
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2);
if (!intern->code) {
return props;
}
#if PHP_VERSION_ID >= 70000
{
zval code;
ZVAL_STRING(&code, intern->code);
zend_hash_str_update(props, "code", sizeof("code")-1, &code);
if (intern->scope) {
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
if (php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) {
Z_ADDREF(state.zchild);
zend_hash_str_update(props, "scope", sizeof("scope")-1, &state.zchild);
} else {
zval scope;
ZVAL_NULL(&scope);
zend_hash_str_update(props, "scope", sizeof("scope")-1, &scope);
}
zval_ptr_dtor(&state.zchild);
} else {
zval scope;
ZVAL_NULL(&scope);
zend_hash_str_update(props, "scope", sizeof("scope")-1, &scope);
}
}
#else
{
zval *code;
MAKE_STD_ZVAL(code);
ZVAL_STRING(code, intern->code, 1);
zend_hash_update(props, "code", sizeof("code"), &code, sizeof(code), NULL);
if (intern->scope) {
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
if (php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) {
Z_ADDREF_P(state.zchild);
zend_hash_update(props, "scope", sizeof("scope"), &state.zchild, sizeof(state.zchild), NULL);
} else {
zval *scope;
MAKE_STD_ZVAL(scope);
ZVAL_NULL(scope);
zend_hash_update(props, "scope", sizeof("scope"), &scope, sizeof(scope), NULL);
}
zval_ptr_dtor(&state.zchild);
} else {
zval *scope;
MAKE_STD_ZVAL(scope);
ZVAL_NULL(scope);
zend_hash_update(props, "scope", sizeof("scope"), &scope, sizeof(scope), NULL);
}
}
#endif
return props;
} /* }}} */
static HashTable *php_phongo_javascript_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
*is_temp = 1;
return php_phongo_javascript_get_properties_hash(object, true TSRMLS_CC);
} /* }}} */
static HashTable *php_phongo_javascript_get_properties(zval *object TSRMLS_DC) /* {{{ */
{
return php_phongo_javascript_get_properties_hash(object, false TSRMLS_CC);
} /* }}} */
/* }}} */
void php_phongo_javascript_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Javascript", php_phongo_javascript_me);
php_phongo_javascript_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_javascript_ce->create_object = php_phongo_javascript_create_object;
PHONGO_CE_FINAL(php_phongo_javascript_ce);
zend_class_implements(php_phongo_javascript_ce TSRMLS_CC, 1, php_phongo_javascript_interface_ce);
zend_class_implements(php_phongo_javascript_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
zend_class_implements(php_phongo_javascript_ce TSRMLS_CC, 1, php_phongo_type_ce);
zend_class_implements(php_phongo_javascript_ce TSRMLS_CC, 1, zend_ce_serializable);
memcpy(&php_phongo_handler_javascript, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_javascript.compare_objects = php_phongo_javascript_compare_objects;
php_phongo_handler_javascript.get_debug_info = php_phongo_javascript_get_debug_info;
php_phongo_handler_javascript.get_gc = php_phongo_javascript_get_gc;
php_phongo_handler_javascript.get_properties = php_phongo_javascript_get_properties;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_javascript.free_obj = php_phongo_javascript_free_object;
php_phongo_handler_javascript.offset = XtOffsetOf(php_phongo_javascript_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/JavascriptInterface.c 0000664 0001750 0001750 00000003215 13210321137 020421 0 ustar jmikola jmikola /*
* Copyright 2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_javascript_interface_ce;
/* {{{ MongoDB\BSON\JavascriptInterface function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_JavascriptInterface_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_javascript_interface_me[] = {
ZEND_ABSTRACT_ME(JavascriptInterface, getCode, ai_JavascriptInterface_void)
ZEND_ABSTRACT_ME(JavascriptInterface, getScope, ai_JavascriptInterface_void)
ZEND_ABSTRACT_ME(JavascriptInterface, __toString, ai_JavascriptInterface_void)
PHP_FE_END
};
/* }}} */
void php_phongo_javascript_interface_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "JavascriptInterface", php_phongo_javascript_interface_me);
php_phongo_javascript_interface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/MaxKey.c 0000664 0001750 0001750 00000012104 13210321137 015665 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#if PHP_VERSION_ID >= 70000
# include
#else
# include
#endif
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_maxkey_ce;
/* {{{ proto void MongoDB\BSON\MaxKey::__set_state(array $properties)
*/
static PHP_METHOD(MaxKey, __set_state)
{
zval *array;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
RETURN_FALSE;
}
object_init_ex(return_value, php_phongo_maxkey_ce);
} /* }}} */
/* {{{ proto array MongoDB\BSON\MaxKey::jsonSerialize()
*/
static PHP_METHOD(MaxKey, jsonSerialize)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
array_init_size(return_value, 1);
ADD_ASSOC_LONG_EX(return_value, "$maxKey", 1);
} /* }}} */
/* {{{ proto string MongoDB\BSON\MaxKey::serialize()
*/
static PHP_METHOD(MaxKey, serialize)
{
PHONGO_RETURN_STRING("");
} /* }}} */
/* {{{ proto void MongoDB\BSON\MaxKey::unserialize(string $serialized)
*/
static PHP_METHOD(MaxKey, unserialize)
{
zend_error_handling error_handling;
char *serialized;
phongo_zpp_char_len serialized_len;
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &serialized_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
} /* }}} */
/* {{{ MongoDB\BSON\MaxKey function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_MaxKey___set_state, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, properties, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_MaxKey_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_MaxKey_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_maxkey_me[] = {
PHP_ME(MaxKey, __set_state, ai_MaxKey___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(MaxKey, jsonSerialize, ai_MaxKey_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(MaxKey, serialize, ai_MaxKey_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(MaxKey, unserialize, ai_MaxKey_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\BSON\MaxKey object handlers */
static zend_object_handlers php_phongo_handler_maxkey;
static void php_phongo_maxkey_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_maxkey_t *intern = Z_OBJ_MAXKEY(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_maxkey_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_maxkey_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_maxkey_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_maxkey;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_maxkey_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_maxkey;
return retval;
}
#endif
} /* }}} */
/* }}} */
void php_phongo_maxkey_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "MaxKey", php_phongo_maxkey_me);
php_phongo_maxkey_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_maxkey_ce->create_object = php_phongo_maxkey_create_object;
PHONGO_CE_FINAL(php_phongo_maxkey_ce);
zend_class_implements(php_phongo_maxkey_ce TSRMLS_CC, 1, php_phongo_maxkey_interface_ce);
zend_class_implements(php_phongo_maxkey_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
zend_class_implements(php_phongo_maxkey_ce TSRMLS_CC, 1, php_phongo_type_ce);
zend_class_implements(php_phongo_maxkey_ce TSRMLS_CC, 1, zend_ce_serializable);
memcpy(&php_phongo_handler_maxkey, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
#if PHP_VERSION_ID >= 70000
php_phongo_handler_maxkey.free_obj = php_phongo_maxkey_free_object;
php_phongo_handler_maxkey.offset = XtOffsetOf(php_phongo_maxkey_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/MaxKeyInterface.c 0000664 0001750 0001750 00000002464 13210321137 017516 0 ustar jmikola jmikola /*
* Copyright 2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_maxkey_interface_ce;
/* {{{ MongoDB\BSON\MaxKeyInterface function entries */
static zend_function_entry php_phongo_maxkey_interface_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_maxkey_interface_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "MaxKeyInterface", php_phongo_maxkey_interface_me);
php_phongo_maxkey_interface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/MinKey.c 0000664 0001750 0001750 00000012105 13210321137 015664 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#if PHP_VERSION_ID >= 70000
# include
#else
# include
#endif
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_minkey_ce;
/* {{{ proto void MongoDB\BSON\MinKey::__set_state(array $properties)
*/
static PHP_METHOD(MinKey, __set_state)
{
zval *array;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
RETURN_FALSE;
}
object_init_ex(return_value, php_phongo_minkey_ce);
} /* }}} */
/* {{{ proto array MongoDB\BSON\MinKey::jsonSerialize()
*/
static PHP_METHOD(MinKey, jsonSerialize)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
array_init_size(return_value, 1);
ADD_ASSOC_LONG_EX(return_value, "$minKey", 1);
} /* }}} */
/* {{{ proto string MongoDB\BSON\MinKey::serialize()
*/
static PHP_METHOD(MinKey, serialize)
{
PHONGO_RETURN_STRING("");
} /* }}} */
/* {{{ proto void MongoDB\BSON\MinKey::unserialize(string $serialized)
*/
static PHP_METHOD(MinKey, unserialize)
{
zend_error_handling error_handling;
char *serialized;
phongo_zpp_char_len serialized_len;
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &serialized_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
} /* }}} */
/* {{{ MongoDB\BSON\MinKey function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_MinKey___set_state, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, properties, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_MinKey_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_MinKey_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_minkey_me[] = {
PHP_ME(MinKey, __set_state, ai_MinKey___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(MinKey, jsonSerialize, ai_MinKey_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(MinKey, serialize, ai_MinKey_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(MinKey, unserialize, ai_MinKey_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\BSON\MinKey object handlers */
static zend_object_handlers php_phongo_handler_minkey;
static void php_phongo_minkey_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_minkey_t *intern = Z_OBJ_MINKEY(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_minkey_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_minkey_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_minkey_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_minkey;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_minkey_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_minkey;
return retval;
}
#endif
} /* }}} */
/* }}} */
void php_phongo_minkey_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "MinKey", php_phongo_minkey_me);
php_phongo_minkey_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_minkey_ce->create_object = php_phongo_minkey_create_object;
PHONGO_CE_FINAL(php_phongo_minkey_ce);
zend_class_implements(php_phongo_minkey_ce TSRMLS_CC, 1, php_phongo_minkey_interface_ce);
zend_class_implements(php_phongo_minkey_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
zend_class_implements(php_phongo_minkey_ce TSRMLS_CC, 1, php_phongo_type_ce);
zend_class_implements(php_phongo_minkey_ce TSRMLS_CC, 1, zend_ce_serializable);
memcpy(&php_phongo_handler_minkey, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
#if PHP_VERSION_ID >= 70000
php_phongo_handler_minkey.free_obj = php_phongo_minkey_free_object;
php_phongo_handler_minkey.offset = XtOffsetOf(php_phongo_minkey_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/MinKeyInterface.c 0000664 0001750 0001750 00000002464 13210321137 017514 0 ustar jmikola jmikola /*
* Copyright 2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_minkey_interface_ce;
/* {{{ MongoDB\BSON\MinKeyInterface function entries */
static zend_function_entry php_phongo_minkey_interface_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_minkey_interface_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "MinKeyInterface", php_phongo_minkey_interface_me);
php_phongo_minkey_interface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/ObjectId.c 0000664 0001750 0001750 00000031230 13210321137 016153 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#if PHP_VERSION_ID >= 70000
# include
#else
# include
#endif
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_objectid_ce;
/* Initialize the object with a generated value and return whether it was
* successful. */
static bool php_phongo_objectid_init(php_phongo_objectid_t *intern)
{
bson_oid_t oid;
intern->initialized = true;
bson_oid_init(&oid, NULL);
bson_oid_to_string(&oid, intern->oid);
return true;
}
/* Initialize the object from a hex string and return whether it was successful.
* An exception will be thrown on error. */
static bool php_phongo_objectid_init_from_hex_string(php_phongo_objectid_t *intern, const char *hex, phongo_zpp_char_len hex_len TSRMLS_DC) /* {{{ */
{
if (bson_oid_is_valid(hex, hex_len)) {
bson_oid_t oid;
bson_oid_init_from_string(&oid, hex);
bson_oid_to_string(&oid, intern->oid);
intern->initialized = true;
return true;
}
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error parsing ObjectId string: %s", hex);
return false;
} /* }}} */
/* Initialize the object from a HashTable and return whether it was successful.
* An exception will be thrown on error. */
static bool php_phongo_objectid_init_from_hash(php_phongo_objectid_t *intern, HashTable *props TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval *z_oid;
z_oid = zend_hash_str_find(props, "oid", sizeof("oid")-1);
if (z_oid && Z_TYPE_P(z_oid) == IS_STRING) {
return php_phongo_objectid_init_from_hex_string(intern, Z_STRVAL_P(z_oid), Z_STRLEN_P(z_oid) TSRMLS_CC);
}
#else
zval **z_oid;
if (zend_hash_find(props, "oid", sizeof("oid"), (void**) &z_oid) == SUCCESS && Z_TYPE_PP(z_oid) == IS_STRING) {
return php_phongo_objectid_init_from_hex_string(intern, Z_STRVAL_PP(z_oid), Z_STRLEN_PP(z_oid) TSRMLS_CC);
}
#endif
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"oid\" string field", ZSTR_VAL(php_phongo_objectid_ce->name));
return false;
} /* }}} */
/* {{{ proto void MongoDB\BSON\ObjectId::__construct([string $id])
Constructs a new BSON ObjectId type, optionally from a hex string. */
static PHP_METHOD(ObjectId, __construct)
{
php_phongo_objectid_t *intern;
zend_error_handling error_handling;
char *id = NULL;
phongo_zpp_char_len id_len;
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_OBJECTID_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &id, &id_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
if (id) {
php_phongo_objectid_init_from_hex_string(intern, id, id_len TSRMLS_CC);
} else {
php_phongo_objectid_init(intern);
}
} /* }}} */
/* {{{ proto integer MongoDB\BSON\ObjectId::getTimestamp()
*/
static PHP_METHOD(ObjectId, getTimestamp)
{
php_phongo_objectid_t *intern;
bson_oid_t tmp_oid;
intern = Z_OBJECTID_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
bson_oid_init_from_string(&tmp_oid, intern->oid);
RETVAL_LONG(bson_oid_get_time_t(&tmp_oid));
} /* }}} */
/* {{{ proto MongoDB\BSON\ObjectId::__set_state(array $properties)
*/
static PHP_METHOD(ObjectId, __set_state)
{
php_phongo_objectid_t *intern;
HashTable *props;
zval *array;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
RETURN_FALSE;
}
object_init_ex(return_value, php_phongo_objectid_ce);
intern = Z_OBJECTID_OBJ_P(return_value);
props = Z_ARRVAL_P(array);
php_phongo_objectid_init_from_hash(intern, props TSRMLS_CC);
} /* }}} */
/* {{{ proto string MongoDB\BSON\ObjectId::__toString()
*/
static PHP_METHOD(ObjectId, __toString)
{
php_phongo_objectid_t *intern;
intern = Z_OBJECTID_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_RETURN_STRINGL(intern->oid, 24);
} /* }}} */
/* {{{ proto array MongoDB\BSON\ObjectId::jsonSerialize()
*/
static PHP_METHOD(ObjectId, jsonSerialize)
{
php_phongo_objectid_t *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_OBJECTID_OBJ_P(getThis());
array_init_size(return_value, 1);
ADD_ASSOC_STRINGL(return_value, "$oid", intern->oid, 24);
} /* }}} */
/* {{{ proto string MongoDB\BSON\ObjectId::serialize()
*/
static PHP_METHOD(ObjectId, serialize)
{
php_phongo_objectid_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval *retval;
#endif
php_serialize_data_t var_hash;
smart_str buf = { 0 };
intern = Z_OBJECTID_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
#if PHP_VERSION_ID >= 70000
array_init_size(&retval, 2);
ADD_ASSOC_STRINGL(&retval, "oid", intern->oid, 24);
#else
ALLOC_INIT_ZVAL(retval);
array_init_size(retval, 2);
ADD_ASSOC_STRINGL(retval, "oid", intern->oid, 24);
#endif
PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&buf, &retval, &var_hash TSRMLS_CC);
smart_str_0(&buf);
PHP_VAR_SERIALIZE_DESTROY(var_hash);
PHONGO_RETVAL_SMART_STR(buf);
smart_str_free(&buf);
zval_ptr_dtor(&retval);
} /* }}} */
/* {{{ proto void MongoDB\BSON\ObjectId::unserialize(string $serialized)
*/
static PHP_METHOD(ObjectId, unserialize)
{
php_phongo_objectid_t *intern;
zend_error_handling error_handling;
char *serialized;
phongo_zpp_char_len serialized_len;
#if PHP_VERSION_ID >= 70000
zval props;
#else
zval *props;
#endif
php_unserialize_data_t var_hash;
intern = Z_OBJECTID_OBJ_P(getThis());
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &serialized_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
#if PHP_VERSION_ID < 70000
ALLOC_INIT_ZVAL(props);
#endif
PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char *) serialized + serialized_len, &var_hash TSRMLS_CC)) {
zval_ptr_dtor(&props);
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "%s unserialization failed", ZSTR_VAL(php_phongo_objectid_ce->name));
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
#if PHP_VERSION_ID >= 70000
php_phongo_objectid_init_from_hash(intern, HASH_OF(&props) TSRMLS_CC);
#else
php_phongo_objectid_init_from_hash(intern, HASH_OF(props) TSRMLS_CC);
#endif
zval_ptr_dtor(&props);
} /* }}} */
/* {{{ MongoDB\BSON\ObjectId function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_ObjectId___construct, 0, 0, 0)
ZEND_ARG_INFO(0, id)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_ObjectId___set_state, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, properties, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_ObjectId_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_ObjectId_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_objectid_me[] = {
PHP_ME(ObjectId, __construct, ai_ObjectId___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ObjectId, getTimestamp, ai_ObjectId_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ObjectId, __set_state, ai_ObjectId___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(ObjectId, __toString, ai_ObjectId_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ObjectId, jsonSerialize, ai_ObjectId_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ObjectId, serialize, ai_ObjectId_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ObjectId, unserialize, ai_ObjectId_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\BSON\ObjectId object handlers */
static zend_object_handlers php_phongo_handler_objectid;
static void php_phongo_objectid_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_objectid_t *intern = Z_OBJ_OBJECTID(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->properties) {
zend_hash_destroy(intern->properties);
FREE_HASHTABLE(intern->properties);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_objectid_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_objectid_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_objectid_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_objectid;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_objectid_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_objectid;
return retval;
}
#endif
} /* }}} */
static int php_phongo_objectid_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
{
php_phongo_objectid_t *intern1;
php_phongo_objectid_t *intern2;
intern1 = Z_OBJECTID_OBJ_P(o1);
intern2 = Z_OBJECTID_OBJ_P(o2);
return strcmp(intern1->oid, intern2->oid);
} /* }}} */
static HashTable *php_phongo_objectid_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
{
*table = NULL;
*n = 0;
return Z_OBJECTID_OBJ_P(object)->properties;
} /* }}} */
static HashTable *php_phongo_objectid_get_properties_hash(zval *object, bool is_debug TSRMLS_DC) /* {{{ */
{
php_phongo_objectid_t *intern;
HashTable *props;
intern = Z_OBJECTID_OBJ_P(object);
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 1);
if (!intern->oid) {
return props;
}
#if PHP_VERSION_ID >= 70000
{
zval zv;
ZVAL_STRING(&zv, intern->oid);
zend_hash_str_update(props, "oid", sizeof("oid")-1, &zv);
}
#else
{
zval *zv;
MAKE_STD_ZVAL(zv);
ZVAL_STRING(zv, intern->oid, 1);
zend_hash_update(props, "oid", sizeof("oid"), &zv, sizeof(zv), NULL);
}
#endif
return props;
} /* }}} */
static HashTable *php_phongo_objectid_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
*is_temp = 1;
return php_phongo_objectid_get_properties_hash(object, true TSRMLS_CC);
} /* }}} */
static HashTable *php_phongo_objectid_get_properties(zval *object TSRMLS_DC) /* {{{ */
{
return php_phongo_objectid_get_properties_hash(object, false TSRMLS_CC);
} /* }}} */
/* }}} */
void php_phongo_objectid_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "ObjectId", php_phongo_objectid_me);
php_phongo_objectid_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_objectid_ce->create_object = php_phongo_objectid_create_object;
PHONGO_CE_FINAL(php_phongo_objectid_ce);
zend_class_implements(php_phongo_objectid_ce TSRMLS_CC, 1, php_phongo_objectid_interface_ce);
zend_class_implements(php_phongo_objectid_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
zend_class_implements(php_phongo_objectid_ce TSRMLS_CC, 1, php_phongo_type_ce);
zend_class_implements(php_phongo_objectid_ce TSRMLS_CC, 1, zend_ce_serializable);
memcpy(&php_phongo_handler_objectid, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_objectid.compare_objects = php_phongo_objectid_compare_objects;
php_phongo_handler_objectid.get_debug_info = php_phongo_objectid_get_debug_info;
php_phongo_handler_objectid.get_gc = php_phongo_objectid_get_gc;
php_phongo_handler_objectid.get_properties = php_phongo_objectid_get_properties;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_objectid.free_obj = php_phongo_objectid_free_object;
php_phongo_handler_objectid.offset = XtOffsetOf(php_phongo_objectid_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/ObjectIdInterface.c 0000664 0001750 0001750 00000003054 13210321137 017777 0 ustar jmikola jmikola /*
* Copyright 2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_objectid_interface_ce;
/* {{{ MongoDB\BSON\ObjectIdInterface function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_ObjectIdInterface_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_objectid_interface_me[] = {
ZEND_ABSTRACT_ME(ObjectIdInterface, getTimestamp, ai_ObjectIdInterface_void)
ZEND_ABSTRACT_ME(ObjectIdInterface, __toString, ai_ObjectIdInterface_void)
PHP_FE_END
};
/* }}} */
void php_phongo_objectid_interface_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "ObjectIdInterface", php_phongo_objectid_interface_me);
php_phongo_objectid_interface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/Persistable.c 0000664 0001750 0001750 00000002621 13210321137 016747 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_persistable_ce;
/* {{{ MongoDB\BSON\Persistable function entries */
static zend_function_entry php_phongo_persistable_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_persistable_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Persistable", php_phongo_persistable_me);
php_phongo_persistable_ce = zend_register_internal_interface(&ce TSRMLS_CC);
zend_class_implements(php_phongo_persistable_ce TSRMLS_CC, 2, php_phongo_unserializable_ce, php_phongo_serializable_ce);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/Regex.c 0000664 0001750 0001750 00000035203 13210321137 015546 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#if PHP_VERSION_ID >= 70000
# include
#else
# include
#endif
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_regex_ce;
/* qsort() compare callback for alphabetizing regex flags upon initialization */
static int php_phongo_regex_compare_flags(const void *f1, const void *f2) /* {{{ */
{
if (* (const char *) f1 == * (const char *) f2) {
return 0;
}
return (* (const char *) f1 > * (const char *) f2) ? 1 : -1;
} /* }}} */
/* Initialize the object and return whether it was successful. An exception will
* be thrown on error. */
static bool php_phongo_regex_init(php_phongo_regex_t *intern, const char *pattern, phongo_zpp_char_len pattern_len, const char *flags, phongo_zpp_char_len flags_len TSRMLS_DC) /* {{{ */
{
if (strlen(pattern) != pattern_len) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Pattern cannot contain null bytes");
return false;
}
intern->pattern = estrndup(pattern, pattern_len);
intern->pattern_len = pattern_len;
if (flags) {
if (strlen(flags) != flags_len) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Flags cannot contain null bytes");
return false;
}
intern->flags = estrndup(flags, flags_len);
intern->flags_len = flags_len;
/* Ensure flags are alphabetized upon initialization */
qsort((void *) intern->flags, flags_len, 1, php_phongo_regex_compare_flags);
} else {
intern->flags = estrdup("");
intern->flags_len = 0;
}
return true;
} /* }}} */
/* Initialize the object from a HashTable and return whether it was successful.
* An exception will be thrown on error. */
static bool php_phongo_regex_init_from_hash(php_phongo_regex_t *intern, HashTable *props TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval *pattern, *flags;
if ((pattern = zend_hash_str_find(props, "pattern", sizeof("pattern")-1)) && Z_TYPE_P(pattern) == IS_STRING &&
(flags = zend_hash_str_find(props, "flags", sizeof("flags")-1)) && Z_TYPE_P(flags) == IS_STRING) {
return php_phongo_regex_init(intern, Z_STRVAL_P(pattern), Z_STRLEN_P(pattern), Z_STRVAL_P(flags), Z_STRLEN_P(flags) TSRMLS_CC);
}
#else
zval **pattern, **flags;
if (zend_hash_find(props, "pattern", sizeof("pattern"), (void**) &pattern) == SUCCESS && Z_TYPE_PP(pattern) == IS_STRING &&
zend_hash_find(props, "flags", sizeof("flags"), (void**) &flags) == SUCCESS && Z_TYPE_PP(flags) == IS_STRING) {
return php_phongo_regex_init(intern, Z_STRVAL_PP(pattern), Z_STRLEN_PP(pattern), Z_STRVAL_PP(flags), Z_STRLEN_PP(flags) TSRMLS_CC);
}
#endif
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"pattern\" and \"flags\" string fields", ZSTR_VAL(php_phongo_regex_ce->name));
return false;
} /* }}} */
/* {{{ proto void MongoDB\BSON\Regex::__construct(string $pattern [, string $flags])
Constructs a new BSON regular expression type. */
static PHP_METHOD(Regex, __construct)
{
php_phongo_regex_t *intern;
zend_error_handling error_handling;
char *pattern;
phongo_zpp_char_len pattern_len;
char *flags = NULL;
phongo_zpp_char_len flags_len = 0;
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_REGEX_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &pattern, &pattern_len, &flags, &flags_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
php_phongo_regex_init(intern, pattern, pattern_len, flags, flags_len TSRMLS_CC);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Regex::getPattern()
*/
static PHP_METHOD(Regex, getPattern)
{
php_phongo_regex_t *intern;
intern = Z_REGEX_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_RETURN_STRINGL(intern->pattern, intern->pattern_len);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Regex::getFlags()
*/
static PHP_METHOD(Regex, getFlags)
{
php_phongo_regex_t *intern;
intern = Z_REGEX_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_RETURN_STRINGL(intern->flags, intern->flags_len);
} /* }}} */
/* {{{ proto void MongoDB\BSON\Regex::__set_state(array $properties)
*/
static PHP_METHOD(Regex, __set_state)
{
php_phongo_regex_t *intern;
HashTable *props;
zval *array;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
RETURN_FALSE;
}
object_init_ex(return_value, php_phongo_regex_ce);
intern = Z_REGEX_OBJ_P(return_value);
props = Z_ARRVAL_P(array);
php_phongo_regex_init_from_hash(intern, props TSRMLS_CC);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Regex::__toString()
Returns a string in the form: /pattern/flags */
static PHP_METHOD(Regex, __toString)
{
php_phongo_regex_t *intern;
char *regex;
int regex_len;
intern = Z_REGEX_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
regex_len = spprintf(®ex, 0, "/%s/%s", intern->pattern, intern->flags);
PHONGO_RETVAL_STRINGL(regex, regex_len);
efree(regex);
} /* }}} */
/* {{{ proto array MongoDB\BSON\Regex::jsonSerialize()
*/
static PHP_METHOD(Regex, jsonSerialize)
{
php_phongo_regex_t *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_REGEX_OBJ_P(getThis());
array_init_size(return_value, 2);
ADD_ASSOC_STRINGL(return_value, "$regex", intern->pattern, intern->pattern_len);
ADD_ASSOC_STRINGL(return_value, "$options", intern->flags, intern->flags_len);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Regex::serialize()
*/
static PHP_METHOD(Regex, serialize)
{
php_phongo_regex_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval *retval;
#endif
php_serialize_data_t var_hash;
smart_str buf = { 0 };
intern = Z_REGEX_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
#if PHP_VERSION_ID >= 70000
array_init_size(&retval, 2);
ADD_ASSOC_STRINGL(&retval, "pattern", intern->pattern, intern->pattern_len);
ADD_ASSOC_STRINGL(&retval, "flags", intern->flags, intern->flags_len);
#else
ALLOC_INIT_ZVAL(retval);
array_init_size(retval, 2);
ADD_ASSOC_STRINGL(retval, "pattern", intern->pattern, intern->pattern_len);
ADD_ASSOC_STRINGL(retval, "flags", intern->flags, intern->flags_len);
#endif
PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&buf, &retval, &var_hash TSRMLS_CC);
smart_str_0(&buf);
PHP_VAR_SERIALIZE_DESTROY(var_hash);
PHONGO_RETVAL_SMART_STR(buf);
smart_str_free(&buf);
zval_ptr_dtor(&retval);
} /* }}} */
/* {{{ proto void MongoDB\BSON\Regex::unserialize(string $serialized)
*/
static PHP_METHOD(Regex, unserialize)
{
php_phongo_regex_t *intern;
zend_error_handling error_handling;
char *serialized;
phongo_zpp_char_len serialized_len;
#if PHP_VERSION_ID >= 70000
zval props;
#else
zval *props;
#endif
php_unserialize_data_t var_hash;
intern = Z_REGEX_OBJ_P(getThis());
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &serialized_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
#if PHP_VERSION_ID < 70000
ALLOC_INIT_ZVAL(props);
#endif
PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char *) serialized + serialized_len, &var_hash TSRMLS_CC)) {
zval_ptr_dtor(&props);
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "%s unserialization failed", ZSTR_VAL(php_phongo_regex_ce->name));
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
#if PHP_VERSION_ID >= 70000
php_phongo_regex_init_from_hash(intern, HASH_OF(&props) TSRMLS_CC);
#else
php_phongo_regex_init_from_hash(intern, HASH_OF(props) TSRMLS_CC);
#endif
zval_ptr_dtor(&props);
} /* }}} */
/* {{{ MongoDB\BSON\Regex function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Regex___construct, 0, 0, 2)
ZEND_ARG_INFO(0, pattern)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Regex___set_state, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, properties, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Regex_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Regex_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_regex_me[] = {
PHP_ME(Regex, __construct, ai_Regex___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Regex, __set_state, ai_Regex___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Regex, __toString, ai_Regex_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Regex, jsonSerialize, ai_Regex_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Regex, serialize, ai_Regex_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Regex, unserialize, ai_Regex_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Regex, getPattern, ai_Regex_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Regex, getFlags, ai_Regex_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\BSON\Regex object handlers */
static zend_object_handlers php_phongo_handler_regex;
static void php_phongo_regex_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_regex_t *intern = Z_OBJ_REGEX(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->pattern) {
efree(intern->pattern);
}
if (intern->flags) {
efree(intern->flags);
}
if (intern->properties) {
zend_hash_destroy(intern->properties);
FREE_HASHTABLE(intern->properties);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_regex_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_regex_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_regex_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_regex;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_regex_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_regex;
return retval;
}
#endif
} /* }}} */
static int php_phongo_regex_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
{
php_phongo_regex_t *intern1, *intern2;
int retval;
intern1 = Z_REGEX_OBJ_P(o1);
intern2 = Z_REGEX_OBJ_P(o2);
/* MongoDB compares the pattern string before the flags. */
retval = strcmp(intern1->pattern, intern2->pattern);
if (retval != 0) {
return retval;
}
return strcmp(intern1->flags, intern2->flags);
} /* }}} */
static HashTable *php_phongo_regex_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
{
*table = NULL;
*n = 0;
return Z_REGEX_OBJ_P(object)->properties;
} /* }}} */
static HashTable *php_phongo_regex_get_properties_hash(zval *object, bool is_debug TSRMLS_DC) /* {{{ */
{
php_phongo_regex_t *intern;
HashTable *props;
intern = Z_REGEX_OBJ_P(object);
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2);
if (!intern->pattern) {
return props;
}
#if PHP_VERSION_ID >= 70000
{
zval pattern, flags;
ZVAL_STRINGL(&pattern, intern->pattern, intern->pattern_len);
zend_hash_str_update(props, "pattern", sizeof("pattern")-1, &pattern);
ZVAL_STRINGL(&flags, intern->flags, intern->flags_len);
zend_hash_str_update(props, "flags", sizeof("flags")-1, &flags);
}
#else
{
zval *pattern, *flags;
MAKE_STD_ZVAL(pattern);
ZVAL_STRINGL(pattern, intern->pattern, intern->pattern_len, 1);
zend_hash_update(props, "pattern", sizeof("pattern"), &pattern, sizeof(pattern), NULL);
MAKE_STD_ZVAL(flags);
ZVAL_STRINGL(flags, intern->flags, intern->flags_len, 1);
zend_hash_update(props, "flags", sizeof("flags"), &flags, sizeof(flags), NULL);
}
#endif
return props;
} /* }}} */
static HashTable *php_phongo_regex_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
*is_temp = 1;
return php_phongo_regex_get_properties_hash(object, true TSRMLS_CC);
} /* }}} */
static HashTable *php_phongo_regex_get_properties(zval *object TSRMLS_DC) /* {{{ */
{
return php_phongo_regex_get_properties_hash(object, false TSRMLS_CC);
} /* }}} */
/* }}} */
void php_phongo_regex_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Regex", php_phongo_regex_me);
php_phongo_regex_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_regex_ce->create_object = php_phongo_regex_create_object;
PHONGO_CE_FINAL(php_phongo_regex_ce);
zend_class_implements(php_phongo_regex_ce TSRMLS_CC, 1, php_phongo_regex_interface_ce);
zend_class_implements(php_phongo_regex_ce TSRMLS_CC, 1, php_phongo_type_ce);
zend_class_implements(php_phongo_regex_ce TSRMLS_CC, 1, zend_ce_serializable);
zend_class_implements(php_phongo_regex_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
memcpy(&php_phongo_handler_regex, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_regex.compare_objects = php_phongo_regex_compare_objects;
php_phongo_handler_regex.get_debug_info = php_phongo_regex_get_debug_info;
php_phongo_handler_regex.get_gc = php_phongo_regex_get_gc;
php_phongo_handler_regex.get_properties = php_phongo_regex_get_properties;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_regex.free_obj = php_phongo_regex_free_object;
php_phongo_handler_regex.offset = XtOffsetOf(php_phongo_regex_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/RegexInterface.c 0000664 0001750 0001750 00000003112 13210321137 017361 0 ustar jmikola jmikola /*
* Copyright 2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_regex_interface_ce;
/* {{{ MongoDB\BSON\RegexInterface function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_RegexInterface_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_regex_interface_me[] = {
ZEND_ABSTRACT_ME(RegexInterface, getFlags, ai_RegexInterface_void)
ZEND_ABSTRACT_ME(RegexInterface, getPattern, ai_RegexInterface_void)
ZEND_ABSTRACT_ME(RegexInterface, __toString, ai_RegexInterface_void)
PHP_FE_END
};
/* }}} */
void php_phongo_regex_interface_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "RegexInterface", php_phongo_regex_interface_me);
php_phongo_regex_interface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/Serializable.c 0000664 0001750 0001750 00000003003 13210321137 017073 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_serializable_ce;
/* {{{ MongoDB\BSON\Serializable function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Serializable_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_serializable_me[] = {
ZEND_ABSTRACT_ME(Serializable, bsonSerialize, ai_Serializable_void)
PHP_FE_END
};
/* }}} */
void php_phongo_serializable_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Serializable", php_phongo_serializable_me);
php_phongo_serializable_ce = zend_register_internal_interface(&ce TSRMLS_CC);
zend_class_implements(php_phongo_serializable_ce TSRMLS_CC, 1, php_phongo_type_ce);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/Timestamp.c 0000664 0001750 0001750 00000045375 13210321137 016452 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#if PHP_VERSION_ID >= 70000
# include
#else
# include
#endif
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_timestamp_ce;
/* Initialize the object and return whether it was successful. An exception will
* be thrown on error. */
static bool php_phongo_timestamp_init(php_phongo_timestamp_t *intern, int64_t increment, int64_t timestamp TSRMLS_DC) /* {{{ */
{
if (increment < 0 || increment > UINT32_MAX) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected increment to be an unsigned 32-bit integer, %" PHONGO_LONG_FORMAT " given", increment);
return false;
}
if (timestamp < 0 || timestamp > UINT32_MAX) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected timestamp to be an unsigned 32-bit integer, %" PHONGO_LONG_FORMAT " given", timestamp);
return false;
}
intern->increment = (uint32_t) increment;
intern->timestamp = (uint32_t) timestamp;
intern->initialized = true;
return true;
} /* }}} */
/* Initialize the object from numeric strings and return whether it was
* successful. An exception will be thrown on error. */
static bool php_phongo_timestamp_init_from_string(php_phongo_timestamp_t *intern, const char *s_increment, phongo_zpp_char_len s_increment_len, const char *s_timestamp, phongo_zpp_char_len s_timestamp_len TSRMLS_DC) /* {{{ */
{
int64_t increment, timestamp;
char *endptr = NULL;
errno = 0;
/* errno will set errno if conversion fails; however, we do not need to
* specify the type of error.
*
* Note: bson_ascii_strtoll() does not properly detect out-of-range values
* (see: CDRIVER-1377). strtoll() would be preferable, but it is not
* available on all platforms (e.g. HP-UX), and atoll() provides no error
* reporting at all. */
increment = bson_ascii_strtoll(s_increment, &endptr, 10);
if (errno || (endptr && endptr != ((const char *)s_increment + s_increment_len))) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error parsing \"%s\" as 64-bit integer increment for %s initialization", s_increment, ZSTR_VAL(php_phongo_timestamp_ce->name));
return false;
}
timestamp = bson_ascii_strtoll(s_timestamp, &endptr, 10);
if (errno || (endptr && endptr != ((const char *)s_timestamp + s_timestamp_len))) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error parsing \"%s\" as 64-bit integer timestamp for %s initialization", s_timestamp, ZSTR_VAL(php_phongo_timestamp_ce->name));
return false;
}
return php_phongo_timestamp_init(intern, increment, timestamp TSRMLS_CC);
} /* }}} */
/* Initialize the object from a HashTable and return whether it was successful.
* An exception will be thrown on error. */
static bool php_phongo_timestamp_init_from_hash(php_phongo_timestamp_t *intern, HashTable *props TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval *increment, *timestamp;
if ((increment = zend_hash_str_find(props, "increment", sizeof("increment")-1)) && Z_TYPE_P(increment) == IS_LONG &&
(timestamp = zend_hash_str_find(props, "timestamp", sizeof("timestamp")-1)) && Z_TYPE_P(timestamp) == IS_LONG) {
return php_phongo_timestamp_init(intern, Z_LVAL_P(increment), Z_LVAL_P(timestamp) TSRMLS_CC);
}
if ((increment = zend_hash_str_find(props, "increment", sizeof("increment")-1)) && Z_TYPE_P(increment) == IS_STRING &&
(timestamp = zend_hash_str_find(props, "timestamp", sizeof("timestamp")-1)) && Z_TYPE_P(timestamp) == IS_STRING) {
return php_phongo_timestamp_init_from_string(intern, Z_STRVAL_P(increment), Z_STRLEN_P(increment), Z_STRVAL_P(timestamp), Z_STRLEN_P(timestamp) TSRMLS_CC);
}
#else
zval **increment, **timestamp;
if (zend_hash_find(props, "increment", sizeof("increment"), (void**) &increment) == SUCCESS && Z_TYPE_PP(increment) == IS_LONG &&
zend_hash_find(props, "timestamp", sizeof("timestamp"), (void**) ×tamp) == SUCCESS && Z_TYPE_PP(timestamp) == IS_LONG) {
return php_phongo_timestamp_init(intern, Z_LVAL_PP(increment), Z_LVAL_PP(timestamp) TSRMLS_CC);
}
if (zend_hash_find(props, "increment", sizeof("increment"), (void**) &increment) == SUCCESS && Z_TYPE_PP(increment) == IS_STRING &&
zend_hash_find(props, "timestamp", sizeof("timestamp"), (void**) ×tamp) == SUCCESS && Z_TYPE_PP(timestamp) == IS_STRING) {
return php_phongo_timestamp_init_from_string(intern, Z_STRVAL_PP(increment), Z_STRLEN_PP(increment), Z_STRVAL_PP(timestamp), Z_STRLEN_PP(timestamp) TSRMLS_CC);
}
#endif
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"increment\" and \"timestamp\" integer or numeric string fields", ZSTR_VAL(php_phongo_timestamp_ce->name));
return false;
} /* }}} */
/* {{{ proto void MongoDB\BSON\Timestamp::__construct(int|string $increment, int|string $timestamp)
Construct a new BSON timestamp type, which consists of a 4-byte increment and
4-byte timestamp. */
static PHP_METHOD(Timestamp, __construct)
{
php_phongo_timestamp_t *intern;
zend_error_handling error_handling;
zval *increment = NULL, *timestamp = NULL;
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_TIMESTAMP_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &increment, ×tamp) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
if (Z_TYPE_P(increment) == IS_LONG && Z_TYPE_P(timestamp) == IS_LONG) {
php_phongo_timestamp_init(intern, Z_LVAL_P(increment), Z_LVAL_P(timestamp) TSRMLS_CC);
return;
}
if (Z_TYPE_P(increment) == IS_LONG) {
convert_to_string(increment);
}
if (Z_TYPE_P(increment) != IS_STRING) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected increment to be an unsigned 32-bit integer or string, %s given", zend_get_type_by_const(Z_TYPE_P(increment)));
return;
}
if (Z_TYPE_P(timestamp) == IS_LONG) {
convert_to_string(timestamp);
}
if (Z_TYPE_P(timestamp) != IS_STRING) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected timestamp to be an unsigned 32-bit integer or string, %s given", zend_get_type_by_const(Z_TYPE_P(timestamp)));
return;
}
php_phongo_timestamp_init_from_string(intern, Z_STRVAL_P(increment), Z_STRLEN_P(increment), Z_STRVAL_P(timestamp), Z_STRLEN_P(timestamp) TSRMLS_CC);
} /* }}} */
/* {{{ proto integer MongoDB\BSON\Timestamp::getIncrement()
*/
static PHP_METHOD(Timestamp, getIncrement)
{
php_phongo_timestamp_t *intern;
intern = Z_TIMESTAMP_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETVAL_LONG(intern->increment);
} /* }}} */
/* {{{ proto integer MongoDB\BSON\Timestamp::getTimestamp()
*/
static PHP_METHOD(Timestamp, getTimestamp)
{
php_phongo_timestamp_t *intern;
intern = Z_TIMESTAMP_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETVAL_LONG(intern->timestamp);
} /* }}} */
/* {{{ proto void MongoDB\BSON\Timestamp::__set_state(array $properties)
*/
static PHP_METHOD(Timestamp, __set_state)
{
php_phongo_timestamp_t *intern;
HashTable *props;
zval *array;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
RETURN_FALSE;
}
object_init_ex(return_value, php_phongo_timestamp_ce);
intern = Z_TIMESTAMP_OBJ_P(return_value);
props = Z_ARRVAL_P(array);
php_phongo_timestamp_init_from_hash(intern, props TSRMLS_CC);
} /* }}} */
/* {{{ proto string MongoDB\BSON\Timestamp::__toString()
Returns a string in the form: [increment:timestamp] */
static PHP_METHOD(Timestamp, __toString)
{
php_phongo_timestamp_t *intern;
char *retval;
int retval_len;
intern = Z_TIMESTAMP_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
retval_len = spprintf(&retval, 0, "[%" PRIu32 ":%" PRIu32 "]", intern->increment, intern->timestamp);
PHONGO_RETVAL_STRINGL(retval, retval_len);
efree(retval);
} /* }}} */
/* {{{ proto array MongoDB\BSON\Timestamp::jsonSerialize()
*/
static PHP_METHOD(Timestamp, jsonSerialize)
{
php_phongo_timestamp_t *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_TIMESTAMP_OBJ_P(getThis());
array_init_size(return_value, 1);
#if PHP_VERSION_ID >= 70000
{
zval ts;
array_init_size(&ts, 2);
ADD_ASSOC_LONG_EX(&ts, "t", intern->timestamp);
ADD_ASSOC_LONG_EX(&ts, "i", intern->increment);
ADD_ASSOC_ZVAL_EX(return_value, "$timestamp", &ts);
}
#else
{
zval *ts;
MAKE_STD_ZVAL(ts);
array_init_size(ts, 2);
ADD_ASSOC_LONG_EX(ts, "t", intern->timestamp);
ADD_ASSOC_LONG_EX(ts, "i", intern->increment);
ADD_ASSOC_ZVAL_EX(return_value, "$timestamp", ts);
}
#endif
} /* }}} */
/* {{{ proto string MongoDB\BSON\Timestamp::serialize()
*/
static PHP_METHOD(Timestamp, serialize)
{
php_phongo_timestamp_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval *retval;
#endif
php_serialize_data_t var_hash;
smart_str buf = { 0 };
char s_increment[12];
char s_timestamp[12];
int s_increment_len;
int s_timestamp_len;
intern = Z_TIMESTAMP_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
s_increment_len = snprintf(s_increment, sizeof(s_increment), "%" PRIu32, intern->increment);
s_timestamp_len = snprintf(s_timestamp, sizeof(s_timestamp), "%" PRIu32, intern->timestamp);
#if PHP_VERSION_ID >= 70000
array_init_size(&retval, 2);
ADD_ASSOC_STRINGL(&retval, "increment", s_increment, s_increment_len);
ADD_ASSOC_STRINGL(&retval, "timestamp", s_timestamp, s_timestamp_len);
#else
ALLOC_INIT_ZVAL(retval);
array_init_size(retval, 2);
ADD_ASSOC_STRINGL(retval, "increment", s_increment, s_increment_len);
ADD_ASSOC_STRINGL(retval, "timestamp", s_timestamp, s_timestamp_len);
#endif
PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&buf, &retval, &var_hash TSRMLS_CC);
smart_str_0(&buf);
PHP_VAR_SERIALIZE_DESTROY(var_hash);
PHONGO_RETVAL_SMART_STR(buf);
smart_str_free(&buf);
zval_ptr_dtor(&retval);
} /* }}} */
/* {{{ proto void MongoDB\BSON\Timestamp::unserialize(string $serialized)
*/
static PHP_METHOD(Timestamp, unserialize)
{
php_phongo_timestamp_t *intern;
zend_error_handling error_handling;
char *serialized;
phongo_zpp_char_len serialized_len;
#if PHP_VERSION_ID >= 70000
zval props;
#else
zval *props;
#endif
php_unserialize_data_t var_hash;
intern = Z_TIMESTAMP_OBJ_P(getThis());
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &serialized_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
#if PHP_VERSION_ID < 70000
ALLOC_INIT_ZVAL(props);
#endif
PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char *) serialized + serialized_len, &var_hash TSRMLS_CC)) {
zval_ptr_dtor(&props);
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "%s unserialization failed", ZSTR_VAL(php_phongo_timestamp_ce->name));
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
#if PHP_VERSION_ID >= 70000
php_phongo_timestamp_init_from_hash(intern, HASH_OF(&props) TSRMLS_CC);
#else
php_phongo_timestamp_init_from_hash(intern, HASH_OF(props) TSRMLS_CC);
#endif
zval_ptr_dtor(&props);
} /* }}} */
/* {{{ MongoDB\BSON\Timestamp function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Timestamp___construct, 0, 0, 2)
ZEND_ARG_INFO(0, increment)
ZEND_ARG_INFO(0, timestamp)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Timestamp___set_state, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, properties, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Timestamp_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Timestamp_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_timestamp_me[] = {
PHP_ME(Timestamp, __construct, ai_Timestamp___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Timestamp, __set_state, ai_Timestamp___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Timestamp, __toString, ai_Timestamp_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Timestamp, jsonSerialize, ai_Timestamp_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Timestamp, serialize, ai_Timestamp_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Timestamp, unserialize, ai_Timestamp_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Timestamp, getIncrement, ai_Timestamp_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Timestamp, getTimestamp, ai_Timestamp_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\BSON\Timestamp object handlers */
static zend_object_handlers php_phongo_handler_timestamp;
static void php_phongo_timestamp_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_timestamp_t *intern = Z_OBJ_TIMESTAMP(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->properties) {
zend_hash_destroy(intern->properties);
FREE_HASHTABLE(intern->properties);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_timestamp_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_timestamp_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_timestamp_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_timestamp;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_timestamp_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_timestamp;
return retval;
}
#endif
} /* }}} */
static int php_phongo_timestamp_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
{
php_phongo_timestamp_t *intern1, *intern2;
intern1 = Z_TIMESTAMP_OBJ_P(o1);
intern2 = Z_TIMESTAMP_OBJ_P(o2);
/* MongoDB compares the timestamp before the increment. */
if (intern1->timestamp != intern2->timestamp) {
return intern1->timestamp < intern2->timestamp ? -1 : 1;
}
if (intern1->increment != intern2->increment) {
return intern1->increment < intern2->increment ? -1 : 1;
}
return 0;
} /* }}} */
static HashTable *php_phongo_timestamp_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
{
*table = NULL;
*n = 0;
return Z_TIMESTAMP_OBJ_P(object)->properties;
} /* }}} */
static HashTable *php_phongo_timestamp_get_properties_hash(zval *object, bool is_debug TSRMLS_DC) /* {{{ */
{
php_phongo_timestamp_t *intern;
HashTable *props;
char s_increment[24];
char s_timestamp[24];
int s_increment_len;
int s_timestamp_len;
intern = Z_TIMESTAMP_OBJ_P(object);
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2);
if (!intern->initialized) {
return props;
}
s_increment_len = snprintf(s_increment, sizeof(s_increment), "%" PRIu32, intern->increment);
s_timestamp_len = snprintf(s_timestamp, sizeof(s_timestamp), "%" PRIu32, intern->timestamp);
#if PHP_VERSION_ID >= 70000
{
zval increment, timestamp;
ZVAL_STRINGL(&increment, s_increment, s_increment_len);
zend_hash_str_update(props, "increment", sizeof("increment")-1, &increment);
ZVAL_STRINGL(×tamp, s_timestamp, s_timestamp_len);
zend_hash_str_update(props, "timestamp", sizeof("timestamp")-1, ×tamp);
}
#else
{
zval *increment, *timestamp;
MAKE_STD_ZVAL(increment);
ZVAL_STRINGL(increment, s_increment, s_increment_len, 1);
zend_hash_update(props, "increment", sizeof("increment"), &increment, sizeof(increment), NULL);
MAKE_STD_ZVAL(timestamp);
ZVAL_STRINGL(timestamp, s_timestamp, s_timestamp_len, 1);
zend_hash_update(props, "timestamp", sizeof("timestamp"), ×tamp, sizeof(timestamp), NULL);
}
#endif
return props;
} /* }}} */
static HashTable *php_phongo_timestamp_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
*is_temp = 1;
return php_phongo_timestamp_get_properties_hash(object, true TSRMLS_CC);
} /* }}} */
static HashTable *php_phongo_timestamp_get_properties(zval *object TSRMLS_DC) /* {{{ */
{
return php_phongo_timestamp_get_properties_hash(object, false TSRMLS_CC);
} /* }}} */
/* }}} */
void php_phongo_timestamp_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Timestamp", php_phongo_timestamp_me);
php_phongo_timestamp_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_timestamp_ce->create_object = php_phongo_timestamp_create_object;
PHONGO_CE_FINAL(php_phongo_timestamp_ce);
zend_class_implements(php_phongo_timestamp_ce TSRMLS_CC, 1, php_phongo_timestamp_interface_ce);
zend_class_implements(php_phongo_timestamp_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
zend_class_implements(php_phongo_timestamp_ce TSRMLS_CC, 1, php_phongo_type_ce);
zend_class_implements(php_phongo_timestamp_ce TSRMLS_CC, 1, zend_ce_serializable);
memcpy(&php_phongo_handler_timestamp, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_timestamp.compare_objects = php_phongo_timestamp_compare_objects;
php_phongo_handler_timestamp.get_debug_info = php_phongo_timestamp_get_debug_info;
php_phongo_handler_timestamp.get_gc = php_phongo_timestamp_get_gc;
php_phongo_handler_timestamp.get_properties = php_phongo_timestamp_get_properties;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_timestamp.free_obj = php_phongo_timestamp_free_object;
php_phongo_handler_timestamp.offset = XtOffsetOf(php_phongo_timestamp_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/TimestampInterface.c 0000664 0001750 0001750 00000003210 13210321137 020251 0 ustar jmikola jmikola /*
* Copyright 2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_timestamp_interface_ce;
/* {{{ MongoDB\BSON\TimestampInterface function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_TimestampInterface_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_timestamp_interface_me[] = {
ZEND_ABSTRACT_ME(TimestampInterface, getIncrement, ai_TimestampInterface_void)
ZEND_ABSTRACT_ME(TimestampInterface, getTimestamp, ai_TimestampInterface_void)
ZEND_ABSTRACT_ME(TimestampInterface, __toString, ai_TimestampInterface_void)
PHP_FE_END
};
/* }}} */
void php_phongo_timestamp_interface_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "TimestampInterface", php_phongo_timestamp_interface_me);
php_phongo_timestamp_interface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/Type.c 0000664 0001750 0001750 00000002346 13210321137 015417 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_type_ce;
/* {{{ MongoDB\BSON\Type function entries */
static zend_function_entry php_phongo_type_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_type_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Type", php_phongo_type_me);
php_phongo_type_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/UTCDateTime.c 0000664 0001750 0001750 00000044515 13210321137 016552 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#include
#include
#if PHP_VERSION_ID >= 70000
# include
#else
# include
#endif
#ifdef PHP_WIN32
# include "win32/time.h"
#endif
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_utcdatetime_ce;
/* Initialize the object and return whether it was successful. */
static bool php_phongo_utcdatetime_init(php_phongo_utcdatetime_t *intern, int64_t milliseconds) /* {{{ */
{
intern->milliseconds = milliseconds;
intern->initialized = true;
return true;
} /* }}} */
/* Initialize the object from a numeric string and return whether it was
* successful. An exception will be thrown on error. */
static bool php_phongo_utcdatetime_init_from_string(php_phongo_utcdatetime_t *intern, const char *s_milliseconds, phongo_zpp_char_len s_milliseconds_len TSRMLS_DC) /* {{{ */
{
int64_t milliseconds;
char *endptr = NULL;
errno = 0;
milliseconds = bson_ascii_strtoll(s_milliseconds, &endptr, 10);
/* errno will set errno if conversion fails; however, we do not need to
* specify the type of error.
*
* Note: bson_ascii_strtoll() does not properly detect out-of-range values
* (see: CDRIVER-1377). strtoll() would be preferable, but it is not
* available on all platforms (e.g. HP-UX), and atoll() provides no error
* reporting at all. */
if (errno || (endptr && endptr != ((const char *)s_milliseconds + s_milliseconds_len))) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error parsing \"%s\" as 64-bit integer for %s initialization", s_milliseconds, ZSTR_VAL(php_phongo_utcdatetime_ce->name));
return false;
}
return php_phongo_utcdatetime_init(intern, milliseconds);
} /* }}} */
/* Initialize the object from a HashTable and return whether it was successful.
* An exception will be thrown on error. */
static bool php_phongo_utcdatetime_init_from_hash(php_phongo_utcdatetime_t *intern, HashTable *props TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval *milliseconds;
if ((milliseconds = zend_hash_str_find(props, "milliseconds", sizeof("milliseconds")-1)) && Z_TYPE_P(milliseconds) == IS_LONG) {
return php_phongo_utcdatetime_init(intern, Z_LVAL_P(milliseconds));
}
if ((milliseconds = zend_hash_str_find(props, "milliseconds", sizeof("milliseconds")-1)) && Z_TYPE_P(milliseconds) == IS_STRING) {
return php_phongo_utcdatetime_init_from_string(intern, Z_STRVAL_P(milliseconds), Z_STRLEN_P(milliseconds) TSRMLS_CC);
}
#else
zval **milliseconds;
if (zend_hash_find(props, "milliseconds", sizeof("milliseconds"), (void**) &milliseconds) == SUCCESS && Z_TYPE_PP(milliseconds) == IS_LONG) {
return php_phongo_utcdatetime_init(intern, Z_LVAL_PP(milliseconds));
}
if (zend_hash_find(props, "milliseconds", sizeof("milliseconds"), (void**) &milliseconds) == SUCCESS && Z_TYPE_PP(milliseconds) == IS_STRING) {
return php_phongo_utcdatetime_init_from_string(intern, Z_STRVAL_PP(milliseconds), Z_STRLEN_PP(milliseconds) TSRMLS_CC);
}
#endif
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"milliseconds\" integer or numeric string field", ZSTR_VAL(php_phongo_utcdatetime_ce->name));
return false;
} /* }}} */
/* Initialize the object from the current time and return whether it was
* successful. */
static bool php_phongo_utcdatetime_init_from_current_time(php_phongo_utcdatetime_t *intern) /* {{{ */
{
int64_t sec, usec;
struct timeval cur_time;
gettimeofday(&cur_time, NULL);
sec = cur_time.tv_sec;
usec = cur_time.tv_usec;
intern->milliseconds = (sec * 1000) + (usec / 1000);
intern->initialized = true;
return true;
} /* }}} */
/* Initialize the object from a DateTime object and return whether it was
* successful. */
static bool php_phongo_utcdatetime_init_from_date(php_phongo_utcdatetime_t *intern, php_date_obj *datetime_obj) /* {{{ */
{
int64_t sec, usec;
/* The following assignments use the same logic as date_format() in php_date.c */
sec = datetime_obj->time->sse;
#if PHP_VERSION_ID >= 70200
usec = (int64_t) floor(datetime_obj->time->us);
#else
usec = (int64_t) floor(datetime_obj->time->f * 1000000 + 0.5);
#endif
intern->milliseconds = (sec * 1000) + (usec / 1000);
intern->initialized = true;
return true;
} /* }}} */
/* {{{ proto void MongoDB\BSON\UTCDateTime::__construct([int|float|string|DateTimeInterface $milliseconds = null])
Construct a new BSON UTCDateTime type from either the current time,
milliseconds since the epoch, or a DateTimeInterface object. Defaults to the
current time. */
static PHP_METHOD(UTCDateTime, __construct)
{
php_phongo_utcdatetime_t *intern;
zend_error_handling error_handling;
zval *milliseconds = NULL;
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_UTCDATETIME_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!", &milliseconds) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
if (milliseconds == NULL) {
php_phongo_utcdatetime_init_from_current_time(intern);
return;
}
if (Z_TYPE_P(milliseconds) == IS_OBJECT) {
if (instanceof_function(Z_OBJCE_P(milliseconds), php_date_get_date_ce() TSRMLS_CC) ||
(php_phongo_date_immutable_ce && instanceof_function(Z_OBJCE_P(milliseconds), php_phongo_date_immutable_ce TSRMLS_CC))) {
php_phongo_utcdatetime_init_from_date(intern, Z_PHPDATE_P(milliseconds));
} else {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected instance of DateTimeInterface, %s given", ZSTR_VAL(Z_OBJCE_P(milliseconds)->name));
}
return;
}
if (Z_TYPE_P(milliseconds) == IS_LONG) {
php_phongo_utcdatetime_init(intern, Z_LVAL_P(milliseconds));
return;
}
if (Z_TYPE_P(milliseconds) == IS_DOUBLE) {
char tmp[24];
int tmp_len;
tmp_len = snprintf(tmp, sizeof(tmp), "%.0f", Z_DVAL_P(milliseconds) > 0 ? floor(Z_DVAL_P(milliseconds)) : ceil(Z_DVAL_P(milliseconds)));
php_phongo_utcdatetime_init_from_string(intern, tmp, tmp_len TSRMLS_CC);
return;
}
if (Z_TYPE_P(milliseconds) != IS_STRING) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected integer or string, %s given", zend_get_type_by_const(Z_TYPE_P(milliseconds)));
return;
}
php_phongo_utcdatetime_init_from_string(intern, Z_STRVAL_P(milliseconds), Z_STRLEN_P(milliseconds) TSRMLS_CC);
} /* }}} */
/* {{{ proto void MongoDB\BSON\UTCDateTime::__set_state(array $properties)
*/
static PHP_METHOD(UTCDateTime, __set_state)
{
php_phongo_utcdatetime_t *intern;
HashTable *props;
zval *array;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
RETURN_FALSE;
}
object_init_ex(return_value, php_phongo_utcdatetime_ce);
intern = Z_UTCDATETIME_OBJ_P(return_value);
props = Z_ARRVAL_P(array);
php_phongo_utcdatetime_init_from_hash(intern, props TSRMLS_CC);
} /* }}} */
/* {{{ proto string MongoDB\BSON\UTCDateTime::__toString()
Returns the UTCDateTime's milliseconds as a string */
static PHP_METHOD(UTCDateTime, __toString)
{
php_phongo_utcdatetime_t *intern;
char *tmp;
int tmp_len;
intern = Z_UTCDATETIME_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
tmp_len = spprintf(&tmp, 0, "%" PRId64, intern->milliseconds);
PHONGO_RETVAL_STRINGL(tmp, tmp_len);
efree(tmp);
} /* }}} */
/* {{{ proto DateTime MongoDB\BSON\UTCDateTime::toDateTime()
Returns a DateTime object representing this UTCDateTime */
static PHP_METHOD(UTCDateTime, toDateTime)
{
php_phongo_utcdatetime_t *intern;
php_date_obj *datetime_obj;
char *sec;
size_t sec_len;
intern = Z_UTCDATETIME_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
object_init_ex(return_value, php_date_get_date_ce());
datetime_obj = Z_PHPDATE_P(return_value);
sec_len = spprintf(&sec, 0, "@%" PRId64, intern->milliseconds / 1000);
php_date_initialize(datetime_obj, sec, sec_len, NULL, NULL, 0 TSRMLS_CC);
efree(sec);
#if PHP_VERSION_ID >= 70200
datetime_obj->time->us = (intern->milliseconds % 1000) * 1000;
#else
datetime_obj->time->f = (double) (intern->milliseconds % 1000) / 1000;
#endif
}
/* }}} */
/* {{{ proto array MongoDB\BSON\UTCDateTime::jsonSerialize()
*/
static PHP_METHOD(UTCDateTime, jsonSerialize)
{
php_phongo_utcdatetime_t *intern;
char s_milliseconds[24];
int s_milliseconds_len;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_UTCDATETIME_OBJ_P(getThis());
s_milliseconds_len = snprintf(s_milliseconds, sizeof(s_milliseconds), "%" PRId64, intern->milliseconds);
array_init_size(return_value, 1);
#if PHP_VERSION_ID >= 70000
{
zval udt;
array_init_size(&udt, 1);
ADD_ASSOC_STRINGL(&udt, "$numberLong", s_milliseconds, s_milliseconds_len);
ADD_ASSOC_ZVAL_EX(return_value, "$date", &udt);
}
#else
{
zval *udt;
MAKE_STD_ZVAL(udt);
array_init_size(udt, 1);
ADD_ASSOC_STRINGL(udt, "$numberLong", s_milliseconds, s_milliseconds_len);
ADD_ASSOC_ZVAL_EX(return_value, "$date", udt);
}
#endif
} /* }}} */
/* {{{ proto string MongoDB\BSON\UTCDateTime::serialize()
*/
static PHP_METHOD(UTCDateTime, serialize)
{
php_phongo_utcdatetime_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval *retval;
#endif
php_serialize_data_t var_hash;
smart_str buf = { 0 };
char s_milliseconds[24];
int s_milliseconds_len;
intern = Z_UTCDATETIME_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
s_milliseconds_len = snprintf(s_milliseconds, sizeof(s_milliseconds), "%" PRId64, intern->milliseconds);
#if PHP_VERSION_ID >= 70000
array_init_size(&retval, 2);
ADD_ASSOC_STRINGL(&retval, "milliseconds", s_milliseconds, s_milliseconds_len);
#else
ALLOC_INIT_ZVAL(retval);
array_init_size(retval, 2);
ADD_ASSOC_STRINGL(retval, "milliseconds", s_milliseconds, s_milliseconds_len);
#endif
PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&buf, &retval, &var_hash TSRMLS_CC);
smart_str_0(&buf);
PHP_VAR_SERIALIZE_DESTROY(var_hash);
PHONGO_RETVAL_SMART_STR(buf);
smart_str_free(&buf);
zval_ptr_dtor(&retval);
} /* }}} */
/* {{{ proto void MongoDB\BSON\UTCDateTime::unserialize(string $serialized)
*/
static PHP_METHOD(UTCDateTime, unserialize)
{
php_phongo_utcdatetime_t *intern;
zend_error_handling error_handling;
char *serialized;
phongo_zpp_char_len serialized_len;
#if PHP_VERSION_ID >= 70000
zval props;
#else
zval *props;
#endif
php_unserialize_data_t var_hash;
intern = Z_UTCDATETIME_OBJ_P(getThis());
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &serialized_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
#if PHP_VERSION_ID < 70000
ALLOC_INIT_ZVAL(props);
#endif
PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char *) serialized + serialized_len, &var_hash TSRMLS_CC)) {
zval_ptr_dtor(&props);
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "%s unserialization failed", ZSTR_VAL(php_phongo_utcdatetime_ce->name));
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
#if PHP_VERSION_ID >= 70000
php_phongo_utcdatetime_init_from_hash(intern, HASH_OF(&props) TSRMLS_CC);
#else
php_phongo_utcdatetime_init_from_hash(intern, HASH_OF(props) TSRMLS_CC);
#endif
zval_ptr_dtor(&props);
} /* }}} */
/* {{{ MongoDB\BSON\UTCDateTime function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_UTCDateTime___construct, 0, 0, 0)
ZEND_ARG_INFO(0, milliseconds)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_UTCDateTime___set_state, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, properties, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_UTCDateTime_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_UTCDateTime_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_utcdatetime_me[] = {
PHP_ME(UTCDateTime, __construct, ai_UTCDateTime___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(UTCDateTime, __set_state, ai_UTCDateTime___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(UTCDateTime, __toString, ai_UTCDateTime_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(UTCDateTime, jsonSerialize, ai_UTCDateTime_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(UTCDateTime, serialize, ai_UTCDateTime_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(UTCDateTime, unserialize, ai_UTCDateTime_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(UTCDateTime, toDateTime, ai_UTCDateTime_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\BSON\UTCDateTime object handlers */
static zend_object_handlers php_phongo_handler_utcdatetime;
static void php_phongo_utcdatetime_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_utcdatetime_t *intern = Z_OBJ_UTCDATETIME(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->properties) {
zend_hash_destroy(intern->properties);
FREE_HASHTABLE(intern->properties);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_utcdatetime_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_utcdatetime_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_utcdatetime_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_utcdatetime;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_utcdatetime_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_utcdatetime;
return retval;
}
#endif
} /* }}} */
static int php_phongo_utcdatetime_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
{
php_phongo_utcdatetime_t *intern1, *intern2;
intern1 = Z_UTCDATETIME_OBJ_P(o1);
intern2 = Z_UTCDATETIME_OBJ_P(o2);
if (intern1->milliseconds != intern2->milliseconds) {
return intern1->milliseconds < intern2->milliseconds ? -1 : 1;
}
return 0;
} /* }}} */
static HashTable *php_phongo_utcdatetime_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
{
*table = NULL;
*n = 0;
return Z_UTCDATETIME_OBJ_P(object)->properties;
} /* }}} */
static HashTable *php_phongo_utcdatetime_get_properties_hash(zval *object, bool is_debug TSRMLS_DC) /* {{{ */
{
php_phongo_utcdatetime_t *intern;
HashTable *props;
char s_milliseconds[24];
int s_milliseconds_len;
intern = Z_UTCDATETIME_OBJ_P(object);
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2);
if (!intern->initialized) {
return props;
}
s_milliseconds_len = snprintf(s_milliseconds, sizeof(s_milliseconds), "%" PRId64, intern->milliseconds);
#if PHP_VERSION_ID >= 70000
{
zval milliseconds;
ZVAL_STRINGL(&milliseconds, s_milliseconds, s_milliseconds_len);
zend_hash_str_update(props, "milliseconds", sizeof("milliseconds")-1, &milliseconds);
}
#else
{
zval *milliseconds;
MAKE_STD_ZVAL(milliseconds);
ZVAL_STRINGL(milliseconds, s_milliseconds, s_milliseconds_len, 1);
zend_hash_update(props, "milliseconds", sizeof("milliseconds"), &milliseconds, sizeof(milliseconds), NULL);
}
#endif
return props;
} /* }}} */
static HashTable *php_phongo_utcdatetime_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
*is_temp = 1;
return php_phongo_utcdatetime_get_properties_hash(object, true TSRMLS_CC);
} /* }}} */
static HashTable *php_phongo_utcdatetime_get_properties(zval *object TSRMLS_DC) /* {{{ */
{
return php_phongo_utcdatetime_get_properties_hash(object, false TSRMLS_CC);
} /* }}} */
/* }}} */
void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "UTCDateTime", php_phongo_utcdatetime_me);
php_phongo_utcdatetime_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_utcdatetime_ce->create_object = php_phongo_utcdatetime_create_object;
PHONGO_CE_FINAL(php_phongo_utcdatetime_ce);
zend_class_implements(php_phongo_utcdatetime_ce TSRMLS_CC, 1, php_phongo_utcdatetime_interface_ce);
zend_class_implements(php_phongo_utcdatetime_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
zend_class_implements(php_phongo_utcdatetime_ce TSRMLS_CC, 1, php_phongo_type_ce);
zend_class_implements(php_phongo_utcdatetime_ce TSRMLS_CC, 1, zend_ce_serializable);
memcpy(&php_phongo_handler_utcdatetime, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_utcdatetime.compare_objects = php_phongo_utcdatetime_compare_objects;
php_phongo_handler_utcdatetime.get_debug_info = php_phongo_utcdatetime_get_debug_info;
php_phongo_handler_utcdatetime.get_gc = php_phongo_utcdatetime_get_gc;
php_phongo_handler_utcdatetime.get_properties = php_phongo_utcdatetime_get_properties;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_utcdatetime.free_obj = php_phongo_utcdatetime_free_object;
php_phongo_handler_utcdatetime.offset = XtOffsetOf(php_phongo_utcdatetime_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/UTCDateTimeInterface.c 0000664 0001750 0001750 00000003116 13210321137 020363 0 ustar jmikola jmikola /*
* Copyright 2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_utcdatetime_interface_ce;
/* {{{ MongoDB\BSON\UTCDateTimeInterface function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_UTCDateTimeInterface_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_utcdatetime_interface_me[] = {
ZEND_ABSTRACT_ME(UTCDateTimeInterface, toDateTime, ai_UTCDateTimeInterface_void)
ZEND_ABSTRACT_ME(UTCDateTimeInterface, __toString, ai_UTCDateTimeInterface_void)
PHP_FE_END
};
/* }}} */
void php_phongo_utcdatetime_interface_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "UTCDateTimeInterface", php_phongo_utcdatetime_interface_me);
php_phongo_utcdatetime_interface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/Unserializable.c 0000664 0001750 0001750 00000002773 13210321137 017453 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_unserializable_ce;
/* {{{ MongoDB\BSON\Unserializable function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Unserializable_bsonUnserialize, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, data, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_unserializable_me[] = {
ZEND_ABSTRACT_ME(Unserializable, bsonUnserialize, ai_Unserializable_bsonUnserialize)
PHP_FE_END
};
/* }}} */
void php_phongo_unserializable_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Unserializable", php_phongo_unserializable_me);
php_phongo_unserializable_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/functions.c 0000664 0001750 0001750 00000013457 13210321137 016513 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
#include "php_bson.h"
typedef enum {
PHONGO_JSON_MODE_LEGACY,
PHONGO_JSON_MODE_CANONICAL,
PHONGO_JSON_MODE_RELAXED,
} php_phongo_json_mode_t;
/* {{{ proto string MongoDB\BSON\fromPHP(array|object $value)
Returns the BSON representation of a PHP value */
PHP_FUNCTION(MongoDB_BSON_fromPHP)
{
zval *data;
bson_t *bson;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(this_ptr) SUPPRESS_UNUSED_WARNING(return_value_used) /* We don't use these */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "A", &data) == FAILURE) {
return;
}
bson = bson_new();
php_phongo_zval_to_bson(data, PHONGO_BSON_NONE, bson, NULL TSRMLS_CC);
PHONGO_RETVAL_STRINGL((const char *) bson_get_data(bson), bson->len);
bson_destroy(bson);
} /* }}} */
/* {{{ proto array|object MongoDB\BSON\toPHP(string $bson [, array $typemap = array()])
Returns the PHP representation of a BSON value, optionally converting it into a custom class */
PHP_FUNCTION(MongoDB_BSON_toPHP)
{
char *data;
phongo_zpp_char_len data_len;
zval *typemap = NULL;
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(this_ptr) SUPPRESS_UNUSED_WARNING(return_value_used) /* We don't use these */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a!", &data, &data_len, &typemap) == FAILURE) {
return;
}
if (!php_phongo_bson_typemap_to_state(typemap, &state.map TSRMLS_CC)) {
return;
}
if (!php_phongo_bson_to_zval_ex((const unsigned char *)data, data_len, &state)) {
zval_ptr_dtor(&state.zchild);
RETURN_NULL();
}
#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
RETURN_ZVAL(state.zchild, 0, 1);
#endif
} /* }}} */
/* {{{ proto string MongoDB\BSON\fromJSON(string $json)
Returns the BSON representation of a JSON value */
PHP_FUNCTION(MongoDB_BSON_fromJSON)
{
char *json;
phongo_zpp_char_len json_len;
bson_t bson = BSON_INITIALIZER;
bson_error_t error;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(this_ptr) SUPPRESS_UNUSED_WARNING(return_value_used) /* We don't use these */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &json, &json_len) == FAILURE) {
return;
}
if (bson_init_from_json(&bson, (const char *)json, json_len, &error)) {
PHONGO_RETVAL_STRINGL((const char *) bson_get_data(&bson), bson.len);
bson_destroy(&bson);
} else {
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "%s", error.domain == BSON_ERROR_JSON ? error.message : "Error parsing JSON");
}
} /* }}} */
static void phongo_bson_to_json(INTERNAL_FUNCTION_PARAMETERS, php_phongo_json_mode_t mode)
{
char *data;
phongo_zpp_char_len data_len;
const bson_t *bson;
bool eof = false;
bson_reader_t *reader;
char *json = NULL;
size_t json_len;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(this_ptr) SUPPRESS_UNUSED_WARNING(return_value_used) /* We don't use these */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) == FAILURE) {
return;
}
reader = bson_reader_new_from_data((const unsigned char *)data, data_len);
bson = bson_reader_read(reader, NULL);
if (!bson) {
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Could not read document from BSON reader");
bson_reader_destroy(reader);
return;
}
if (mode == PHONGO_JSON_MODE_LEGACY) {
json = bson_as_json(bson, &json_len);
} else if (mode == PHONGO_JSON_MODE_CANONICAL) {
json = bson_as_canonical_extended_json(bson, &json_len);
} else if (mode == PHONGO_JSON_MODE_RELAXED) {
json = bson_as_relaxed_extended_json(bson, &json_len);
}
if (!json) {
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Could not convert BSON document to a JSON string");
bson_reader_destroy(reader);
return;
}
PHONGO_RETVAL_STRINGL(json, json_len);
bson_free(json);
if (bson_reader_read(reader, &eof) || !eof) {
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Reading document did not exhaust input buffer");
}
bson_reader_destroy(reader);
} /* }}} */
/* {{{ proto string MongoDB\BSON\toJSON(string $bson)
Returns the legacy extended JSON representation of a BSON value */
PHP_FUNCTION(MongoDB_BSON_toJSON)
{
phongo_bson_to_json(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHONGO_JSON_MODE_LEGACY);
} /* }}} */
/* {{{ proto string MongoDB\BSON\toCanonicalExtendedJSON(string $bson)
Returns the canonical extended JSON representation of a BSON value */
PHP_FUNCTION(MongoDB_BSON_toCanonicalExtendedJSON)
{
phongo_bson_to_json(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHONGO_JSON_MODE_CANONICAL);
} /* }}} */
/* {{{ proto string MongoDB\BSON\toRelaxedExtendedJSON(string $bson)
Returns the relaxed extended JSON representation of a BSON value */
PHP_FUNCTION(MongoDB_BSON_toRelaxedExtendedJSON)
{
phongo_bson_to_json(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHONGO_JSON_MODE_RELAXED);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/BSON/functions.h 0000664 0001750 0001750 00000002121 13210321137 016502 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PHONGO_BSON_FUNCTIONS_H
#define PHONGO_BSON_FUNCTIONS_H
#include
PHP_FUNCTION(MongoDB_BSON_fromPHP);
PHP_FUNCTION(MongoDB_BSON_toPHP);
PHP_FUNCTION(MongoDB_BSON_fromJSON);
PHP_FUNCTION(MongoDB_BSON_toJSON);
PHP_FUNCTION(MongoDB_BSON_toCanonicalExtendedJSON);
PHP_FUNCTION(MongoDB_BSON_toRelaxedExtendedJSON);
#endif /* PHONGO_BSON_FUNCTIONS_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/AuthenticationException.c 0000664 0001750 0001750 00000003107 13210321137 024012 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_authenticationexception_ce;
/* {{{ MongoDB\Driver\Exception\AuthenticationException function entries */
static zend_function_entry php_phongo_authenticationexception_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_authenticationexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "AuthenticationException", php_phongo_authenticationexception_me);
#if PHP_VERSION_ID >= 70000
php_phongo_authenticationexception_ce = zend_register_internal_class_ex(&ce, php_phongo_connectionexception_ce);
#else
php_phongo_authenticationexception_ce = zend_register_internal_class_ex(&ce, php_phongo_connectionexception_ce, NULL TSRMLS_CC);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/BulkWriteException.c 0000664 0001750 0001750 00000003025 13210321137 022742 0 ustar jmikola jmikola /*
* Copyright 2015-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_bulkwriteexception_ce;
/* {{{ MongoDB\Driver\Exception\BulkWriteException function entries */
static zend_function_entry php_phongo_bulkwriteexception_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_bulkwriteexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "BulkWriteException", php_phongo_bulkwriteexception_me);
#if PHP_VERSION_ID >= 70000
php_phongo_bulkwriteexception_ce = zend_register_internal_class_ex(&ce, php_phongo_writeexception_ce);
#else
php_phongo_bulkwriteexception_ce = zend_register_internal_class_ex(&ce, php_phongo_writeexception_ce, NULL TSRMLS_CC);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/ConnectionException.c 0000664 0001750 0001750 00000003041 13210321137 023127 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_connectionexception_ce;
/* {{{ MongoDB\Driver\Exception\ConnectionException function entries */
static zend_function_entry php_phongo_connectionexception_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_connectionexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "ConnectionException", php_phongo_connectionexception_me);
#if PHP_VERSION_ID >= 70000
php_phongo_connectionexception_ce = zend_register_internal_class_ex(&ce, php_phongo_runtimeexception_ce);
#else
php_phongo_connectionexception_ce = zend_register_internal_class_ex(&ce, php_phongo_runtimeexception_ce, NULL TSRMLS_CC);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/ConnectionTimeoutException.c 0000664 0001750 0001750 00000003233 13210321137 024501 0 ustar jmikola jmikola /*
* Copyright 2015-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_connectiontimeoutexception_ce;
/* {{{ MongoDB\Driver\Exception\ConnectionTimeoutException function entries */
static zend_function_entry php_phongo_connectiontimeoutexception_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_connectiontimeoutexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "ConnectionTimeoutException", php_phongo_connectiontimeoutexception_me);
#if PHP_VERSION_ID >= 70000
php_phongo_connectiontimeoutexception_ce = zend_register_internal_class_ex(&ce, php_phongo_connectionexception_ce);
#else
php_phongo_connectiontimeoutexception_ce = zend_register_internal_class_ex(&ce, php_phongo_connectionexception_ce, NULL TSRMLS_CC);
#endif
PHONGO_CE_FINAL(php_phongo_connectiontimeoutexception_ce);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/Exception.c 0000664 0001750 0001750 00000002442 13210321137 021113 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_exception_ce;
/* {{{ MongoDB\Driver\Exception\Exception function entries */
static zend_function_entry php_phongo_exception_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_exception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "Exception", php_phongo_exception_me);
php_phongo_exception_ce = zend_register_internal_interface(&ce TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/ExecutionTimeoutException.c 0000664 0001750 0001750 00000003214 13210321137 024344 0 ustar jmikola jmikola /*
* Copyright 2015-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_executiontimeoutexception_ce;
/* {{{ MongoDB\Driver\Exception\ExecutionTimeoutException function entries */
static zend_function_entry php_phongo_executiontimeoutexception_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_executiontimeoutexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "ExecutionTimeoutException", php_phongo_executiontimeoutexception_me);
#if PHP_VERSION_ID >= 70000
php_phongo_executiontimeoutexception_ce = zend_register_internal_class_ex(&ce, php_phongo_runtimeexception_ce);
#else
php_phongo_executiontimeoutexception_ce = zend_register_internal_class_ex(&ce, php_phongo_runtimeexception_ce, NULL TSRMLS_CC);
#endif
PHONGO_CE_FINAL(php_phongo_executiontimeoutexception_ce);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/InvalidArgumentException.c 0000664 0001750 0001750 00000003325 13210321137 024126 0 ustar jmikola jmikola /*
* Copyright 2015-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_invalidargumentexception_ce;
/* {{{ MongoDB\Driver\Exception\InvalidArgumentException function entries */
static zend_function_entry php_phongo_invalidargumentexception_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_invalidargumentexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "InvalidArgumentException", php_phongo_invalidargumentexception_me);
#if PHP_VERSION_ID >= 70000
php_phongo_invalidargumentexception_ce = zend_register_internal_class_ex(&ce, spl_ce_InvalidArgumentException);
#else
php_phongo_invalidargumentexception_ce = zend_register_internal_class_ex(&ce, spl_ce_InvalidArgumentException, NULL TSRMLS_CC);
#endif
zend_class_implements(php_phongo_invalidargumentexception_ce TSRMLS_CC, 1, php_phongo_exception_ce);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/LogicException.c 0000664 0001750 0001750 00000003147 13210321137 022074 0 ustar jmikola jmikola /*
* Copyright 2015-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_logicexception_ce;
/* {{{ MongoDB\Driver\Exception\LogicException function entries */
static zend_function_entry php_phongo_logicexception_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_logicexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "LogicException", php_phongo_logicexception_me);
#if PHP_VERSION_ID >= 70000
php_phongo_logicexception_ce = zend_register_internal_class_ex(&ce, spl_ce_LogicException);
#else
php_phongo_logicexception_ce = zend_register_internal_class_ex(&ce, spl_ce_LogicException, NULL TSRMLS_CC);
#endif
zend_class_implements(php_phongo_logicexception_ce TSRMLS_CC, 1, php_phongo_exception_ce);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/RuntimeException.c 0000664 0001750 0001750 00000003175 13210321137 022463 0 ustar jmikola jmikola /*
* Copyright 2015-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_runtimeexception_ce;
/* {{{ MongoDB\Driver\Exception\RuntimeException function entries */
static zend_function_entry php_phongo_runtimeexception_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_runtimeexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "RuntimeException", php_phongo_runtimeexception_me);
#if PHP_VERSION_ID >= 70000
php_phongo_runtimeexception_ce = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException);
#else
php_phongo_runtimeexception_ce = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, NULL TSRMLS_CC);
#endif
zend_class_implements(php_phongo_runtimeexception_ce TSRMLS_CC, 1, php_phongo_exception_ce);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/SSLConnectionException.c 0000664 0001750 0001750 00000003167 13210321137 023522 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_sslconnectionexception_ce;
/* {{{ MongoDB\Driver\Exception\SSLConnectionException function entries */
static zend_function_entry php_phongo_sslconnectionexception_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_sslconnectionexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "SSLConnectionException", php_phongo_sslconnectionexception_me);
#if PHP_VERSION_ID >= 70000
php_phongo_sslconnectionexception_ce = zend_register_internal_class_ex(&ce, php_phongo_connectionexception_ce);
#else
php_phongo_sslconnectionexception_ce = zend_register_internal_class_ex(&ce, php_phongo_connectionexception_ce, NULL TSRMLS_CC);
#endif
PHONGO_CE_FINAL(php_phongo_sslconnectionexception_ce);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/UnexpectedValueException.c 0000664 0001750 0001750 00000003325 13210321137 024136 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_unexpectedvalueexception_ce;
/* {{{ MongoDB\Driver\Exception\UnexpectedValueException function entries */
static zend_function_entry php_phongo_unexpectedvalueexception_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_unexpectedvalueexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "UnexpectedValueException", php_phongo_unexpectedvalueexception_me);
#if PHP_VERSION_ID >= 70000
php_phongo_unexpectedvalueexception_ce = zend_register_internal_class_ex(&ce, spl_ce_UnexpectedValueException);
#else
php_phongo_unexpectedvalueexception_ce = zend_register_internal_class_ex(&ce, spl_ce_UnexpectedValueException, NULL TSRMLS_CC);
#endif
zend_class_implements(php_phongo_unexpectedvalueexception_ce TSRMLS_CC, 1, php_phongo_exception_ce);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Exception/WriteException.c 0000664 0001750 0001750 00000005000 13210321137 022117 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_writeexception_ce;
/* {{{ proto MongoDB\Driver\WriteResult MongoDB\Driver\Exception\WriteException::getWriteResult()
Returns the WriteResult from the failed write operation. */
static PHP_METHOD(WriteException, getWriteResult)
{
zval *writeresult;
#if PHP_VERSION_ID >= 70000
zval rv;
#endif
if (zend_parse_parameters_none() == FAILURE) {
return;
}
#if PHP_VERSION_ID >= 70000
writeresult = zend_read_property(php_phongo_writeexception_ce, getThis(), ZEND_STRL("writeResult"), 0, &rv TSRMLS_CC);
#else
writeresult = zend_read_property(php_phongo_writeexception_ce, getThis(), ZEND_STRL("writeResult"), 0 TSRMLS_CC);
#endif
RETURN_ZVAL(writeresult, 1, 0);
} /* }}} */
/* {{{ MongoDB\Driver\Exception\WriteException function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_WriteException_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_writeexception_me[] = {
PHP_ME(WriteException, getWriteResult, ai_WriteException_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
void php_phongo_writeexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "WriteException", php_phongo_writeexception_me);
#if PHP_VERSION_ID >= 70000
php_phongo_writeexception_ce = zend_register_internal_class_ex(&ce, php_phongo_runtimeexception_ce);
#else
php_phongo_writeexception_ce = zend_register_internal_class_ex(&ce, php_phongo_runtimeexception_ce, NULL TSRMLS_CC);
#endif
php_phongo_writeexception_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
zend_declare_property_null(php_phongo_writeexception_ce, ZEND_STRL("writeResult"), ZEND_ACC_PROTECTED TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Monitoring/CommandFailedEvent.c 0000664 0001750 0001750 00000021360 13210321137 023031 0 ustar jmikola jmikola /*
* Copyright 2016-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_commandfailedevent_ce;
/* {{{ proto string CommandFailedEvent::getCommandName()
Returns the command name for this event */
PHP_METHOD(CommandFailedEvent, getCommandName)
{
php_phongo_commandfailedevent_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_RETVAL_STRING(intern->command_name);
} /* }}} */
/* {{{ proto int CommandFailedEvent::getDurationMicros()
Returns the event's duration in microseconds */
PHP_METHOD(CommandFailedEvent, getDurationMicros)
{
php_phongo_commandfailedevent_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(intern->duration_micros);
} /* }}} */
/* {{{ proto Exception CommandFailedEvent::getError()
Returns the error document associated with the event */
PHP_METHOD(CommandFailedEvent, getError)
{
php_phongo_commandfailedevent_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&intern->z_error, 1, 0);
#else
RETURN_ZVAL(intern->z_error, 1, 0);
#endif
} /* }}} */
/* {{{ proto string CommandFailedEvent::getOperationId()
Returns the event's operation ID */
PHP_METHOD(CommandFailedEvent, getOperationId)
{
php_phongo_commandfailedevent_t *intern;
char int_as_string[20];
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
sprintf(int_as_string, "%" PHONGO_LONG_FORMAT, intern->operation_id);
PHONGO_RETVAL_STRING(int_as_string);
} /* }}} */
/* {{{ proto string CommandFailedEvent::getRequestId()
Returns the event's request ID */
PHP_METHOD(CommandFailedEvent, getRequestId)
{
php_phongo_commandfailedevent_t *intern;
char int_as_string[20];
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
sprintf(int_as_string, "%" PHONGO_LONG_FORMAT, intern->request_id);
PHONGO_RETVAL_STRING(int_as_string);
} /* }}} */
/* {{{ proto MongoDB\Driver\Server CommandFailedEvent::getServer()
Returns the Server from which the event originated */
PHP_METHOD(CommandFailedEvent, getServer)
{
php_phongo_commandfailedevent_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
phongo_server_init(return_value, intern->client, intern->server_id TSRMLS_CC);
} /* }}} */
/**
* Event thrown when a command has failed to execute.
*
* This class is only constructed internally.
*/
/* {{{ MongoDB\Driver\Monitoring\CommandFailedEvent function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_CommandFailedEvent_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_commandfailedevent_me[] = {
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_CommandFailedEvent_void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
PHP_ME(CommandFailedEvent, getCommandName, ai_CommandFailedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandFailedEvent, getError, ai_CommandFailedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandFailedEvent, getDurationMicros, ai_CommandFailedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandFailedEvent, getOperationId, ai_CommandFailedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandFailedEvent, getRequestId, ai_CommandFailedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandFailedEvent, getServer, ai_CommandFailedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_CommandFailedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\Monitoring\CommandFailedEvent object handlers */
static zend_object_handlers php_phongo_handler_commandfailedevent;
static void php_phongo_commandfailedevent_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_commandfailedevent_t *intern = Z_OBJ_COMMANDFAILEDEVENT(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (!Z_ISUNDEF(intern->z_error)) {
zval_ptr_dtor(&intern->z_error);
}
if (intern->command_name) {
efree(intern->command_name);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_commandfailedevent_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_commandfailedevent_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_commandfailedevent_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_commandfailedevent;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_commandfailedevent_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_commandfailedevent;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_commandfailedevent_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_commandfailedevent_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
char operation_id[20], request_id[20];
intern = Z_COMMANDFAILEDEVENT_OBJ_P(object);
*is_temp = 1;
array_init_size(&retval, 6);
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "error", &intern->z_error);
Z_ADDREF(intern->z_error);
#else
ADD_ASSOC_ZVAL_EX(&retval, "error", intern->z_error);
Z_ADDREF_P(intern->z_error);
#endif
sprintf(operation_id, "%" PHONGO_LONG_FORMAT, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
sprintf(request_id, "%" PHONGO_LONG_FORMAT, intern->request_id);
ADD_ASSOC_STRING(&retval, "requestId", request_id);
{
#if PHP_VERSION_ID >= 70000
zval server;
phongo_server_init(&server, intern->client, intern->server_id TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "server", &server);
#else
zval *server = NULL;
MAKE_STD_ZVAL(server);
phongo_server_init(server, intern->client, intern->server_id TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "server", server);
#endif
}
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_commandfailedevent_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
(void)type;(void)module_number;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Monitoring", "CommandFailedEvent", php_phongo_commandfailedevent_me);
php_phongo_commandfailedevent_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_commandfailedevent_ce->create_object = php_phongo_commandfailedevent_create_object;
PHONGO_CE_FINAL(php_phongo_commandfailedevent_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_commandfailedevent_ce);
memcpy(&php_phongo_handler_commandfailedevent, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_commandfailedevent.get_debug_info = php_phongo_commandfailedevent_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_commandfailedevent.free_obj = php_phongo_commandfailedevent_free_object;
php_phongo_handler_commandfailedevent.offset = XtOffsetOf(php_phongo_commandfailedevent_t, std);
#endif
return;
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Monitoring/CommandStartedEvent.c 0000664 0001750 0001750 00000022170 13210321137 023253 0 ustar jmikola jmikola /*
* Copyright 2016-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_commandstartedevent_ce;
/* {{{ proto stdClass CommandStartedEvent::getCommand()
Returns the command document associated with the event */
PHP_METHOD(CommandStartedEvent, getCommand)
{
php_phongo_commandstartedevent_t *intern;
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &state);
#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
RETURN_ZVAL(state.zchild, 0, 1);
#endif
} /* }}} */
/* {{{ proto string CommandStartedEvent::getCommandName()
Returns the command name for this event */
PHP_METHOD(CommandStartedEvent, getCommandName)
{
php_phongo_commandstartedevent_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_RETVAL_STRING(intern->command_name);
} /* }}} */
/* {{{ proto string CommandStartedEvent::getDatabaseName()
Returns the database name for this event */
PHP_METHOD(CommandStartedEvent, getDatabaseName)
{
php_phongo_commandstartedevent_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_RETVAL_STRING(intern->database_name);
} /* }}} */
/* {{{ proto string CommandStartedEvent::getOperationId()
Returns the event's operation ID */
PHP_METHOD(CommandStartedEvent, getOperationId)
{
php_phongo_commandstartedevent_t *intern;
char int_as_string[20];
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
sprintf(int_as_string, "%" PHONGO_LONG_FORMAT, intern->operation_id);
PHONGO_RETVAL_STRING(int_as_string);
} /* }}} */
/* {{{ proto string CommandStartedEvent::getRequestId()
Returns the event's request ID */
PHP_METHOD(CommandStartedEvent, getRequestId)
{
php_phongo_commandstartedevent_t *intern;
char int_as_string[20];
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
sprintf(int_as_string, "%" PHONGO_LONG_FORMAT, intern->request_id);
PHONGO_RETVAL_STRING(int_as_string);
} /* }}} */
/* {{{ proto MongoDB\Driver\Server CommandStartedEvent::getServer()
Returns the Server from which the event originated */
PHP_METHOD(CommandStartedEvent, getServer)
{
php_phongo_commandstartedevent_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
phongo_server_init(return_value, intern->client, intern->server_id TSRMLS_CC);
} /* }}} */
/**
* Event thrown when a command has started to execute.
*
* This class is only constructed internally.
*/
/* {{{ MongoDB\Driver\Monitoring\CommandStartedEvent function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_CommandStartedEvent_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_commandstartedevent_me[] = {
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_CommandStartedEvent_void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
PHP_ME(CommandStartedEvent, getCommand, ai_CommandStartedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandStartedEvent, getCommandName, ai_CommandStartedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandStartedEvent, getDatabaseName, ai_CommandStartedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandStartedEvent, getOperationId, ai_CommandStartedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandStartedEvent, getRequestId, ai_CommandStartedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandStartedEvent, getServer, ai_CommandStartedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_CommandStartedEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\Monitoring\CommandStartedEvent object handlers */
static zend_object_handlers php_phongo_handler_commandstartedevent;
static void php_phongo_commandstartedevent_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_commandstartedevent_t *intern = Z_OBJ_COMMANDSTARTEDEVENT(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->command) {
bson_destroy(intern->command);
}
if (intern->command_name) {
efree(intern->command_name);
}
if (intern->database_name) {
efree(intern->database_name);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_commandstartedevent_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_commandstartedevent_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_commandstartedevent_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_commandstartedevent;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_commandstartedevent_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_commandstartedevent;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_commandstartedevent_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_commandstartedevent_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
char operation_id[20], request_id[20];
php_phongo_bson_state command_state = PHONGO_BSON_STATE_INITIALIZER;
intern = Z_COMMANDSTARTEDEVENT_OBJ_P(object);
*is_temp = 1;
array_init_size(&retval, 6);
php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &command_state);
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL(&retval, "command", &command_state.zchild);
#else
ADD_ASSOC_ZVAL(&retval, "command", command_state.zchild);
#endif
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
ADD_ASSOC_STRING(&retval, "databaseName", intern->database_name);
sprintf(operation_id, "%" PHONGO_LONG_FORMAT, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
sprintf(request_id, "%" PHONGO_LONG_FORMAT, intern->request_id);
ADD_ASSOC_STRING(&retval, "requestId", request_id);
{
#if PHP_VERSION_ID >= 70000
zval server;
phongo_server_init(&server, intern->client, intern->server_id TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "server", &server);
#else
zval *server = NULL;
MAKE_STD_ZVAL(server);
phongo_server_init(server, intern->client, intern->server_id TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "server", server);
#endif
}
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_commandstartedevent_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
(void)type;(void)module_number;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Monitoring", "CommandStartedEvent", php_phongo_commandstartedevent_me);
php_phongo_commandstartedevent_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_commandstartedevent_ce->create_object = php_phongo_commandstartedevent_create_object;
PHONGO_CE_FINAL(php_phongo_commandstartedevent_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_commandstartedevent_ce);
memcpy(&php_phongo_handler_commandstartedevent, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_commandstartedevent.get_debug_info = php_phongo_commandstartedevent_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_commandstartedevent.free_obj = php_phongo_commandstartedevent_free_object;
php_phongo_handler_commandstartedevent.offset = XtOffsetOf(php_phongo_commandstartedevent_t, std);
#endif
return;
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Monitoring/CommandSubscriber.c 0000664 0001750 0001750 00000004437 13210321137 022754 0 ustar jmikola jmikola /*
* Copyright 2016-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_commandsubscriber_ce;
/* {{{ MongoDB\Driver\Monitoring\CommandSubscriber function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_CommandSubscriber_commandStarted, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, event, MongoDB\\Driver\\Monitoring\\CommandStartedEvent, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_CommandSubscriber_commandSucceeded, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, event, MongoDB\\Driver\\Monitoring\\CommandSucceededEvent, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_CommandSubscriber_commandFailed, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, event, MongoDB\\Driver\\Monitoring\\CommandFailedEvent, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_commandsubscriber_me[] = {
ZEND_ABSTRACT_ME(CommandSubscriber, commandStarted, ai_CommandSubscriber_commandStarted)
ZEND_ABSTRACT_ME(CommandSubscriber, commandSucceeded, ai_CommandSubscriber_commandSucceeded)
ZEND_ABSTRACT_ME(CommandSubscriber, commandFailed, ai_CommandSubscriber_commandFailed)
PHP_FE_END
};
/* }}} */
void php_phongo_commandsubscriber_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
(void)type;(void)module_number;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Monitoring", "CommandSubscriber", php_phongo_commandsubscriber_me);
php_phongo_commandsubscriber_ce = zend_register_internal_interface(&ce TSRMLS_CC);
zend_class_implements(php_phongo_commandsubscriber_ce TSRMLS_CC, 1, php_phongo_subscriber_ce);
return;
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Monitoring/CommandSucceededEvent.c 0000664 0001750 0001750 00000022252 13210321137 023532 0 ustar jmikola jmikola /*
* Copyright 2016-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_commandsucceededevent_ce;
/* {{{ proto string CommandSucceededEvent::getCommandName()
Returns the command name for this event */
PHP_METHOD(CommandSucceededEvent, getCommandName)
{
php_phongo_commandsucceededevent_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_RETVAL_STRING(intern->command_name);
} /* }}} */
/* {{{ proto int CommandSucceededEvent::getDurationMicros()
Returns the event's duration in microseconds */
PHP_METHOD(CommandSucceededEvent, getDurationMicros)
{
php_phongo_commandsucceededevent_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(intern->duration_micros);
} /* }}} */
/* {{{ proto string CommandSucceededEvent::getOperationId()
Returns the event's operation ID */
PHP_METHOD(CommandSucceededEvent, getOperationId)
{
php_phongo_commandsucceededevent_t *intern;
char int_as_string[20];
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
sprintf(int_as_string, "%" PHONGO_LONG_FORMAT, intern->operation_id);
PHONGO_RETVAL_STRING(int_as_string);
} /* }}} */
/* {{{ proto stdClass CommandSucceededEvent::getReply()
Returns the reply document associated with the event */
PHP_METHOD(CommandSucceededEvent, getReply)
{
php_phongo_commandsucceededevent_t *intern;
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state);
#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
RETURN_ZVAL(state.zchild, 0, 1);
#endif
} /* }}} */
/* {{{ proto string CommandsucceededEvent::getRequestId()
Returns the event's request ID */
PHP_METHOD(CommandSucceededEvent, getRequestId)
{
php_phongo_commandsucceededevent_t *intern;
char int_as_string[20];
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
sprintf(int_as_string, "%" PHONGO_LONG_FORMAT, intern->request_id);
PHONGO_RETVAL_STRING(int_as_string);
} /* }}} */
/* {{{ proto MongoDB\Driver\Server CommandSucceededEvent::getServer()
Returns the Server from which the event originated */
PHP_METHOD(CommandSucceededEvent, getServer)
{
php_phongo_commandsucceededevent_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
phongo_server_init(return_value, intern->client, intern->server_id TSRMLS_CC);
} /* }}} */
/**
* Event thrown when a command has succeeded to execute.
*
* This class is only constructed internally.
*/
/* {{{ MongoDB\Driver\Monitoring\CommandSucceededEvent function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_CommandSucceededEvent_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_commandsucceededevent_me[] = {
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_CommandSucceededEvent_void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
PHP_ME(CommandSucceededEvent, getCommandName, ai_CommandSucceededEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandSucceededEvent, getDurationMicros, ai_CommandSucceededEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandSucceededEvent, getOperationId, ai_CommandSucceededEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandSucceededEvent, getReply, ai_CommandSucceededEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandSucceededEvent, getRequestId, ai_CommandSucceededEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(CommandSucceededEvent, getServer, ai_CommandSucceededEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_CommandSucceededEvent_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\Monitoring\CommandSucceededEvent object handlers */
static zend_object_handlers php_phongo_handler_commandsucceededevent;
static void php_phongo_commandsucceededevent_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_commandsucceededevent_t *intern = Z_OBJ_COMMANDSUCCEEDEDEVENT(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->reply) {
bson_destroy(intern->reply);
}
if (intern->command_name) {
efree(intern->command_name);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_commandsucceededevent_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_commandsucceededevent_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_commandsucceededevent_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_commandsucceededevent;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_commandsucceededevent_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_commandsucceededevent;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_commandsucceededevent_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_commandsucceededevent_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
char operation_id[20], request_id[20];
php_phongo_bson_state reply_state = PHONGO_BSON_STATE_INITIALIZER;
intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(object);
*is_temp = 1;
array_init_size(&retval, 6);
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);
sprintf(operation_id, "%" PHONGO_LONG_FORMAT, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state);
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL(&retval, "reply", &reply_state.zchild);
#else
ADD_ASSOC_ZVAL(&retval, "reply", reply_state.zchild);
#endif
sprintf(request_id, "%" PHONGO_LONG_FORMAT, intern->request_id);
ADD_ASSOC_STRING(&retval, "requestId", request_id);
{
#if PHP_VERSION_ID >= 70000
zval server;
phongo_server_init(&server, intern->client, intern->server_id TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "server", &server);
#else
zval *server = NULL;
MAKE_STD_ZVAL(server);
phongo_server_init(server, intern->client, intern->server_id TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "server", server);
#endif
}
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_commandsucceededevent_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
(void)type;(void)module_number;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Monitoring", "CommandSucceededEvent", php_phongo_commandsucceededevent_me);
php_phongo_commandsucceededevent_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_commandsucceededevent_ce->create_object = php_phongo_commandsucceededevent_create_object;
PHONGO_CE_FINAL(php_phongo_commandsucceededevent_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_commandsucceededevent_ce);
memcpy(&php_phongo_handler_commandsucceededevent, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_commandsucceededevent.get_debug_info = php_phongo_commandsucceededevent_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_commandsucceededevent.free_obj = php_phongo_commandsucceededevent_free_object;
php_phongo_handler_commandsucceededevent.offset = XtOffsetOf(php_phongo_commandsucceededevent_t, std);
#endif
return;
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Monitoring/Subscriber.c 0000664 0001750 0001750 00000002570 13210321137 021451 0 ustar jmikola jmikola /*
* Copyright 2016-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_subscriber_ce;
/* {{{ MongoDB\Driver\Monitoring\Subscriber function entries */
static zend_function_entry php_phongo_subscriber_me[] = {
PHP_FE_END
};
/* }}} */
void php_phongo_subscriber_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
(void)type;(void)module_number;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Monitoring", "Subscriber", php_phongo_subscriber_me);
php_phongo_subscriber_ce = zend_register_internal_interface(&ce TSRMLS_CC);
return;
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Monitoring/functions.c 0000664 0001750 0001750 00000006767 13210321137 021372 0 ustar jmikola jmikola /*
* Copyright 2016-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include "phongo_compat.h"
#include "php_phongo.h"
ZEND_EXTERN_MODULE_GLOBALS(mongodb)
static char *php_phongo_make_subscriber_hash(zval *subscriber TSRMLS_DC)
{
char *hash;
int hash_len;
hash_len = spprintf(&hash, 0, "SUBS-%09d", Z_OBJ_HANDLE_P(subscriber));
return hash;
}
/* {{{ proto void MongoDB\Driver\Monitoring\addSubscriber(MongoDB\Driver\Monitoring\Subscriber $subscriber)
Adds a monitoring subscriber to the set of subscribers */
PHP_FUNCTION(MongoDB_Driver_Monitoring_addSubscriber)
{
zval *zSubscriber = NULL;
char *hash;
#if PHP_VERSION_ID >= 70000
zval *subscriber;
#else
zval **subscriber;
#endif
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zSubscriber, php_phongo_subscriber_ce) == FAILURE) {
return;
}
/* The HashTable should never be NULL, as it's initialized during RINIT and
* destroyed during RSHUTDOWN. This is simply a defensive guard. */
if (!MONGODB_G(subscribers)) {
return;
}
hash = php_phongo_make_subscriber_hash(zSubscriber TSRMLS_CC);
/* If we have already stored the subscriber, bail out. Otherwise, add
* subscriber to list */
#if PHP_VERSION_ID >= 70000
if ((subscriber = zend_hash_str_find(MONGODB_G(subscribers), hash, strlen(hash)))) {
efree(hash);
return;
}
zend_hash_str_update(MONGODB_G(subscribers), hash, strlen(hash), zSubscriber);
#else
if (zend_hash_find(MONGODB_G(subscribers), hash, strlen(hash) + 1, (void**) &subscriber) == SUCCESS) {
efree(hash);
return;
}
zend_hash_update(MONGODB_G(subscribers), hash, strlen(hash) + 1, (void*) &zSubscriber, sizeof(zval*), NULL);
#endif
Z_ADDREF_P(zSubscriber);
efree(hash);
} /* }}} */
/* {{{ proto void MongoDB\Driver\Monitoring\removeSubscriber(MongoDB\Driver\Monitoring\Subscriber $subscriber)
Removes a monitoring subscriber from the set of subscribers */
PHP_FUNCTION(MongoDB_Driver_Monitoring_removeSubscriber)
{
zval *zSubscriber = NULL;
char *hash;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zSubscriber, php_phongo_subscriber_ce) == FAILURE) {
return;
}
/* The HashTable should never be NULL, as it's initialized during RINIT and
* destroyed during RSHUTDOWN. This is simply a defensive guard. */
if (!MONGODB_G(subscribers)) {
return;
}
hash = php_phongo_make_subscriber_hash(zSubscriber TSRMLS_CC);
#if PHP_VERSION_ID >= 70000
zend_hash_str_del(MONGODB_G(subscribers), hash, strlen(hash));
#else
zend_hash_del(MONGODB_G(subscribers), hash, strlen(hash) + 1);
#endif
efree(hash);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Monitoring/functions.h 0000664 0001750 0001750 00000001737 13210321137 021367 0 ustar jmikola jmikola /*
* Copyright 2016-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PHONGO_MONITORING_FUNCTIONS_H
#define PHONGO_MONITORING_FUNCTIONS_H
#include
PHP_FUNCTION(MongoDB_Driver_Monitoring_addSubscriber);
PHP_FUNCTION(MongoDB_Driver_Monitoring_removeSubscriber);
#endif /* PHONGO_MONITORING_FUNCTIONS_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/BulkWrite.c 0000664 0001750 0001750 00000043452 13210321137 017135 0 ustar jmikola jmikola /*
* Copyright 2015-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#include "php_array_api.h"
#include "phongo_compat.h"
#include "php_phongo.h"
#include "php_bson.h"
#define PHONGO_BULKWRITE_BYPASS_UNSET -1
zend_class_entry *php_phongo_bulkwrite_ce;
/* Returns whether the insert document appears to be a legacy index. */
static inline bool php_phongo_bulkwrite_insert_is_legacy_index(bson_t *bdocument) /* {{{ */
{
bson_iter_t iter;
if (bson_iter_init_find(&iter, bdocument, "key") && BSON_ITER_HOLDS_DOCUMENT(&iter) &&
bson_iter_init_find(&iter, bdocument, "name") && BSON_ITER_HOLDS_UTF8(&iter) &&
bson_iter_init_find(&iter, bdocument, "ns") && BSON_ITER_HOLDS_UTF8(&iter)) {
return true;
}
return false;
} /* }}} */
/* Extracts the "_id" field of a BSON document into a return value. */
static void php_phongo_bulkwrite_extract_id(bson_t *doc, zval **return_value) /* {{{ */
{
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
zval *id = NULL;
state.map.root_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
if (!php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &state)) {
goto cleanup;
}
#if PHP_VERSION_ID >= 70000
id = php_array_fetchc(&state.zchild, "_id");
#else
id = php_array_fetchc(state.zchild, "_id");
#endif
if (id) {
ZVAL_ZVAL(*return_value, id, 1, 0);
}
cleanup:
zval_ptr_dtor(&state.zchild);
} /* }}} */
/* Returns whether any top-level field names in the document contain a "$". */
static inline bool php_phongo_bulkwrite_update_has_operators(bson_t *bupdate) /* {{{ */
{
bson_iter_t iter;
if (bson_iter_init(&iter, bupdate)) {
while (bson_iter_next (&iter)) {
if (strchr(bson_iter_key(&iter), '$')) {
return true;
}
}
}
return false;
} /* }}} */
/* Appends a document field for the given opts document and key. Returns true on
* success; otherwise, false is returned and an exception is thrown. */
static bool php_phongo_bulkwrite_opts_append_document(bson_t *opts, const char *opts_key, zval *zarr, const char *zarr_key TSRMLS_DC) /* {{{ */
{
zval *value = php_array_fetch(zarr, zarr_key);
bson_t b = BSON_INITIALIZER;
if (Z_TYPE_P(value) != IS_OBJECT && Z_TYPE_P(value) != IS_ARRAY) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"%s\" option to be array or object, %s given", zarr_key, zend_get_type_by_const(Z_TYPE_P(value)));
return false;
}
php_phongo_zval_to_bson(value, PHONGO_BSON_NONE, &b, NULL TSRMLS_CC);
if (EG(exception)) {
bson_destroy(&b);
return false;
}
if (!BSON_APPEND_DOCUMENT(opts, opts_key, &b)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", opts_key);
bson_destroy(&b);
return false;
}
bson_destroy(&b);
return true;
} /* }}} */
#define PHONGO_BULKWRITE_APPEND_BOOL(opt, value) \
if (!BSON_APPEND_BOOL(boptions, (opt), (value))) { \
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", (opt)); \
return false; \
}
#define PHONGO_BULKWRITE_APPEND_INT32(opt, value) \
if (!BSON_APPEND_INT32(boptions, (opt), (value))) { \
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", (opt)); \
return false; \
}
#define PHONGO_BULKWRITE_OPT_DOCUMENT(opt) \
if (zoptions && php_array_existsc(zoptions, (opt))) { \
if (!php_phongo_bulkwrite_opts_append_document(boptions, (opt), zoptions, (opt) TSRMLS_CC)) { \
return false; \
} \
}
/* Applies options (including defaults) for an update operation. */
static bool php_phongo_bulkwrite_update_apply_options(bson_t *boptions, zval *zoptions TSRMLS_DC)/* {{{ */
{
bool multi = false, upsert = false;
if (zoptions) {
if (php_array_existsc(zoptions, "multi")) {
multi = php_array_fetchc_bool(zoptions, "multi");
}
if (php_array_existsc(zoptions, "upsert")) {
upsert = php_array_fetchc_bool(zoptions, "upsert");
}
}
PHONGO_BULKWRITE_APPEND_BOOL("multi", multi);
PHONGO_BULKWRITE_APPEND_BOOL("upsert", upsert);
PHONGO_BULKWRITE_OPT_DOCUMENT("collation");
return true;
} /* }}} */
/* Applies options (including defaults) for an delete operation. */
static bool php_phongo_bulkwrite_delete_apply_options(bson_t *boptions, zval *zoptions TSRMLS_DC)/* {{{ */
{
int32_t limit = 0;
if (zoptions) {
if (php_array_existsc(zoptions, "limit")) {
limit = php_array_fetchc_bool(zoptions, "limit") ? 1 : 0;
}
}
PHONGO_BULKWRITE_APPEND_INT32("limit", limit);
PHONGO_BULKWRITE_OPT_DOCUMENT("collation");
return true;
} /* }}} */
#undef PHONGO_BULKWRITE_APPEND_BOOL
#undef PHONGO_BULKWRITE_APPEND_INT32
#undef PHONGO_BULKWRITE_OPT_DOCUMENT
/* {{{ proto void MongoDB\Driver\BulkWrite::__construct([array $options = array()])
Constructs a new BulkWrite */
static PHP_METHOD(BulkWrite, __construct)
{
php_phongo_bulkwrite_t *intern;
zend_error_handling error_handling;
zval *options = NULL;
zend_bool ordered = 1;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value) SUPPRESS_UNUSED_WARNING(return_value_used)
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_BULKWRITE_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!", &options) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
if (options && php_array_existsc(options, "ordered")) {
ordered = php_array_fetchc_bool(options, "ordered");
}
intern->bulk = phongo_bulkwrite_init(ordered);
intern->ordered = ordered;
intern->bypass = PHONGO_BULKWRITE_BYPASS_UNSET;
intern->num_ops = 0;
if (options && php_array_existsc(options, "bypassDocumentValidation")) {
zend_bool bypass = php_array_fetchc_bool(options, "bypassDocumentValidation");
mongoc_bulk_operation_set_bypass_document_validation(intern->bulk, bypass);
intern->bypass = bypass;
}
} /* }}} */
/* {{{ proto mixed MongoDB\Driver\BulkWrite::insert(array|object $document)
Adds an insert operation to the BulkWrite */
static PHP_METHOD(BulkWrite, insert)
{
php_phongo_bulkwrite_t *intern;
zval *zdocument;
bson_t bdocument = BSON_INITIALIZER, boptions = BSON_INITIALIZER;
bson_t *bson_out = NULL;
int bson_flags = PHONGO_BSON_ADD_ID;
bson_error_t error = {0};
DECLARE_RETURN_VALUE_USED
SUPPRESS_UNUSED_WARNING(return_value_ptr)
intern = Z_BULKWRITE_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "A", &zdocument) == FAILURE) {
return;
}
if (return_value_used) {
bson_flags |= PHONGO_BSON_RETURN_ID;
}
php_phongo_zval_to_bson(zdocument, bson_flags, &bdocument, &bson_out TSRMLS_CC);
if (EG(exception)) {
goto cleanup;
}
/* If the insert document appears to be a legacy index, instruct libmongoc
* to allow dots in BSON keys by setting the "legacyIndex" option.
*
* Note: php_phongo_zval_to_bson() may have added an ObjectId if the "_id"
* field was unset. We don't know at this point if the insert is destined
* for a pre-2.6 server's "system.indexes" collection, but legacy index
* creation will ignore the "_id" so there is no harm in leaving it. In the
* event php_phongo_bulkwrite_insert_is_legacy_index() returns a false
* positive, we absolutely want ObjectId added if "_id" was unset. */
if (php_phongo_bulkwrite_insert_is_legacy_index(&bdocument) &&
!BSON_APPEND_BOOL(&boptions, "legacyIndex", true)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"legacyIndex\" option");
goto cleanup;
}
if (!mongoc_bulk_operation_insert_with_opts(intern->bulk, &bdocument, &boptions, &error)) {
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
goto cleanup;
}
intern->num_ops++;
if (bson_out && return_value_used) {
php_phongo_bulkwrite_extract_id(bson_out, &return_value);
}
cleanup:
bson_destroy(&bdocument);
bson_destroy(&boptions);
bson_clear(&bson_out);
} /* }}} */
/* {{{ proto void MongoDB\Driver\BulkWrite::update(array|object $query, array|object $newObj[, array $updateOptions = array()])
Adds an update operation to the BulkWrite */
static PHP_METHOD(BulkWrite, update)
{
php_phongo_bulkwrite_t *intern;
zval *zquery, *zupdate, *zoptions = NULL;
bson_t bquery = BSON_INITIALIZER, bupdate = BSON_INITIALIZER, boptions = BSON_INITIALIZER;
bson_error_t error = {0};
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_BULKWRITE_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "AA|a!", &zquery, &zupdate, &zoptions) == FAILURE) {
return;
}
php_phongo_zval_to_bson(zquery, PHONGO_BSON_NONE, &bquery, NULL TSRMLS_CC);
if (EG(exception)) {
goto cleanup;
}
php_phongo_zval_to_bson(zupdate, PHONGO_BSON_NONE, &bupdate, NULL TSRMLS_CC);
if (EG(exception)) {
goto cleanup;
}
if (!php_phongo_bulkwrite_update_apply_options(&boptions, zoptions TSRMLS_CC)) {
goto cleanup;
}
if (php_phongo_bulkwrite_update_has_operators(&bupdate)) {
if (zoptions && php_array_existsc(zoptions, "multi") && php_array_fetchc_bool(zoptions, "multi")) {
if (!mongoc_bulk_operation_update_many_with_opts(intern->bulk, &bquery, &bupdate, &boptions, &error)) {
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
goto cleanup;
}
} else {
if (!mongoc_bulk_operation_update_one_with_opts(intern->bulk, &bquery, &bupdate, &boptions, &error)) {
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
goto cleanup;
}
}
} else {
if (zoptions && php_array_existsc(zoptions, "multi") && php_array_fetchc_bool(zoptions, "multi")) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Replacement document conflicts with true \"multi\" option");
goto cleanup;
}
if (!mongoc_bulk_operation_replace_one_with_opts(intern->bulk, &bquery, &bupdate, &boptions, &error)) {
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
goto cleanup;
}
}
intern->num_ops++;
cleanup:
bson_destroy(&bquery);
bson_destroy(&bupdate);
bson_destroy(&boptions);
} /* }}} */
/* {{{ proto void MongoDB\Driver\BulkWrite::delete(array|object $query[, array $deleteOptions = array()])
Adds a delete operation to the BulkWrite */
static PHP_METHOD(BulkWrite, delete)
{
php_phongo_bulkwrite_t *intern;
zval *zquery, *zoptions = NULL;
bson_t bquery = BSON_INITIALIZER, boptions = BSON_INITIALIZER;
bson_error_t error = {0};
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_BULKWRITE_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "A|a!", &zquery, &zoptions) == FAILURE) {
return;
}
php_phongo_zval_to_bson(zquery, PHONGO_BSON_NONE, &bquery, NULL TSRMLS_CC);
if (EG(exception)) {
goto cleanup;
}
if (!php_phongo_bulkwrite_delete_apply_options(&boptions, zoptions TSRMLS_CC)) {
goto cleanup;
}
if (zoptions && php_array_existsc(zoptions, "limit") && php_array_fetchc_bool(zoptions, "limit")) {
if (!mongoc_bulk_operation_remove_one_with_opts(intern->bulk, &bquery, &boptions, &error)) {
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
goto cleanup;
}
} else {
if (!mongoc_bulk_operation_remove_many_with_opts(intern->bulk, &bquery, &boptions, &error)) {
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
goto cleanup;
}
}
intern->num_ops++;
cleanup:
bson_destroy(&bquery);
bson_destroy(&boptions);
} /* }}} */
/* {{{ proto integer MongoDB\Driver\BulkWrite::count()
Returns the number of operations that have been added to the BulkWrite */
static PHP_METHOD(BulkWrite, count)
{
php_phongo_bulkwrite_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_BULKWRITE_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(intern->num_ops);
} /* }}} */
/* {{{ MongoDB\Driver\BulkWrite function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_BulkWrite___construct, 0, 0, 0)
ZEND_ARG_ARRAY_INFO(0, options, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_BulkWrite_insert, 0, 0, 1)
ZEND_ARG_INFO(0, document)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_BulkWrite_update, 0, 0, 2)
ZEND_ARG_INFO(0, query)
ZEND_ARG_INFO(0, newObj)
ZEND_ARG_ARRAY_INFO(0, updateOptions, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_BulkWrite_delete, 0, 0, 1)
ZEND_ARG_INFO(0, query)
ZEND_ARG_ARRAY_INFO(0, deleteOptions, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_BulkWrite_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_bulkwrite_me[] = {
PHP_ME(BulkWrite, __construct, ai_BulkWrite___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(BulkWrite, insert, ai_BulkWrite_insert, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(BulkWrite, update, ai_BulkWrite_update, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(BulkWrite, delete, ai_BulkWrite_delete, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(BulkWrite, count, ai_BulkWrite_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_BulkWrite_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\BulkWrite object handlers */
static zend_object_handlers php_phongo_handler_bulkwrite;
static void php_phongo_bulkwrite_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_bulkwrite_t *intern = Z_OBJ_BULKWRITE(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->bulk) {
mongoc_bulk_operation_destroy(intern->bulk);
}
if (intern->database) {
efree(intern->database);
}
if (intern->collection) {
efree(intern->collection);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_bulkwrite_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_bulkwrite_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_bulkwrite_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_bulkwrite;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_bulkwrite_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_bulkwrite;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_bulkwrite_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
php_phongo_bulkwrite_t *intern = NULL;
*is_temp = 1;
intern = Z_BULKWRITE_OBJ_P(object);
array_init(&retval);
if (intern->database) {
ADD_ASSOC_STRING(&retval, "database", intern->database);
} else {
ADD_ASSOC_NULL_EX(&retval, "database");
}
if (intern->collection) {
ADD_ASSOC_STRING(&retval, "collection", intern->collection);
} else {
ADD_ASSOC_NULL_EX(&retval, "collection");
}
ADD_ASSOC_BOOL_EX(&retval, "ordered", intern->ordered);
if (intern->bypass != PHONGO_BULKWRITE_BYPASS_UNSET) {
ADD_ASSOC_BOOL_EX(&retval, "bypassDocumentValidation", intern->bypass);
} else {
ADD_ASSOC_NULL_EX(&retval, "bypassDocumentValidation");
}
ADD_ASSOC_BOOL_EX(&retval, "executed", intern->executed);
ADD_ASSOC_LONG_EX(&retval, "server_id", mongoc_bulk_operation_get_hint(intern->bulk));
if (mongoc_bulk_operation_get_write_concern(intern->bulk)) {
#if PHP_VERSION_ID >= 70000
zval write_concern;
php_phongo_write_concern_to_zval(&write_concern, mongoc_bulk_operation_get_write_concern(intern->bulk));
ADD_ASSOC_ZVAL_EX(&retval, "write_concern", &write_concern);
#else
zval *write_concern = NULL;
MAKE_STD_ZVAL(write_concern);
php_phongo_write_concern_to_zval(write_concern, mongoc_bulk_operation_get_write_concern(intern->bulk));
ADD_ASSOC_ZVAL_EX(&retval, "write_concern", write_concern);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "write_concern");
}
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_bulkwrite_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "BulkWrite", php_phongo_bulkwrite_me);
php_phongo_bulkwrite_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_bulkwrite_ce->create_object = php_phongo_bulkwrite_create_object;
PHONGO_CE_FINAL(php_phongo_bulkwrite_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_bulkwrite_ce);
memcpy(&php_phongo_handler_bulkwrite, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_bulkwrite.get_debug_info = php_phongo_bulkwrite_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_bulkwrite.free_obj = php_phongo_bulkwrite_free_object;
php_phongo_handler_bulkwrite.offset = XtOffsetOf(php_phongo_bulkwrite_t, std);
#endif
zend_class_implements(php_phongo_bulkwrite_ce TSRMLS_CC, 1, spl_ce_Countable);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Command.c 0000664 0001750 0001750 00000011720 13210321137 016574 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
#include "php_bson.h"
zend_class_entry *php_phongo_command_ce;
/* {{{ proto void MongoDB\Driver\Command::__construct(array|object $document)
Constructs a new Command */
static PHP_METHOD(Command, __construct)
{
php_phongo_command_t *intern;
zend_error_handling error_handling;
zval *document;
bson_t *bson = bson_new();
SUPPRESS_UNUSED_WARNING(return_value) SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_COMMAND_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "A", &document) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
php_phongo_zval_to_bson(document, PHONGO_BSON_NONE, bson, NULL TSRMLS_CC);
intern->bson = bson;
} /* }}} */
/* {{{ MongoDB\Driver\Command function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Command___construct, 0, 0, 1)
ZEND_ARG_INFO(0, document)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Command_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_command_me[] = {
PHP_ME(Command, __construct, ai_Command___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_Command_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\Command object handlers */
static zend_object_handlers php_phongo_handler_command;
static void php_phongo_command_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_command_t *intern = Z_OBJ_COMMAND(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->bson) {
bson_clear(&intern->bson);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_command_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_command_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_command_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_command;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_command_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_command;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_command_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_command_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
*is_temp = 1;
intern = Z_COMMAND_OBJ_P(object);
array_init_size(&retval, 1);
if (intern->bson) {
#if PHP_VERSION_ID >= 70000
zval zv;
#else
zval *zv;
#endif
php_phongo_bson_to_zval(bson_get_data(intern->bson), intern->bson->len, &zv);
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "command", &zv);
#else
ADD_ASSOC_ZVAL_EX(&retval, "command", zv);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "command");
}
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_command_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "Command", php_phongo_command_me);
php_phongo_command_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_command_ce->create_object = php_phongo_command_create_object;
PHONGO_CE_FINAL(php_phongo_command_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_command_ce);
memcpy(&php_phongo_handler_command, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_command.get_debug_info = php_phongo_command_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_command.free_obj = php_phongo_command_free_object;
php_phongo_handler_command.offset = XtOffsetOf(php_phongo_command_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Cursor.c 0000664 0001750 0001750 00000036161 13210321137 016501 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
#include "php_bson.h"
zend_class_entry *php_phongo_cursor_ce;
static void php_phongo_cursor_free_current(php_phongo_cursor_t *cursor) /* {{{ */
{
if (!Z_ISUNDEF(cursor->visitor_data.zchild)) {
zval_ptr_dtor(&cursor->visitor_data.zchild);
ZVAL_UNDEF(&cursor->visitor_data.zchild);
}
} /* }}} */
/* {{{ MongoDB\Driver\Cursor iterator handlers */
static void php_phongo_cursor_iterator_dtor(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
{
php_phongo_cursor_iterator *cursor_it = (php_phongo_cursor_iterator *)iter;
if (!Z_ISUNDEF(cursor_it->intern.data)) {
#if PHP_VERSION_ID >= 70000
zval_ptr_dtor(&cursor_it->intern.data);
#else
zval_ptr_dtor((zval**)&cursor_it->intern.data);
cursor_it->intern.data = NULL;
#endif
}
#if PHP_VERSION_ID < 70000
efree(cursor_it);
#endif
} /* }}} */
static int php_phongo_cursor_iterator_valid(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
{
php_phongo_cursor_t *cursor = ((php_phongo_cursor_iterator *)iter)->cursor;
if (!Z_ISUNDEF(cursor->visitor_data.zchild)) {
return SUCCESS;
}
return FAILURE;
} /* }}} */
static void php_phongo_cursor_iterator_get_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC) /* {{{ */
{
php_phongo_cursor_t *cursor = ((php_phongo_cursor_iterator *)iter)->cursor;
ZVAL_LONG(key, cursor->current);
} /* }}} */
#if PHP_VERSION_ID < 70000
static void php_phongo_cursor_iterator_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) /* {{{ */
{
php_phongo_cursor_t *cursor = ((php_phongo_cursor_iterator *)iter)->cursor;
*data = &cursor->visitor_data.zchild;
} /* }}} */
#else
static zval* php_phongo_cursor_iterator_get_current_data(zend_object_iterator *iter) /* {{{ */
{
php_phongo_cursor_t *cursor = ((php_phongo_cursor_iterator *)iter)->cursor;
return &cursor->visitor_data.zchild;
} /* }}} */
#endif
static void php_phongo_cursor_iterator_move_forward(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
{
php_phongo_cursor_iterator *cursor_it = (php_phongo_cursor_iterator *)iter;
php_phongo_cursor_t *cursor = cursor_it->cursor;
const bson_t *doc;
php_phongo_cursor_free_current(cursor);
cursor->current++;
if (mongoc_cursor_next(cursor->cursor, &doc)) {
php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &cursor->visitor_data);
} else {
bson_error_t error;
if (mongoc_cursor_error(cursor->cursor, &error)) {
/* Intentionally not destroying the cursor as it will happen
* naturally now that there are no more results */
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
}
}
} /* }}} */
static void php_phongo_cursor_iterator_rewind(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
{
php_phongo_cursor_iterator *cursor_it = (php_phongo_cursor_iterator *)iter;
php_phongo_cursor_t *cursor = cursor_it->cursor;
const bson_t *doc;
if (cursor->current > 0) {
phongo_throw_exception(PHONGO_ERROR_LOGIC TSRMLS_CC, "Cursors cannot rewind after starting iteration");
return;
}
php_phongo_cursor_free_current(cursor);
doc = mongoc_cursor_current(cursor->cursor);
if (doc) {
php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &cursor->visitor_data);
}
} /* }}} */
static zend_object_iterator_funcs php_phongo_cursor_iterator_funcs = {
php_phongo_cursor_iterator_dtor,
php_phongo_cursor_iterator_valid,
php_phongo_cursor_iterator_get_current_data,
php_phongo_cursor_iterator_get_current_key,
php_phongo_cursor_iterator_move_forward,
php_phongo_cursor_iterator_rewind,
NULL /* invalidate_current is not used */
};
static zend_object_iterator *php_phongo_cursor_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) /* {{{ */
{
php_phongo_cursor_iterator *cursor_it = NULL;
php_phongo_cursor_t *cursor = Z_CURSOR_OBJ_P(object);
if (by_ref) {
zend_error(E_ERROR, "An iterator cannot be used with foreach by reference");
}
if (cursor->got_iterator) {
phongo_throw_exception(PHONGO_ERROR_LOGIC TSRMLS_CC, "Cursors cannot yield multiple iterators");
return NULL;
}
cursor->got_iterator = 1;
cursor_it = ecalloc(1, sizeof(php_phongo_cursor_iterator));
#if PHP_VERSION_ID >= 70000
zend_iterator_init(&cursor_it->intern);
#endif
#if PHP_VERSION_ID >= 70000
ZVAL_COPY(&cursor_it->intern.data, object);
#else
Z_ADDREF_P(object);
cursor_it->intern.data = (void*)object;
#endif
cursor_it->intern.funcs = &php_phongo_cursor_iterator_funcs;
cursor_it->cursor = cursor;
/* cursor_it->current should already be allocated to zero */
php_phongo_cursor_free_current(cursor_it->cursor);
return &cursor_it->intern;
} /* }}} */
/* }}} */
/* {{{ proto void MongoDB\Driver\Cursor::setTypeMap(array $typemap)
Sets a type map to use for BSON unserialization */
static PHP_METHOD(Cursor, setTypeMap)
{
php_phongo_cursor_t *intern;
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
zval *typemap = NULL;
bool restore_current_element = false;
SUPPRESS_UNUSED_WARNING(return_value) SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_CURSOR_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!", &typemap) == FAILURE) {
return;
}
if (!php_phongo_bson_typemap_to_state(typemap, &state.map TSRMLS_CC)) {
return;
}
/* Check if the existing element needs to be freed before we overwrite
* visitor_data, which contains the only reference to it. */
if (!Z_ISUNDEF(intern->visitor_data.zchild)) {
php_phongo_cursor_free_current(intern);
restore_current_element = true;
}
intern->visitor_data = state;
/* If the cursor has a current element, we just freed it and should restore
* it with a new type map applied. */
if (restore_current_element && mongoc_cursor_current(intern->cursor)) {
const bson_t *doc = mongoc_cursor_current(intern->cursor);
php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &intern->visitor_data);
}
} /* }}} */
static int php_phongo_cursor_to_array_apply(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval *data;
zval *return_value = (zval*)puser;
data = iter->funcs->get_current_data(iter TSRMLS_CC);
if (EG(exception)) {
return ZEND_HASH_APPLY_STOP;
}
if (Z_ISUNDEF_P(data)) {
return ZEND_HASH_APPLY_STOP;
}
Z_TRY_ADDREF_P(data);
add_next_index_zval(return_value, data);
#else
zval **data;
zval *return_value = (zval*)puser;
iter->funcs->get_current_data(iter, &data TSRMLS_CC);
if (EG(exception)) {
return ZEND_HASH_APPLY_STOP;
}
if (data == NULL || *data == NULL) {
return ZEND_HASH_APPLY_STOP;
}
Z_ADDREF_PP(data);
add_next_index_zval(return_value, *data);
#endif
return ZEND_HASH_APPLY_KEEP;
} /* }}} */
/* {{{ proto array MongoDB\Driver\Cursor::toArray()
Returns an array of all result documents for this cursor */
static PHP_METHOD(Cursor, toArray)
{
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
if (zend_parse_parameters_none() == FAILURE) {
return;
}
array_init(return_value);
if (spl_iterator_apply(getThis(), php_phongo_cursor_to_array_apply, (void*)return_value TSRMLS_CC) != SUCCESS) {
zval_dtor(return_value);
RETURN_NULL();
}
} /* }}} */
/* {{{ proto MongoDB\Driver\CursorId MongoDB\Driver\Cursor::getId()
Returns the CursorId for this cursor */
static PHP_METHOD(Cursor, getId)
{
php_phongo_cursor_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_CURSOR_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
php_phongo_cursor_id_new_from_id(return_value, mongoc_cursor_get_id(intern->cursor) TSRMLS_CC);
} /* }}} */
/* {{{ proto MongoDB\Driver\Server MongoDB\Driver\Cursor::getServer()
Returns the Server object to which this cursor is attached */
static PHP_METHOD(Cursor, getServer)
{
php_phongo_cursor_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_CURSOR_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
phongo_server_init(return_value, intern->client, intern->server_id TSRMLS_CC);
} /* }}} */
/* {{{ proto boolean MongoDB\Driver\Cursor::isDead()
Checks if a cursor is still alive */
static PHP_METHOD(Cursor, isDead)
{
php_phongo_cursor_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_CURSOR_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_BOOL(!mongoc_cursor_is_alive(intern->cursor));
} /* }}} */
/* {{{ MongoDB\Driver\Cursor function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Cursor_setTypeMap, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, typemap, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Cursor_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_cursor_me[] = {
PHP_ME(Cursor, setTypeMap, ai_Cursor_setTypeMap, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Cursor, toArray, ai_Cursor_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Cursor, getId, ai_Cursor_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Cursor, getServer, ai_Cursor_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Cursor, isDead, ai_Cursor_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_Cursor_void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_Cursor_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\Cursor object handlers */
static zend_object_handlers php_phongo_handler_cursor;
static void php_phongo_cursor_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_cursor_t *intern = Z_OBJ_CURSOR(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->cursor) {
mongoc_cursor_destroy(intern->cursor);
}
if (intern->database) {
efree(intern->database);
}
if (intern->collection) {
efree(intern->collection);
}
if (!Z_ISUNDEF(intern->query)) {
zval_ptr_dtor(&intern->query);
}
if (!Z_ISUNDEF(intern->command)) {
zval_ptr_dtor(&intern->command);
}
if (!Z_ISUNDEF(intern->read_preference)) {
zval_ptr_dtor(&intern->read_preference);
}
php_phongo_cursor_free_current(intern);
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_cursor_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_cursor_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_cursor_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_cursor;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_cursor_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_cursor;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_cursor_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_cursor_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
*is_temp = 1;
intern = Z_CURSOR_OBJ_P(object);
array_init_size(&retval, 9);
if (intern->database) {
ADD_ASSOC_STRING(&retval, "database", intern->database);
} else {
ADD_ASSOC_NULL_EX(&retval, "database");
}
if (intern->collection) {
ADD_ASSOC_STRING(&retval, "collection", intern->collection);
} else {
ADD_ASSOC_NULL_EX(&retval, "collection");
}
if (!Z_ISUNDEF(intern->query)) {
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "query", &intern->query);
Z_ADDREF(intern->query);
#else
ADD_ASSOC_ZVAL_EX(&retval, "query", intern->query);
Z_ADDREF_P(intern->query);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "query");
}
if (!Z_ISUNDEF(intern->command)) {
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "command", &intern->command);
Z_ADDREF(intern->command);
#else
ADD_ASSOC_ZVAL_EX(&retval, "command", intern->command);
Z_ADDREF_P(intern->command);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "command");
}
if (!Z_ISUNDEF(intern->read_preference)) {
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "readPreference", &intern->read_preference);
Z_ADDREF(intern->read_preference);
#else
ADD_ASSOC_ZVAL_EX(&retval, "readPreference", intern->read_preference);
Z_ADDREF_P(intern->read_preference);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "readPreference");
}
ADD_ASSOC_BOOL_EX(&retval, "isDead", !mongoc_cursor_is_alive(intern->cursor));
ADD_ASSOC_LONG_EX(&retval, "currentIndex", intern->current);
if (!Z_ISUNDEF(intern->visitor_data.zchild)) {
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "currentDocument", &intern->visitor_data.zchild);
/*Z_ADDREF(intern->visitor_data.zchild);*/
#else
ADD_ASSOC_ZVAL_EX(&retval, "currentDocument", intern->visitor_data.zchild);
Z_ADDREF_P(intern->visitor_data.zchild);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "currentDocument");
}
{
#if PHP_VERSION_ID >= 70000
zval server;
phongo_server_init(&server, intern->client, intern->server_id TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "server", &server);
#else
zval *server = NULL;
MAKE_STD_ZVAL(server);
phongo_server_init(server, intern->client, intern->server_id TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "server", server);
#endif
}
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_cursor_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "Cursor", php_phongo_cursor_me);
php_phongo_cursor_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_cursor_ce->create_object = php_phongo_cursor_create_object;
PHONGO_CE_FINAL(php_phongo_cursor_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_cursor_ce);
php_phongo_cursor_ce->get_iterator = php_phongo_cursor_get_iterator;
memcpy(&php_phongo_handler_cursor, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_cursor.get_debug_info = php_phongo_cursor_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_cursor.free_obj = php_phongo_cursor_free_object;
php_phongo_handler_cursor.offset = XtOffsetOf(php_phongo_cursor_t, std);
#endif
zend_class_implements(php_phongo_cursor_ce TSRMLS_CC, 1, zend_ce_traversable);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/CursorId.c 0000664 0001750 0001750 00000010617 13210321137 016754 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_cursorid_ce;
/* {{{ proto string MongoDB\Driver\CursorId::__toString()
Returns the string representation of the CursorId */
static PHP_METHOD(CursorId, __toString)
{
php_phongo_cursorid_t *intern;
char *tmp;
int tmp_len;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_CURSORID_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
tmp_len = spprintf(&tmp, 0, "%" PRId64, intern->id);
PHONGO_RETVAL_STRINGL(tmp, tmp_len);
efree(tmp);
} /* }}} */
/* {{{ MongoDB\Driver\CursorId function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_CursorId_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_cursorid_me[] = {
PHP_ME(CursorId, __toString, ai_CursorId_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_CursorId_void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_CursorId_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\CursorId object handlers */
static zend_object_handlers php_phongo_handler_cursorid;
static void php_phongo_cursorid_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_cursorid_t *intern = Z_OBJ_CURSORID(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_cursorid_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_cursorid_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_cursorid_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_cursorid;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_cursorid_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_cursorid;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_cursorid_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_cursorid_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
*is_temp = 1;
intern = Z_CURSORID_OBJ_P(object);
array_init(&retval);
#if SIZEOF_LONG == 4
{
char tmp[24];
int tmp_len;
tmp_len = snprintf(tmp, sizeof(tmp), "%" PRId64, intern->id);
ADD_ASSOC_STRINGL(&retval, "id", tmp, tmp_len);
}
#else
ADD_ASSOC_LONG_EX(&retval, "id", intern->id);
#endif
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_cursorid_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "CursorId", php_phongo_cursorid_me);
php_phongo_cursorid_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_cursorid_ce->create_object = php_phongo_cursorid_create_object;
PHONGO_CE_FINAL(php_phongo_cursorid_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_cursorid_ce);
memcpy(&php_phongo_handler_cursorid, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_cursorid.get_debug_info = php_phongo_cursorid_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_cursorid.free_obj = php_phongo_cursorid_free_object;
php_phongo_handler_cursorid.offset = XtOffsetOf(php_phongo_cursorid_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Manager.c 0000664 0001750 0001750 00000052071 13210321137 016574 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include
#include
#include "php_array_api.h"
#include "phongo_compat.h"
#include "php_phongo.h"
#define PHONGO_MANAGER_URI_DEFAULT "mongodb://127.0.0.1/"
/**
* Manager abstracts a cluster of Server objects (i.e. socket connections).
*
* Typically, users will connect to a cluster using a URI, and the Manager will
* perform tasks such as replica set discovery and create the necessary Server
* objects. That said, it is also possible to create a Manager with an arbitrary
* collection of Server objects using the static factory method (this can be
* useful for testing or administration).
*
* Operation methods do not take socket-level options (e.g. socketTimeoutMS).
* Those options should be specified during construction.
*/
zend_class_entry *php_phongo_manager_ce;
/* Checks if driverOptions contains a stream context resource in the "context"
* key and incorporates any of its SSL options into the base array that did not
* already exist (i.e. array union). The "context" key is then unset from the
* base array.
*
* This handles the merging of any legacy SSL context options and also makes
* driverOptions suitable for serialization by removing the resource zval. */
static bool php_phongo_manager_merge_context_options(zval *zdriverOptions TSRMLS_DC) /* {{{ */
{
php_stream_context *context;
zval *zcontext, *zcontextOptions;
if (!php_array_existsc(zdriverOptions, "context")) {
return true;
}
zcontext = php_array_fetchc(zdriverOptions, "context");
context = php_stream_context_from_zval(zcontext, 1);
if (!context) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "\"context\" driver option is not a valid Stream-Context resource");
return false;
}
#if PHP_VERSION_ID >= 70000
zcontextOptions = php_array_fetchc_array(&context->options, "ssl");
#else
zcontextOptions = php_array_fetchc_array(context->options, "ssl");
#endif
if (!zcontextOptions) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Stream-Context resource does not contain \"ssl\" options array");
return false;
}
/* Perform array union (see: add_function() in zend_operators.c) */
#if PHP_VERSION_ID >= 70000
zend_hash_merge(Z_ARRVAL_P(zdriverOptions), Z_ARRVAL_P(zcontextOptions), zval_add_ref, 0);
#else
{
zval *tmp;
zend_hash_merge(Z_ARRVAL_P(zdriverOptions), Z_ARRVAL_P(zcontextOptions), (void (*)(void *pData)) zval_add_ref, (void *) &tmp, sizeof(zval *), 0);
}
#endif
php_array_unsetc(zdriverOptions, "context");
return true;
} /* }}} */
/* Prepare authMechanismProperties for BSON encoding by converting a boolean
* value for the "CANONICALIZE_HOST_NAME" option to a string.
*
* Note: URI options are case-insensitive, so we must iterate through the
* HashTable in order to detect options. */
static void php_phongo_manager_prep_authmechanismproperties(zval *properties TSRMLS_DC) /* {{{ */
{
HashTable *ht_data;
if (Z_TYPE_P(properties) != IS_ARRAY && Z_TYPE_P(properties) != IS_OBJECT) {
return;
}
ht_data = HASH_OF(properties);
#if PHP_VERSION_ID >= 70000
{
zend_string *string_key = NULL;
zend_ulong num_key = 0;
zval *property;
ZEND_HASH_FOREACH_KEY_VAL(ht_data, num_key, string_key, property) {
if (!string_key) {
continue;
}
/* URI options are case-insensitive */
if (!strcasecmp(ZSTR_VAL(string_key), "CANONICALIZE_HOST_NAME")) {
ZVAL_DEREF(property);
if (Z_TYPE_P(property) != IS_STRING && zend_is_true(property)) {
SEPARATE_ZVAL_NOREF(property);
ZVAL_NEW_STR(property, zend_string_init(ZEND_STRL("true"), 0));
}
}
} ZEND_HASH_FOREACH_END();
}
#else
{
HashPosition pos;
zval **property;
for (zend_hash_internal_pointer_reset_ex(ht_data, &pos);
zend_hash_get_current_data_ex(ht_data, (void **) &property, &pos) == SUCCESS;
zend_hash_move_forward_ex(ht_data, &pos)) {
char *string_key = NULL;
uint string_key_len = 0;
ulong num_key = 0;
if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(ht_data, &string_key, &string_key_len, &num_key, 0, &pos)) {
continue;
}
/* URI options are case-insensitive */
if (!strcasecmp(string_key, "CANONICALIZE_HOST_NAME")) {
if (Z_TYPE_PP(property) != IS_STRING && zend_is_true(*property)) {
SEPARATE_ZVAL_IF_NOT_REF(property);
Z_TYPE_PP(property) = IS_STRING;
Z_STRVAL_PP(property) = estrndup("true", sizeof("true")-1);
Z_STRLEN_PP(property) = sizeof("true")-1;
}
}
}
}
#endif
return;
} /* }}} */
/* Prepare URI options for BSON encoding.
*
* Read preference tag sets must be an array of documents. In order to ensure
* that empty arrays serialize as empty documents, array elements will be
* converted to objects. php_phongo_read_preference_tags_are_valid() handles
* actual validation of the tag set structure.
*
* Auth mechanism properties must have string values, so a boolean true value
* for the "CANONICALIZE_HOST_NAME" property will be converted to "true".
*
* Note: URI options are case-insensitive, so we must iterate through the
* HashTable in order to detect options. */
static void php_phongo_manager_prep_uri_options(zval *options TSRMLS_DC) /* {{{ */
{
HashTable *ht_data;
if (Z_TYPE_P(options) != IS_ARRAY) {
return;
}
ht_data = HASH_OF(options);
#if PHP_VERSION_ID >= 70000
{
zend_string *string_key = NULL;
zend_ulong num_key = 0;
zval *option;
ZEND_HASH_FOREACH_KEY_VAL(ht_data, num_key, string_key, option) {
if (!string_key) {
continue;
}
if (!strcasecmp(ZSTR_VAL(string_key), MONGOC_URI_READPREFERENCETAGS)) {
ZVAL_DEREF(option);
SEPARATE_ZVAL_NOREF(option);
php_phongo_read_preference_prep_tagsets(option TSRMLS_CC);
continue;
}
if (!strcasecmp(ZSTR_VAL(string_key), MONGOC_URI_AUTHMECHANISMPROPERTIES)) {
ZVAL_DEREF(option);
SEPARATE_ZVAL_NOREF(option);
php_phongo_manager_prep_authmechanismproperties(option TSRMLS_CC);
continue;
}
} ZEND_HASH_FOREACH_END();
}
#else
{
HashPosition pos;
zval **option;
for (zend_hash_internal_pointer_reset_ex(ht_data, &pos);
zend_hash_get_current_data_ex(ht_data, (void **) &option, &pos) == SUCCESS;
zend_hash_move_forward_ex(ht_data, &pos)) {
char *string_key = NULL;
uint string_key_len = 0;
ulong num_key = 0;
if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(ht_data, &string_key, &string_key_len, &num_key, 0, &pos)) {
continue;
}
if (!strcasecmp(string_key, MONGOC_URI_READPREFERENCETAGS)) {
SEPARATE_ZVAL_IF_NOT_REF(option);
php_phongo_read_preference_prep_tagsets(*option TSRMLS_CC);
continue;
}
if (!strcasecmp(string_key, MONGOC_URI_AUTHMECHANISMPROPERTIES)) {
SEPARATE_ZVAL_IF_NOT_REF(option);
php_phongo_manager_prep_authmechanismproperties(*option TSRMLS_CC);
continue;
}
}
}
#endif
return;
} /* }}} */
/* {{{ proto void MongoDB\Driver\Manager::__construct([string $uri = "mongodb://127.0.0.1/"[, array $options = array()[, array $driverOptions = array()]]])
Constructs a new Manager */
static PHP_METHOD(Manager, __construct)
{
php_phongo_manager_t *intern;
zend_error_handling error_handling;
char *uri_string = NULL;
phongo_zpp_char_len uri_string_len = 0;
zval *options = NULL;
zval *driverOptions = NULL;
SUPPRESS_UNUSED_WARNING(return_value) SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_MANAGER_OBJ_P(getThis());
/* Separate the options and driverOptions zvals, since we may end up
* modifying them in php_phongo_manager_prep_uri_options() and
* php_phongo_manager_merge_context_options() below, respectively. */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!a/!a/!", &uri_string, &uri_string_len, &options, &driverOptions) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
if (options) {
php_phongo_manager_prep_uri_options(options TSRMLS_CC);
}
if (driverOptions && !php_phongo_manager_merge_context_options(driverOptions TSRMLS_CC)) {
/* Exception should already have been thrown */
return;
}
phongo_manager_init(intern, uri_string ? uri_string : PHONGO_MANAGER_URI_DEFAULT, options, driverOptions TSRMLS_CC);
if (intern->client) {
php_phongo_set_monitoring_callbacks(intern->client);
}
} /* }}} */
/* {{{ proto MongoDB\Driver\Cursor MongoDB\Driver\Manager::executeCommand(string $db, MongoDB\Driver\Command $command[, MongoDB\Driver\ReadPreference $readPreference = null])
Execute a Command */
static PHP_METHOD(Manager, executeCommand)
{
php_phongo_manager_t *intern;
char *db;
phongo_zpp_char_len db_len;
zval *command;
zval *readPreference = NULL;
DECLARE_RETURN_VALUE_USED
SUPPRESS_UNUSED_WARNING(return_value_ptr)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO|O!", &db, &db_len, &command, php_phongo_command_ce, &readPreference, php_phongo_readpreference_ce) == FAILURE) {
return;
}
intern = Z_MANAGER_OBJ_P(getThis());
phongo_execute_command(intern->client, db, command, readPreference, -1, return_value, return_value_used TSRMLS_CC);
} /* }}} */
/* {{{ proto MongoDB\Driver\Cursor MongoDB\Driver\Manager::executeQuery(string $namespace, MongoDB\Driver\Query $query[, MongoDB\Driver\ReadPreference $readPreference = null])
Execute a Query */
static PHP_METHOD(Manager, executeQuery)
{
php_phongo_manager_t *intern;
char *namespace;
phongo_zpp_char_len namespace_len;
zval *query;
zval *readPreference = NULL;
DECLARE_RETURN_VALUE_USED
SUPPRESS_UNUSED_WARNING(return_value_ptr)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO|O!", &namespace, &namespace_len, &query, php_phongo_query_ce, &readPreference, php_phongo_readpreference_ce) == FAILURE) {
return;
}
intern = Z_MANAGER_OBJ_P(getThis());
phongo_execute_query(intern->client, namespace, query, readPreference, -1, return_value, return_value_used TSRMLS_CC);
} /* }}} */
/* {{{ proto MongoDB\Driver\WriteResult MongoDB\Driver\Manager::executeBulkWrite(string $namespace, MongoDB\Driver\BulkWrite $zbulk[, MongoDB\Driver\WriteConcern $writeConcern = null])
Executes a BulkWrite (i.e. any number of insert, update, and delete ops) */
static PHP_METHOD(Manager, executeBulkWrite)
{
php_phongo_manager_t *intern;
char *namespace;
phongo_zpp_char_len namespace_len;
zval *zbulk;
zval *zwrite_concern = NULL;
php_phongo_bulkwrite_t *bulk;
DECLARE_RETURN_VALUE_USED
SUPPRESS_UNUSED_WARNING(return_value_ptr)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO|O!", &namespace, &namespace_len, &zbulk, php_phongo_bulkwrite_ce, &zwrite_concern, php_phongo_writeconcern_ce) == FAILURE) {
return;
}
intern = Z_MANAGER_OBJ_P(getThis());
bulk = Z_BULKWRITE_OBJ_P(zbulk);
phongo_execute_write(intern->client, namespace, bulk, phongo_write_concern_from_zval(zwrite_concern TSRMLS_CC), -1, return_value, return_value_used TSRMLS_CC);
} /* }}} */
/* {{{ proto MongoDB\Driver\ReadConcern MongoDB\Driver\Manager::getReadConcern()
Returns the ReadConcern associated with this Manager */
static PHP_METHOD(Manager, getReadConcern)
{
php_phongo_manager_t *intern;
DECLARE_RETURN_VALUE_USED
SUPPRESS_UNUSED_WARNING(return_value_ptr)
intern = Z_MANAGER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (return_value_used) {
phongo_readconcern_init(return_value, mongoc_client_get_read_concern(intern->client) TSRMLS_CC);
}
} /* }}} */
/* {{{ proto MongoDB\Driver\ReadPreference MongoDB\Driver\Manager::getReadPreference()
Returns the ReadPreference associated with this Manager */
static PHP_METHOD(Manager, getReadPreference)
{
php_phongo_manager_t *intern;
DECLARE_RETURN_VALUE_USED
SUPPRESS_UNUSED_WARNING(return_value_ptr)
intern = Z_MANAGER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (return_value_used) {
phongo_readpreference_init(return_value, mongoc_client_get_read_prefs(intern->client) TSRMLS_CC);
}
} /* }}} */
/* {{{ proto MongoDB\Driver\Server[] MongoDB\Driver\Manager::getServers()
Returns the Servers associated with this Manager */
static PHP_METHOD(Manager, getServers)
{
php_phongo_manager_t *intern;
mongoc_server_description_t **sds;
size_t i, n = 0;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_MANAGER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
sds = mongoc_client_get_server_descriptions(intern->client, &n);
array_init_size(return_value, n);
for (i = 0; i < n; i++) {
#if PHP_VERSION_ID >= 70000
zval obj;
phongo_server_init(&obj, intern->client, mongoc_server_description_id(sds[i]) TSRMLS_CC);
add_next_index_zval(return_value, &obj);
#else
zval *obj = NULL;
MAKE_STD_ZVAL(obj);
phongo_server_init(obj, intern->client, mongoc_server_description_id(sds[i]) TSRMLS_CC);
add_next_index_zval(return_value, obj);
#endif
}
mongoc_server_descriptions_destroy_all(sds, n);
} /* }}} */
/* {{{ proto MongoDB\Driver\WriteConcern MongoDB\Driver\Manager::getWriteConcern()
Returns the WriteConcern associated with this Manager */
static PHP_METHOD(Manager, getWriteConcern)
{
php_phongo_manager_t *intern;
DECLARE_RETURN_VALUE_USED
SUPPRESS_UNUSED_WARNING(return_value_ptr)
intern = Z_MANAGER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (return_value_used) {
phongo_writeconcern_init(return_value, mongoc_client_get_write_concern(intern->client) TSRMLS_CC);
}
} /* }}} */
/* {{{ proto MongoDB\Driver\Server MongoDB\Driver\Manager::selectServers(MongoDB\Driver\ReadPreference $readPreference)
Returns a suitable Server for the given ReadPreference */
static PHP_METHOD(Manager, selectServer)
{
php_phongo_manager_t *intern;
zval *zreadPreference = NULL;
const mongoc_read_prefs_t *readPreference;
bson_error_t error;
mongoc_server_description_t *selected_server = NULL;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_MANAGER_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zreadPreference, php_phongo_readpreference_ce) == FAILURE) {
return;
}
readPreference = phongo_read_preference_from_zval(zreadPreference TSRMLS_CC);
selected_server = mongoc_client_select_server(intern->client, false, readPreference, &error);
if (selected_server) {
phongo_server_init(return_value, intern->client, mongoc_server_description_id(selected_server) TSRMLS_CC);
mongoc_server_description_destroy(selected_server);
} else {
/* Check for connection related exceptions */
if (EG(exception)) {
return;
}
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
}
} /* }}} */
/* {{{ MongoDB\Driver\Manager function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Manager___construct, 0, 0, 0)
ZEND_ARG_INFO(0, uri)
ZEND_ARG_ARRAY_INFO(0, options, 0)
ZEND_ARG_ARRAY_INFO(0, driverOptions, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Manager_executeCommand, 0, 0, 2)
ZEND_ARG_INFO(0, db)
ZEND_ARG_OBJ_INFO(0, command, MongoDB\\Driver\\Command, 0)
ZEND_ARG_OBJ_INFO(0, readPreference, MongoDB\\Driver\\ReadPreference, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Manager_executeQuery, 0, 0, 2)
ZEND_ARG_INFO(0, namespace)
ZEND_ARG_OBJ_INFO(0, zquery, MongoDB\\Driver\\Query, 0)
ZEND_ARG_OBJ_INFO(0, readPreference, MongoDB\\Driver\\ReadPreference, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Manager_executeBulkWrite, 0, 0, 2)
ZEND_ARG_INFO(0, namespace)
ZEND_ARG_OBJ_INFO(0, zbulk, MongoDB\\Driver\\BulkWrite, 0)
ZEND_ARG_OBJ_INFO(0, writeConcern, MongoDB\\Driver\\WriteConcern, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Manager_selectServer, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, readPreference, MongoDB\\Driver\\ReadPreference, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Manager_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_manager_me[] = {
PHP_ME(Manager, __construct, ai_Manager___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Manager, executeCommand, ai_Manager_executeCommand, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Manager, executeQuery, ai_Manager_executeQuery, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Manager, executeBulkWrite, ai_Manager_executeBulkWrite, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Manager, getReadConcern, ai_Manager_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Manager, getReadPreference, ai_Manager_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Manager, getServers, ai_Manager_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Manager, getWriteConcern, ai_Manager_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Manager, selectServer, ai_Manager_selectServer, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_Manager_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\Manager object handlers */
static zend_object_handlers php_phongo_handler_manager;
static void php_phongo_manager_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_manager_t *intern = Z_OBJ_MANAGER(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->client) {
MONGOC_DEBUG("Not destroying persistent client for Manager");
intern->client = NULL;
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_manager_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_manager_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_manager_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_manager;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_manager_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_manager;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_manager_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_manager_t *intern;
mongoc_server_description_t **sds;
size_t i, n = 0;
#if PHP_VERSION_ID >= 70000
zval retval, cluster;
#else
zval retval = zval_used_for_init;
zval *cluster = NULL;
#endif
*is_temp = 1;
intern = Z_MANAGER_OBJ_P(object);
array_init_size(&retval, 2);
ADD_ASSOC_STRING(&retval, "uri", mongoc_uri_get_string(mongoc_client_get_uri(intern->client)));
sds = mongoc_client_get_server_descriptions(intern->client, &n);
#if PHP_VERSION_ID >= 70000
array_init_size(&cluster, n);
for (i = 0; i < n; i++) {
zval obj;
php_phongo_server_to_zval(&obj, sds[i]);
add_next_index_zval(&cluster, &obj);
}
ADD_ASSOC_ZVAL_EX(&retval, "cluster", &cluster);
#else
MAKE_STD_ZVAL(cluster);
array_init_size(cluster, n);
for (i = 0; i < n; i++) {
zval *obj = NULL;
MAKE_STD_ZVAL(obj);
php_phongo_server_to_zval(obj, sds[i]);
add_next_index_zval(cluster, obj);
}
ADD_ASSOC_ZVAL_EX(&retval, "cluster", cluster);
#endif
mongoc_server_descriptions_destroy_all(sds, n);
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_manager_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "Manager", php_phongo_manager_me);
php_phongo_manager_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_manager_ce->create_object = php_phongo_manager_create_object;
PHONGO_CE_FINAL(php_phongo_manager_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_manager_ce);
memcpy(&php_phongo_handler_manager, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_manager.get_debug_info = php_phongo_manager_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_manager.free_obj = php_phongo_manager_free_object;
php_phongo_handler_manager.offset = XtOffsetOf(php_phongo_manager_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Query.c 0000664 0001750 0001750 00000044021 13210321137 016323 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "php_array_api.h"
#include "phongo_compat.h"
#include "php_phongo.h"
#include "php_bson.h"
zend_class_entry *php_phongo_query_ce;
/* Appends a string field into the BSON options. Returns true on success;
* otherwise, false is returned and an exception is thrown. */
static bool php_phongo_query_opts_append_string(bson_t *opts, const char *opts_key, zval *zarr, const char *zarr_key TSRMLS_DC) /* {{{ */
{
zval *value = php_array_fetch(zarr, zarr_key);
if (Z_TYPE_P(value) != IS_STRING) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"%s\" %s to be string, %s given", zarr_key, zarr_key[0] == '$' ? "modifier" : "option", zend_get_type_by_const(Z_TYPE_P(value)));
return false;
}
if (!bson_append_utf8(opts, opts_key, strlen(opts_key), Z_STRVAL_P(value), Z_STRLEN_P(value))) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", opts_key);
return false;
}
return true;
} /* }}} */
/* Appends a document field for the given opts document and key. Returns true on
* success; otherwise, false is returned and an exception is thrown. */
static bool php_phongo_query_opts_append_document(bson_t *opts, const char *opts_key, zval *zarr, const char *zarr_key TSRMLS_DC) /* {{{ */
{
zval *value = php_array_fetch(zarr, zarr_key);
bson_t b = BSON_INITIALIZER;
if (Z_TYPE_P(value) != IS_OBJECT && Z_TYPE_P(value) != IS_ARRAY) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"%s\" %s to be array or object, %s given", zarr_key, zarr_key[0] == '$' ? "modifier" : "option", zend_get_type_by_const(Z_TYPE_P(value)));
return false;
}
php_phongo_zval_to_bson(value, PHONGO_BSON_NONE, &b, NULL TSRMLS_CC);
if (EG(exception)) {
bson_destroy(&b);
return false;
}
if (!bson_validate(&b, BSON_VALIDATE_EMPTY_KEYS, NULL)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Cannot use empty keys in \"%s\" %s", zarr_key, zarr_key[0] == '$' ? "modifier" : "option");
bson_destroy(&b);
return false;
}
if (!BSON_APPEND_DOCUMENT(opts, opts_key, &b)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", opts_key);
bson_destroy(&b);
return false;
}
bson_destroy(&b);
return true;
} /* }}} */
#define PHONGO_QUERY_OPT_BOOL(opt, zarr, key) \
if ((zarr) && php_array_existsc((zarr), (key))) { \
if (!BSON_APPEND_BOOL(intern->opts, (opt), php_array_fetchc_bool((zarr), (key)))) { \
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", (opt)); \
return false; \
} \
}
#define PHONGO_QUERY_OPT_DOCUMENT(opt, zarr, key) \
if ((zarr) && php_array_existsc((zarr), (key))) { \
if (!php_phongo_query_opts_append_document(intern->opts, (opt), (zarr), (key) TSRMLS_CC)) { \
return false; \
} \
}
/* Note: handling of integer options will depend on SIZEOF_ZEND_LONG and we
* are not converting strings to 64-bit integers for 32-bit platforms. */
#define PHONGO_QUERY_OPT_INT64(opt, zarr, key) \
if ((zarr) && php_array_existsc((zarr), (key))) { \
if (!BSON_APPEND_INT64(intern->opts, (opt), php_array_fetchc_long((zarr), (key)))) { \
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", (opt)); \
return false; \
} \
}
#define PHONGO_QUERY_OPT_STRING(opt, zarr, key) \
if ((zarr) && php_array_existsc((zarr), (key))) { \
if (!php_phongo_query_opts_append_string(intern->opts, (opt), (zarr), (key) TSRMLS_CC)) { \
return false; \
} \
}
/* Initialize the "hint" option. Returns true on success; otherwise, false is
* returned and an exception is thrown.
*
* The "hint" option (or "$hint" modifier) must be a string or document. Check
* for both types and merge into BSON options accordingly. */
static bool php_phongo_query_init_hint(php_phongo_query_t *intern, zval *options, zval *modifiers TSRMLS_DC) /* {{{ */
{
/* The "hint" option (or "$hint" modifier) must be a string or document.
* Check for both types and merge into BSON options accordingly. */
if (php_array_existsc(options, "hint")) {
zend_uchar type = Z_TYPE_P(php_array_fetchc(options, "hint"));
if (type == IS_STRING) {
PHONGO_QUERY_OPT_STRING("hint", options, "hint");
} else if (type == IS_OBJECT || type == IS_ARRAY) {
PHONGO_QUERY_OPT_DOCUMENT("hint", options, "hint");
} else {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"hint\" option to be string, array, or object, %s given", zend_get_type_by_const(type));
return false;
}
} else if (modifiers && php_array_existsc(modifiers, "$hint")) {
zend_uchar type = Z_TYPE_P(php_array_fetchc(modifiers, "$hint"));
if (type == IS_STRING) {
PHONGO_QUERY_OPT_STRING("hint", modifiers, "$hint");
} else if (type == IS_OBJECT || type == IS_ARRAY) {
PHONGO_QUERY_OPT_DOCUMENT("hint", modifiers, "$hint");
} else {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"$hint\" modifier to be string, array, or object, %s given", zend_get_type_by_const(type));
return false;
}
}
return true;
} /* }}} */
/* Initialize the "limit" and "singleBatch" options. Returns true on success;
* otherwise, false is returned and an exception is thrown.
*
* mongoc_collection_find_with_opts() requires a non-negative limit. For
* backwards compatibility, a negative limit should be set as a positive value
* and default singleBatch to true. */
static bool php_phongo_query_init_limit_and_singlebatch(php_phongo_query_t *intern, zval *options TSRMLS_DC) /* {{{ */
{
if (php_array_existsc(options, "limit") && php_array_fetchc_long(options, "limit") < 0) {
phongo_long limit = php_array_fetchc_long(options, "limit");
if (!BSON_APPEND_INT64(intern->opts, "limit", -limit)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"limit\" option");
return false;
}
if (php_array_existsc(options, "singleBatch") && !php_array_fetchc_bool(options, "singleBatch")) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Negative \"limit\" option conflicts with false \"singleBatch\" option");
return false;
} else {
if (!BSON_APPEND_BOOL(intern->opts, "singleBatch", true)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"singleBatch\" option");
return false;
}
}
} else {
PHONGO_QUERY_OPT_INT64("limit", options, "limit");
PHONGO_QUERY_OPT_BOOL("singleBatch", options, "singleBatch");
}
return true;
} /* }}} */
/* Initialize the "readConcern" option. Returns true on success; otherwise,
* false is returned and an exception is thrown.
*
* The "readConcern" option should be a MongoDB\Driver\ReadConcern instance,
* which must be converted to a mongoc_read_concern_t. */
static bool php_phongo_query_init_readconcern(php_phongo_query_t *intern, zval *options TSRMLS_DC) /* {{{ */
{
if (php_array_existsc(options, "readConcern")) {
zval *read_concern = php_array_fetchc(options, "readConcern");
if (Z_TYPE_P(read_concern) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(read_concern), php_phongo_readconcern_ce TSRMLS_CC)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"readConcern\" option to be %s, %s given", ZSTR_VAL(php_phongo_readconcern_ce->name), zend_get_type_by_const(Z_TYPE_P(read_concern)));
return false;
}
intern->read_concern = mongoc_read_concern_copy(phongo_read_concern_from_zval(read_concern TSRMLS_CC));
}
return true;
} /* }}} */
/* Initialize the "maxAwaitTimeMS" option. Returns true on success; otherwise,
* false is returned and an exception is thrown.
*
* The "maxAwaitTimeMS" option is assigned to the cursor after query execution
* via mongoc_cursor_set_max_await_time_ms(). */
static bool php_phongo_query_init_max_await_time_ms(php_phongo_query_t *intern, zval *options TSRMLS_DC) /* {{{ */
{
if (php_array_existsc(options, "maxAwaitTimeMS")) {
int64_t max_await_time_ms = php_array_fetchc_long(options, "maxAwaitTimeMS");
if (max_await_time_ms < 0) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"maxAwaitTimeMS\" option to be >= 0, %" PRId64 " given", max_await_time_ms);
return false;
}
if (max_await_time_ms > UINT32_MAX) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"maxAwaitTimeMS\" option to be <= %" PRIu32 ", %" PRId64 " given", UINT32_MAX, max_await_time_ms);
return false;
}
intern->max_await_time_ms = (uint32_t) max_await_time_ms;
}
return true;
} /* }}} */
/* Initializes the php_phongo_query_t from filter and options arguments. This
* function will fall back to a modifier in the absence of a top-level option
* (where applicable). */
static bool php_phongo_query_init(php_phongo_query_t *intern, zval *filter, zval *options TSRMLS_DC) /* {{{ */
{
zval *modifiers = NULL;
intern->filter = bson_new();
intern->opts = bson_new();
php_phongo_zval_to_bson(filter, PHONGO_BSON_NONE, intern->filter, NULL TSRMLS_CC);
/* Note: if any exceptions are thrown, we can simply return as PHP will
* invoke php_phongo_query_free_object to destruct the object. */
if (EG(exception)) {
return false;
}
if (!bson_validate(intern->filter, BSON_VALIDATE_EMPTY_KEYS, NULL)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Cannot use empty keys in filter document");
return false;
}
if (!options) {
return true;
}
if (php_array_existsc(options, "modifiers")) {
modifiers = php_array_fetchc(options, "modifiers");
if (Z_TYPE_P(modifiers) != IS_ARRAY) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"modifiers\" option to be array, %s given", zend_get_type_by_const(Z_TYPE_P(modifiers)));
return false;
}
}
PHONGO_QUERY_OPT_BOOL("allowPartialResults", options, "allowPartialResults")
else PHONGO_QUERY_OPT_BOOL("allowPartialResults", options, "partial");
PHONGO_QUERY_OPT_BOOL("awaitData", options, "awaitData");
PHONGO_QUERY_OPT_INT64("batchSize", options, "batchSize");
PHONGO_QUERY_OPT_DOCUMENT("collation", options, "collation");
PHONGO_QUERY_OPT_STRING("comment", options, "comment")
else PHONGO_QUERY_OPT_STRING("comment", modifiers, "$comment");
PHONGO_QUERY_OPT_BOOL("exhaust", options, "exhaust");
PHONGO_QUERY_OPT_DOCUMENT("max", options, "max")
else PHONGO_QUERY_OPT_DOCUMENT("max", modifiers, "$max");
PHONGO_QUERY_OPT_INT64("maxScan", options, "maxScan")
else PHONGO_QUERY_OPT_INT64("maxScan", modifiers, "$maxScan");
PHONGO_QUERY_OPT_INT64("maxTimeMS", options, "maxTimeMS")
else PHONGO_QUERY_OPT_INT64("maxTimeMS", modifiers, "$maxTimeMS");
PHONGO_QUERY_OPT_DOCUMENT("min", options, "min")
else PHONGO_QUERY_OPT_DOCUMENT("min", modifiers, "$min");
PHONGO_QUERY_OPT_BOOL("noCursorTimeout", options, "noCursorTimeout");
PHONGO_QUERY_OPT_BOOL("oplogReplay", options, "oplogReplay");
PHONGO_QUERY_OPT_DOCUMENT("projection", options, "projection");
PHONGO_QUERY_OPT_BOOL("returnKey", options, "returnKey")
else PHONGO_QUERY_OPT_BOOL("returnKey", modifiers, "$returnKey");
PHONGO_QUERY_OPT_BOOL("showRecordId", options, "showRecordId")
else PHONGO_QUERY_OPT_BOOL("showRecordId", modifiers, "$showDiskLoc");
PHONGO_QUERY_OPT_INT64("skip", options, "skip");
PHONGO_QUERY_OPT_DOCUMENT("sort", options, "sort")
else PHONGO_QUERY_OPT_DOCUMENT("sort", modifiers, "$orderby");
PHONGO_QUERY_OPT_BOOL("snapshot", options, "snapshot")
else PHONGO_QUERY_OPT_BOOL("snapshot", modifiers, "$snapshot");
PHONGO_QUERY_OPT_BOOL("tailable", options, "tailable");
/* The "$explain" modifier should be converted to an "explain" option, which
* libmongoc will later convert back to a modifier for the OP_QUERY code
* path. This modifier will be ignored for the find command code path. */
PHONGO_QUERY_OPT_BOOL("explain", modifiers, "$explain");
if (!php_phongo_query_init_hint(intern, options, modifiers TSRMLS_CC)) {
return false;
}
if (!php_phongo_query_init_limit_and_singlebatch(intern, options TSRMLS_CC)) {
return false;
}
if (!php_phongo_query_init_readconcern(intern, options TSRMLS_CC)) {
return false;
}
if (!php_phongo_query_init_max_await_time_ms(intern, options TSRMLS_CC)) {
return false;
}
return true;
} /* }}} */
#undef PHONGO_QUERY_OPT_BOOL
#undef PHONGO_QUERY_OPT_DOCUMENT
#undef PHONGO_QUERY_OPT_INT64
#undef PHONGO_QUERY_OPT_STRING
/* {{{ proto void MongoDB\Driver\Query::__construct(array|object $filter[, array $options = array()])
Constructs a new Query */
static PHP_METHOD(Query, __construct)
{
php_phongo_query_t *intern;
zend_error_handling error_handling;
zval *filter;
zval *options = NULL;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value) SUPPRESS_UNUSED_WARNING(return_value_used)
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_QUERY_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "A|a!", &filter, &options) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
php_phongo_query_init(intern, filter, options TSRMLS_CC);
} /* }}} */
/* {{{ MongoDB\Driver\Query function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Query___construct, 0, 0, 1)
ZEND_ARG_INFO(0, filter)
ZEND_ARG_ARRAY_INFO(0, options, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Query_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_query_me[] = {
PHP_ME(Query, __construct, ai_Query___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_Query_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\Query object handlers */
static zend_object_handlers php_phongo_handler_query;
static void php_phongo_query_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_query_t *intern = Z_OBJ_QUERY(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->filter) {
bson_clear(&intern->filter);
}
if (intern->opts) {
bson_clear(&intern->opts);
}
if (intern->read_concern) {
mongoc_read_concern_destroy(intern->read_concern);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_query_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_query_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_query_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_query;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_query_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_query;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_query_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_query_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
*is_temp = 1;
intern = Z_QUERY_OBJ_P(object);
array_init_size(&retval, 3);
/* Avoid using PHONGO_TYPEMAP_NATIVE_ARRAY for decoding filter and opts
* documents so that users can differentiate BSON arrays and documents. */
if (intern->filter) {
#if PHP_VERSION_ID >= 70000
zval zv;
#else
zval *zv;
#endif
php_phongo_bson_to_zval(bson_get_data(intern->filter), intern->filter->len, &zv);
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "filter", &zv);
#else
ADD_ASSOC_ZVAL_EX(&retval, "filter", zv);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "filter");
}
if (intern->opts) {
#if PHP_VERSION_ID >= 70000
zval zv;
#else
zval *zv;
#endif
php_phongo_bson_to_zval(bson_get_data(intern->opts), intern->opts->len, &zv);
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "options", &zv);
#else
ADD_ASSOC_ZVAL_EX(&retval, "options", zv);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "options");
}
if (intern->read_concern) {
#if PHP_VERSION_ID >= 70000
zval read_concern;
php_phongo_read_concern_to_zval(&read_concern, intern->read_concern);
ADD_ASSOC_ZVAL_EX(&retval, "readConcern", &read_concern);
#else
zval *read_concern = NULL;
MAKE_STD_ZVAL(read_concern);
php_phongo_read_concern_to_zval(read_concern, intern->read_concern);
ADD_ASSOC_ZVAL_EX(&retval, "readConcern", read_concern);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "readConcern");
}
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_query_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "Query", php_phongo_query_me);
php_phongo_query_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_query_ce->create_object = php_phongo_query_create_object;
PHONGO_CE_FINAL(php_phongo_query_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_query_ce);
memcpy(&php_phongo_handler_query, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_query.get_debug_info = php_phongo_query_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_query.free_obj = php_phongo_query_free_object;
php_phongo_handler_query.offset = XtOffsetOf(php_phongo_query_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/ReadConcern.c 0000664 0001750 0001750 00000015672 13210321137 017413 0 ustar jmikola jmikola /*
* Copyright 2015-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_readconcern_ce;
/* {{{ proto void MongoDB\Driver\ReadConcern::__construct([string $level])
Constructs a new ReadConcern */
static PHP_METHOD(ReadConcern, __construct)
{
php_phongo_readconcern_t *intern;
zend_error_handling error_handling;
char *level = NULL;
phongo_zpp_char_len level_len = 0;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value) SUPPRESS_UNUSED_WARNING(return_value_used)
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_READCONCERN_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &level, &level_len) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
intern->read_concern = mongoc_read_concern_new();
if (level) {
mongoc_read_concern_set_level(intern->read_concern, level);
}
} /* }}} */
/* {{{ proto string|null MongoDB\Driver\ReadConcern::getLevel()
Returns the ReadConcern "level" option */
static PHP_METHOD(ReadConcern, getLevel)
{
php_phongo_readconcern_t *intern;
const char *level;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_READCONCERN_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
level = mongoc_read_concern_get_level(intern->read_concern);
if (level) {
PHONGO_RETURN_STRING(level);
}
RETURN_NULL();
} /* }}} */
/* {{{ proto boolean MongoDB\Driver\ReadConcern::isDefault()
Returns whether the read concern has not been modified (i.e. constructed
without a level or from a Manager with no read concern URI options). */
static PHP_METHOD(ReadConcern, isDefault)
{
php_phongo_readconcern_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_READCONCERN_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_BOOL(mongoc_read_concern_is_default(intern->read_concern));
} /* }}} */
/* {{{ proto array MongoDB\Driver\ReadConcern::bsonSerialize()
*/
static PHP_METHOD(ReadConcern, bsonSerialize)
{
const mongoc_read_concern_t *read_concern = phongo_read_concern_from_zval(getThis() TSRMLS_CC);
if (zend_parse_parameters_none() == FAILURE) {
return;
}
php_phongo_read_concern_to_zval(return_value, read_concern);
convert_to_object(return_value);
} /* }}} */
/* {{{ MongoDB\Driver\ReadConcern function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_ReadConcern___construct, 0, 0, 0)
ZEND_ARG_INFO(0, level)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_ReadConcern_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_readconcern_me[] = {
PHP_ME(ReadConcern, __construct, ai_ReadConcern___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ReadConcern, getLevel, ai_ReadConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ReadConcern, isDefault, ai_ReadConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ReadConcern, bsonSerialize, ai_ReadConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\ReadConcern object handlers */
static zend_object_handlers php_phongo_handler_readconcern;
static void php_phongo_readconcern_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_readconcern_t *intern = Z_OBJ_READCONCERN(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->read_concern) {
mongoc_read_concern_destroy(intern->read_concern);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_readconcern_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_readconcern_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_readconcern_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_readconcern;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_readconcern_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_readconcern;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_readconcern_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
const mongoc_read_concern_t *read_concern = phongo_read_concern_from_zval(object TSRMLS_CC);
*is_temp = 1;
php_phongo_read_concern_to_zval(&retval, read_concern);
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "ReadConcern", php_phongo_readconcern_me);
php_phongo_readconcern_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_readconcern_ce->create_object = php_phongo_readconcern_create_object;
PHONGO_CE_FINAL(php_phongo_readconcern_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_readconcern_ce);
zend_class_implements(php_phongo_readconcern_ce TSRMLS_CC, 1, php_phongo_serializable_ce);
memcpy(&php_phongo_handler_readconcern, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_readconcern.get_debug_info = php_phongo_readconcern_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_readconcern.free_obj = php_phongo_readconcern_free_object;
php_phongo_handler_readconcern.offset = XtOffsetOf(php_phongo_readconcern_t, std);
#endif
zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("LOCAL"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_LOCAL) TSRMLS_CC);
zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("MAJORITY"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_MAJORITY) TSRMLS_CC);
zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("LINEARIZABLE"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_LINEARIZABLE) TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/ReadPreference.c 0000664 0001750 0001750 00000030317 13210321137 020073 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "php_array_api.h"
#include "phongo_compat.h"
#include "php_phongo.h"
#include "php_bson.h"
zend_class_entry *php_phongo_readpreference_ce;
/* {{{ proto void MongoDB\Driver\ReadPreference::__construct(int|string $mode[, array $tagSets = array()[, array $options = array()]])
Constructs a new ReadPreference */
static PHP_METHOD(ReadPreference, __construct)
{
php_phongo_readpreference_t *intern;
zend_error_handling error_handling;
zval *mode;
zval *tagSets = NULL;
zval *options = NULL;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value) SUPPRESS_UNUSED_WARNING(return_value_used)
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_READPREFERENCE_OBJ_P(getThis());
/* Separate the tagSets zval, since we may end up modifying it in
* php_phongo_read_preference_prep_tagsets() below. */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|a/!a!", &mode, &tagSets, &options) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
if (Z_TYPE_P(mode) == IS_LONG) {
switch(Z_LVAL_P(mode)) {
case MONGOC_READ_PRIMARY:
case MONGOC_READ_SECONDARY:
case MONGOC_READ_PRIMARY_PREFERRED:
case MONGOC_READ_SECONDARY_PREFERRED:
case MONGOC_READ_NEAREST:
intern->read_preference = mongoc_read_prefs_new(Z_LVAL_P(mode));
break;
default:
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Invalid mode: %" PHONGO_LONG_FORMAT, Z_LVAL_P(mode));
return;
}
} else if (Z_TYPE_P(mode) == IS_STRING) {
if (strcasecmp(Z_STRVAL_P(mode), "primary") == 0) {
intern->read_preference = mongoc_read_prefs_new(MONGOC_READ_PRIMARY);
} else if (strcasecmp(Z_STRVAL_P(mode), "primaryPreferred") == 0) {
intern->read_preference = mongoc_read_prefs_new(MONGOC_READ_PRIMARY_PREFERRED);
} else if (strcasecmp(Z_STRVAL_P(mode), "secondary") == 0) {
intern->read_preference = mongoc_read_prefs_new(MONGOC_READ_SECONDARY);
} else if (strcasecmp(Z_STRVAL_P(mode), "secondaryPreferred") == 0) {
intern->read_preference = mongoc_read_prefs_new(MONGOC_READ_SECONDARY_PREFERRED);
} else if (strcasecmp(Z_STRVAL_P(mode), "nearest") == 0) {
intern->read_preference = mongoc_read_prefs_new(MONGOC_READ_NEAREST);
} else {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Invalid mode: '%s'", Z_STRVAL_P(mode));
return;
}
} else {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected mode to be integer or string, %s given", zend_get_type_by_const(Z_TYPE_P(mode)));
return;
}
if (tagSets) {
bson_t *tags = bson_new();
php_phongo_read_preference_prep_tagsets(tagSets TSRMLS_CC);
php_phongo_zval_to_bson(tagSets, PHONGO_BSON_NONE, (bson_t *)tags, NULL TSRMLS_CC);
if (!php_phongo_read_preference_tags_are_valid(tags)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "tagSets must be an array of zero or more documents");
bson_destroy(tags);
return;
}
if (!bson_empty(tags) && (mongoc_read_prefs_get_mode(intern->read_preference) == MONGOC_READ_PRIMARY)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "tagSets may not be used with primary mode");
bson_destroy(tags);
return;
}
mongoc_read_prefs_set_tags(intern->read_preference, tags);
bson_destroy(tags);
}
if (options && php_array_exists(options, "maxStalenessSeconds")) {
phongo_long maxStalenessSeconds = php_array_fetchc_long(options, "maxStalenessSeconds");
if (maxStalenessSeconds != MONGOC_NO_MAX_STALENESS) {
if (maxStalenessSeconds < MONGOC_SMALLEST_MAX_STALENESS_SECONDS) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected maxStalenessSeconds to be >= %d, %" PHONGO_LONG_FORMAT " given", MONGOC_SMALLEST_MAX_STALENESS_SECONDS, maxStalenessSeconds);
return;
}
if (maxStalenessSeconds > INT32_MAX) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected maxStalenessSeconds to be <= %" PRId32 ", %" PHONGO_LONG_FORMAT " given", INT32_MAX, maxStalenessSeconds);
return;
}
if (mongoc_read_prefs_get_mode(intern->read_preference) == MONGOC_READ_PRIMARY) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "maxStalenessSeconds may not be used with primary mode");
return;
}
}
mongoc_read_prefs_set_max_staleness_seconds(intern->read_preference, maxStalenessSeconds);
}
if (!mongoc_read_prefs_is_valid(intern->read_preference)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Read preference is not valid");
return;
}
} /* }}} */
/* {{{ proto integer MongoDB\Driver\ReadPreference::getMaxStalenessSeconds()
Returns the ReadPreference maxStalenessSeconds value */
static PHP_METHOD(ReadPreference, getMaxStalenessSeconds)
{
php_phongo_readpreference_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_READPREFERENCE_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(mongoc_read_prefs_get_max_staleness_seconds(intern->read_preference));
} /* }}} */
/* {{{ proto integer MongoDB\Driver\ReadPreference::getMode()
Returns the ReadPreference mode */
static PHP_METHOD(ReadPreference, getMode)
{
php_phongo_readpreference_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_READPREFERENCE_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(mongoc_read_prefs_get_mode(intern->read_preference));
} /* }}} */
/* {{{ proto array MongoDB\Driver\ReadPreference::getTagSets()
Returns the ReadPreference tag sets */
static PHP_METHOD(ReadPreference, getTagSets)
{
php_phongo_readpreference_t *intern;
const bson_t *tags;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_READPREFERENCE_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
tags = mongoc_read_prefs_get_tags(intern->read_preference);
if (tags->len) {
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
/* Use native arrays for debugging output */
state.map.root_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
state.map.document_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state);
#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
RETURN_ZVAL(state.zchild, 0, 1);
#endif
} else {
RETURN_NULL();
}
} /* }}} */
/* {{{ proto array MongoDB\Driver\ReadPreference::bsonSerialize()
*/
static PHP_METHOD(ReadPreference, bsonSerialize)
{
const mongoc_read_prefs_t *read_preference = phongo_read_preference_from_zval(getThis() TSRMLS_CC);
if (zend_parse_parameters_none() == FAILURE) {
return;
}
php_phongo_read_preference_to_zval(return_value, read_preference);
convert_to_object(return_value);
} /* }}} */
/* {{{ MongoDB\Driver\ReadPreference function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_ReadPreference___construct, 0, 0, 1)
ZEND_ARG_INFO(0, mode)
ZEND_ARG_ARRAY_INFO(0, tagSets, 1)
ZEND_ARG_ARRAY_INFO(0, options, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_ReadPreference_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_readpreference_me[] = {
PHP_ME(ReadPreference, __construct, ai_ReadPreference___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ReadPreference, getMaxStalenessSeconds, ai_ReadPreference_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ReadPreference, getMode, ai_ReadPreference_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ReadPreference, getTagSets, ai_ReadPreference_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(ReadPreference, bsonSerialize, ai_ReadPreference_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\ReadPreference object handlers */
static zend_object_handlers php_phongo_handler_readpreference;
static void php_phongo_readpreference_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_readpreference_t *intern = Z_OBJ_READPREFERENCE(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->read_preference) {
mongoc_read_prefs_destroy(intern->read_preference);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_readpreference_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_readpreference_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_readpreference_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_readpreference;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_readpreference_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_readpreference;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_readpreference_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
const mongoc_read_prefs_t *read_prefs = phongo_read_preference_from_zval(object TSRMLS_CC);
*is_temp = 1;
php_phongo_read_preference_to_zval(&retval, read_prefs);
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_readpreference_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "ReadPreference", php_phongo_readpreference_me);
php_phongo_readpreference_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_readpreference_ce->create_object = php_phongo_readpreference_create_object;
PHONGO_CE_FINAL(php_phongo_readpreference_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_readpreference_ce);
zend_class_implements(php_phongo_readpreference_ce TSRMLS_CC, 1, php_phongo_serializable_ce);
memcpy(&php_phongo_handler_readpreference, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_readpreference.get_debug_info = php_phongo_readpreference_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_readpreference.free_obj = php_phongo_readpreference_free_object;
php_phongo_handler_readpreference.offset = XtOffsetOf(php_phongo_readpreference_t, std);
#endif
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_PRIMARY"), MONGOC_READ_PRIMARY TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_PRIMARY_PREFERRED"), MONGOC_READ_PRIMARY_PREFERRED TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_SECONDARY"), MONGOC_READ_SECONDARY TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_SECONDARY_PREFERRED"), MONGOC_READ_SECONDARY_PREFERRED TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_NEAREST"), MONGOC_READ_NEAREST TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("NO_MAX_STALENESS"), MONGOC_NO_MAX_STALENESS TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("SMALLEST_MAX_STALENESS_SECONDS"), MONGOC_SMALLEST_MAX_STALENESS_SECONDS TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/Server.c 0000664 0001750 0001750 00000047526 13210321137 016501 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
#include "php_bson.h"
zend_class_entry *php_phongo_server_ce;
/* {{{ proto MongoDB\Driver\Cursor MongoDB\Driver\Server::executeCommand(string $db, MongoDB\Driver\Command $command[, MongoDB\Driver\ReadPreference $readPreference = null]))
Executes a Command on this Server */
static PHP_METHOD(Server, executeCommand)
{
php_phongo_server_t *intern;
char *db;
phongo_zpp_char_len db_len;
zval *command;
zval *readPreference = NULL;
DECLARE_RETURN_VALUE_USED
SUPPRESS_UNUSED_WARNING(return_value_ptr)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO|O!", &db, &db_len, &command, php_phongo_command_ce, &readPreference, php_phongo_readpreference_ce) == FAILURE) {
return;
}
phongo_execute_command(intern->client, db, command, readPreference, intern->server_id, return_value, return_value_used TSRMLS_CC);
} /* }}} */
/* {{{ proto MongoDB\Driver\Cursor MongoDB\Driver\Server::executeQuery(string $namespace, MongoDB\Driver\Query $query[, MongoDB\Driver\ReadPreference $readPreference = null]))
Executes a Query on this Server */
static PHP_METHOD(Server, executeQuery)
{
php_phongo_server_t *intern;
char *namespace;
phongo_zpp_char_len namespace_len;
zval *query;
zval *readPreference = NULL;
DECLARE_RETURN_VALUE_USED
SUPPRESS_UNUSED_WARNING(return_value_ptr)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO|O!", &namespace, &namespace_len, &query, php_phongo_query_ce, &readPreference, php_phongo_readpreference_ce) == FAILURE) {
return;
}
phongo_execute_query(intern->client, namespace, query, readPreference, intern->server_id, return_value, return_value_used TSRMLS_CC);
} /* }}} */
/* {{{ proto MongoDB\Driver\WriteResult MongoDB\Driver\Server::executeBulkWrite(string $namespace, MongoDB\Driver\BulkWrite $zbulk[, MongoDB\Driver\WriteConcern $writeConcern = null])
Executes a BulkWrite (i.e. any number of insert, update, and delete ops) on
this Server */
static PHP_METHOD(Server, executeBulkWrite)
{
php_phongo_server_t *intern;
char *namespace;
phongo_zpp_char_len namespace_len;
zval *zbulk;
zval *zwrite_concern = NULL;
php_phongo_bulkwrite_t *bulk;
DECLARE_RETURN_VALUE_USED
SUPPRESS_UNUSED_WARNING(return_value_ptr)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO|O!", &namespace, &namespace_len, &zbulk, php_phongo_bulkwrite_ce, &zwrite_concern, php_phongo_writeconcern_ce) == FAILURE) {
return;
}
bulk = Z_BULKWRITE_OBJ_P(zbulk);
phongo_execute_write(intern->client, namespace, bulk, phongo_write_concern_from_zval(zwrite_concern TSRMLS_CC), intern->server_id, return_value, return_value_used TSRMLS_CC);
} /* }}} */
/* {{{ proto string MongoDB\Driver\Server::getHost()
Returns the hostname for this Server */
static PHP_METHOD(Server, getHost)
{
php_phongo_server_t *intern;
mongoc_server_description_t *sd;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
PHONGO_RETVAL_STRING(mongoc_server_description_host(sd)->host);
mongoc_server_description_destroy(sd);
return;
}
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
} /* }}} */
/* {{{ proto array MongoDB\Driver\Server::getTags()
Returns the currently configured tags for this Server */
static PHP_METHOD(Server, getTags)
{
php_phongo_server_t *intern;
mongoc_server_description_t *sd;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
const bson_t *is_master = mongoc_server_description_ismaster(sd);
bson_iter_t iter;
if (bson_iter_init_find(&iter, is_master, "tags") && BSON_ITER_HOLDS_DOCUMENT(&iter)) {
const uint8_t *bytes;
uint32_t len;
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
state.map.root_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
state.map.document_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
bson_iter_document(&iter, &len, &bytes);
if (!php_phongo_bson_to_zval_ex(bytes, len, &state)) {
/* Exception should already have been thrown */
zval_ptr_dtor(&state.zchild);
mongoc_server_description_destroy(sd);
return;
}
mongoc_server_description_destroy(sd);
#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
RETURN_ZVAL(state.zchild, 0, 1);
#endif
}
array_init(return_value);
mongoc_server_description_destroy(sd);
return;
}
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
} /* }}} */
/* {{{ proto array MongoDB\Driver\Server::getInfo()
Returns the last isMaster result document for this Server */
static PHP_METHOD(Server, getInfo)
{
php_phongo_server_t *intern;
mongoc_server_description_t *sd;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
const bson_t *is_master = mongoc_server_description_ismaster(sd);
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
state.map.root_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
state.map.document_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
if (!php_phongo_bson_to_zval_ex(bson_get_data(is_master), is_master->len, &state)) {
/* Exception should already have been thrown */
zval_ptr_dtor(&state.zchild);
mongoc_server_description_destroy(sd);
return;
}
mongoc_server_description_destroy(sd);
#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
RETURN_ZVAL(state.zchild, 0, 1);
#endif
}
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
} /* }}} */
/* {{{ proto integer MongoDB\Driver\Server::getLatency()
Returns the last measured latency for this Server */
static PHP_METHOD(Server, getLatency)
{
php_phongo_server_t *intern;
mongoc_server_description_t *sd;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
RETVAL_LONG((phongo_long) mongoc_server_description_round_trip_time(sd));
mongoc_server_description_destroy(sd);
return;
}
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
} /* }}} */
/* {{{ proto integer MongoDB\Driver\Server::getPort()
Returns the port for this Server */
static PHP_METHOD(Server, getPort)
{
php_phongo_server_t *intern;
mongoc_server_description_t *sd;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
RETVAL_LONG(mongoc_server_description_host(sd)->port);
mongoc_server_description_destroy(sd);
return;
}
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
} /* }}} */
/* {{{ proto integer MongoDB\Driver\Server::getType()
Returns the node type of this Server */
static PHP_METHOD(Server, getType)
{
php_phongo_server_t *intern;
mongoc_server_description_t *sd;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
RETVAL_LONG(php_phongo_server_description_type(sd));
mongoc_server_description_destroy(sd);
return;
}
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
} /* }}} */
/* {{{ proto boolean MongoDB\Driver\Server::isPrimary()
Returns whether this Server is a primary member of a replica set */
static PHP_METHOD(Server, isPrimary)
{
php_phongo_server_t *intern;
mongoc_server_description_t *sd;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
RETVAL_BOOL(!strcmp(mongoc_server_description_type(sd), php_phongo_server_description_type_map[PHONGO_SERVER_RS_PRIMARY].name));
mongoc_server_description_destroy(sd);
return;
}
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
} /* }}} */
/* {{{ proto boolean MongoDB\Driver\Server::isSecondary()
Returns whether this Server is a secondary member of a replica set */
static PHP_METHOD(Server, isSecondary)
{
php_phongo_server_t *intern;
mongoc_server_description_t *sd;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
RETVAL_BOOL(!strcmp(mongoc_server_description_type(sd), php_phongo_server_description_type_map[PHONGO_SERVER_RS_SECONDARY].name));
mongoc_server_description_destroy(sd);
return;
}
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
} /* }}} */
/* {{{ proto boolean MongoDB\Driver\Server::isArbiter()
Returns whether this Server is an arbiter member of a replica set */
static PHP_METHOD(Server, isArbiter)
{
php_phongo_server_t *intern;
mongoc_server_description_t *sd;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
RETVAL_BOOL(!strcmp(mongoc_server_description_type(sd), php_phongo_server_description_type_map[PHONGO_SERVER_RS_ARBITER].name));
mongoc_server_description_destroy(sd);
return;
}
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
} /* }}} */
/* {{{ proto boolean MongoDB\Driver\Server::isHidden()
Returns whether this Server is a hidden member of a replica set */
static PHP_METHOD(Server, isHidden)
{
php_phongo_server_t *intern;
mongoc_server_description_t *sd;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
bson_iter_t iter;
RETVAL_BOOL(bson_iter_init_find_case(&iter, mongoc_server_description_ismaster(sd), "hidden") && bson_iter_as_bool(&iter));
mongoc_server_description_destroy(sd);
return;
}
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
} /* }}} */
/* {{{ proto boolean MongoDB\Driver\Server::isPassive()
Returns whether this Server is a passive member of a replica set */
static PHP_METHOD(Server, isPassive)
{
php_phongo_server_t *intern;
mongoc_server_description_t *sd;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_SERVER_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
bson_iter_t iter;
RETVAL_BOOL(bson_iter_init_find_case(&iter, mongoc_server_description_ismaster(sd), "passive") && bson_iter_as_bool(&iter));
mongoc_server_description_destroy(sd);
return;
}
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
} /* }}} */
/* {{{ MongoDB\Driver\Server function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_Server_executeCommand, 0, 0, 2)
ZEND_ARG_INFO(0, db)
ZEND_ARG_OBJ_INFO(0, command, MongoDB\\Driver\\Command, 0)
ZEND_ARG_OBJ_INFO(0, readPreference, MongoDB\\Driver\\ReadPreference, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Server_executeQuery, 0, 0, 2)
ZEND_ARG_INFO(0, namespace)
ZEND_ARG_OBJ_INFO(0, zquery, MongoDB\\Driver\\Query, 0)
ZEND_ARG_OBJ_INFO(0, readPreference, MongoDB\\Driver\\ReadPreference, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Server_executeBulkWrite, 0, 0, 2)
ZEND_ARG_INFO(0, namespace)
ZEND_ARG_OBJ_INFO(0, zbulk, MongoDB\\Driver\\BulkWrite, 0)
ZEND_ARG_OBJ_INFO(0, writeConcern, MongoDB\\Driver\\WriteConcern, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_Server_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_server_me[] = {
PHP_ME(Server, executeCommand, ai_Server_executeCommand, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, executeQuery, ai_Server_executeQuery, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, executeBulkWrite, ai_Server_executeBulkWrite, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, getHost, ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, getTags, ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, getInfo, ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, getLatency, ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, getPort, ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, getType, ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, isPrimary, ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, isSecondary, ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, isArbiter, ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, isHidden, ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(Server, isPassive, ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_Server_void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_Server_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\Server object handlers */
static zend_object_handlers php_phongo_handler_server;
static int php_phongo_server_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
{
php_phongo_server_t *intern1, *intern2;
mongoc_server_description_t *sd1, *sd2;
int retval = 0;
intern1 = Z_SERVER_OBJ_P(o1);
intern2 = Z_SERVER_OBJ_P(o2);
sd1 = mongoc_client_get_server_description(intern1->client, intern1->server_id);
sd2 = mongoc_client_get_server_description(intern2->client, intern2->server_id);
if (sd1 && sd2) {
retval = strcasecmp(mongoc_server_description_host(sd1)->host_and_port, mongoc_server_description_host(sd2)->host_and_port);
} else {
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description(s)");
}
if (sd1) {
mongoc_server_description_destroy(sd1);
}
if (sd2) {
mongoc_server_description_destroy(sd2);
}
return retval;
} /* }}} */
static void php_phongo_server_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_server_t *intern = Z_OBJ_SERVER(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_server_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_server_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_server_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_server;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_server_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_server;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_server_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_server_t *intern = NULL;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
mongoc_server_description_t *sd;
*is_temp = 1;
intern = Z_SERVER_OBJ_P(object);
if (!(sd = mongoc_client_get_server_description(intern->client, intern->server_id))) {
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description");
return NULL;
}
php_phongo_server_to_zval(&retval, sd);
mongoc_server_description_destroy(sd);
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_server_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "Server", php_phongo_server_me);
php_phongo_server_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_server_ce->create_object = php_phongo_server_create_object;
PHONGO_CE_FINAL(php_phongo_server_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_server_ce);
memcpy(&php_phongo_handler_server, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_server.compare_objects = php_phongo_server_compare_objects;
php_phongo_handler_server.get_debug_info = php_phongo_server_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_server.free_obj = php_phongo_server_free_object;
php_phongo_handler_server.offset = XtOffsetOf(php_phongo_server_t, std);
#endif
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_UNKNOWN"), PHONGO_SERVER_UNKNOWN TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_STANDALONE"), PHONGO_SERVER_STANDALONE TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_MONGOS"), PHONGO_SERVER_MONGOS TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_POSSIBLE_PRIMARY"), PHONGO_SERVER_POSSIBLE_PRIMARY TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_RS_PRIMARY"), PHONGO_SERVER_RS_PRIMARY TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_RS_SECONDARY"), PHONGO_SERVER_RS_SECONDARY TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_RS_ARBITER"), PHONGO_SERVER_RS_ARBITER TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_RS_OTHER"), PHONGO_SERVER_RS_OTHER TSRMLS_CC);
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_RS_GHOST"), PHONGO_SERVER_RS_GHOST TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/WriteConcern.c 0000664 0001750 0001750 00000023256 13210321137 017627 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_writeconcern_ce;
/* {{{ proto void MongoDB\Driver\WriteConcern::__construct(integer|string $w[, integer $wtimeout[, boolean $journal]])
Constructs a new WriteConcern */
static PHP_METHOD(WriteConcern, __construct)
{
php_phongo_writeconcern_t *intern;
zend_error_handling error_handling;
zval *w, *journal;
phongo_long wtimeout = 0;
SUPPRESS_UNUSED_WARNING(return_value) SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = Z_WRITECONCERN_OBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|lz", &w, &wtimeout, &journal) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
intern->write_concern = mongoc_write_concern_new();
if (Z_TYPE_P(w) == IS_LONG) {
if (Z_LVAL_P(w) < -3) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected w to be >= -3, %ld given", Z_LVAL_P(w));
return;
}
mongoc_write_concern_set_w(intern->write_concern, Z_LVAL_P(w));
} else if (Z_TYPE_P(w) == IS_STRING) {
if (strcmp(Z_STRVAL_P(w), PHONGO_WRITE_CONCERN_W_MAJORITY) == 0) {
mongoc_write_concern_set_w(intern->write_concern, MONGOC_WRITE_CONCERN_W_MAJORITY);
} else {
mongoc_write_concern_set_wtag(intern->write_concern, Z_STRVAL_P(w));
}
} else {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected w to be integer or string, %s given", zend_get_type_by_const(Z_TYPE_P(w)));
return;
}
switch(ZEND_NUM_ARGS()) {
case 3:
if (Z_TYPE_P(journal) != IS_NULL) {
#ifdef ZEND_ENGINE_3
mongoc_write_concern_set_journal(intern->write_concern, zend_is_true(journal));
#else
mongoc_write_concern_set_journal(intern->write_concern, Z_BVAL_P(journal));
#endif
}
/* fallthrough */
case 2:
if (wtimeout < 0) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected wtimeout to be >= 0, %" PHONGO_LONG_FORMAT " given", wtimeout);
return;
}
if (wtimeout > INT32_MAX) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected wtimeout to be <= %" PRId32 ", %" PHONGO_LONG_FORMAT " given", INT32_MAX, wtimeout);
return;
}
mongoc_write_concern_set_wtimeout(intern->write_concern, wtimeout);
}
} /* }}} */
/* {{{ proto string|integer|null MongoDB\Driver\WriteConcern::getW()
Returns the WriteConcern "w" option */
static PHP_METHOD(WriteConcern, getW)
{
php_phongo_writeconcern_t *intern;
const char *wtag;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITECONCERN_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
wtag = mongoc_write_concern_get_wtag(intern->write_concern);
if (wtag) {
PHONGO_RETURN_STRING(wtag);
}
if (mongoc_write_concern_get_wmajority(intern->write_concern)) {
PHONGO_RETURN_STRING(PHONGO_WRITE_CONCERN_W_MAJORITY);
}
if (mongoc_write_concern_get_w(intern->write_concern) != MONGOC_WRITE_CONCERN_W_DEFAULT) {
RETURN_LONG(mongoc_write_concern_get_w(intern->write_concern));
}
RETURN_NULL();
} /* }}} */
/* {{{ proto integer MongoDB\Driver\WriteConcern::getWtimeout()
Returns the WriteConcern "wtimeout" option */
static PHP_METHOD(WriteConcern, getWtimeout)
{
php_phongo_writeconcern_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITECONCERN_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(mongoc_write_concern_get_wtimeout(intern->write_concern));
} /* }}} */
/* {{{ proto null|boolean MongoDB\Driver\WriteConcern::getJournal()
Returns the WriteConcern "journal" option */
static PHP_METHOD(WriteConcern, getJournal)
{
php_phongo_writeconcern_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITECONCERN_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (mongoc_write_concern_journal_is_set(intern->write_concern)) {
RETURN_BOOL(mongoc_write_concern_get_journal(intern->write_concern));
}
RETURN_NULL();
} /* }}} */
/* {{{ proto boolean MongoDB\Driver\WriteConcern::isDefault()
Returns whether the write concern has not been modified (i.e. from a Manager
with no write concern URI options). */
static PHP_METHOD(WriteConcern, isDefault)
{
php_phongo_writeconcern_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITECONCERN_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_BOOL(mongoc_write_concern_is_default(intern->write_concern));
} /* }}} */
/* {{{ proto array MongoDB\Driver\WriteConcern::bsonSerialize()
*/
static PHP_METHOD(WriteConcern, bsonSerialize)
{
const mongoc_write_concern_t *write_concern = phongo_write_concern_from_zval(getThis() TSRMLS_CC);
if (zend_parse_parameters_none() == FAILURE) {
return;
}
php_phongo_write_concern_to_zval(return_value, write_concern);
convert_to_object(return_value);
} /* }}} */
/* {{{ MongoDB\Driver\WriteConcern function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcern___construct, 0, 0, 1)
ZEND_ARG_INFO(0, w)
ZEND_ARG_INFO(0, wtimeout)
ZEND_ARG_INFO(0, journal)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcern_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_writeconcern_me[] = {
PHP_ME(WriteConcern, __construct, ai_WriteConcern___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, getW, ai_WriteConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, getWtimeout, ai_WriteConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, getJournal, ai_WriteConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, isDefault, ai_WriteConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, bsonSerialize, ai_WriteConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\WriteConcern object handlers */
static zend_object_handlers php_phongo_handler_writeconcern;
static void php_phongo_writeconcern_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_writeconcern_t *intern = Z_OBJ_WRITECONCERN(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->write_concern) {
mongoc_write_concern_destroy(intern->write_concern);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_writeconcern_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_writeconcern_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_writeconcern_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_writeconcern;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_writeconcern_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_writeconcern;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_writeconcern_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
const mongoc_write_concern_t *write_concern = phongo_write_concern_from_zval(object TSRMLS_CC);
*is_temp = 1;
php_phongo_write_concern_to_zval(&retval, write_concern);
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_writeconcern_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "WriteConcern", php_phongo_writeconcern_me);
php_phongo_writeconcern_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_writeconcern_ce->create_object = php_phongo_writeconcern_create_object;
PHONGO_CE_FINAL(php_phongo_writeconcern_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_writeconcern_ce);
zend_class_implements(php_phongo_writeconcern_ce TSRMLS_CC, 1, php_phongo_serializable_ce);
memcpy(&php_phongo_handler_writeconcern, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_writeconcern.get_debug_info = php_phongo_writeconcern_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_writeconcern.free_obj = php_phongo_writeconcern_free_object;
php_phongo_handler_writeconcern.offset = XtOffsetOf(php_phongo_writeconcern_t, std);
#endif
zend_declare_class_constant_stringl(php_phongo_writeconcern_ce, ZEND_STRL("MAJORITY"), ZEND_STRL(PHONGO_WRITE_CONCERN_W_MAJORITY) TSRMLS_CC);
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/WriteConcernError.c 0000664 0001750 0001750 00000013556 13210321137 020643 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_writeconcernerror_ce;
/* {{{ proto integer MongoDB\Driver\WriteConcernError::getCode()
Returns the MongoDB error code */
static PHP_METHOD(WriteConcernError, getCode)
{
php_phongo_writeconcernerror_t *intern;
intern = Z_WRITECONCERNERROR_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(intern->code);
} /* }}} */
/* {{{ proto mixed MongoDB\Driver\WriteConcernError::getInfo()
Returns additional metadata for the error */
static PHP_METHOD(WriteConcernError, getInfo)
{
php_phongo_writeconcernerror_t *intern;
intern = Z_WRITECONCERNERROR_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (!Z_ISUNDEF(intern->info)) {
#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&intern->info, 1, 0);
#else
RETURN_ZVAL(intern->info, 1, 0);
#endif
}
} /* }}} */
/* {{{ proto string MongoDB\Driver\WriteConcernError::getMessage()
Returns the actual error message from the server */
static PHP_METHOD(WriteConcernError, getMessage)
{
php_phongo_writeconcernerror_t *intern;
intern = Z_WRITECONCERNERROR_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_RETURN_STRING(intern->message);
} /* }}} */
/* {{{ MongoDB\Driver\WriteConcernError function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcernError_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_writeconcernerror_me[] = {
PHP_ME(WriteConcernError, getCode, ai_WriteConcernError_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcernError, getInfo, ai_WriteConcernError_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcernError, getMessage, ai_WriteConcernError_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_WriteConcernError_void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_WriteConcernError_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\WriteConcernError object handlers */
static zend_object_handlers php_phongo_handler_writeconcernerror;
static void php_phongo_writeconcernerror_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_writeconcernerror_t *intern = Z_OBJ_WRITECONCERNERROR(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->message) {
efree(intern->message);
}
if (!Z_ISUNDEF(intern->info)) {
zval_ptr_dtor(&intern->info);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_writeconcernerror_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_writeconcernerror_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_writeconcernerror_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_writeconcernerror;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_writeconcernerror_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_writeconcernerror;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_writeconcernerror_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_writeconcernerror_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
*is_temp = 1;
intern = Z_WRITECONCERNERROR_OBJ_P(object);
array_init_size(&retval, 3);
ADD_ASSOC_STRING(&retval, "message", intern->message);
ADD_ASSOC_LONG_EX(&retval, "code", intern->code);
if (!Z_ISUNDEF(intern->info)) {
#if PHP_VERSION_ID >= 70000
Z_ADDREF(intern->info);
ADD_ASSOC_ZVAL_EX(&retval, "info", &intern->info);
#else
Z_ADDREF_P(intern->info);
ADD_ASSOC_ZVAL_EX(&retval, "info", intern->info);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "info");
}
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_writeconcernerror_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "WriteConcernError", php_phongo_writeconcernerror_me);
php_phongo_writeconcernerror_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_writeconcernerror_ce->create_object = php_phongo_writeconcernerror_create_object;
PHONGO_CE_FINAL(php_phongo_writeconcernerror_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_writeconcernerror_ce);
memcpy(&php_phongo_handler_writeconcernerror, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_writeconcernerror.get_debug_info = php_phongo_writeconcernerror_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_writeconcernerror.free_obj = php_phongo_writeconcernerror_free_object;
php_phongo_handler_writeconcernerror.offset = XtOffsetOf(php_phongo_writeconcernerror_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/WriteError.c 0000664 0001750 0001750 00000013767 13210321137 017337 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "phongo_compat.h"
#include "php_phongo.h"
zend_class_entry *php_phongo_writeerror_ce;
/* {{{ proto integer MongoDB\Driver\WriteError::getCode()
Returns the MongoDB error code */
static PHP_METHOD(WriteError, getCode)
{
php_phongo_writeerror_t *intern;
intern = Z_WRITEERROR_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(intern->code);
} /* }}} */
/* {{{ proto integer MongoDB\Driver\WriteError::getIndex()
Returns the index of the operation in the BulkWrite to which this WriteError
corresponds. */
static PHP_METHOD(WriteError, getIndex)
{
php_phongo_writeerror_t *intern;
intern = Z_WRITEERROR_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(intern->index);
} /* }}} */
/* {{{ proto string MongoDB\Driver\WriteError::getMessage()
Returns the actual error message from the server */
static PHP_METHOD(WriteError, getMessage)
{
php_phongo_writeerror_t *intern;
intern = Z_WRITEERROR_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_RETURN_STRING(intern->message);
} /* }}} */
/* {{{ proto mixed MongoDB\Driver\WriteError::getInfo()
Returns additional metadata for the error */
static PHP_METHOD(WriteError, getInfo)
{
php_phongo_writeerror_t *intern;
intern = Z_WRITEERROR_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (!Z_ISUNDEF(intern->info)) {
#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&intern->info, 1, 0);
#else
RETURN_ZVAL(intern->info, 1, 0);
#endif
}
} /* }}} */
/* {{{ MongoDB\Driver\WriteError function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_WriteError_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_writeerror_me[] = {
PHP_ME(WriteError, getCode, ai_WriteError_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteError, getIndex, ai_WriteError_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteError, getMessage, ai_WriteError_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteError, getInfo, ai_WriteError_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_WriteError_void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_WriteError_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\WriteError object handlers */
static zend_object_handlers php_phongo_handler_writeerror;
static void php_phongo_writeerror_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_writeerror_t *intern = Z_OBJ_WRITEERROR(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->message) {
efree(intern->message);
}
if (!Z_ISUNDEF(intern->info)) {
zval_ptr_dtor(&intern->info);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_writeerror_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_writeerror_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_writeerror_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_writeerror;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_writeerror_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_writeerror;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_writeerror_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_writeerror_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
*is_temp = 1;
intern = Z_WRITEERROR_OBJ_P(object);
array_init_size(&retval, 3);
ADD_ASSOC_STRING(&retval, "message", intern->message);
ADD_ASSOC_LONG_EX(&retval, "code", intern->code);
ADD_ASSOC_LONG_EX(&retval, "index", intern->index);
if (!Z_ISUNDEF(intern->info)) {
#if PHP_VERSION_ID >= 70000
Z_ADDREF(intern->info);
ADD_ASSOC_ZVAL_EX(&retval, "info", &intern->info);
#else
Z_ADDREF_P(intern->info);
ADD_ASSOC_ZVAL_EX(&retval, "info", intern->info);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "info");
}
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_writeerror_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "WriteError", php_phongo_writeerror_me);
php_phongo_writeerror_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_writeerror_ce->create_object = php_phongo_writeerror_create_object;
PHONGO_CE_FINAL(php_phongo_writeerror_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_writeerror_ce);
memcpy(&php_phongo_handler_writeerror, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_writeerror.get_debug_info = php_phongo_writeerror_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_writeerror.free_obj = php_phongo_writeerror_free_object;
php_phongo_handler_writeerror.offset = XtOffsetOf(php_phongo_writeerror_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/MongoDB/WriteResult.c 0000664 0001750 0001750 00000037757 13210321137 017531 0 ustar jmikola jmikola /*
* Copyright 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
#include
#include "php_array_api.h"
#include "phongo_compat.h"
#include "php_phongo.h"
#include "php_bson.h"
#define PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(iter, bson, key) \
if (bson_iter_init_find((iter), (bson), (key)) && BSON_ITER_HOLDS_INT32((iter))) { \
RETURN_LONG(bson_iter_int32((iter))); \
}
zend_class_entry *php_phongo_writeresult_ce;
static bool php_phongo_writeresult_get_writeconcernerror(php_phongo_writeresult_t *intern, zval *return_value TSRMLS_DC) /* {{{ */
{
bson_iter_t iter, child;
#if PHP_VERSION_ID >= 70000
zval writeconcernerror;
#else
zval *writeconcernerror = NULL;
#endif
ZVAL_NULL(return_value);
if (bson_iter_init_find(&iter, intern->reply, "writeConcernErrors") && BSON_ITER_HOLDS_ARRAY(&iter) && bson_iter_recurse(&iter, &child)) {
while (bson_iter_next(&child)) {
bson_t cbson;
uint32_t len;
const uint8_t *data;
if (!BSON_ITER_HOLDS_DOCUMENT(&child)) {
continue;
}
bson_iter_document(&child, &len, &data);
if (!bson_init_static(&cbson, data, len)) {
continue;
}
#if PHP_VERSION_ID >= 70000
if (!phongo_writeconcernerror_init(&writeconcernerror, &cbson TSRMLS_CC)) {
zval_ptr_dtor(&writeconcernerror);
return false;
}
ZVAL_ZVAL(return_value, &writeconcernerror, 1, 1);
#else
MAKE_STD_ZVAL(writeconcernerror);
if (!phongo_writeconcernerror_init(writeconcernerror, &cbson TSRMLS_CC)) {
zval_ptr_dtor(&writeconcernerror);
return false;
}
ZVAL_ZVAL(return_value, writeconcernerror, 1, 1);
#endif
return true;
}
}
return true;
} /* }}} */
static bool php_phongo_writeresult_get_writeerrors(php_phongo_writeresult_t *intern, zval *return_value TSRMLS_DC) /* {{{ */
{
bson_iter_t iter, child;
array_init(return_value);
if (bson_iter_init_find(&iter, intern->reply, "writeErrors") && BSON_ITER_HOLDS_ARRAY(&iter) && bson_iter_recurse(&iter, &child)) {
while (bson_iter_next(&child)) {
bson_t cbson;
uint32_t len;
const uint8_t *data;
#if PHP_VERSION_ID >= 70000
zval writeerror;
#else
zval *writeerror = NULL;
#endif
if (!BSON_ITER_HOLDS_DOCUMENT(&child)) {
continue;
}
bson_iter_document(&child, &len, &data);
if (!bson_init_static(&cbson, data, len)) {
continue;
}
#if PHP_VERSION_ID >= 70000
if (!phongo_writeerror_init(&writeerror, &cbson TSRMLS_CC)) {
zval_ptr_dtor(&writeerror);
continue;
}
add_next_index_zval(return_value, &writeerror);
#else
MAKE_STD_ZVAL(writeerror);
if (!phongo_writeerror_init(writeerror, &cbson TSRMLS_CC)) {
zval_ptr_dtor(&writeerror);
continue;
}
add_next_index_zval(return_value, writeerror);
#endif
}
}
return true;
} /* }}} */
/* {{{ proto integer|null MongoDB\Driver\WriteResult::getInsertedCount()
Returns the number of documents that were inserted */
static PHP_METHOD(WriteResult, getInsertedCount)
{
bson_iter_t iter;
php_phongo_writeresult_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITERESULT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nInserted");
} /* }}} */
/* {{{ proto integer|null MongoDB\Driver\WriteResult::getMatchedCount()
Returns the number of documents that matched the update criteria */
static PHP_METHOD(WriteResult, getMatchedCount)
{
bson_iter_t iter;
php_phongo_writeresult_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITERESULT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nMatched");
} /* }}} */
/* {{{ proto integer|null MongoDB\Driver\WriteResult::getModifiedCount()
Returns the number of documents that were actually modified by an update */
static PHP_METHOD(WriteResult, getModifiedCount)
{
bson_iter_t iter;
php_phongo_writeresult_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITERESULT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nModified");
} /* }}} */
/* {{{ proto integer|null MongoDB\Driver\WriteResult::getDeletedCount()
Returns the number of documents that were deleted */
static PHP_METHOD(WriteResult, getDeletedCount)
{
bson_iter_t iter;
php_phongo_writeresult_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITERESULT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nRemoved");
} /* }}} */
/* {{{ proto integer|null MongoDB\Driver\WriteResult::getUpsertedCount()
Returns the number of documents that were upserted */
static PHP_METHOD(WriteResult, getUpsertedCount)
{
bson_iter_t iter;
php_phongo_writeresult_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITERESULT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nUpserted");
} /* }}} */
/* {{{ proto MongoDB\Driver\Server MongoDB\Driver\WriteResult::getServer()
Returns the Server from which the result originated */
static PHP_METHOD(WriteResult, getServer)
{
php_phongo_writeresult_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITERESULT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
phongo_server_init(return_value, intern->client, intern->server_id TSRMLS_CC);
} /* }}} */
/* {{{ proto array MongoDB\Driver\WriteResult::getUpsertedIds()
Returns the identifiers generated by the server for upsert operations. */
static PHP_METHOD(WriteResult, getUpsertedIds)
{
bson_iter_t iter, child;
php_phongo_writeresult_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITERESULT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
array_init(return_value);
if (bson_iter_init_find(&iter, intern->reply, "upserted") && BSON_ITER_HOLDS_ARRAY(&iter) && bson_iter_recurse(&iter, &child)) {
while (bson_iter_next(&child)) {
uint32_t data_len;
const uint8_t *data = NULL;
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
/* Use PHONGO_TYPEMAP_NATIVE_ARRAY for the root type so we can
* easily access the "index" and "_id" fields. */
state.map.root_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
if (!BSON_ITER_HOLDS_DOCUMENT(&child)) {
continue;
}
bson_iter_document(&child, &data_len, &data);
if (php_phongo_bson_to_zval_ex(data, data_len, &state)) {
#if PHP_VERSION_ID >= 70000
zval *zid = php_array_fetchc(&state.zchild, "_id");
add_index_zval(return_value, php_array_fetchc_long(&state.zchild, "index"), zid);
zval_add_ref(zid);
#else
zval *zid = php_array_fetchc(state.zchild, "_id");
add_index_zval(return_value, php_array_fetchc_long(state.zchild, "index"), zid);
zval_add_ref(&zid);
#endif
}
zval_ptr_dtor(&state.zchild);
}
}
} /* }}} */
/* {{{ proto WriteConcernError MongoDB\Driver\WriteResult::getWriteConcernError()
Return any write concern error that occurred */
static PHP_METHOD(WriteResult, getWriteConcernError)
{
php_phongo_writeresult_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITERESULT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
php_phongo_writeresult_get_writeconcernerror(intern, return_value TSRMLS_CC);
} /* }}} */
/* {{{ proto WriteError[] MongoDB\Driver\WriteResult::getWriteErrors()
Returns any write errors that occurred */
static PHP_METHOD(WriteResult, getWriteErrors)
{
php_phongo_writeresult_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITERESULT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
php_phongo_writeresult_get_writeerrors(intern, return_value TSRMLS_CC);
} /* }}} */
/* {{{ proto boolean MongoDB\Driver\WriteResult::isAcknowledged()
Returns whether the write operation was acknowledged (based on the write
concern). */
static PHP_METHOD(WriteResult, isAcknowledged)
{
php_phongo_writeresult_t *intern;
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
intern = Z_WRITERESULT_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_BOOL(mongoc_write_concern_is_acknowledged(intern->write_concern));
} /* }}} */
/* {{{ MongoDB\Driver\WriteResult function entries */
ZEND_BEGIN_ARG_INFO_EX(ai_WriteResult_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry php_phongo_writeresult_me[] = {
PHP_ME(WriteResult, getInsertedCount, ai_WriteResult_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteResult, getMatchedCount, ai_WriteResult_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteResult, getModifiedCount, ai_WriteResult_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteResult, getDeletedCount, ai_WriteResult_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteResult, getUpsertedCount, ai_WriteResult_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteResult, getServer, ai_WriteResult_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteResult, getUpsertedIds, ai_WriteResult_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteResult, getWriteConcernError, ai_WriteResult_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteResult, getWriteErrors, ai_WriteResult_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteResult, isAcknowledged, ai_WriteResult_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_WriteResult_void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_WriteResult_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ MongoDB\Driver\WriteResult object handlers */
static zend_object_handlers php_phongo_handler_writeresult;
static void php_phongo_writeresult_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
{
php_phongo_writeresult_t *intern = Z_OBJ_WRITERESULT(object);
zend_object_std_dtor(&intern->std TSRMLS_CC);
if (intern->reply) {
bson_destroy(intern->reply);
}
if (intern->write_concern) {
mongoc_write_concern_destroy(intern->write_concern);
}
#if PHP_VERSION_ID < 70000
efree(intern);
#endif
} /* }}} */
static phongo_create_object_retval php_phongo_writeresult_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
php_phongo_writeresult_t *intern = NULL;
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_writeresult_t, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
#if PHP_VERSION_ID >= 70000
intern->std.handlers = &php_phongo_handler_writeresult;
return &intern->std;
#else
{
zend_object_value retval;
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_writeresult_free_object, NULL TSRMLS_CC);
retval.handlers = &php_phongo_handler_writeresult;
return retval;
}
#endif
} /* }}} */
static HashTable *php_phongo_writeresult_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
php_phongo_writeresult_t *intern;
#if PHP_VERSION_ID >= 70000
zval retval;
#else
zval retval = zval_used_for_init;
#endif
bson_iter_t iter;
intern = Z_WRITERESULT_OBJ_P(object);
*is_temp = 1;
array_init_size(&retval, 9);
#define PHONGO_WRITERESULT_SCP(field) \
if (bson_iter_init_find(&iter, intern->reply, (field)) && BSON_ITER_HOLDS_INT32(&iter)) { \
ADD_ASSOC_LONG_EX(&retval, (field), bson_iter_int32(&iter)); \
} else { \
ADD_ASSOC_NULL_EX(&retval, (field)); \
}
PHONGO_WRITERESULT_SCP("nInserted");
PHONGO_WRITERESULT_SCP("nMatched");
PHONGO_WRITERESULT_SCP("nModified");
PHONGO_WRITERESULT_SCP("nRemoved");
PHONGO_WRITERESULT_SCP("nUpserted");
#undef PHONGO_WRITERESULT_SCP
if (bson_iter_init_find(&iter, intern->reply, "upserted") && BSON_ITER_HOLDS_ARRAY(&iter)) {
uint32_t len;
const uint8_t *data;
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
/* Use native arrays for debugging output */
state.map.root_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
state.map.document_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
bson_iter_array(&iter, &len, &data);
php_phongo_bson_to_zval_ex(data, len, &state);
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "upsertedIds", &state.zchild);
#else
ADD_ASSOC_ZVAL_EX(&retval, "upsertedIds", state.zchild);
#endif
} else {
#if PHP_VERSION_ID >= 70000
zval upsertedIds;
array_init(&upsertedIds);
ADD_ASSOC_ZVAL_EX(&retval, "upsertedIds", &upsertedIds);
#else
zval *upsertedIds = NULL;
MAKE_STD_ZVAL(upsertedIds);
array_init(upsertedIds);
ADD_ASSOC_ZVAL_EX(&retval, "upsertedIds", upsertedIds);
#endif
}
{
#if PHP_VERSION_ID >= 70000
zval writeerrors;
php_phongo_writeresult_get_writeerrors(intern, &writeerrors TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "writeErrors", &writeerrors);
#else
zval *writeerrors = NULL;
MAKE_STD_ZVAL(writeerrors);
php_phongo_writeresult_get_writeerrors(intern, writeerrors TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "writeErrors", writeerrors);
#endif
}
{
#if PHP_VERSION_ID >= 70000
zval writeconcernerror;
php_phongo_writeresult_get_writeconcernerror(intern, &writeconcernerror TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "writeConcernError", &writeconcernerror);
#else
zval *writeconcernerror = NULL;
MAKE_STD_ZVAL(writeconcernerror);
php_phongo_writeresult_get_writeconcernerror(intern, writeconcernerror TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "writeConcernError", writeconcernerror);
#endif
}
if (intern->write_concern) {
#if PHP_VERSION_ID >= 70000
zval write_concern;
phongo_writeconcern_init(&write_concern, intern->write_concern);
ADD_ASSOC_ZVAL_EX(&retval, "writeConcern", &write_concern);
#else
zval *write_concern = NULL;
MAKE_STD_ZVAL(write_concern);
phongo_writeconcern_init(write_concern, intern->write_concern TSRMLS_CC);
ADD_ASSOC_ZVAL_EX(&retval, "writeConcern", write_concern);
#endif
} else {
ADD_ASSOC_NULL_EX(&retval, "writeConcern");
}
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
void php_phongo_writeresult_init_ce(INIT_FUNC_ARGS) /* {{{ */
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "WriteResult", php_phongo_writeresult_me);
php_phongo_writeresult_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_writeresult_ce->create_object = php_phongo_writeresult_create_object;
PHONGO_CE_FINAL(php_phongo_writeresult_ce);
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_writeresult_ce);
memcpy(&php_phongo_handler_writeresult, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
php_phongo_handler_writeresult.get_debug_info = php_phongo_writeresult_get_debug_info;
#if PHP_VERSION_ID >= 70000
php_phongo_handler_writeresult.free_obj = php_phongo_writeresult_free_object;
php_phongo_handler_writeresult.offset = XtOffsetOf(php_phongo_writeresult_t, std);
#endif
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
mongodb-1.3.4/src/contrib/php_array_api.h 0000664 0001750 0001750 00000050765 13210321137 020230 0 ustar jmikola jmikola /* +----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2013 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Sara Golemon (pollita@php.net) |
+----------------------------------------------------------------------+
*/
#ifndef PHP_ARRAY_API_H
#define PHP_ARRAY_API_H
#include "zend.h"
#include "zend_execute.h"
#include "zend_API.h"
#include "zend_operators.h"
#include "zend_hash.h"
#include "zend_list.h"
#ifdef ZEND_ENGINE_3
# define PAA_LENGTH_ADJ(l) (l)
# define PAA_SYM_EXISTS zend_symtable_str_exists
# define PAA_SYM_DEL zend_symtable_str_del
#else
# define PAA_LENGTH_ADJ(l) (l+1)
# define PAA_SYM_EXISTS zend_symtable_exists
# define PAA_SYM_DEL zend_symtable_del
#endif
/**
* All APIs in this file follow a general format:
*
* php_array_{$verb}{$modifier}_{$type}(zval *zarr, ...)
*
* $verb is one of:
* exists - Boolean check whether the array offset exists
* fetch - Retrieve the value at $zarr[$key]
* unset - Delete the named offset from the array
*
* $modifier specifies what type of offset (key) is being used:
* - NULL terminated string variable, unknown length
* l - NULL terminated string variable, known length
* l_safe - String variable of known length, not necessarily NULL terminated
* n - Long (integer) offset
* c - NULL terminated string literal (e.g. "foo" rather than foo)
* z - zval* offset, type should be NULL, BOOL, LONG, DOUBLE, or STRING
*
* $type is specific to the "fetch" verb:
* - Fetch a zval* of any type
* bool - Fetch a zend_bool (converting as needed)
* long - Fetch a long (converting as needed)
* double - Fetch a double (converting as needed)
* string - Fetch a string (converting as needed, caller may need to free)
* array - Fetch an array (no conversion from other types)
* object - Fetch an object (no conversion, type spec optional)
* resource - Fetch a resource (no conversion, type spec mandatory)
*
* See the specific subsection for additional details
*/
/* isset($zarr[$key]) - Check for the existence of a key within an array
*
* zend_bool php_array_exists(zval *zarr, const char *key)
* zend_bool php_array_existsc(zval *zarr, const char *litstr)
* zend_bool php_array_existsl(zval *zarr, const char *key, int key_len)
* zend_bool php_array_existsl_safe(zval *zarr, const char *key, int key_len)
* zend_bool php_array_existsn(zval *zarr, long idx)
* zend_bool php_array_existsz(zval *zarr, zval *key)
*/
static inline
zend_bool php_array_exists(zval *zarr, const char *key) {
return PAA_SYM_EXISTS(Z_ARRVAL_P(zarr), key, PAA_LENGTH_ADJ(strlen(key)));
}
#define php_array_existsc(zarr, litstr) \
PAA_SYM_EXISTS(Z_ARRVAL_P(zarr), litstr, PAA_LENGTH_ADJ(sizeof(litstr) - 1))
#define php_array_existsl(zarr, key, len) \
PAA_SYM_EXISTS(Z_ARRVAL_P(zarr), key, PAA_LENGTH_ADJ(len))
static inline
zend_bool php_array_existsl_safe(zval *zarr, const char *key, int key_len) {
#ifdef ZEND_ENGINE_3
zend_string *keystr = zend_string_init(key, key_len, 0);
zend_bool ret = zend_symtable_exists(Z_ARRVAL_P(zarr), keystr);
zend_string_release(keystr);
#else
char *k = estrndup(key, key_len);
zend_bool ret = zend_symtable_exists(Z_ARRVAL_P(zarr), k, key_len + 1);
efree(k);
#endif
return ret;
}
#define php_array_existsn(zarr, idx) \
zend_hash_index_exists(Z_ARRVAL_P(zarr), idx)
static inline
zend_bool php_array_existsz(zval *zarr, zval *key) {
switch (Z_TYPE_P(key)) {
case IS_NULL:
return php_array_existsc(zarr, "");
#ifdef ZEND_ENGINE_3
case IS_FALSE:
return zend_hash_index_exists(Z_ARRVAL_P(zarr), 0);
case IS_TRUE:
return zend_hash_index_exists(Z_ARRVAL_P(zarr), 1);
#else
case IS_BOOL: /* fallthrough */
#endif
case IS_LONG:
return zend_hash_index_exists(Z_ARRVAL_P(zarr), Z_LVAL_P(key));
case IS_DOUBLE:
return zend_hash_index_exists(Z_ARRVAL_P(zarr),
zend_dval_to_lval(Z_DVAL_P(key)));
case IS_STRING:
return php_array_existsl(zarr, Z_STRVAL_P(key), Z_STRLEN_P(key));
default:
return 0;
}
}
/* =$zarr[$key] - Fetch a zval (or appropriate type) from an array
*
* Methods returning pointers yield NULL on key not existing,
* others yield 0, false, etc... as appropriate.
* Callers needing to distinguish empty scalars from non-existent
* scalars should use php_array_exists*() or fetch the zval then convert.
*
* If the type of the value does not match what is requested
* it will be implicitly converted (if possible).
*
* See each type section for specific prototypes
*
* php_array_fetch* - Fetch a zval
* php_array_fetch*_bool - Fetch a boolean
* php_array_fetch*_long - Fetch a long
* php_array_fetch*_double - Fetch a double
* php_array_fetch*_string - Fetch a string (must be efree()'d by caller)
* php_array_fetch*_array - Fetch an array
* php_array_fetch*_resource - Fetch a resource or a specific type
* php_array_fetch*_object - Fetch an object
*
* For each result type, there are six key forms:
* php_array_fetch_T(zval *zarr, const char *key, ...)
* NULL terminated string key
* php_array_fetchc_T(zval *zarr, const char *litkey, ...)
* String literal key
* php_array_fetchl_T(zval *zarr, const char *key, int key_len, ...)
* NULL terminated string key of known length
* php_array_fetchl_safe_T(zval *zarr, const char *key, int key_len, ...)
* String key of known length, may not be NULL terminated
* php_array_fetchn_T(zval *zarr, long idx, ...)
* Numeric key
* php_array_fetchz_T(zval *zarr, zval *key, ...)
* zval* key
*/
/* Fetch zval*
*
* zval *php_array_fetch(zval *zarr, const char *key)
* zval *php_array_fetchl(zval *zarr, const char *key, int key_len)
* zval *php_array_fetchl_safe(zval *zarr, const char *key, int key_len)
* zval *php_array_fetchn(zval *zarr, long idx)
* zval *php_array_fetchc(zval *zarr, const char *litstr)
* zval *php_array_fetchz(zval *zarr, zval *key)
*/
static inline
zval *php_array_fetchl(zval *zarr, const char *key, int key_len) {
#ifdef ZEND_ENGINE_3
return zend_symtable_str_find(Z_ARRVAL_P(zarr), key, key_len);
#else
zval **ppzval;
if (FAILURE == zend_symtable_find(Z_ARRVAL_P(zarr),
key, key_len + 1,
(void**)&ppzval)) {
return NULL;
}
return *ppzval;
#endif
}
static inline
zval *php_array_fetch(zval *zarr, const char *key) {
return php_array_fetchl(zarr, key, strlen(key));
}
#define php_array_fetchc(zarr, litstr) php_array_fetchl(zarr, litstr, sizeof(litstr)-1)
static inline
zval *php_array_fetchl_safe(zval *zarr, const char *key, int key_len) {
#ifdef ZEND_ENGINE_3
zend_string *keystr = zend_string_init(key, key_len, 0);
zval *ret = zend_symtable_find(Z_ARRVAL_P(zarr), keystr);
zend_string_release(keystr);
#else
char *k = estrndup(key, key_len);
zval *ret = php_array_fetchl(zarr, k, key_len);
efree(k);
#endif
return ret;
}
static inline
zval *php_array_fetchn(zval *zarr, long idx) {
#ifdef ZEND_ENGINE_3
return zend_hash_index_find(Z_ARRVAL_P(zarr), idx);
#else
zval **ppzval;
if (FAILURE == zend_hash_index_find(Z_ARRVAL_P(zarr),
idx, (void**)&ppzval)) {
return NULL;
}
return *ppzval;
#endif
}
static inline
zval *php_array_fetchz(zval *zarr, zval *key) {
switch (Z_TYPE_P(key)) {
case IS_NULL:
return php_array_fetchn(zarr, 0);
#ifdef ZEND_ENGINE_3
case IS_FALSE:
return php_array_fetchn(zarr, 0);
case IS_TRUE:
return php_array_fetchn(zarr, 1);
#else
case IS_BOOL: /* fallthrough */
#endif
case IS_LONG:
return php_array_fetchn(zarr, Z_LVAL_P(key));
case IS_DOUBLE:
return php_array_fetchn(zarr, (long)Z_DVAL_P(key));
case IS_STRING:
return php_array_fetchl(zarr, Z_STRVAL_P(key), Z_STRLEN_P(key));
default:
return NULL;
}
}
#define PHP_ARRAY_FETCH_TYPE_MAP(ctype, ztype) \
static inline ctype php_array_fetch_##ztype(zval *zarr, const char *key) \
{ return php_array_zval_to_##ztype(php_array_fetch(zarr, key)); } \
static inline ctype php_array_fetchl_##ztype(zval *zarr, const char *key, int key_len) \
{ return php_array_zval_to_##ztype(php_array_fetchl(zarr, key, key_len)); } \
static inline ctype php_array_fetchl_safe_##ztype(zval *zarr, const char *key, int key_len) \
{ return php_array_zval_to_##ztype(php_array_fetchl_safe(zarr, key, key_len)); } \
static inline ctype php_array_fetchn_##ztype(zval *zarr, long idx) \
{ return php_array_zval_to_##ztype(php_array_fetchn(zarr, idx)); } \
static inline ctype php_array_fetchz_##ztype(zval *zarr, zval *key) \
{ return php_array_zval_to_##ztype(php_array_fetchz(zarr, key)); }
/* Fetch zend_bool
*
* zend_bool php_array_fetch_bool(zval *zarr, const char *key)
* zend_bool php_array_fetchl_bool(zval *zarr, const char *key, int key_len)
* zend_bool php_array_fetchl_safe_bool(zval *zarr, const char *key, int key_len)
* zend_bool php_array_fetchn_bool(zval *zarr, long idx)
* zend_bool php_array_fetchc_bool(zval *zarr, const char *litstr)
* zend_bool php_array_fetchz_bool(zval *zarr, zval *key)
*/
static inline
zend_bool php_array_zval_to_bool(zval *z) {
return z && zend_is_true(z);
}
PHP_ARRAY_FETCH_TYPE_MAP(zend_bool, bool)
#define php_array_fetchc_bool(zarr, litstr) \
php_array_zval_to_bool(php_array_fetchc(zarr, litstr))
/* Fetch long
*
* long php_array_fetch_long(zval *zarr, const char *key)
* long php_array_fetchl_long(zval *zarr, const char *key, int key_len)
* long php_array_fetchl_safe_long(zval *zarr, const char *key, int key_len)
* long php_array_fetchn_long(zval *zarr, long idx)
* long php_array_fetchc_long(zval *zarr, const char *litstr)
* long php_array_fetchz_long(zval *zarr, zval *key)
*/
static inline
long php_array_zval_to_long(zval *z) {
if (!z) { return 0; }
switch(Z_TYPE_P(z)) {
case IS_NULL: return 0;
#ifdef ZEND_ENGINE_3
case IS_FALSE: return 0;
case IS_TRUE: return 1;
#else
case IS_BOOL: return Z_BVAL_P(z);
#endif
case IS_LONG: return Z_LVAL_P(z);
case IS_DOUBLE: return (long)Z_DVAL_P(z);
default:
{
zval c = *z;
zval_copy_ctor(&c);
convert_to_long(&c);
return Z_LVAL(c);
}
}
}
PHP_ARRAY_FETCH_TYPE_MAP(long, long)
#define php_array_fetchc_long(zarr, litstr) \
php_array_zval_to_long(php_array_fetchc(zarr, litstr))
/* Fetch double
*
* double php_array_fetch_double(zval *zarr, const char *key)
* double php_array_fetchl_double(zval *zarr, const char *key, int key_len)
* double php_array_fetchl_safe_double(zval *zarr, const char *key, int key_len)
* double php_array_fetchn_double(zval *zarr, long idx)
* double php_array_fetchc_double(zval *zarr, const char *litstr)
* double php_array_fetchz_double(zval *zarr, zval *key)
*/
static inline
double php_array_zval_to_double(zval *z) {
if (!z) { return 0.0; }
switch (Z_TYPE_P(z)) {
case IS_NULL: return 0.0;
#ifdef ZEND_ENGINE_3
case IS_FALSE: return 0.0;
case IS_TRUE: return 1.0;
#else
case IS_BOOL: return (double)Z_BVAL_P(z);
#endif
case IS_LONG: return (double)Z_LVAL_P(z);
case IS_DOUBLE: return Z_DVAL_P(z);
default:
{
zval c = *z;
zval_copy_ctor(&c);
convert_to_double(&c);
return Z_DVAL(c);
}
}
}
PHP_ARRAY_FETCH_TYPE_MAP(double, double)
#define php_array_fetchc_double(zarr, litstr) \
php_array_zval_to_double(php_array_fetchc(zarr, litstr))
/* Fetch string
*
* If the pfree is set to 1 on exit, then the return value is owned by the caller
* and must be efree()'d once it is no longer in use.
*
* plen is populated with the binary safe length of the string returned.
*
* char *php_array_fetch_string(zval *zarr, const char *key, int *plen, zend_bool *pfree)
* char *php_array_fetchl_string(zval *zarr, const char *key, int key_len, int *plen, zend_bool *pfree)
* char *php_array_fetchl_safe_string(zval *zarr, const char *key, int key_len, int *plen, zend_bool *pfree)
* char *php_array_fetchn_string(zval *zarr, long idx, int *plen, zend_bool *pfree)
* char *php_array_fetchc_string(zval *zarr, const char *litstr, int *plen, zend_bool *pfree)
* char *php_array_fetchz_string(zval *zarr, zval *key, int *plen, zend_bool *pfree)
*/
static inline
char *php_array_zval_to_string(zval *z, int *plen, zend_bool *pfree) {
*plen = 0;
*pfree = 0;
if (!z) { return NULL; }
switch (Z_TYPE_P(z)) {
case IS_NULL:
return (char *)"";
case IS_STRING:
*plen = Z_STRLEN_P(z);
return Z_STRVAL_P(z);
default:
{
zval c = *z;
zval_copy_ctor(&c);
convert_to_string(&c);
#ifdef ZEND_ENGINE_3
*pfree = ! IS_INTERNED(Z_STR(c));
#else
*pfree = ! IS_INTERNED(Z_STRVAL(c));
#endif
*plen = Z_STRLEN(c);
return Z_STRVAL(c);
}
}
}
#define php_array_fetch_string(zarr, key, plen, pfree) \
php_array_zval_to_string(php_array_fetch(zarr, key), plen, pfree)
#define php_array_fetchl_string(zarr, key, key_len, plen, pfree) \
php_array_zval_to_string(php_array_fetchl(zarr, key, key_len), plen, pfree)
#define php_array_fetchl_safe_string(zarr, key, key_len, plen, pfree) \
php_array_zval_to_string(php_array_fetchl_safe(zarr, key, key_len), plen, pfree)
#define php_array_fetchn_string(zarr, idx, plen, pfree) \
php_array_zval_to_string(php_array_fetchn(zarr, idx), plen, pfree)
#define php_array_fetchc_string(zarr, litstr, plen, pfree) \
php_array_zval_to_string(php_array_fetchc(zarr, litstr), plen, pfree)
#define php_array_fetchz_string(zarr, key, plen, pfree) \
php_array_zval_to_string(php_array_fetchz(zarr, key), plen, pfree)
/* Fetch array
*
* No implicit conversion is performed.
*
* If the value is an array, then that zval is returned,
* otherwise NULL is returned.
*
* zval *php_array_fetch_array(zval *zarr, const char *key)
* zval *php_array_fetchl_array(zval *zarr, const char *key, int key_len)
* zval *php_array_fetchl_safe_array(zval *zarr, const char *key, int key_len)
* zval *php_array_fetchn_array(zval *zarr, long idx)
* zval *php_array_fetchc_array(zval *zarr, const char *litstr)
* zval *php_array_fetchz_array(zval *zarr, zval *key)
*/
static inline zval *php_array_zval_to_array(zval *zarr) {
return (zarr && (Z_TYPE_P(zarr) == IS_ARRAY)) ? zarr : NULL;
}
PHP_ARRAY_FETCH_TYPE_MAP(zval*, array)
#define php_array_fetchc_array(zarr, litstr) \
php_array_zval_to_array(php_array_fetchc(zarr, litstr))
/* count($arr) - Count number of elements in the array
*
* int php_array_count(zval *arr)
*/
#define php_array_count(zarr) zend_hash_num_elements(Z_ARRVAL_P(zarr))
/* Fetch resource
*
* No implicit conversion is performed.
*
* If the value is a resource of the named type,
* then the pointer for it is returned,
* otherwise NULL is returned.
*
* To test for multiple resource types (e.g. 'stream' and 'persistent stream')
* Fetch a generic zval* and use Zend's ZEND_FETCH_RESOURCE() macro.
*
* zval *php_array_fetch_resource(zval *zarr, const char *key, int le)
* zval *php_array_fetchl_resource(zval *zarr, const char *key, int key_len, int le)
* zval *php_array_fetchl_safe_resource(zval *zarr, const char *key, int key_len, int le)
* zval *php_array_fetchn_resource(zval *zarr, long idx, int le)
* zval *php_array_fetchc_resource(zval *zarr, const char *litstr, int le)
* zval *php_array_fetchz_resource(zval *zarr, zval *key, int le)
*/
static inline
void *php_array_zval_to_resource(zval *z, int le TSRMLS_DC) {
#ifdef ZEND_ENGINE_3
return zend_fetch_resource_ex(z, NULL, le);
#else
void *ret;
int rtype;
if (!z || Z_TYPE_P(z) != IS_RESOURCE) { return NULL; }
ret = zend_list_find(Z_RESVAL_P(z), &rtype);
if (!ret || (rtype != le)) {
return NULL;
}
return ret;
#endif
}
#define php_array_fetch_resource(zarr, key, le) \
php_array_zval_to_resource(php_array_fetch(zarr, key), le TSRMLS_CC)
#define php_array_fetchl_resource(zarr, key, key_len, le) \
php_array_zval_to_resource(php_array_fetchl(zarr, key, key_len), le TSRMLS_CC)
#define php_array_fetchl_safe_resource(zarr, key, key_len, le) \
php_array_zval_to_resource(php_array_fetchl_safe(zarr, key, key_len), le TSRMLS_CC)
#define php_array_fetchn_resource(zarr, idx, le) \
php_array_zval_to_resource(php_array_fetchn(zarr, idx), le TSRMLS_CC)
#define php_array_fetchc_resource(zarr, litstr, le) \
php_array_zval_to_resource(php_array_fetchc(zarr, litstr), le TSRMLS_CC)
#define php_array_fetchz_resource(zarr, key, le) \
php_array_zval_to_resource(php_array_fetchz(zarr, key), le TSRMLS_CC)
/* Fetch Object
*
* Fetch an object of a specific or non-specific type (pass ce == NULL)
*
* No implicit conversion is performed
*
* zval *php_array_fetch_object(zval *zarr, const char *key, zend_class_entry *ce)
* zval *php_array_fetchl_object(zval *zarr, const char *key, int key_len, zend_class_entry *ce)
* zval *php_array_fetchl_safe_object(zval *zarr, const char *key, int key_len, zend_class_entry *ce)
* zval *php_array_fetchn_object(zval *zarr, long idx, zend_class_entry *ce)
* zval *php_array_fetchc_object(zval *zarr, const char *litstr, zend_class_entry *ce)
* zval *php_array_fetchz_object(zval *zarr, zval *key, zend_class_entry *ce)
*/
static inline
zval *php_array_zval_to_object(zval *z, zend_class_entry *ce TSRMLS_DC) {
return (z && (Z_TYPE_P(z) == IS_OBJECT) &&
((!ce) || instanceof_function(Z_OBJCE_P(z), ce TSRMLS_CC))) ? z : NULL;
}
#define php_array_fetch_object(zarr, key, ce) \
php_array_zval_to_object(php_array_fetch(zarr, key), ce TSRMLS_CC)
#define php_array_fetchl_object(zarr, key, len, ce) \
php_array_zval_to_object(php_array_fetchl(zarr, key, len), ce TSRMLS_CC)
#define php_array_fetchl_safe_object(zarr, key, len, ce) \
php_array_zval_to_object(php_array_fetchl_safe(zarr, key, len), ce TSRMLS_CC)
#define php_array_fetchn_object(zarr, idx, ce) \
php_array_zval_to_object(php_array_fetchn(zarr, idx), ce TSRMLS_CC)
#define php_array_fetchc_object(zarr, litstr, ce) \
php_array_zval_to_object(php_array_fetchc(zarr, litstr), ce TSRMLS_CC)
#define php_array_fetchz_object(zarr, key, ce) \
php_array_zval_to_object(php_array_fetchz(zarr, key), ce TSRMLS_CC)
/* unset($zarr[$key]) - Erase a key from an array
*
* void php_array_unset(zval *zarr, const char *key)
* void php_array_unsetl(zval *zarr, const char *key, int key_len)
* void php_array_unsetl_safe(zval *zarr, const char *key, int key_len)
* void php_array_unsetn(zval *zarr, long idx)
* void php_array_unsetc(zval *zarr, const char *litstr)
* void php_array_unsetz(zval *zarr, zval *key)
*/
static inline
void php_array_unset(zval *zarr, const char *key) {
PAA_SYM_DEL(Z_ARRVAL_P(zarr), key, PAA_LENGTH_ADJ(strlen(key)));
}
#define php_array_unsetl(zarr, key, len) \
PAA_SYM_DEL(Z_ARRVAL_P(zarr), key, PAA_LENGTH_ADJ(len))
static inline
void php_array_unsetl_safe(zval *zarr, const char *key, int key_len) {
char *k = estrndup(key, key_len);
PAA_SYM_DEL(Z_ARRVAL_P(zarr), k, PAA_LENGTH_ADJ(key_len));
efree(k);
}
#define php_array_unsetn(zarr, idx) \
zend_symtable_index_del(Z_ARRVAL_P(zarr), idx)
#ifdef ZEND_ENGINE_3
# define php_array_unsetc(zarr, litstr) \
zend_symtable_str_del(Z_ARRVAL_P(zarr), litstr, PAA_LENGTH_ADJ(sizeof(litstr) - 1))
#else
# define php_array_unsetc(zarr, litstr) \
zend_symtable_del(Z_ARRVAL_P(zarr), litstr, PAA_LENGTH_ADJ(sizeof(litstr) - 1))
#endif
static inline void php_array_unsetz(zval *zarr, zval *key) {
switch (Z_TYPE_P(key)) {
case IS_NULL:
zend_hash_index_del(Z_ARRVAL_P(zarr), 0);
return;
#ifdef ZEND_ENGINE_3
case IS_FALSE:
zend_hash_index_del(Z_ARRVAL_P(zarr), 0);
return;
case IS_TRUE:
zend_hash_index_del(Z_ARRVAL_P(zarr), 1);
return;
#else
case IS_BOOL: /* fallthrough */
#endif
case IS_LONG:
zend_hash_index_del(Z_ARRVAL_P(zarr), Z_LVAL_P(key));
return;
case IS_DOUBLE:
zend_hash_index_del(Z_ARRVAL_P(zarr), (long)Z_DVAL_P(key));
break;
case IS_STRING:
php_array_unsetl(zarr, Z_STRVAL_P(key), Z_STRLEN_P(key));
break;
}
}
#endif /* PHP_ARRAY_API_H */
mongodb-1.3.4/src/libbson/build/autotools/m4/ac_check_typedef.m4 0000664 0001750 0001750 00000002640 13210321137 024370 0 ustar jmikola jmikola dnl @synopsis AC_CHECK_TYPEDEF_(TYPEDEF, HEADER [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]])
dnl
dnl check if the given typedef-name is recognized as a type. The trick
dnl is to use a sizeof(TYPEDEF) and see if the compiler is happy with
dnl that.
dnl
dnl this can be thought of as a mixture of
dnl AC_CHECK_TYPE(TYPEDEF,DEFAULT) and
dnl AC_CHECK_LIB(LIBRARY,FUNCTION,ACTION-IF-FOUND,ACTION-IF-NOT-FOUND)
dnl
dnl a convenience macro AC_CHECK_TYPEDEF_ is provided that will not
dnl emit any message to the user - it just executes one of the actions.
dnl
dnl @category C
dnl @author Guido U. Draheim
dnl @version 2006-10-13
dnl @license GPLWithACException
AC_DEFUN([AC_CHECK_TYPEDEF_],
[dnl
ac_lib_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'`
AC_CACHE_VAL(ac_cv_lib_$ac_lib_var,
[ eval "ac_cv_type_$ac_lib_var='not-found'"
ac_cv_check_typedef_header=`echo ifelse([$2], , stddef.h, $2)`
AC_TRY_COMPILE( [#include <$ac_cv_check_typedef_header>],
[int x = sizeof($1); x = x;],
eval "ac_cv_type_$ac_lib_var=yes" ,
eval "ac_cv_type_$ac_lib_var=no" )
if test `eval echo '$ac_cv_type_'$ac_lib_var` = "no" ; then
ifelse([$4], , :, $4)
else
ifelse([$3], , :, $3)
fi
])])
dnl AC_CHECK_TYPEDEF(TYPEDEF, HEADER [, ACTION-IF-FOUND,
dnl [, ACTION-IF-NOT-FOUND ]])
AC_DEFUN([AC_CHECK_TYPEDEF],
[dnl
AC_MSG_CHECKING([for $1 in $2])
AC_CHECK_TYPEDEF_($1,$2,AC_MSG_RESULT(yes),AC_MSG_RESULT(no))dnl
])
mongodb-1.3.4/src/libbson/build/autotools/m4/ac_compile_check_sizeof.m4 0000664 0001750 0001750 00000001566 13210321137 025745 0 ustar jmikola jmikola AC_DEFUN([AC_COMPILE_CHECK_SIZEOF],
[changequote(<<, >>)dnl
dnl The name to #define.
define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl
dnl The cache variable name.
define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
changequote([, ])dnl
AC_MSG_CHECKING(size of $1)
AC_CACHE_VAL(AC_CV_NAME,
[for ac_size in 4 8 1 2 16 $2 ; do # List sizes in rough order of prevalence.
AC_TRY_COMPILE([#include "confdefs.h"
#include <sys/types.h>
$2
], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size)
if test x$AC_CV_NAME != x ; then break; fi
done
])
if test x$AC_CV_NAME = x ; then
AC_MSG_ERROR([cannot determine a size for $1])
fi
AC_MSG_RESULT($AC_CV_NAME)
AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1])
undefine([AC_TYPE_NAME])dnl
undefine([AC_CV_NAME])dnl
])
mongodb-1.3.4/src/libbson/build/autotools/m4/ac_create_stdint_h.m4 0000664 0001750 0001750 00000036622 13210321137 024741 0 ustar jmikola jmikola dnl @synopsis AC_CREATE_STDINT_H [( HEADER-TO-GENERATE [, HEDERS-TO-CHECK])]
dnl
dnl the "ISO C9X: 7.18 Integer types " section requires the
dnl existence of an include file that defines a set of
dnl typedefs, especially uint8_t,int32_t,uintptr_t. Many older
dnl installations will not provide this file, but some will have the
dnl very same definitions in . In other enviroments we can
dnl use the inet-types in which would define the typedefs
dnl int8_t and u_int8_t respectivly.
dnl
dnl This macros will create a local "_stdint.h" or the headerfile given
dnl as an argument. In many cases that file will just have a singular
dnl "#include " or "#include " statement, while
dnl in other environments it will provide the set of basic 'stdint's
dnl defined:
dnl int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,intptr_t,uintptr_t
dnl int_least32_t.. int_fast32_t.. intmax_t which may or may not rely
dnl on the definitions of other files, or using the
dnl AC_COMPILE_CHECK_SIZEOF macro to determine the actual sizeof each
dnl type.
dnl
dnl if your header files require the stdint-types you will want to
dnl create an installable file mylib-int.h that all your other
dnl installable header may include. So if you have a library package
dnl named "mylib", just use
dnl
dnl AC_CREATE_STDINT_H(mylib-int.h)
dnl
dnl in configure.in and go to install that very header file in
dnl Makefile.am along with the other headers (mylib.h) - and the
dnl mylib-specific headers can simply use "#include " to
dnl obtain the stdint-types.
dnl
dnl Remember, if the system already had a valid , the
dnl generated file will include it directly. No need for fuzzy
dnl HAVE_STDINT_H things...
dnl
dnl (note also the newer variant AX_CREATE_STDINT_H of this macro)
dnl
dnl @category C
dnl @author Guido U. Draheim
dnl @version 2003-05-21
dnl @license GPLWithACException
AC_DEFUN([AC_CREATE_STDINT_H],
[# ------ AC CREATE STDINT H -------------------------------------
AC_MSG_CHECKING([for stdint-types....])
ac_stdint_h=`echo ifelse($1, , _stdint.h, $1)`
if test "$ac_stdint_h" = "stdint.h" ; then
AC_MSG_RESULT("(are you sure you want them in ./stdint.h?)")
elif test "$ac_stdint_h" = "inttypes.h" ; then
AC_MSG_RESULT("(are you sure you want them in ./inttypes.h?)")
else
AC_MSG_RESULT("(putting them into $ac_stdint_h)")
mkdir -p $(dirname "$ac_stdint_h")
fi
inttype_headers=`echo inttypes.h sys/inttypes.h sys/inttypes.h $2 \
| sed -e 's/,/ /g'`
ac_cv_header_stdint_x="no-file"
ac_cv_header_stdint_o="no-file"
ac_cv_header_stdint_u="no-file"
for i in stdint.h $inttype_headers ; do
unset ac_cv_type_uintptr_t
unset ac_cv_type_uint64_t
_AC_CHECK_TYPE_NEW(uintptr_t,[ac_cv_header_stdint_x=$i],dnl
continue,[#include <$i>])
AC_CHECK_TYPE(uint64_t,[and64="(uint64_t too)"],[and64=""],[#include<$i>])
AC_MSG_RESULT(... seen our uintptr_t in $i $and64)
break;
done
if test "$ac_cv_header_stdint_x" = "no-file" ; then
for i in stdint.h $inttype_headers ; do
unset ac_cv_type_uint32_t
unset ac_cv_type_uint64_t
AC_CHECK_TYPE(uint32_t,[ac_cv_header_stdint_o=$i],dnl
continue,[#include <$i>])
AC_CHECK_TYPE(uint64_t,[and64="(uint64_t too)"],[and64=""],[#include<$i>])
AC_MSG_RESULT(... seen our uint32_t in $i $and64)
break;
done
if test "$ac_cv_header_stdint_o" = "no-file" ; then
for i in sys/types.h $inttype_headers ; do
unset ac_cv_type_u_int32_t
unset ac_cv_type_u_int64_t
AC_CHECK_TYPE(u_int32_t,[ac_cv_header_stdint_u=$i],dnl
continue,[#include <$i>])
AC_CHECK_TYPE(uint64_t,[and64="(u_int64_t too)"],[and64=""],[#include<$i>])
AC_MSG_RESULT(... seen our u_int32_t in $i $and64)
break;
done
fi
fi
# ----------------- DONE inttypes.h checks MAYBE C basic types --------
if test "$ac_cv_header_stdint_x" = "no-file" ; then
AC_COMPILE_CHECK_SIZEOF(char)
AC_COMPILE_CHECK_SIZEOF(short)
AC_COMPILE_CHECK_SIZEOF(int)
AC_COMPILE_CHECK_SIZEOF(long)
AC_COMPILE_CHECK_SIZEOF(void*)
ac_cv_header_stdint_test="yes"
else
ac_cv_header_stdint_test="no"
fi
# ----------------- DONE inttypes.h checks START header -------------
_ac_stdint_h=AS_TR_CPP(_$ac_stdint_h)
AC_MSG_RESULT(creating $ac_stdint_h : $_ac_stdint_h)
echo "#ifndef" $_ac_stdint_h >$ac_stdint_h
echo "#define" $_ac_stdint_h "1" >>$ac_stdint_h
echo "#ifndef" _GENERATED_STDINT_H >>$ac_stdint_h
echo "#define" _GENERATED_STDINT_H '"'$PACKAGE $VERSION'"' >>$ac_stdint_h
if test "$GCC" = "yes" ; then
echo "/* generated using a gnu compiler version" `$CC --version` "*/" \
>>$ac_stdint_h
else
echo "/* generated using $CC */" >>$ac_stdint_h
fi
echo "" >>$ac_stdint_h
if test "$ac_cv_header_stdint_x" != "no-file" ; then
ac_cv_header_stdint="$ac_cv_header_stdint_x"
elif test "$ac_cv_header_stdint_o" != "no-file" ; then
ac_cv_header_stdint="$ac_cv_header_stdint_o"
elif test "$ac_cv_header_stdint_u" != "no-file" ; then
ac_cv_header_stdint="$ac_cv_header_stdint_u"
else
ac_cv_header_stdint="stddef.h"
fi
# ----------------- See if int_least and int_fast types are present
unset ac_cv_type_int_least32_t
unset ac_cv_type_int_fast32_t
AC_CHECK_TYPE(int_least32_t,,,[#include <$ac_cv_header_stdint>])
AC_CHECK_TYPE(int_fast32_t,,,[#include<$ac_cv_header_stdint>])
if test "$ac_cv_header_stdint" != "stddef.h" ; then
if test "$ac_cv_header_stdint" != "stdint.h" ; then
AC_MSG_RESULT(..adding include stddef.h)
echo "#include " >>$ac_stdint_h
fi ; fi
AC_MSG_RESULT(..adding include $ac_cv_header_stdint)
echo "#include <$ac_cv_header_stdint>" >>$ac_stdint_h
echo "" >>$ac_stdint_h
# ----------------- DONE header START basic int types -------------
if test "$ac_cv_header_stdint_x" = "no-file" ; then
AC_MSG_RESULT(... need to look at C basic types)
dnl ac_cv_header_stdint_test="yes" # moved up before creating the file
else
AC_MSG_RESULT(... seen good stdint.h inttypes)
dnl ac_cv_header_stdint_test="no" # moved up before creating the file
fi
if test "$ac_cv_header_stdint_u" != "no-file" ; then
AC_MSG_RESULT(... seen bsd/sysv typedefs)
cat >>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h < 199901L
#ifndef _HAVE_UINT64_T
#define _HAVE_UINT64_T
typedef long long int64_t;
typedef unsigned long long uint64_t;
#endif
#elif !defined __STRICT_ANSI__
#if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__
#ifndef _HAVE_UINT64_T
#define _HAVE_UINT64_T
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#endif
#elif defined __GNUC__ || defined __MWERKS__ || defined __ELF__
dnl /* note: all ELF-systems seem to have loff-support which needs 64-bit */
#if !defined _NO_LONGLONG
#ifndef _HAVE_UINT64_T
#define _HAVE_UINT64_T
typedef long long int64_t;
typedef unsigned long long uint64_t;
#endif
#endif
#elif defined __alpha || (defined __mips && defined _ABIN32)
#if !defined _NO_LONGLONG
#ifndef _HAVE_UINT64_T
#define _HAVE_UINT64_T
typedef long int64_t;
typedef unsigned long uint64_t;
#endif
#endif
/* compiler/cpu type ... or just ISO C99 */
#endif
#endif
EOF
# plus a default 64-bit for systems that are likely to be 64-bit ready
case "$ac_cv_sizeof_x:$ac_cv_sizeof_voidp:$ac_cv_sizeof_long" in
1:2:8:8) AC_MSG_RESULT(..adding uint64_t default, normal 64-bit system)
cat >>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <>$ac_stdint_h <